Hello :) Sorry to pin you, I just gave pandoc a try but it doesn’t work and I had to dig a bit further into the web to find out why !
Links to Headings with Spaces are not specified by CommonMark and each tool implement a different approach… Most replace space with hyphens other use URL encoding (%20). So even though pandoc looks awesome it doesn’t work for my use case (or did i miss something? Feel free to comment).
You can give it a try on https://pandoc.org/try/ with commonmark to gfm:
[Just a test](#Just a test)
[Just a link](https://mylink/%20with%20space.com)
[External link](Readme.md#JUST%20a%20test)
[Link with numbers](readme.md#1.3%20this%20is%20another%20test)
[Link with numbers](Another%20file%20to%20readme.md#1.3%20this%20is%20another%20test)
If you prefere a cli version:
pandoc --from=commonmark_x --to=gfm+gfm_auto_identifiers "/home/user/Documents/test.md" -o "pandoc_test.md"
Thank you ! It does actually ticks every use case (for my files) looks pretty rad !
I totally agree but I will keep your regex as reference, in the near future I will give it a try to decompose you regex as learning process but it looks rather very complex !
Another user came up with the following solution:
sed -E ':l;s/(\[[^]]*\]\()([^)#]*#[^)]*\))/\1\n\2/;Te;H;g;s/\n//;s/\n.*//;x;s/.*\n//;/^https?:/!{:h;s/^([^#]*#[^)]*)(%20|\.)([^)]*\))/\1-\3/;th;s/(#[^)]*\))/\L\1/;};tl;:e;H;z;x;s/\n//;'
Just as a little experiment, If you want to spend some time and give me a answer, what do you think? It’s a another way to achieve the same kind of results but they are significantly different. I know there a thousand ways to achieve the same results but I’m kinda curious how it looks from an experts eyes :).
Thanks again for your help and the time you took to write up a complex regex for my use case ! 👍