Add opt-in Discord-style __underline__ rendering#10
Open
PiotrCzapla wants to merge 1 commit into
Open
Conversation
With underline=True (Python kwarg, --underline CLI flag, or Options::underline), __x__ renders as <u>x</u> instead of <strong>x</strong>, following Discord's convention. All the usual underscore emphasis rules apply: no intraword matching, ___x___ nests as <em><u>x</u></em>, and empty-attr nesting flattens like strong. **x** is unaffected, and the default stays CommonMark strong, so conformance is unchanged. Callbacks get a new "underline" inline kind. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
I'm open to this, although my preference would be to use WDYT? |
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.
What changed
New
underlineoption (off by default). When enabled, Discord-style__x__renders as<u>x</u>instead of<strong>x</strong>:Also exposed as
xhtmlmd --underlineon the CLI andOptions::underlinein Rust. Callbacks get a newunderlineinline kind.Behavior details
**x**stays<strong>,_x_stays<em>.intra__word__stays literal), delimiter-run pairing is unchanged, and___x___nests as<em><u>x</u></em>— which matches Discord's underline-italics.____x____flattens to a single<u>the same way nested empty-attr<strong>already flattens.{.class}span attributes are not applied to__x__, consistent with existing**x**/_x_behavior (bracketed spans are the attribute mechanism).Why opt-in
CommonMark defines
__x__as strong emphasis, and the crate's dialect policy is Pandoc-closest. Making this the default would deviate from every emphasis spec example using__; as an option it costs nothing when off — the full conformance suite passes with no examples disabled.Implementation
Inline::Underlineis a new AST variant mirroringStrong; theunderlineflag threads fromOptionsthrough delimiter processing, and the_-with-length-2 case inwrap_delimiterspicks the variant. Renderer emits<u>, and the Python node/callback plumbing treats it like the other child-bearing inlines.Testing
tests/test_focused.py: opt-in gating, coexistence with**/_, nesting/flattening/intraword rules, and theunderlinecallback.fastpylight,math_core).tools/gen_docs.py --checkis clean. README anddocs/DIALECT.mdupdated.🤖 Generated with Claude Code