mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-18 17:20:15 -04:00
feat(destinations): add strikethrough extension
This commit is contained in:
parent
cef0799efd
commit
56464ec231
|
@ -2,10 +2,14 @@ from markdown import markdown
|
|||
|
||||
from django import template
|
||||
|
||||
from .strikethrough import StrikethroughExtension
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter(name="markdown")
|
||||
def convert_markdown(text: str):
|
||||
"""Convert text to markdown HTML."""
|
||||
return markdown(text, extensions=["extra", "codehilite", "smarty"])
|
||||
return markdown(
|
||||
text, extensions=["extra", "codehilite", "smarty", StrikethroughExtension()]
|
||||
)
|
||||
|
|
|
@ -5,7 +5,11 @@ from django import template
|
|||
|
||||
register = template.Library()
|
||||
|
||||
tags = ALLOWED_TAGS + ["h" + str(i) for i in range(1, 7)] + ["div", "p", "pre", "span"]
|
||||
tags = (
|
||||
ALLOWED_TAGS
|
||||
+ ["h" + str(i) for i in range(1, 7)]
|
||||
+ ["div", "p", "pre", "span", "s"]
|
||||
)
|
||||
attrs = {"*": ["class"]}
|
||||
|
||||
|
||||
|
|
39
tjdests/apps/destinations/templatetags/strikethrough.py
Normal file
39
tjdests/apps/destinations/templatetags/strikethrough.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# pylint: skip-file
|
||||
"""Markdown Strikethrough Extension
|
||||
Extends the Python-Markdown library to support strikethrough text.
|
||||
Given the text:
|
||||
The molecular composition of water is ~~HCl~~.
|
||||
Will output:
|
||||
<p>The molecular composition of water is <s>HCl</s>.</p>
|
||||
Based on Markdown Subscript Extension
|
||||
:website: https://github.com/jambonrose/markdown_subscript_extension
|
||||
:copyright: Copyright 2014-2018 Andrew Pinkham
|
||||
:license: Simplified BSD, see LICENSE for details.
|
||||
This version by Shreyas Mayya.
|
||||
Pylint was skipped here because python-markdown appears to require
|
||||
a specific syntax which is at odds with pylint's ruleset.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from markdown import Extension
|
||||
from markdown.inlinepatterns import SimpleTagPattern
|
||||
|
||||
# match ~~, at least one character that is not ~, and ~~ again
|
||||
SUBSCRIPT_RE = r"(\~\~)([^(\~)]+)(\~\~)"
|
||||
|
||||
|
||||
def makeExtension(*args, **kwargs): # noqa: N802
|
||||
"""Inform Markdown of the existence of the extension."""
|
||||
return StrikethroughExtension(*args, **kwargs)
|
||||
|
||||
|
||||
class StrikethroughExtension(Extension):
|
||||
"""Extension: text between ~~ characters will be struck through."""
|
||||
|
||||
def extendMarkdown(self, md, md_globals): # noqa: N802
|
||||
"""Insert 's' pattern before 'not_strong' pattern."""
|
||||
md.inlinePatterns.add(
|
||||
"strikethrough", SimpleTagPattern(SUBSCRIPT_RE, "s"), "<not_strong"
|
||||
)
|
Loading…
Reference in New Issue
Block a user