fix: handle markdown backslash escapes in EPUB, HTML, PDF, and DOCX exports - #92
Merged
Merged
Conversation
…xports Escaped punctuation (\*, \|, \[, …) was not recognized by the basic markdown converter or the DOCX inline parser, so an escaped asterisk paired as an emphasis delimiter: inside EPUB tables it produced an <em> that crossed <td> boundaries, yielding invalid XHTML that Apple Books refuses to open. Outside tables, escapes rendered with a strailing backslash. - Extract backslash escapes into placeholders before any syntax rule runs and restore them as literal characters afterwards (basic HTML converter and DOCX parseInline, sharing MARKDOWN_ESCAPE_RE) - Split table rows on unescaped pipes only so \| keeps a literal pipe inside the cell (basic converter and DOCX parseTableRow) - Require non-whitespace content edges for bold/italic per CommonMark delimiter rules, so bare multiplication asterisks (3 * 4 * 5) stay literal Fixes #91
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #91
Problem
Escaped punctuation (
\*,\|,\[, …) was not recognized by the basic markdown converter (markdownToBasicHtml) or the DOCX inline parser, so an escaped asterisk was treated as an emphasis delimiter:\*in the same row paired into an<em>that crossed<td>boundaries, producing invalid XHTML — Apple Books fails withOpening and ending tag mismatch: em … and td. EPUB always uses this converter, so every export with escaped asterisks in tables was affected.\*rendered literally with its backslash; two escapes in one paragraph produced wrong italics plus a leaked backslash.\|split a table cell in two,\[text\](url)still rendered as a link,\_/\\/\#kept their backslashes, and bare multiplication (3 * 4 * 5) was wrongly italicized (no CommonMark whitespace rules).Fix
markdownToBasicHtmland DOCXparseInline, sharing one exportedMARKDOWN_ESCAPE_RE(CommonMark escapable punctuation). This alone fixes escaped asterisks, pipes, brackets, and all other escapes in both converters.\|stays inside the cell) — basic converter table step and DOCXparseTableRow.3 * 4 * 5stays literal.Restored characters are HTML-escaped like surrounding text (
\<comes back as<). Code blocks and inline code are extracted before the escape pass, so their content is untouched.Verification
html-document.test.ts(escaped*/|/[/\, HTML-escape on restore, inline code untouched, multiplication boundary), 1 end-to-end EPUB test asserting balanced<em>tags in the chapter XHTML, 2 DOCX tests. All failed before the fix, pass after.tsctype check, esbuild production build, and eslint clean.