markdown: make header slugs unique in every thread
This commit is contained in:
parent
eae66986a3
commit
007b2111e5
|
@ -67,7 +67,7 @@
|
|||
{{ post_actions(c) }}
|
||||
</div>
|
||||
|
||||
{{ c.text|md }}
|
||||
{{ c.text|md(c.id) }}
|
||||
{{ widget_attachments.attachments(c) }}
|
||||
|
||||
{% if c.author.signature %}
|
||||
|
|
|
@ -3,7 +3,7 @@ from markupsafe import Markup
|
|||
from markdown import markdown
|
||||
from markdown.extensions.codehilite import CodeHiliteExtension
|
||||
from markdown.extensions.footnotes import FootnoteExtension
|
||||
from markdown.extensions.toc import TocExtension
|
||||
from markdown.extensions.toc import TocExtension, slugify_unicode
|
||||
from bleach import clean
|
||||
from app.utils.bleach_allowlist import markdown_tags, markdown_attrs
|
||||
|
||||
|
@ -15,8 +15,14 @@ from app.utils.markdown_extensions.media import MediaExtension
|
|||
from app.utils.markdown_extensions.gallery import GalleryExtension
|
||||
|
||||
|
||||
def slug(prefix, text, sep):
|
||||
if prefix is None:
|
||||
return slugify_unicode(text, sep)
|
||||
else:
|
||||
return str(prefix) + sep + slugify_unicode(text, sep)
|
||||
|
||||
@app.template_filter('md')
|
||||
def md(text):
|
||||
def md(text, prefix=None):
|
||||
"""
|
||||
Converts markdown to html5
|
||||
"""
|
||||
|
@ -33,7 +39,7 @@ def md(text):
|
|||
FootnoteExtension(UNIQUE_IDS=True),
|
||||
HardBreakExtension(),
|
||||
LinkifyExtension(),
|
||||
TocExtension(baselevel=2),
|
||||
TocExtension(baselevel=2, slugify=lambda *args: slug(prefix, *args)),
|
||||
PCLinkExtension(),
|
||||
MediaExtension(),
|
||||
GalleryExtension(),
|
||||
|
|
Loading…
Reference in New Issue