✨ NEW: Add highlight_verbatim option to skip the <pre><code> wrapper (#256) - #419
Open
cjchanh wants to merge 2 commits into
Open
✨ NEW: Add highlight_verbatim option to skip the <pre><code> wrapper (#256)#419cjchanh wants to merge 2 commits into
highlight_verbatim option to skip the <pre><code> wrapper (#256)#419cjchanh wants to merge 2 commits into
Conversation
The verbatim path appended "\n" to the highlighter's return, breaking byte-exactness (the very contract of the option). Verbatim now returns the highlighter's bytes untouched; four tests that pinned the added newline are corrected, and a byte-exactness regression test added.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
highlight_verbatimoption to skip the<pre><code>wrapperFixes #256.
Summary
New
highlight_verbatimoption: when set, the renderer passes thehighlighter's output through byte-exact — no
<pre><code>wrapper, nolanguage-class injection, no renderer-added newline. The highlighter's return
value is the final rendered block, byte for byte.
Motivation (from #256)
When
highlightreturns pygments-style output (starts with<div, not<pre>), markdown-it-py wraps it in<pre><code>…</code></pre>anyway,forcing users to rewrite their Pygments CSS themes for the duplicated
wrapper. Existing workarounds require subclassing
RendererHTMLandreimplementing
fence().Behavior
highlight_verbatim=False(default): behavior byte-identical to todayfor every existing case, including the
<pre-continues heuristic.highlight_verbatim=True:fence()returns the highlighter's outputuntouched. The option is inert without a
highlightcallback.Byte-exactness guarantee
The renderer does not append, strip, or alter a single byte — trailing
newline or none, the output equals the highlighter's return. Regression-tested
in both directions.
Tests
Nine tests in
tests/test_api/test_highlight_verbatim.py: default wrappingunchanged,
<prepassthrough, non-<prepassthrough, byte-exactness bothways, language-class injection skipped, instance-toggle, default-path
inertness. Full suite: 991 passed.
Verification
Docs & changelog
docs/using.mdupdated;CHANGELOG.mdentry added.