fairdm.utils.markdown#

Markdown rendering with HTML sanitisation.

Module Contents#

Functions#

markdownify

Render markdown to HTML that is safe to insert into a page.

API#

markdownify(content)[source]#

Render markdown to HTML that is safe to insert into a page.

Markdown authored by users may contain raw HTML, so the rendered output is sanitised before it is returned: scripts, event-handler attributes and dangerous URL schemes are stripped, and links gain rel="noopener noreferrer". The extensions applied come from settings.FAIRDM_MARKDOWN_EXTENSIONS.

Both the safe_markdown template filter and the editor’s live preview render through this function, so a preview always matches the page.

Args: content: The markdown source. None renders as an empty string.

Returns: The sanitised HTML.

Example: >>> markdownify(“bold ”) ‘

bold

’