Ignore empty or whitespace-only inline roots when deciding whether a paragraph precedes a pipe table. Add regression coverage for emphasis with a trailing lone pipe, preserve real leading text, and document the permissive table behavior.
Fixes#977.
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: CodeAlta <noreply@codealta.io>
- Use the indexer in OrderedList<T>.Replace instead of RemoveAt and Insert.
- Use `AddIfNotAlready<T>()` in `FooterExtension` and `FootnoteExtension` to match the other AddIfNotAlready calls.
* Write custom containers between ::: fences of their original length,
with their info and arguments, and close an unclosed container
* Write footnote references as [^label] and footnotes as
[^label]: content with continuation lines indented by four spaces,
leaving out the back links and the paragraph the parser adds for them
* Skip link reference definitions that create their own inline, such as
those of footnotes and auto-identifier headings, which wrote [^1]: and
[]: lines once a footnote put the definition group into the document
* End the definition group with a blank line, so that a following
footnote or line is not read back as part of a definition
Co-authored-by: CodeAlta <noreply@codealta.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Add table of contents extension (#71)
* Replace a paragraph that consists of [TOC] alone with a TableOfContentsBlock
when it closes, so the marker wins over links labeled TOC
* Render a nav with role doc-toc around nested lists of plain-text entries,
and nothing for a document without headings
* Leave the marker a paragraph under trivia tracking, because no roundtrip
renderer could write a replacement block back losslessly
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Add links from table of contents entries to headings
* Link an entry to its heading whenever the heading has a non-empty ID, and
leave other entries as plain text instead of enabling AutoIdentifiers
* Write the link with WriteEscapeUrl, so BaseUrl and LinkRewriter treat it
like a Markdown link to the same fragment
* Ignore the footnote test until the footnote link renderer honors
EnableHtmlForInline, which a separate pull request fixes first
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Add heading level range to table of contents options
* Add MinLevel and MaxLevel, so a document title or deep subsections can be
left out of the table of contents, as requested in #71
* Reject a minimum below 1 or a maximum below the minimum, but set no upper
bound, because HeadingBlockParser.MaxLeadingCount can raise heading levels
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Update doc for table of contents extension
* Add a docs page covering the marker rules, the nav markup and its doc-toc
role, links, options, CSS recipes and a custom renderer
* List the extension in the readme, the extension overview and menu, the
Configure token list and the specs readme, as relative file links did
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Update test for footnote references in table of contents entries
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Adds ParagraphBlockParser.ParseSetextHeadings and keeps ParseSetexHeadings as an [Obsolete] alias, fixes typos in exception messages and XML docs, corrects the footnotes, media links and DisableHtml docs that contradicted the code, and removes the stale PackageReleaseNotes link to changelog.md.
Both bounds of the autolink scheme length are checked when the colon is reached, so 2-character schemes such as ws: are accepted and schemes longer than 32 characters are rejected, as the CommonMark spec says.
The footnote link, footnote group and custom container inline renderers now honor EnableHtmlForInline/EnableHtmlForBlock, so their markup no longer leaks into Markdown.ToPlainText or image alt attributes.
A thematic break indented to the content column of the current list item is parsed inside the item instead of closing the list, matching cmark and commonmark.js.
BlockProcessor.NextColumn now stays on a tab only while the tab still spans columns after the current one, so a tab after a block quote marker is no longer counted twice or short. Fenced code content lines remove the fence indentation column by column, so tabs count as the spaces they expand to. The quote parser keeps a consumed tab in the trivia for roundtrip.
The <source src> of audio/video media links is now written through HtmlRenderer.WriteEscapeUrl, like image src and the iframe branch, so a destination containing a quote can no longer inject attributes. Media sources also go through BaseUrl and LinkRewriter now.
HtmlHelper.Unescape now skips the escaped character after a backslash escape, so an escaped backslash no longer starts another escape and an escaped & no longer starts an entity reference, as the CommonMark spec says (matches commonmark.js).
Adds the opt-in UseRelativeFileLinks() extension, which rewrites relative links to .md/.markdown files into links to the generated pages through HtmlRenderer.LinkRewriter, keeping the query and fragment. Also fixes email autolinks to pass mailto: through WriteEscapeUrl, so BaseUrl no longer prefixes them and a LinkRewriter sees the full mailto: URL.
Paragraphs, headings and fenced code info strings are now trimmed of spaces and tabs only, as the CommonMark spec says, so a trailing or leading U+00A0, U+3000 or form feed is kept, matching cmark.
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>