Skip to content

Support Pandoc escaped spaces and end-of-block backslash hard breaks#9

Closed
PiotrCzapla wants to merge 1 commit into
mainfrom
claude/pandoc-escaped-space
Closed

Support Pandoc escaped spaces and end-of-block backslash hard breaks#9
PiotrCzapla wants to merge 1 commit into
mainfrom
claude/pandoc-escaped-space

Conversation

@PiotrCzapla

@PiotrCzapla PiotrCzapla commented Jul 5, 2026

Copy link
Copy Markdown

I've added support for a bare \ to represent a newline in Pandoc, and \ to represent a non-breaking space.
This makes it easy to add vertical space in .docx files by simply adding a few newlines and a backslash, or a backslash followed by a space.

This seems to contradict the cmark-gfm specification. I'm not sure what the rationale was for not allowing a trailing backslash to add line breaks, but if we want to adhere to the standard, we can use <br/> or &nbsp;.

Here is an example of contract that uses \ to add spacing around signature blocks:

Screenshot 2026-07-06 at 00 13 18

Follow Pandoc's escaped_line_breaks/escaped-space rules: backslash
before a space renders a non-breaking space, and a backslash at the
end of a line is a hard break even at the end of a block, so a
paragraph of just "\" renders as <p><br /></p>. This restores the
"\" / "\ " spacer-paragraph authoring convention used in md-to-docx
pipelines.

Also fix a pre-existing bug where an escaped backslash before a
newline ("a\\" + newline) was treated as a hard break instead of a
literal backslash plus soft break.

Four cmark spec examples that assert the CommonMark literal-text
behavior are marked disabled as deliberate dialect deviations,
matching pandoc output exactly in each case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@PiotrCzapla PiotrCzapla requested a review from jph00 July 5, 2026 22:14
@jph00

jph00 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This would break prose like stored in C:\data\ which… -- I'm not sure we want to deviate from CommonMark; we haven't done so yet, and there are workarounds as you mentioned. I normally use <br/> myself in markdown.

We could consider adding an option for each of the two backslash escapes (nbsp and br) if you feel it's important.

@PiotrCzapla

Copy link
Copy Markdown
Author

Really good example I wasn't aware that windows path would break. I like <br/> but it doesn't work in pandoc, similar to <u>, it is represented as RawHtml and not NewLine or Underline. But this won't be an issue with xhtmlmd since we will go through pandoc -t html anyway so all &nbsp;,<br/> and <u> will work.

Let me close this.

@PiotrCzapla PiotrCzapla closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants