feat: add regex to fix <br>#1210
Conversation
kellyjosephprice
left a comment
There was a problem hiding this comment.
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.
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.
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.
I've also created a generic function for migration html tags in general in case we want to regex more tags
## 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