mdit-py-plugins icon indicating copy to clipboard operation
mdit-py-plugins copied to clipboard

Do you want a "set base url" plugin?

Open jarofgreen opened this issue 1 year ago • 1 comments

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 avatar Aug 01 '24 09:08 jarofgreen

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

jarofgreen avatar Aug 21 '24 07:08 jarofgreen