executablebooks / mdit-py-plugins

Collection of core plugins for markdown-it-py
https://mdit-py-plugins.readthedocs.io
MIT License
30 stars 32 forks source link

Do you want a "set base url" plugin? #113

Open jarofgreen opened 3 months ago

jarofgreen commented 3 months ago

Context

Sometimes you have some markdown content that is intended to be hosted at http://www.example.com and so it has things like images with relative links, like /images/cat.png

But sometimes you want to show rendering of this content in other situations. eg Maybe you are providing a nice CMS for people to edit this website at http://cms.example.com or even http://third-party-cms.com/project/example.com

Now, all your links are broken!!!

Proposal

A new "set base url" plugin.

You configure it with a base url like http://www.example.com and it rewrites all URLs like /images/cat.png to http://www.example.com/images/cat.png

Now the rendered HTML can be shown on http://cms.example.com and links work!

Could also be called "make URLs absolute" maybe.

Tasks and updates

I've already started on this and am happy to contribute it here if it's wanted?

jarofgreen commented 3 months ago

Plugin: https://github.com/DataTig/Hub/blob/main/datatighub/datatighubcore/markdownitpy/setbaseurl/index.py

Tests: https://github.com/DataTig/Hub/blob/main/datatighub/datatighubcore/test/test_markdownitpy_setbaseurl.py