Skip to content

fix(markdown): comprehensive improvements to markdown block/inline parsing and UI rendering - #3094

Open
Yashh56 wants to merge 4 commits into
cinnyapp:devfrom
Yashh56:fix-markdown-parser
Open

fix(markdown): comprehensive improvements to markdown block/inline parsing and UI rendering#3094
Yashh56 wants to merge 4 commits into
cinnyapp:devfrom
Yashh56:fix-markdown-parser

Conversation

@Yashh56

@Yashh56 Yashh56 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

PR Description

Summary

This PR introduces a series of robust fixes to the Markdown parser and UI rendering engine. It addresses multiple edge cases in both block- and inline-Markdown parsing, ensuring that complex combinations—such as nested lists, blockquotes containing lists, and nested inline elements—are formatted precisely to specification.

It also resolves a UI styling conflict with spoiler elements.

Key Changes

1. Block-Level Parsing

  • Nested Lists: Refactored indentation tracking (buildList stack) to accurately map indentation depths, ensuring nested lists are generated with the correct hierarchy rather than being flattened.

  • Ordered Lists:

    • Updated the regex to support multi-digit markers (e.g., 10., 100.), which were previously failing to parse.
    • Restricted alphabetical lists to valid types (a, A, i, I), preventing arbitrary letters (e.g., Q.) from erroneously triggering list creation.
    • Fixed an editor fallback bug where malformed ordered lists would default to a - metadata attribute, accidentally converting them to unordered lists.
  • Unordered Lists: Fixed getListType to properly recognize hyphens (-) alongside asterisks (*) as valid unordered list markers.

  • Blockquotes: Enabled recursive parsing inside BlockQuoteRule, allowing internal block elements (such as lists or headings) to be formatted correctly within a quote rather than rendering as raw text.

2. Inline-Level Parsing

  • Rule Precedence: Moved CodeRule into LeveledRules to fix regex precedence issues. This prevents inline code blocks from prematurely splitting strings, which previously broke outer syntax such as links or spoilers containing code.

  • Escaped Characters: Added \[ and \] to INLINE_SEQUENCE_SET so that escaped square brackets are correctly unescaped and ignored by the link parser.

3. UI & Styling

  • Spoiler Visibility: Fixed a styling conflict where child elements inside an unrevealed spoiler (such as <code /> blocks with distinct backgrounds/colors) remained visible.

    Used Vanilla Extract's globalStyle to apply opacity: 0 to all descendants of an unrevealed spoiler, ensuring everything is completely hidden until clicked.

Testing

  • Verified blockquote recursive rendering.
  • Verified nested unordered/ordered lists mapping to Slate editor states.
  • Verified lists starting with double digits (e.g., 10. Foo).
  • Verified invalid lists (e.g., Q. Foo) are gracefully parsed as regular paragraphs.
  • Verified escaped brackets (\[bracket\]) render as raw text.
  • Verified spoiler tags (||) properly mask inline <code /> blocks.

Close: #2845

@Yashh56

Yashh56 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Tested the changes with the following Markdown cases to verify nested lists, escaped brackets in links, inline code within links, blockquotes, and spoilers containing inline code:

- Foo
  - Bar
- Baz

[This is a link with a \[bracket\]](https://example.com)

[This is a link with `code`](https://example.com)

> #### The story of markdown
>
> Markdown is a thing.

||`hidden code`||

All of the above cases are rendering as expected. I’ve also attached a screenshot of the resulting output below.

image

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown issues

1 participant