Skip to content

Enhancement (configuration): Add keepescape mode 4 to repair Pandoc escapes - #217

Open
klangme1ster wants to merge 1 commit into
theohbrothers:masterfrom
klangme1ster:enhancement/configuration-add-keepescape-mode-4-to-repair-pandoc-escapes
Open

klangme1ster wants to merge 1 commit into
theohbrothers:masterfrom
klangme1ster:enhancement/configuration-add-keepescape-mode-4-to-repair-pandoc-escapes

Conversation

@klangme1ster

Copy link
Copy Markdown

OneNote pages often start paragraphs with a literal - or 7. instead of using real lists. Pandoc escapes such text so it does not turn into a list (\- item, 7\. item). In an export of two notebooks (393 pages) this left the notes with plain paragraphs instead of lists, a blank line between every item, a literal \ at the end of many lines (Pandoc's hard line break) and many needless escapes (--\>, snake\_case).

The existing keepescape modes cannot fix this: 1 deletes every backslash (also in Windows paths such as C:\Program Files), 2 and 3 keep the list escapes.

This PR adds keepescape = 4, implemented as the function Repair-MarkdownEscapes, run on Pandoc's output before the existing replacements:

  • Rebuilds lists from \- item and 7\. item (also inside block quotes and when a non-breaking space follows the marker), removes the blank lines between list items, and drops lone - lines (empty bullets, or an accidental heading underline).
  • Turns a \ at the end of a line into two trailing spaces, or drops it at the end of a paragraph.
  • Removes escapes that cannot change the rendering (\> in --\>, \_ in snake\_case, \. and \- in the middle of a line).
  • Keeps escapes that matter: at the start of a line, \[, \], \* pairs, \, Windows and UNC paths.
  • Never touches code fences and inline code.

The default (1) and modes 1 to 3 are unchanged. A literal - at the start of a line is treated as a list in mode 4; use 3 if that is not wanted.

Tested

  • 22 new unit tests: each rule, cases that must stay untouched (Windows and UNC paths, \*, code), block quotes, non-breaking spaces, running it twice gives the same result, and that mode 4 adds no replacement that touches backslashes.
  • Real run against OneNote with two notebooks (393 pages, same .docx files, mode 3 against mode 4): escaped bullets 601 to 0, blank lines between list items 67 to 0, line-end backslashes 1804 to 0, lone - lines 29 to 0, escaped numbers 133 to 0. The letters and digits of every page are identical in both modes, so no text is lost.
  • Unit tests: 96 passed in Windows PowerShell 5.1; the one failure ("Throw if -Length is greater than 255") expects the English .NET error message and also fails on master on a German Windows.
  • Not tested here: PowerShell 6.x and 7.0 (see CI: Remove the retired windows-2019 job and the unusable PowerShell 6.x/7.0 container jobs #216).

🤖 Generated with Claude Code

…scapes

OneNote pages often start paragraphs with a literal '- ' or '7.'. Pandoc
escapes them ('\- item', '7\. item'), so the notes lose their lists and
carry loose blank lines, line-end backslashes and needless escapes. The
existing modes cannot fix that: 1 deletes every backslash (also in Windows
paths), 2 and 3 keep the list escapes.

Mode 4 (Repair-MarkdownEscapes) rebuilds those lists (also inside block
quotes and after non-breaking spaces), turns a line-end backslash into two
spaces, and removes only escapes that cannot change the rendering. Code
fences and inline code are untouched. Modes 1 to 3 and the default are
unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011zGMypgzLxRQFiU563LLb5
klangme1ster added a commit to klangme1ster/ConvertOneNote2MarkDown that referenced this pull request Nov 1, 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.

1 participant