https://bugs.documentfoundation.org/show_bug.cgi?id=172819
Bug ID: 172819
Summary: Markdown export escapes characters inside fenced code
blocks (violates CommonMark)
Product: LibreOffice
Version: 26.2.4.2 release
Hardware: All
OS: Windows (All)
Status: UNCONFIRMED
Severity: normal
Priority: medium
Component: Writer
Assignee: [email protected]
Reporter: [email protected]
Description:
When exporting a Writer document to Markdown, LibreOffice escapes characters
inside fenced code blocks.
Backslashes are added before Markdown‑special characters, for example:
Code
\*text\_with\_underscore\*
\#
\[\]
\(\)
This behavior violates the CommonMark specification:
Content inside fenced code blocks must be emitted verbatim, without any
escaping.
Backslash escapes are not allowed and not needed inside code blocks.
Expected behavior:
LibreOffice should export the content of fenced code blocks raw, without
inserting backslashes.
Example:
Code
*text_with_underscore*
#[]()
Actual behavior:
LibreOffice escapes all “escapable characters”, even inside code blocks.
Technical analysis:
The Markdown exporter applies its escape routine to all text, including text
inside fenced code blocks.
A fix would be:
disable the escape routine when inside a fenced code block,
or
treat code blocks as raw text and bypass escaping entirely.
Impact:
Markdown export becomes unusable for technical documentation containing code,
configuration files, or scripts.
Suggested fix:
Add a guard in the Markdown exporter so that escaping is skipped when
IsInCodeBlock == true.
🧩 Optional developer note (helps the maintainers)
You can optionally add this line:
The issue appears to be in sw/source/filter/markdown.
The escape function is applied unconditionally and should be disabled
inside fenced code blocks.
Steps to Reproduce:
1. Open a correct md document with a code block containing characters []{}_
2. Save it back
3. Open the saved document in LO or any md viewer
Actual Results:
\[\]\{\}\_
Expected Results:
[]{}_
Reproducible: Always
User Profile Reset: No
Additional Info:
confirmed by copilot
--
You are receiving this mail because:
You are the assignee for the bug.