feat(core): move markdown parser py-markdown -> markdown-it
py-markdown was missing a lot of the common/gfm items. ref: #14 #96 #93 #95 #90 #250 #270
This commit is contained in:
@ -1,8 +1,17 @@
|
||||
import markdown as md
|
||||
import re
|
||||
|
||||
from markdown_it import MarkdownIt
|
||||
|
||||
from mdit_py_plugins import admon, footnote, tasklists
|
||||
|
||||
from pygments import highlight
|
||||
from pygments.formatters.html import HtmlFormatter
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
|
||||
|
||||
class TicketMarkdown:
|
||||
"""Ticket and Comment markdown functions
|
||||
|
||||
@ -10,11 +19,43 @@ class TicketMarkdown:
|
||||
"""
|
||||
|
||||
|
||||
def highlight_func(self, code: str, lang: str, _) -> str | None:
|
||||
"""Use pygments for code high lighting"""
|
||||
|
||||
if not lang:
|
||||
|
||||
return None
|
||||
|
||||
lexer = get_lexer_by_name(lang)
|
||||
|
||||
formatter = HtmlFormatter(style='vs', cssclass='codehilite')
|
||||
|
||||
return highlight(code, lexer, formatter)
|
||||
|
||||
|
||||
def render_markdown(self, markdown_text):
|
||||
"""Render Markdown
|
||||
|
||||
implemented using https://markdown-it-py.readthedocs.io/en/latest/index.html
|
||||
|
||||
Args:
|
||||
markdown_text (str): Markdown text
|
||||
|
||||
Returns:
|
||||
str: HTML text
|
||||
"""
|
||||
|
||||
markdown_text = self.ticket_reference(markdown_text)
|
||||
|
||||
return md.markdown(markdown_text, extensions=['markdown.extensions.fenced_code', 'codehilite'])
|
||||
md = (
|
||||
MarkdownIt(
|
||||
config = "commonmark",
|
||||
options_update={
|
||||
'highlight': self.highlight_func
|
||||
}
|
||||
)
|
||||
|
||||
return md.render(markdown_text)
|
||||
|
||||
|
||||
def build_ticket_html(self, match):
|
||||
|
@ -1,7 +1,7 @@
|
||||
from django import template
|
||||
from django.template.defaultfilters import stringfilter
|
||||
|
||||
import markdown as md
|
||||
from core.models.ticket.markdown import TicketMarkdown
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@ -9,7 +9,13 @@ register = template.Library()
|
||||
@register.filter()
|
||||
@stringfilter
|
||||
def markdown(value):
|
||||
return md.markdown(value, extensions=['markdown.extensions.fenced_code', 'codehilite'])
|
||||
|
||||
if not value:
|
||||
value = None
|
||||
|
||||
markdown = TicketMarkdown()
|
||||
|
||||
return markdown.render_markdown(value)
|
||||
|
||||
@register.filter()
|
||||
@stringfilter
|
||||
|
@ -45,6 +45,8 @@ Centurion ERP contains the following modules:
|
||||
|
||||
- History
|
||||
|
||||
- [Markdown](./user/core/markdown.md)
|
||||
|
||||
- [Multi-Tenant](./development/api/models/access_organization_permission_checking.md#permission-checking)
|
||||
|
||||
- [Single Sign-On {SSO}](./user/configuration.md#single-sign-on)
|
||||
|
26
docs/projects/centurion_erp/user/core/markdown.md
Normal file
26
docs/projects/centurion_erp/user/core/markdown.md
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
title: Markdown
|
||||
description: Markdown Documentation as part of the Core Module for Centurion ERP by No Fuss Computing
|
||||
date: 2024-06-07
|
||||
template: project.html
|
||||
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp
|
||||
---
|
||||
|
||||
All Text fields, that is those that are multi-lined support markdown text.
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
- CommonMark Markdown
|
||||
|
||||
- Tables
|
||||
|
||||
- Strikethrough
|
||||
|
||||
- Code highlighting
|
||||
|
||||
- Admonitions
|
||||
|
||||
- Linkify
|
||||
|
||||
- Task Lists
|
@ -190,6 +190,8 @@ nav:
|
||||
|
||||
- projects/centurion_erp/user/core/index.md
|
||||
|
||||
- projects/centurion_erp/user/core/markdown.md
|
||||
|
||||
- projects/centurion_erp/user/core/tickets.md
|
||||
|
||||
- ITAM:
|
||||
|
@ -18,8 +18,11 @@ drf-spectacular[sidecar]==0.27.2
|
||||
|
||||
django_split_settings==1.3.1
|
||||
|
||||
markdown==3.6
|
||||
Pygments
|
||||
markdown-it-py[plugins]==3.0.0
|
||||
markdown-it-py[linkify]==3.0.0
|
||||
Pygments==2.18.0
|
||||
|
||||
|
||||
|
||||
celery==5.4.0
|
||||
django-celery-results==2.5.1
|
||||
|
Reference in New Issue
Block a user