Skip to content

Commit c9ac901

Browse files
committed
fix: strip trailing whitespace from code block fences
1 parent 77347fd commit c9ac901

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/utils/readme.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,11 @@ ${html}
586586

587587
marked.setOptions({ renderer })
588588

589-
const rawHtml = marked.parse(content) as string
589+
// Strip trailing whitespace (tabs/spaces) from code block closing fences.
590+
// While marky-markdown handles these gracefully, marked fails to recognize
591+
// the end of a code block if the closing fences are followed by unexpected whitespaces.
592+
const normalizedContent = content.replace(/^( {0,3}(?:`{3,}|~{3,}))\s*$/gm, '$1')
593+
const rawHtml = marked.parse(normalizedContent) as string
590594

591595
const sanitized = sanitizeHtml(rawHtml, {
592596
allowedTags: ALLOWED_TAGS,

0 commit comments

Comments
 (0)