fix: allow list markers indented by up to 4 spaces
Marked version: 16.4.0
Markdown flavor: CommonMark
Description Fixes #2832 - Render bullet-pointed incorrectly The issue was that nested lists with 4-space indentation were not being parsed correctly. When users indented nested list items with 4 spaces (which is common in some editors), the parser would incorrectly treat the nested bullet as part of the parent list item's content, leading to malformed HTML output where nested bullets were rendered as headings instead of proper nested lists.
Expectation Nested lists with 4-space indentation should render as proper nested HTML lists:
<li>title<ul>
<li>desc</li>
<li></li>
</ul>
</li>
</ul>
Result Previously, 4-space indented nested lists would produce incorrect output like:
<li><h2>title
- desc</h2>
</li>
</ul>
What was attempted The root cause was that the regex patterns for list markers in rules.ts only allowed 0-3 spaces before bullet markers, but CommonMark parsing should be more lenient to handle various indentation styles. Updated the following regexes to allow 0-4 spaces:
list regex: ^( {0,4}bull) listItemRegex: ^( {0,4}${bull}) nextBulletRegex: ^ {0,4}(?:[*+-]|\d{1,9}[.)]) hrRegex: ^ {0,4}((?:- *){3,}|(?:_ ){3,}|(?:\ ){3,}) fencesBeginRegex: ^ {0,4}(?:``|~~~)` headingBeginRegex: ^ {0,4}# htmlBeginRegex: ^ {0,4}<(?:[a-z].>|!--) Contributor Test(s) exist to ensure functionality and minimize regression (all existing spec and unit tests pass) no tests required for this PR. Committer In most cases, this should be a different person than the contributor.
CI is green (no forced merge required). Squash and Merge PR following conventional commit guidelines.
@tishajain25 is attempting to deploy a commit to the MarkedJS Team on Vercel.
A member of the Team first needs to authorize it.
Summary of Changes
Hello @tishajain25, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request resolves a parsing defect in the Markdown renderer that caused nested bulleted lists with 4-space indentation to render incorrectly. The core change involves updating regular expressions responsible for identifying list markers and other block-level elements to correctly interpret 4-space leading indentation, thereby ensuring proper CommonMark compliance and accurate HTML generation for such list structures. A new test file has been added to confirm the fix.
Highlights
- Bug Fix for Nested Lists: Addresses an issue where nested lists with 4-space indentation were incorrectly parsed, resulting in malformed HTML output (e.g., nested bullets rendered as headings instead of proper nested lists).
- Regex Pattern Update: Modified several regex patterns in
src/rules.tsto allow for up to 4 leading spaces (instead of the previous 3) for list markers and other block elements, aligning with CommonMark's leniency for indentation. - New Test Case: Introduced
test-bullet-issue.jsto specifically validate the correct rendering of nested lists with both 2-space and 4-space indentations, ensuring the fix works as expected and prevents regressions.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.
The tests aren't passing