Repository navigation
fix(export): keep backslash escapes at the start of a line - #13721
yuxi-liu-wired wants to merge 5 commits into
Conversation
mldoc parses \# x as the text # x; the text export printed that text without the backslash, so pasting the export back turned it into a heading, a list item or a quote.
…r heading A later line of a block starting with "- " or "#" is shown by the block as text, but the text export wrote it as a child block or heading. The text export (not the Markdown mirror) now writes a backslash before it.
The text export wrote both as "> text". A plain block starting with > is now written as "\> text". See #13733 for which form of quote is intended.
|
After that regex is valid,
|
DB graphs parse with parse_marker false, so a task word at a line start is text and gets no backslash (a plain block 'TODO x' came back as '\TODO x'); a lone '>' is text too, and '* ' lines are written back as '* '. A '+ ' list line and a '> text' line on a later line are escaped. A backslash the text itself has at a line start is doubled before parsing, so mldoc keeps it.
A plain block whose text starts with a task marker, a heading marker or >, or has a later line starting with - or #, is written with a backslash, as the text export does (logseq#13721). A block with a status or heading is written as before.
|
Closing: this patches one symptom of a design problem, logseq/db-test#1442 (a block's body is a Markdown string sharing one grammar with every text format). The bug is listed there; the fix is the design, not this patch. |
A block can keep Markdown syntax as plain text with a backslash, for example
\# not a headingor a second line\- not a list item, and it displays as written. Exporting it as text and pasting the text back turns it into what the backslash was there to prevent: a heading, a child block, a quote.Cause
The text export (
frontend.handler.export.text-impl) parses the block's Markdown with mldoc and prints the result. mldoc reads\# xas the plain text# x, and the export prints that plain text as is, so the backslash is gone from the exported text. Paste then reads# xas a heading.Fix
Only what the DB graph's mldoc reads as structure is escaped. DB graphs parse with
parse_marker false, so a task word (TODO,DONE, ...) at the start of a line is plain text and gets no backslash; a lone>is plain text too.keep-line-start-backslashesinlogseq.common.export.file), so mldoc reads it as one literal backslash and the export keeps it:\# x,\TODO xand\- xcome back as typed.#) or a quote (>followed by text); on a later line also a list item (-,+,1.).-,+,#or> textwithout a backslash is shown by the block as text (the block's title is rendered as- <title>, so such a line is not a list), but the export wrote it as a child block, a list, a heading or a quote. The text export now writes a backslash before such a line (outside code fences).*lines need none: the export writes such a list back as*.>(not a quote block) is written as\> text, so it does not come back as a quote block. The DB version has two forms of quote here, see DB: two forms of quote break export/paste round-trip (quote block vs. text starting with "> ") db-test#1439.All of this is set only by the text export's content config (
:escape-block-markers?); the Markdown mirror is left as it is.Test
frontend.handler.export-escape-testexports blocks with escaped headings, task words, list items and quotes (on the first and on later lines), pastes the text back, and checks each block comes back with the same text and no heading. Blocks that need no escape come back unchanged: a numbered first line, a plain block starting withTODO, a later line starting withTODO, a lone>, a*list inside the block, a-line in a code fence, two backslashes. Blocks with an unescaped later-,+,#or> textline come back as one block with that line escaped. On master 13 assertions fail; with the fix all 257 export, paste and Markdown mirror assertions pass.