Skip to content

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

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

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

@Yashh56

Yashh56 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Hey @kfiven, can you please review this PR and share your feedback

@wigmarbled

Copy link
Copy Markdown

https://github.com/cinnyapp/cinny/blob/dev/CONTRIBUTING.md#ai-usage

As per their contribution policy, no AI code is allowed.

@Yashh56

Yashh56 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

I reviewed the AI generated Code by myself. I don't think this might generate any problem in future.

@kfiven

kfiven commented Sep 15, 2026

Copy link
Copy Markdown
Member

Hi @Yashh56
Since we review all the code by ourselves, we expect same from contributors as per new policy. There is also licensing concern regarding the AI generated code. We are happy to help you out on any issues but please follow the policy.

@Yashh56

Yashh56 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Hey @kfiven, thanks for clarifying. I understand the concern regarding the new policy and the licensing aspects of AI-generated code.

I’ll make sure to review and understand the code myself before submitting any further contributions and follow the project’s contribution guidelines going forward.

@Yashh56

Yashh56 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Hey @kfiven, Should I close this PR now and recreate a new one or make changes in it?

@kfiven

kfiven commented Sep 16, 2026

Copy link
Copy Markdown
Member

Hi, A new one will be better.

@Yashh56 Yashh56 closed this Sep 16, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown issues

3 participants