-
Couldn't load subscription status.
- Fork 14
feat: add regex to fix <br> #1210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add regex to fix <br> #1210
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good, but I also think we could improve it slightly.
Also, would you add a test here: https://github.com/readmeio/markdown/tree/next/__tests__/migration
lib/migrate.ts
Outdated
| // parsing weird cases. | ||
| .replaceAll(/a/g, 'a') | ||
| // A common issue is that <br> tags are not properly closed | ||
| .replaceAll(/<br(?!\s*\/)\s*>/g, '<br />') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most 'correct' way to do this would be to traverse the tree:
| .replaceAll(/<br(?!\s*\/)\s*>/g, '<br />') | |
| import { visit } from 'unist-util-visit'; | |
| visit(ast, 'text', textNode => { | |
| textNode.value = textNode.value.replaceAll(/<br(?!\s*\/)\s*>/g, '<br />') | |
| }) |
This would prevent replacing <br> strings when they're inside inline code or code blocks, eq:
Not a `<br>` tag
```
Also not a <br> tag
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, implemented it! Though I've had to use 'html' to visit instead of text for it to work, let me know if that's not right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also created a generic function for migration html tags in general in case we want to regex more tags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
## Version 11.4.0 ### ✨ New & Improved * add regex to fix <br> ([#1210](#1210)) ([ff4aa28](ff4aa28)) ### 🛠 Fixes & Updates * **deps:** bump actions/checkout from 4 to 5 ([#1171](#1171)) ([6610a81](6610a81)), closes [actions/checkout#2226](actions/checkout#2226) [actions/checkout#2238](actions/checkout#2238) [actions/checkout#1971](actions/checkout#1971) [actions/checkout#1977](actions/checkout#1977) [actions/checkout#2043](actions/checkout#2043) [actions/checkout#2044](actions/checkout#2044) [actions/checkout#2194](actions/checkout#2194) [actions/checkout#2224](actions/checkout#2224) [actions/checkout#2236](actions/checkout#2236) [actions/checkout#2237](actions/checkout#2237) [actions/checkout#1971](actions/checkout#1971) [actions/checkout#1977](actions/checkout#1977) [actions/checkout#2043](actions/checkout#2043) [actions/checkout#2194](actions/checkout#2194) [actions/checkout#2236](actions/checkout#2236) [actions/checkout#1941](actions/checkout#1941) [actions/checkout#1946](actions/checkout#1946) [actions/checkout#1924](actions/checkout#1924) [actions/checkout#1919](actions/checkout#1919) [actions/checkout#2226](actions/checkout#2226) [actions/checkout#1971](actions/checkout#1971) [actions/checkout#1977](actions/checkout#1977) [actions/checkout#2043](actions/checkout#2043) [actions/checkout#2044](actions/checkout#2044) [actions/checkout#2194](actions/checkout#2194) [actions/checkout#2224](actions/checkout#2224) [actions/checkout#2236](actions/checkout#2236) [actions/checkout#1941](actions/checkout#1941) [actions/checkout#1946](actions/checkout#1946) [actions/checkout#1924](actions/checkout#1924) [actions/checkout#1180](actions/checkout#1180) [actions/checkout#1777](actions/checkout#1777) [actions/checkout#1872](actions/checkout#1872) [actions/checkout#1739](actions/checkout#1739) [actions/checkout#1697](actions/checkout#1697) [actions/checkout#1774](actions/checkout#1774) [actions/checkout#1776](actions/checkout#1776) [actions/checkout#1732](actions/checkout#1732) [actions/checkout#1703](actions/checkout#1703) [actions/checkout#1694](actions/checkout#1694) [actions/checkout#1696](actions/checkout#1696) [actions/checkout#1695](actions/checkout#1695) [actions/checkout#1707](actions/checkout#1707) [actions/checkout#1692](actions/checkout#1692) [actions/checkout#1688](actions/checkout#1688) [actions/checkout#1693](actions/checkout#1693) [actions/checkout#1643](actions/checkout#1643) [#2238](https://github.com/readmeio/markdown/issues/2238) [#2226](https://github.com/readmeio/markdown/issues/2226) * **deps:** bump github/codeql-action from 3 to 4 ([#1208](#1208)) ([9db6259](9db6259)), closes [#3168](https://github.com/readmeio/markdown/issues/3168) [#3160](https://github.com/readmeio/markdown/issues/3160) [#2935](https://github.com/readmeio/markdown/issues/2935) [#2938](https://github.com/readmeio/markdown/issues/2938) [#2950](https://github.com/readmeio/markdown/issues/2950) [#2925](https://github.com/readmeio/markdown/issues/2925) [#2912](https://github.com/readmeio/markdown/issues/2912) [#2959](https://github.com/readmeio/markdown/issues/2959) [#2910](https://github.com/readmeio/markdown/issues/2910) [#2893](https://github.com/readmeio/markdown/issues/2893) [#2894](https://github.com/readmeio/markdown/issues/2894) [#2891](https://github.com/readmeio/markdown/issues/2891) [#2872](https://github.com/readmeio/markdown/issues/2872) [#3189](https://github.com/readmeio/markdown/issues/3189) [#3188](https://github.com/readmeio/markdown/issues/3188) * creating a CODEOWNERS file ([8a24361](8a24361)) <!--SKIP CI-->
This PR was released!🚀 Changes included in v11.4.0 |

🧰 Changes
Add another regex in the migrator to replace unclosed
tags to closed
tags
🧬 QA & Testing