Skip to content

Comments

chore: clean up blockskip#3801

Merged
UziTech merged 2 commits intomarkedjs:masterfrom
UziTech:clean-blockskip
Oct 17, 2025
Merged

chore: clean up blockskip#3801
UziTech merged 2 commits intomarkedjs:masterfrom
UziTech:clean-blockskip

Conversation

@UziTech
Copy link
Member

@UziTech UziTech commented Oct 17, 2025

Marked version: 16.4.0

Description

clean up blockskip regexp

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel
Copy link

vercel bot commented Oct 17, 2025

@UziTech 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
Contributor

Summary of Changes

Hello @UziTech, 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 PR primarily focuses on enhancing the clarity, structure, and robustness of a core regular expression used for parsing, specifically improving how it handles complex patterns like nested code within links. Additionally, it includes a minor cleanup of test file names. The changes aim to make the codebase easier to understand and maintain while improving parsing accuracy.

Highlights

  • blockSkip Regular Expression Enhancement: The "blockSkip" regular expression in "src/rules.ts" has been refactored for improved readability and maintainability. It now uses a modular approach, defining separate regex components for links, code blocks, and HTML tags. Notably, the "link" component has been enhanced with more robust logic to correctly handle nested code blocks within link titles using named capture groups and negative lookbehind.
  • Test File Renames: Two test files, "issue_3776_backtick_precedence.html" and "issue_3776_backtick_precedence.md", have been renamed to "backtick_precedence.html" and "backtick_precedence.md" respectively, removing the issue number from their names for better organization.
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.

@UziTech UziTech merged commit f9fa5bb into markedjs:master Oct 17, 2025
6 of 7 checks passed
@UziTech UziTech deleted the clean-blockskip branch October 17, 2025 07:21
Copy link
Contributor

@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 refactors the blockSkip regular expression for better readability and maintainability, which is a great improvement. The use of named placeholders makes the complex regex much easier to understand. I've found a potential correctness issue in the regex used for matching code spans, which was present before this change but is now more prominent. The current implementation for code span content does not correctly handle nested backticks. My review includes a suggestion to fix this, which will make the markdown parsing more robust.

Comment on lines +271 to +272
.replace('link', /\[(?:[^\[\]`]|(?<!`)(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/)
.replace('code', /(?<!`)(?<b>`+)[^`]+\k<b>(?!`)/)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The regex part [^]+for matching code span content is incorrect as it doesn't allow backticks inside the code span. For example, it would fail to match a code span like ``a``. This applies to code spans within links as well as standalone code spans considered byblockSkip`.

A more robust approach is to use a non-greedy match for any character, such as [\s\S]+?, for the content. This will correctly handle cases with backticks inside the code span.

Suggested change
.replace('link', /\[(?:[^\[\]`]|(?<!`)(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/)
.replace('code', /(?<!`)(?<b>`+)[^`]+\k<b>(?!`)/)
.replace('link', /[\[(?:[^\[\]`]|(?<!`)(?<a>`+)([\s\S]+?)\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/)
.replace('code', /(?<!`)(?<b>`+)([\s\S]+?)\k<b>(?!`)/)

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.

1 participant