Skip to content

Commit b42bb01

Browse files
committed
fix(html_converter): Escape ${ in markdown for JavaScript template strings
Add proper escaping for ${ to prevent template expression interpretation in JavaScript template literals. This fixes empty markdown content in generated HTML files.
1 parent 41e9191 commit b42bb01

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tools/ai-markmap-agent/src/output/html_converter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,14 @@ def convert(
285285
Returns:
286286
HTML string
287287
"""
288-
# Escape backticks and backslashes in markdown for JS template literal
289-
escaped_content = markdown_content.replace("\\", "\\\\").replace("`", "\\`")
288+
# Escape special characters for JavaScript template literal
289+
# Order matters: escape backslash first, then backtick, then ${ to prevent template expression interpretation
290+
escaped_content = (
291+
markdown_content
292+
.replace("\\", "\\\\") # Escape backslashes first
293+
.replace("`", "\\`") # Escape backticks
294+
.replace("${", "\\${") # Escape ${ to prevent template expression interpretation
295+
)
290296

291297
# Prepare template variables
292298
template_vars = {

0 commit comments

Comments
 (0)