mirror of
https://codeberg.org/dribdat/dribdat.git
synced 2026-03-23 12:23:33 +00:00
Use markdown_it
This commit is contained in:
parent
e4178a3d3e
commit
211606796b
6 changed files with 54 additions and 42 deletions
|
|
@ -7,7 +7,6 @@ import bleach
|
|||
import logging
|
||||
from pyquery import PyQuery as pq # noqa: N813
|
||||
from base64 import b64decode
|
||||
from flask_misaka import markdown
|
||||
from bleach.sanitizer import ALLOWED_ATTRIBUTES
|
||||
from urllib.parse import quote_plus
|
||||
from .apievents import (
|
||||
|
|
@ -16,7 +15,7 @@ from .apievents import (
|
|||
fetch_commits_gitea,
|
||||
)
|
||||
from .utils import (
|
||||
sanitize_url, load_presets, load_yaml_presets, fix_relative_links
|
||||
sanitize_url, load_presets, load_yaml_presets, fix_relative_links, markdownit
|
||||
)
|
||||
from future.standard_library import install_aliases
|
||||
install_aliases()
|
||||
|
|
@ -24,7 +23,6 @@ install_aliases()
|
|||
# In seconds, how long to wait for API response
|
||||
REQUEST_TIMEOUT = 10
|
||||
|
||||
|
||||
def FetchStageConfig(url, top_element='stages', by_col='name'):
|
||||
"""Download a remote YAML stages configuration."""
|
||||
if not url.startswith('http:') and not url.startswith('https:'):
|
||||
|
|
@ -421,7 +419,7 @@ def FetchWebCodiMD(text, url):
|
|||
obj = {}
|
||||
obj['type'] = 'Markdown'
|
||||
obj['name'] = ptitle.text()
|
||||
obj['description'] = markdown(content)
|
||||
obj['description'] = markdownit(content)
|
||||
obj['source_url'] = url
|
||||
obj['logo_icon'] = 'outdent'
|
||||
return obj
|
||||
|
|
|
|||
|
|
@ -3,13 +3,11 @@
|
|||
|
||||
from flask import Flask, render_template
|
||||
from flask_cors import CORS
|
||||
from flask_misaka import Misaka
|
||||
from flask_mailman import Mail
|
||||
from flask_talisman import Talisman
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from micawber.providers import bootstrap_basic
|
||||
from whitenoise import WhiteNoise
|
||||
from datetime import datetime
|
||||
from urllib.parse import quote_plus
|
||||
from dribdat import commands, public, admin
|
||||
from dribdat.assets import assets # noqa: I005
|
||||
|
|
@ -22,7 +20,7 @@ from dribdat.extensions import (
|
|||
migrate,
|
||||
)
|
||||
from dribdat.settings import ProdConfig # noqa: I005
|
||||
from dribdat.utils import timesince
|
||||
from dribdat.utils import timesince, markdownit
|
||||
from dribdat.onebox import make_oembedplus
|
||||
from pytz import timezone
|
||||
|
||||
|
|
@ -147,8 +145,11 @@ def register_filters(app):
|
|||
"""Register filters for templates."""
|
||||
#
|
||||
# Conversion of Markdown to HTML
|
||||
Misaka(app, autolink=True, fenced_code=True,
|
||||
strikethrough=True, tables=True)
|
||||
@app.template_filter()
|
||||
def markdown(value):
|
||||
return markdownit(value)
|
||||
|
||||
#Misaka(app, autolink=True, fenced_code=True, strikethrough=True, tables=True)
|
||||
|
||||
# Registration of handlers for micawber
|
||||
app.oembed_providers = bootstrap_basic()
|
||||
|
|
|
|||
|
|
@ -16,6 +16,15 @@ from random import SystemRandom
|
|||
|
||||
import re, string
|
||||
|
||||
from markdown_it import MarkdownIt
|
||||
|
||||
# Instantiate Markdown parser
|
||||
md = MarkdownIt()
|
||||
|
||||
def markdownit(content):
|
||||
""" Converts a value to Markdown """
|
||||
return md.render(content)
|
||||
|
||||
def strtobool(text):
|
||||
"""Truthy conversion as per PEP 632."""
|
||||
tls = str(text).lower().strip()
|
||||
|
|
|
|||
64
poetry.lock
generated
64
poetry.lock
generated
|
|
@ -972,21 +972,6 @@ alembic = ">=1.9.0"
|
|||
Flask = ">=0.9"
|
||||
Flask-SQLAlchemy = ">=1.0"
|
||||
|
||||
[[package]]
|
||||
name = "flask-misaka"
|
||||
version = "1.0.1"
|
||||
description = "A pleasant interface between the Flask web framework and the Misaka Markdown parser."
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "Flask-Misaka-1.0.1.tar.gz", hash = "sha256:5dc58780b79666c107bdd301764b658d56a97a22af06e716b281d641a98a29fa"},
|
||||
{file = "Flask_Misaka-1.0.1-py3-none-any.whl", hash = "sha256:10a39185b4d3f1bd306ff827deb8d20c8121176e6b26c3d962c15845655f43ce"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
markupsafe = "*"
|
||||
misaka = ">=2.0,<3.0"
|
||||
|
||||
[[package]]
|
||||
name = "flask-openapi3"
|
||||
version = "3.1.3"
|
||||
|
|
@ -1755,6 +1740,26 @@ files = [
|
|||
{file = "legacy_cgi-2.6.1.tar.gz", hash = "sha256:f2ada99c747c3d72a473a6aaff6259a61f226b06fe9f3106e495ab83fd8f7a42"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linkify-it-py"
|
||||
version = "2.0.3"
|
||||
description = "Links recognition library with FULL unicode support."
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "linkify-it-py-2.0.3.tar.gz", hash = "sha256:68cda27e162e9215c17d786649d1da0021a451bdc436ef9e0fa0ba5234b9b048"},
|
||||
{file = "linkify_it_py-2.0.3-py3-none-any.whl", hash = "sha256:6bcbc417b0ac14323382aef5c5192c0075bf8a9d6b41820a2b66371eac6b6d79"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
uc-micro-py = "*"
|
||||
|
||||
[package.extras]
|
||||
benchmark = ["pytest", "pytest-benchmark"]
|
||||
dev = ["black", "flake8", "isort", "pre-commit", "pyproject-flake8"]
|
||||
doc = ["myst-parser", "sphinx", "sphinx-book-theme"]
|
||||
test = ["coverage", "pytest", "pytest-cov"]
|
||||
|
||||
[[package]]
|
||||
name = "lxml"
|
||||
version = "5.3.0"
|
||||
|
|
@ -2069,19 +2074,6 @@ files = [
|
|||
{file = "micawber-0.5.6.tar.gz", hash = "sha256:20dc4e074c17a741880b489cf2558845c050987f5b796c8ff07ea2ff011a8c8d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "misaka"
|
||||
version = "2.1.1"
|
||||
description = "A CFFI binding for Hoedown, a markdown parsing library."
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "misaka-2.1.1.tar.gz", hash = "sha256:62f35254550095d899fc2ab8b33e156fc5e674176f074959cbca43cf7912ecd7"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
cffi = ">=1.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "mkdocs-material-extensions"
|
||||
version = "1.3.1"
|
||||
|
|
@ -3253,6 +3245,20 @@ files = [
|
|||
{file = "tzdata-2024.2.tar.gz", hash = "sha256:7d85cc416e9382e69095b7bdf4afd9e3880418a2413feec7069d533d6b4e31cc"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uc-micro-py"
|
||||
version = "1.0.3"
|
||||
description = "Micro subset of unicode data files for linkify-it-py projects."
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "uc-micro-py-1.0.3.tar.gz", hash = "sha256:d321b92cff673ec58027c04015fcaa8bb1e005478643ff4a500882eaab88c48a"},
|
||||
{file = "uc_micro_py-1.0.3-py3-none-any.whl", hash = "sha256:db1dffff340817673d7b466ec86114a9dc0e9d4d9b5ba229d9d60e5c12600cd5"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
test = ["coverage", "pytest", "pytest-cov"]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "1.26.20"
|
||||
|
|
@ -3510,4 +3516,4 @@ testing = ["coverage[toml]", "zope.event", "zope.testing"]
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.9,<4"
|
||||
content-hash = "afbe51e07b1eebf0d479a53337fea85ccece703fc8cd6374a008fd22c920abba"
|
||||
content-hash = "58c698f93bf65093a30e23edb14b377a9abef0ea61354a3940a954b972d6596f"
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ flask-hashing = "^1.1"
|
|||
flask-login = ">=0.4.0"
|
||||
flask-mailman = "^0.3"
|
||||
flask-migrate = "^4"
|
||||
flask-misaka = "^1"
|
||||
flask-sqlalchemy = ">=2.3.2"
|
||||
flask-talisman = ">=0.7.0"
|
||||
flask-wtf = ">=1.0.1"
|
||||
|
|
@ -53,6 +52,8 @@ whitenoise = "^5.3"
|
|||
wtforms = "^3.0"
|
||||
openai = "^1.35.13"
|
||||
icalendar = "^6.0.1"
|
||||
markdown-it-py = "^3.0.0"
|
||||
linkify-it-py = "^2.0.3"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
factory-boy = "*"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
# Included because many Paas's require a requirements.txt file in the project root
|
||||
|
||||
# Explicitly add misaka due to buildpack detection on Heroku (cffi deployment)
|
||||
misaka>=2.1.1
|
||||
|
||||
# Use PyPi simple repo for automated deployments
|
||||
-i https://pypi.org/simple
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue