1888 Commits

Author SHA1 Message Date
Lior Shmueli
797ae6637e Fix empty paragraph before pipe tables with trailing pipes (#978)
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>
2026-11-14 21:32:22 +01:00
prozolic
ac4f83e79d Simplify OrderedList.Replace and renderer setup. (#976)
- 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.
2026-11-08 08:12:05 +01:00
Alexandre Mutel
8b4ffd59be Fix Markdown.Normalize for custom containers and footnotes
* 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>
1.6.0
2026-11-04 21:35:14 +01:00
Stefan Greve
58d9752a6e Add Table of Contents Extension (#975)
* 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>
2026-11-04 21:06:57 +01:00
Stefan Greve
bbf197eaf3 Fix doc and rename ParseSetexHeadings to ParseSetextHeadings (#973)
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.
1.5.1
2026-10-28 21:02:12 +01:00
Wleeaf
8946b42492 Fix autolink scheme length check to allow 2 to 32 characters (#971)
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.
2026-10-28 21:00:56 +01:00
Stefan Greve
a973d0e430 Fix renderers writing HTML when HTML output is disabled (#972)
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.
2026-10-28 20:58:35 +01:00
Wleeaf
f36a2548d1 Fix thematic break inside a list item closing the list (#970)
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.
2026-10-28 20:58:30 +01:00
Yang Bai
ac2134b46a Fix tabs after quote markers and in fenced code indentation (#974)
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.
2026-10-28 20:58:25 +01:00
Stefan Greve
9900e46eac Fix unescaped source URL in media links (#969)
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.
1.5.0
2026-10-23 23:03:02 +02:00
Huzaifa Iftikhar
18037fea21 Fix escaped backslash in info strings (#967)
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).
2026-10-23 21:11:38 +02:00
Stefan Greve
13b2d9a53b Add relative file links extension (#897) (#968)
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.
2026-10-23 21:09:54 +02:00
Huzaifa Iftikhar
96a7f45ada Fix trimming of Unicode whitespace other than spaces and tabs (#966)
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.
2026-10-23 21:06:06 +02:00
Yang Bai
6a410393ba Fix FindClosestBlock/FindBlockAtPosition with definition groups (#677) (#962)
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>
1.4.2
2026-10-19 20:57:06 +02:00
Stefan Greve
55e9ec7a7a Add IsAotCompatible for net8.0 and later targets (#963)
* 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>
2026-10-19 20:56:50 +02:00
Wahid Rizka Fathurrohman
f1381b61f3 Fix setext underlines in block quotes and list items (#965)
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.
2026-10-19 20:56:38 +02:00
Wahid Rizka Fathurrohman
78d68077bd Fix setext heading line breaks and indented lazy quote lines (#964)
* 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.
2026-10-19 20:56:17 +02:00
Alexandre Mutel
ccb9d8593f Fix concurrent spec generation in parallel builds
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>
1.4.1
2026-10-16 06:35:49 +02:00
Alexandre Mutel
b58e83b427 Update doc for definition-list continuation rules
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 06:34:26 +02:00
Alexandre Mutel
a998839f54 Fix definition paragraphs inside tight lists
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>
2026-10-16 06:34:19 +02:00
Alexandre Mutel
d33c703de0 Fix CommonMark inline HTML declarations
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>
2026-10-16 06:33:14 +02:00
Alexandre Mutel
2fec208589 Fix empty list items with trailing marker whitespace
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>
2026-10-16 06:32:23 +02:00
Alexandre Mutel
05e638f908 Fix CommonMark closing-tag block starts and whitespace 2026-10-15 21:59:19 +02:00
Alexandre Mutel
d5462ae54f Fix CommonMark HTML block start character classes 2026-10-15 21:48:26 +02:00
Michał "DualFroz" Fox
e068f060a4 Fix definition-list marker whitespace requirements (#959)
* Fix definition lists requiring 3 spaces after the marker (#384)

* Update doc for definition-list marker whitespace rules

---------

Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
2026-10-15 21:42:10 +02:00
Wahid Rizka Fathurrohman
76afbbfc42 Fix empty list items after closed paragraphs (#961)
* 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>
2026-10-15 21:36:23 +02:00
Wahid Rizka Fathurrohman
cdf8aedd83 Fix HTML block whitespace terminators and roundtripping (#960)
* 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>
2026-10-15 21:36:18 +02:00
Michał "DualFroz" Fox
55edc078e6 Fix grid-table open last-cell boundaries (#958)
* 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>
2026-10-15 21:36:12 +02:00
SparkUiX
1211a1ac7f Fix definition-list continuation markers and source locations (#957)
* Fix definition list continuation marker (#956)

* Fix test spec generated output (#956)

* Fix indented definition marker rollback and source locations

---------

Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
2026-10-15 21:35:49 +02:00
Alexandre Mutel
56e9c23858 Use NuGet Trusted Publishing via dotnet-releaser 1.4.0 2026-09-20 09:52:24 +02:00
Alexandre Mutel
c6b186b4ce Bump deps 2026-09-20 09:46:49 +02:00
Alexandre Mutel
96b024c2d6 Fix tests warnings 2026-09-20 09:46:41 +02:00
Benny Tordrup
237ef72a0f Reject emoji-parsing if the slice ends with ** (#947)
* 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>
2026-09-20 09:36:57 +02:00
Alexandre Mutel
86866b919c Fix strict GFM tables against native cmark-gfm 2026-09-19 15:20:49 +02:00
Alexandre Mutel
14cd25c744 Add strict GFM pipe table parsing mode 2026-09-19 12:58:58 +02:00
Liangying.Wei
ad7cc00ac3 Fix partially empty pipe table separator regression (#955)
* Fix partially empty pipe table separator regression

Restore historical acceptance of empty separator cells while retaining the row-wide dash requirement introduced for #927. Cover partial and entirely empty rows, alignment, optional pipes, and inferred widths.

Refs: dotnet/docfx#11147

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Fix normalization of empty inferred table separators (#955)

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
2026-09-19 12:42:55 +02:00
boxofyellow
6168275c3f Add Normalization Support for PipeTables (GFM) (#954)
* 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>
2026-09-19 12:24:10 +02:00
boxofyellow
209b347ac2 Fix indent on first list item (#482) (#953)
* 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>
2026-09-19 12:09:15 +02:00
Michał "DualFroz" Fox
27b8c9eb56 Fix: keep trailing content out of an unmatched emphasis closer (#743) (#950)
* 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>
2026-09-19 11:52:40 +02:00
Michał "DualFroz" Fox
baa95a9ca3 Fix heading auto-link hijacking nested link labels (#668) (#949)
* Fix heading auto-link hijacking nested link labels (#668)

* Refactor heading reference resolution to init-only state (#949)

---------

Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
2026-09-19 11:41:48 +02:00
Nicolas Musset
b07b98e1b7 Update 3rd party extensions (#945)
Remove markdig.wpf which is archived and obsolete.
Add MarkView.Avalonia
2026-08-18 18:02:42 +02:00
Alexandre Mutel
fc705234fa Fix emoji table alignment regression (#943) 1.3.2 2026-06-18 18:49:25 +02:00
Alexandre Mutel
25506f20d9 Fix plus superscript parsing (#791) 1.3.1 2026-06-17 08:35:40 +02:00
Alexandre Mutel
50061841a4 Fix LinkHelper non-ASCII urilize (#942) 2026-06-17 08:25:56 +02:00
Alexandre Mutel
bc4e399087 Fix blockquote ordered list parsing (#887) 1.3.0 2026-06-13 14:38:30 +02:00
Alexandre Mutel
9dffce52b6 Fix NormalizeRenderer auto identifiers output (#930) 2026-06-13 14:21:54 +02:00
Alexandre Mutel
d7f13b03cf Fix configurable nesting depth limit (#892) 2026-06-13 14:20:14 +02:00
Alexandre Mutel
b83641351f Fix roundtrip autolink URLs (#919) 2026-06-13 14:03:45 +02:00
Alexandre Mutel
0f98267a85 Fix pipe table cells with unmatched subscript (#932) 2026-06-13 08:47:21 +02:00
Alexandre Mutel
fcbf817063 Fix CJK emphasis after HTML entity newlines (#941) 2026-06-13 08:12:54 +02:00