Skip to content

Conversation

@akilesh1706
Copy link

Marked version: 11.0.0 (bug reported against 11.0.0). Fix implemented on master.

Markdown flavor: CommonMark / GitHub Flavored Markdown (GFM)

Description

When a list item used a tab after the list marker (e.g. 1.\tText or -\tText), and there was preceding text (a paragraph) before the list, the tokenizer sometimes treated the item content as an indented code block (leading four spaces) instead of normal list content. This produced

...
inside
  • for the tab-using list, while the same list using spaces produced normal
  • Text
  • .

    This PR fixes that inconsistency so tabs after the marker are interpreted the same as spaces regardless of text preceding the list.

    Fixes the inconsistent tab handling in list items that could make tabbed list items render as indented code blocks.
    Files changed (key):

    Expectation
    Given input (tabs or spaces after marker):

    I am using spaces after the number:

    Some Text
    Some Text
    Some Text
    I am using tabs after the number: 1. Some Text 2. Some Text 3. Some Text

    Expected HTML (both cases):

    (And similar for unordered lists)

    Result (before this PR)

    Lists that used tabs after the marker were sometimes parsed as indented code blocks and rendered as:

    1. Some Text 
    2. ...

    while the same lists using spaces were parsed/rendered correctly as simple
  • Some Text
  • .

    What was attempted / what this PR does

    Normalizes the first line of a list item by replacing tabs with the same tab normalization used elsewhere in the codebase (tabs -> 4 spaces), then computes indent and slices content from the normalized string so the slice length is correct when tabs are used.
    Ensures indent detection replaces tabs with spaces consistently when finding the first non-space character.
    Adds tests to cover:
    ordered lists using spaces vs tabs,
    ordered lists that follow a paragraph (the reported scenario),
    unordered lists using spaces vs tabs.

    @vercel
    Copy link

    vercel bot commented Oct 3, 2025

    @akilesh1706 is attempting to deploy a commit to the MarkedJS Team on Vercel.

    A member of the Team first needs to authorize it.

    @gemini-code-assist
    Copy link

    Summary of Changes

    Hello @akilesh1706, I'm Gemini Code Assist1! 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 inconsistency in the Marked library where list items using tabs after their markers were sometimes misinterpreted as indented code blocks, particularly when following a paragraph. The changes normalize tab characters to spaces during the initial processing of list item lines and refine indent calculation, ensuring that Marked consistently renders list items whether tabs or spaces are used after the marker. This improves the robustness and predictability of markdown rendering.

    Highlights

    • Inconsistent List Parsing: Fixed a bug where Marked inconsistently parsed list items, treating content after a tab-separated marker as an indented code block instead of normal list content, especially when preceded by a paragraph.
    • Tab Normalization: Implemented consistent normalization of tabs to 4 spaces within list item parsing logic, ensuring uniform handling of tabs and spaces after list markers.
    • Improved Indent Calculation: Enhanced the indent calculation for list items to correctly account for tabs by treating them as 4 spaces when determining the first non-space character.
    • Comprehensive Testing: Added new unit tests covering ordered and unordered lists with both tabs and spaces after markers, including the specific scenario of lists following a paragraph, to validate the fix.
    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 👍 and 👎 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.

    Footnotes

    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.

    Copy link

    @gemini-code-assist gemini-code-assist bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Code Review

    This pull request correctly addresses an inconsistency in how tabs are handled within lists, and the new tests provide good coverage for the fix. However, I've identified a critical indentation error that appears to be accidental and would break list parsing. Additionally, I've provided a couple of suggestions to improve the clarity and efficiency of the updated tokenizer logic.

    akilesh1706 and others added 3 commits October 3, 2025 22:02
    Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
    Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
    Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
    @vercel
    Copy link

    vercel bot commented Oct 4, 2025

    The latest updates on your projects. Learn more about Vercel for GitHub.

    Project Deployment Preview Comments Updated (UTC)
    marked-website Ready Ready Preview Comment Oct 4, 2025 4:52am

    const __filename = fileURLToPath(import.meta.url);
    const __dirname = path.dirname(__filename);

    const mdPath = path.join(__dirname, '../specs/new/list_with_tabs.md');
    Copy link
    Member

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    this is not needed. the files in the new folder are already ran in other tests

    @akilesh1706
    Copy link
    Author

    Necessary changes done, requesting for review.

    Copy link
    Member

    @UziTech UziTech left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    tests don't pass

    @UziTech
    Copy link
    Member

    UziTech commented Oct 16, 2025

    @akilesh1706 are you planning on continuing to work on this?

    @akilesh1706
    Copy link
    Author

    @akilesh1706 are you planning on continuing to work on this?

    Yes, I'm resolving the CI test passes.

    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.

    Marked treats tabs and spaces differently in lists

    2 participants