[PAI-1013] chore: convert md to html for convert to page (#4953)

* chore: convert md to html for conver to page

* chore: remove redundant sanitization
This commit is contained in:
Akhil Vamshi Konam
2025-12-05 13:18:48 +05:30
committed by GitHub
parent d7da84724e
commit c601a4e21a
5 changed files with 43 additions and 9 deletions
@@ -19,6 +19,7 @@ from pi import logger
from pi import settings
from pi.app.api.v1.dependencies import cookie_schema
from pi.app.api.v1.dependencies import is_valid_session
from pi.app.utils.markdown_to_html import md_to_html
from pi.core.db.plane import PlaneDBPool
from pi.core.db.plane_pi.lifecycle import get_async_session
from pi.services.actions.method_executor import MethodExecutor
@@ -65,6 +66,8 @@ async def save_as_page(
user_id = auth.user.id
data.description_html = md_to_html(data.description_html)
# Validate page_type and project_id combination
if data.page_type not in ["workspace", "project"]:
return JSONResponse(
+3
View File
@@ -19,6 +19,7 @@ from pi import logger
from pi import settings
from pi.app.api.v2.dependencies import cookie_schema
from pi.app.api.v2.dependencies import is_valid_session
from pi.app.utils.markdown_to_html import md_to_html
from pi.core.db.plane import PlaneDBPool
from pi.core.db.plane_pi.lifecycle import get_async_session
from pi.services.actions.method_executor import MethodExecutor
@@ -69,6 +70,8 @@ async def save_as_page(
user_id = auth.user.id
data.description_html = md_to_html(data.description_html)
# Validate page_type and project_id combination
if data.page_type not in ["workspace", "project"]:
return JSONResponse(
+24
View File
@@ -0,0 +1,24 @@
from markdown_it import MarkdownIt
from mdit_py_plugins.container import container_plugin
from mdit_py_plugins.deflist import deflist_plugin
from mdit_py_plugins.footnote import footnote_plugin
from mdit_py_plugins.tasklists import tasklists_plugin
md = (
MarkdownIt("commonmark", {"typographer": True})
.enable("table")
.enable("strikethrough")
.use(tasklists_plugin)
.use(footnote_plugin)
.use(container_plugin, name="callout")
.use(deflist_plugin)
)
def md_to_html(markdown_text: str) -> str:
if not markdown_text:
return ""
html = md.render(markdown_text)
return html
+4
View File
@@ -62,3 +62,7 @@ ruff==0.5.5
pylint==3.1.0
types-requests==2.32.0.20240712
pytest==8.3.2
# markdown to html
markdown-it-py==4.0.0
mdit-py-plugins==0.5.0
+9 -9
View File
@@ -1253,16 +1253,16 @@ class APITester:
# Both rejected the invalid file - this is PASS (consistent error handling)
v1_error_msg = v1_data.get('detail', '')
v2_error_msg = v2_data.get('detail', '')
# Check if error messages are similar (both should mention file rejection)
error_match = v1_error_msg == v2_error_msg
self._add_result(TestResult(
endpoint_name="Create Attachment",
v1_url=v1_url,
v2_url=v2_url,
status=TestStatus.PASS if error_match else TestStatus.FAIL,
message=f"Negative test: Both rejected invalid file (V1: 400, V2: 400) - Error match: {'' if error_match else ''}",
message=f"Negative test: Both rejected invalid file(V1: 400, V2: 400) - Error match: {'' if error_match else ''}",
differences=None if error_match else {"error_messages": {"v1": v1_error_msg, "v2": v2_error_msg}},
v1_response=v1_data,
v2_response=v2_data,
@@ -1384,19 +1384,19 @@ class APITester:
# Both rejected the invalid file - this is PASS (consistent error handling)
v1_create_data = v1_create_resp.json()
v2_create_data = v2_create_resp.json()
v1_error_msg = v1_create_data.get('detail', '')
v2_error_msg = v2_create_data.get('detail', '')
# Check if error messages are similar (both should mention file rejection)
error_match = v1_error_msg == v2_error_msg
self._add_result(TestResult(
endpoint_name="Get Attachment URLs",
v1_url=v1_create_url,
v2_url=v2_create_url,
status=TestStatus.PASS if error_match else TestStatus.FAIL,
message=f"Negative test: Both rejected invalid file during upload (V1: 400, V2: 400) - Error match: {'' if error_match else ''}",
message=f"Negative test: Both rejected invalid file during upload(V1: 400, V2: 400) - Error match: {'' if error_match else ''}",
differences=None if error_match else {"error_messages": {"v1": v1_error_msg, "v2": v2_error_msg}},
v1_response=v1_create_data,
v2_response=v2_create_data,
@@ -1407,7 +1407,7 @@ class APITester:
if v1_rejected != v2_rejected:
v1_create_data = v1_create_resp.json()
v2_create_data = v2_create_resp.json()
self._add_result(TestResult(
endpoint_name="Get Attachment URLs",
v1_url=v1_create_url,
@@ -1912,7 +1912,7 @@ class APITester:
elif v1_failed and v2_failed:
# Both failed but with different error codes - document the difference
_, differences = self._compare_responses(v1_data, v2_data)
self._add_result(TestResult(
endpoint_name="Save as Page",
v1_url=v1_url,