CommonMark 0.30 Emphasis Delimiter Update: Preserving Legacy a_b
0 reputation · 06 Dec 2021, 09:52 UTC
0 reputation · 06 Dec 2021, 09:52 UTC
We need to migrate a large repository from legacy Markdown to CommonMark 0.30 while keeping intra‑word emphasis such as a_b rendered correctly.
CommonMark 0.30 removes underscore emphasis inside words, a feature that legacy parsers still support. No standard parser flag currently restores this behavior, and the change creates a compatibility boundary that may break existing documentation.
1. Is there a CommonMark extension or configuration option that re‑enables underscore emphasis inside words?
2. If such an option does not exist, what strategy can be adopted to maintain backward compatibility without manually rewriting all source files?
3. Are there parser implementations that still support this legacy behavior, and how can they be integrated into a CommonMark‑based build pipeline?
35275 reputation · 06 Dec 2021, 15:48 UTC
CommonMark 0.30 does not provide a native configuration flag or standard extension to re-enable intra-word underscore emphasis (e.g., a_b). To preserve legacy rendering without manually rewriting source files, you must implement a pre-processing layer or a custom parser extension that overrides the specification's delimiter matching logic.
The CommonMark specification explicitly distinguishes between intra-word and boundary underscores to prevent technical identifiers (like snake_case_variables) from being accidentally italicized. In CommonMark 0.30, an underscore is only treated as an emphasis delimiter if it is preceded by whitespace/punctuation and followed by a non-whitespace character, or vice versa.
Since no standard flag exists, choose one of the following based on your pipeline flexibility:
<em> tags.commonmark.js or markdown-it), you can override the emphasis rule to ignore the boundary check. Note that this makes your output non-compliant with the CommonMark spec.To verify the current behavior and test your fix, use a sample file with the following patterns:
# Test Case
Intra-word: a_b (Should be plain text in CommonMark)
Boundary: _b_ (Should be italic)
Escaped: a\_b (Should be plain text)
a_b renders as literal text.a_b renders as a_b (if that is the legacy goal).To provide a specific regex or extension snippet, please specify the programming language of your build pipeline (e.g., Node.js, Python, Ruby) and the specific parser library currently in use.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.