Skip to content

Deeply nested block quotes throw inside MarkdownView's render #1004

Closed

Description

@alexeyzimarev

Markdig's MarkdownPipelineBuilder.MaximumNestingDepth (128) is enforced during parsing: Markdown.Parse throws ArgumentException: Markdown elements in the input are too deeply nested for 128 or more nested block quotes. Probed on the #1000 branch: 127 nested > parse and render within the limit; 128, 129, 140 and 300 throw, in a plain MarkdownPipelineBuilder().Build() pipeline exactly as in the reader's.

MarkView's MarkdownViewer.RenderMarkdown calls Markdown.Parse from its Markdown property-changed handler, so the exception surfaces inside MarkdownView's render — for every flavor, chat included. A transcript line or comment body of 256 characters (> × 128) is enough. What the desktop app does with an exception escaping that handler is unverified; at best the view shows nothing for that item.

Independent of #982 / #1000, which budget only the nesting the HTML pass synthesizes; a tree deeper than the limit never reaches the pass because parsing throws first.

Candidate fixes, each its own design:

  • MarkdownView.Render() catches the parse failure and shows the text as plain text (a TextBlock with the source), the same degrade the reader uses for HTML it cannot convert.
  • Cap nesting before handing text to the viewer — cheaper, but it means a second parser.

Repro: new MarkdownView { Text = string.Concat(Enumerable.Repeat("> ", 128)) + "x" }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions