Fix AbbreviationExtension corrupting emphasis/bold/italic resolution (#935)#936
Merged
xoofx merged 2 commits intoxoofx:mainfrom Apr 20, 2026
Merged
Conversation
…asis corruption (xoofx#935) The PostMatch hook approach (running mid-parse) produced a ContainerInline with IsClosed=false that disrupted FindLastContainer(), causing emphasis delimiters to be appended as children of the abbreviation container instead of as root siblings. It also had an off-by-one (i != 0 vs i != content.Start) that caused abbreviations to be missed when the literal started inside emphasis. Replace with a document.ProcessInlinesEnd handler that walks the fully resolved inline tree (after EmphasisInlineParser and LinkInlineParser have run), inserting AbbreviationInline/LiteralInline siblings directly into parent containers without any wrapper ContainerInline. Also update TestSourcePosition.TestAbbreviations to reflect the new tree shape (no container wrapper; empty leading literals at word boundaries are pruned). Fixes xoofx#935
Owner
|
Thanks for the fix! |
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.
Closes #935
Summary
AbbreviationParsersubscribed toLiteralInlineParser.PostMatchto perform abbreviation substitution during inline parsing, before emphasis delimiters were resolved. This caused two bugs:**/*as literal text instead of resolving them.**HTML is great**) were silently dropped due to an off-by-one in the word-boundary guard (i != 0instead ofi != content.Start).The fix moves substitution to
document.ProcessInlinesEnd, so it runs after the full inline tree — including emphasis and links — has been resolved. Abbreviations are inserted as direct siblings into each parent container rather than wrapped in an intermediateContainerInline.Testing
Three new spec examples cover the two bugs and their combination. All 3 764 existing tests pass.
Performance
Benchmarks run on .NET 10 / Intel Core i3-10110U. "Before" =
upstream/main(oldPostMatchapproach); "after" = this PR.Key gains come from eliminating
processor.GetSourcePosition()(a binary search per match, now replaced by O(1) arithmetic) and removing theContainerInlinewrapper allocation per matched literal. The slight allocation uptick in the no-matches case is from theStack<Block>used bydocument.Descendants<LeafBlock>(), which fires even when nothing is substituted; this is within noise for real documents.