-
-
Notifications
You must be signed in to change notification settings - Fork 498
Open
Labels
Description
I convert scanned PDFs to Markdown using Mistral OCR. The OCR sometimes produces sequences like D. M. M. M. … on a single line.
With UseListExtras() enabled, Markdig appears to interpret each X. as an (alpha) list marker, causing pathological nesting and throwing:
Markdown elements in the input are too deeply nested - depth limit exceeded.
Input that triggers the error
Krankenhaus Gepedale di
Brixen Bressanone
ARZTLICHE DIATO
GESCHÄFTE VIT-DE
ARZTLICHEA DIATO
D. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. MExpected behavior
- The problematic line is treated as plain text (a paragraph), or at worst, a single list item like
D. <remaining text>, without creating deep nesting.
Actual behavior
Markdown.ToHtml(...)throwsArgumentException: Markdown elements in the input are too deeply nested - depth limit exceeded.
Minimal repro (NUnit)
using Markdig;
using NUnit.Framework;
[TestFixture]
public class OcrListFalsePositiveTests
{
[Test]
public void FalsePositiveDepthLimit()
{
var mistralOcrMarkdown = """
Krankenhaus Gepedale di
Brixen Bressanone
ARZTLICHE DIATO
GESCHÄFTE VIT-DE
ARZTLICHEA DIATO
D. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M. M
""";
var pipeline = new MarkdownPipelineBuilder()
.UseListExtras() // enables alpha list markers like "a. "
.Build();
Assert.DoesNotThrow(() => {
Markdig.Markdown.ToHtml(mistralOcrMarkdown, pipeline);
});
}
}Current result: the test throws with the “depth limit exceeded” exception.
Environment
- Markdig version: 0.42.0
- .NET: 9
Notes / Hypothesis
- With
UseListExtras(), sequences likeD.,M.are valid alpha list markers. When many appear in a single line, the parser seems to treat them as nested structures, quickly tripping the depth limit. - This looks like a false positive for list parsing when multiple alpha markers occur inline on the same line.
Possible directions
- Only treat alpha list markers as list starts when they appear at the beginning of a line (or after indentation consistent with list blocks), not repeatedly within the same line.
- Alternatively, short-circuit nested list interpretation when multiple markers appear on a single line without intervening newlines.
kristafr