Relative Link¶
Processor name: relative-link
This processor will find any relative links (a link that doesn’t start with http:
), and prepend the link with a Django template placeholder.
When the resulting HTML is rendered with Django, the Django system can insert the root URL into the template placeholder for correct rendering.
The default HTML for relative links is:
<a href='{{ "{{ base_path }}" }}{{ link_path }}{{ link_query }}'>{{ text }}</a>
Using the following example tag:
Check out this [resource](resource/134).
The resulting HTML would be:
<p>Check out this <a href="{{ base_path }}resource/134">resource</a>.</p>
Overriding HTML for Relative Links¶
When overriding the HTML for relative links, the following Jinja2 placeholders are available:
{{ link_path }}
- The given link URL.{{ link_query }}
- The given link query parameters.
Example
For this example, we wish to create HTML to be used in a static site system (not Django). The relative link processor should append the website’s URL to each link.
For example, providing the following HTML template:
http://www.example.com/{{ link_path }}{{ link_query }}
with the following Markdown:
Check out this [resource](resource/556).
would result in:
<p>Check out this <a href="http://www.example.com/resource/556">resource</a>.</p>