LinkReferenceDefinitionGroup and FootnoteGroup are added to the document
by the parsers with Line 0 and a span starting at 0, at a position that
does not follow the source order (the footnote group is even moved to
the end of the document). The binary searches in FindClosestBlock and
FindBlockAtPosition expect children ordered by line/position, so they
could return the group, a definition, or the document itself instead
of the block at the requested line/position.
When a binary search on a document probes one of these groups, compare
the nearest other block within the search range instead, so the search
stays logarithmic and does not allocate. The definitions collected by
the groups are only considered when nothing else matches; the groups
are then taken from the document data (link reference definitions) and
from the last child of the document (footnotes) instead of scanning the
document.
Co-authored-by: ybai08 <271969568+ybai08@users.noreply.github.com>
* Add IsAotCompatible for net8.0 and later targets
* Enable the trim, AOT and single-file analyzers in Markdig's own build, so
CI catches an AOT regression before it ships to consumers
* Limit the property to net8.0+, since the analyzers do not run on
netstandard and net462 targets
* Test the assembly metadata, asserting IsAotCompatible only on net10.0,
because the ILLink 8 build tasks used for net8.0 emit just IsTrimmable
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Fix test by verifying the AOT marking with an IL3058 build check
* Replace the assembly metadata unit tests, which failed in the netstandard
workflow because it builds Markdig for netstandard2.x only
* Add Markdig.AotTests with VerifyReferenceAotCompatibility and IL3058 as an
error, so the CI solution build fails if Markdig loses the AOT marking
* Leave PublishAot unset, so the check restores no package beyond the
ILLink.Tasks package the IsAotCompatible property already requires
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
ParagraphBlockParser and ThematicBreakParser decided whether an
underline line was a lazy continuation by comparing the column of the
paragraph with the column of the line. Inside a block quote or list
item, a paragraph indented further than its container then never got
its underline, and a lazy line at the paragraph's column became a
heading outside the block quote. Use HasUnmatchedBlocks, which tells
whether the line continued every container, in both places.
* Fix line breaks inside setext headings
LineBreakInlineParser only created line breaks in paragraphs, and when
trivia is not tracked the setext heading parser trimmed both ends of
every line. So a hard line break with two trailing spaces inside a
setext heading was lost, and in a block quote the roundtrip output
dropped the quote markers of the heading's later lines. Allow line
breaks in setext headings and trim their lines like a paragraph does.
* Fix roundtrip of indented lazy lines in block quotes
QuoteBlockParser.TryContinue returned early for a line indented by 4
or more spaces without recording a QuoteBlockLine, while a lazy line
without a quote marker gets one. When such a line continued a
paragraph lazily, the quote markers of the following lines moved up by
one line in the roundtrip output. Record the line in both cases.
Each target framework of Markdig.Tests runs SpecFileGen and parallel
builds ran them concurrently, failing with an IOException on the shared
generated files. Serialize the generators with a named mutex.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Complex definitions inherited the implicit-paragraph state of an
enclosing tight list, so their paragraphs were rendered without <p> and
concatenated. Only a simple single-paragraph definition omits <p> now,
regardless of the enclosing list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An inline declaration is `<!`, an ASCII letter, any characters other than
`>`, and `>` (CommonMark 0.31.2). Lowercase names such as
`<!doctype html>` and declarations without whitespace such as `<!x>` were
escaped as text, unlike the matching declaration blocks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A list marker followed only by spaces or tabs now starts the item with a
blank line exactly like a bare marker: the item requires the marker width
plus one column and ends at the first blank line (CommonMark example 280).
More than four trailing spaces no longer let an empty item interrupt a
paragraph.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fix empty list items being parsed as text after a paragraph
An empty list item cannot interrupt a paragraph, but TryParseListItem
rejected it whenever the last block was a paragraph, even one already
closed by a blank line or inside a block quote that the line does not
continue, so the line was read as paragraph text. The check for an
ordered list not starting at 1 already requires an open paragraph and
matched containers, so apply the same condition to empty items.
TestSetextHeading used "A\n\n-\n-", which CommonMark parses as a list,
so it now uses "A\n\nB\n-", a setext heading with the same positions.
* Update doc for empty-list paragraph interruption rules
---------
Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
* Fix HTML blocks not ending at a line with only spaces or tabs
A blank line ends HTML blocks of type 6 and 7, and CommonMark counts a
line with only spaces or tabs as blank. MatchEnd checked IsBlankLine
after going back over the indent, which made such a line non-empty, so
the HTML block went on and the Markdown after it was output as raw
text. Check the line before going back.
* Fix HTML block terminator trivia and add roundtrip coverage
---------
Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
* Fix grid table open last cell taking a `|` from the next line (#494)
To find a closing `|` at the end of the last column, GridTableParser used
PeekCharExtra, which ignores the end of the slice. When the line was
shorter than the table, it could read the next line instead, and a `|`
there made the cell run past the end of the line, so the next line's
leading `|` ended up in the cell. Use PeekChar, which stays within the
current line.
* Fix test coverage for grid-table line endings (#494)
---------
Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
* Reject emoji-parsing if the slice ends with `**`
* Still some emoji false positives
* Cleanup and reduced the number of emojis checked.
* Review comment resolved
* Fix emoji and emphasis precedence (#946)
Resolve trailing emphasis delimiters before converting ambiguous emoji matches. Reuse the existing emphasis parser rather than guessing whether an opener remains active or rejecting only double asterisks.
Cover italics, strong/nested emphasis, custom delimiters, links, images, tables, source positions, renderers, all default mappings, and 2688 emphasis-structure comparisons. Document emphasis and generic-attribute precedence and the named-shortcode escape hatch.
---------
Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
* Add Support for PipeTables (GFM)
* Add additional tests. First two work, later three do not.
* Fix bad merge
* Update to follow style
* Address problem with trailing new lines after the table
* Fix pipe table normalization alignment and separators (#954)
---------
Co-authored-by: T. Thiery <thomas.thiery+git@gmail.com>
Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
* Fix indent on first list item (#482)
* Fix normalization of empty quotes in list items (#953)
* Fix null validation for line-specific indents (#953)
---------
Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
* fix: keep trailing content out of unmatched emphasis closer (#743)
When EnableTrackTrivia() is enabled, an emphasis closer whose delimiter
run is only partially consumed (its leftover dropping below the minimum
count) kept the inlines that follow it nested inside the emphasis. The
roundtrip renderer then emitted the closing delimiters after that
trailing content, corrupting the output, for example a grid table
separator row using the "marked" (==) delimiter from EmphasisExtras.
Move the trailing content out to the outermost enclosing emphasis when
the closer can no longer be matched, mirroring the existing handling for
a fully consumed opener. The leftover closer keeps its position, so
cases without trailing content are unaffected. Adds a regression test.
* Fix unmatched emphasis closer cleanup order (#743)
---------
Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
Introduces AllowNestedAlerts on AlertExtension and AlertInlineParser
(default: false) to allow alert blocks inside blockquotes or list items.
The UseAlertBlocks() pipeline extension method exposes the new option
via an allowNestedAlerts parameter.
Resolves#853
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
* test: add failing regression tests for issue #935 (abbreviation + emphasis)
* fix: AbbreviationParser now substitutes post-inline-parse, fixes emphasis corruption (#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#935
* Fix to calculate LinkReferenceDefinition span positions from StringLineGroup.Lines
* Add test case in TestMultilineInBlockquote
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Change from startPosition + span.End - span.Start to GetAbsolutePosition(lines, span.End)
* Move ConvertToAbsoluteSpan and GetAbsolutePosition to StringLineGroup
* Remove '\r' check in Write(ReadOnlySpan<char>)
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>