Skip to content

Conversation

@eaglethrost
Copy link
Contributor

@eaglethrost eaglethrost commented Nov 13, 2025

PR App Fix RM-XYZ

Context

For a text with an opening bracket right after a complete bracket, the remark library will drop the second opening bracket because it thinks the second part is part of the link reference, will start parsing it as such, but when no closing bracket was found, it only retains the text.

[bar][bar -> [bar]bar

This may look unexpected for users, so this PR provides a workaround to retain the second opening bracket by visiting the tree and regex escaping it, so that it can be retained.

🧰 Changes

Created an additional plugin to the processor to revisit the created AST of a markdown, visits linkRefernce nodes, and compares span recorded in the node positions with the expected [label] length to find dropped ['s & replace it with text node with the bracket reattached

I used this approach instead of just escaping the brackets because it was hard for me to distinguish if the text is inaccurate code block, jsx, etc where we don't want to touch it.

Let me know if there's another approach or if this is too complicated for this case, I feel like the amount of cases of this appearing would be low.

🧬 QA & Testing

@eaglethrost eaglethrost marked this pull request as ready for review November 14, 2025 03:35
Copy link
Contributor

@kellyjosephprice kellyjosephprice left a comment

Choose a reason for hiding this comment

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

I don't believe this is going to work as expected. The @readme/markdown@6 is only used to parse to an AST during the migration. The 'compilation' to a string is all done by '@readme/markdown@>11'. My recommendation would be to move all of this into @readme/markdown@11.

We pass in custom migration specific transformers here: https://github.com/readmeio/markdown/blob/next/lib/mdastV6.ts#L13

We don't really have a concept of migration only compilers, but that would be easy to add. Perhaps a new option for passing in compilers here: https://github.com/readmeio/markdown/blob/next/lib/migrate.ts#L14-L17

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.

2 participants