trentm / python-markdown2

markdown2: A fast and complete implementation of Markdown in Python
Other
2.68k stars 433 forks source link

Easy way to replace links to other markdown files to html files #528

Open sturmf opened 1 year ago

sturmf commented 1 year ago

I might be missing something obvious but I have several markdown files that have links between them. After conversion to html the links still point to .md files. If the extension would have been changed to .html then they would work. So I am wondering if I am missing something obvious to make this change happen?

Crozzers commented 1 year ago

There isn't a dedicated option for this but you can achieve the same effect using the link patterns extra

sturmf commented 1 year ago

Thanks for the info but I utterly failed using that feature 😭 I just haven't really wrapped my brain around how that one works.

For now I am postprocessing the generated html which is fine. But I am still striving for a more elegant solution.

Crozzers commented 1 year ago

The link patterns extra doesn't match against URLs, it matches against plain text, which caught me off guard when I used it. I believe it was designed for snippets like this:

blah blah related to #12345 from the issue tracker

Where you could then have a regex to match these refs and replace them with links to your issue tracker.

Since you've got links to markdown files, you'll have to match your links, including the markdown link syntax (eg: \[.*\]\(.*\.md\) and replace them with your custom <a> tag.


In the future, I think it would be nice to implement this as a custom extra (#519), in the way this comment describes, but that does require the custom extra infrastructure.