From 3475d84d675ad6653b85ec0ef6bc2a61f3acbb37 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Tue, 31 Oct 2023 13:55:03 +0000 Subject: [PATCH] Add flask misaka for markdown --- app/__init__.py | 7 +++---- app/utils.py | 5 ----- poetry.lock | 45 +++++++++++++++++++++++++++++---------------- pyproject.toml | 2 +- templates/note.html | 2 +- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index f3b8967..b91a3cf 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,6 +1,6 @@ from flask import Flask, abort, g, render_template -# from flask_misaka import Misaka +from flask_misaka import Misaka from app.supabase import ( supabase, session_context_processor, @@ -14,11 +14,11 @@ from app.auth import auth from app.account import account from app.notes import notes -from app.utils import humanize_ts, mkdown, resize_image +from app.utils import humanize_ts, resize_image app = Flask(__name__, template_folder="../templates", static_folder="../static") -# Misaka(app) +Misaka(app) # Set the secret key to some random bytes. Keep this really secret! app.secret_key = b"c8af64a6a0672678800db3c5a3a8d179f386e083f559518f2528202a4b7de8f8" @@ -27,7 +27,6 @@ app.register_blueprint(account) app.register_blueprint(notes) app.jinja_env.filters["humanize"] = humanize_ts -app.jinja_env.filters["markdown"] = mkdown @app.teardown_appcontext diff --git a/app/utils.py b/app/utils.py index 1a712da..d48f6d9 100644 --- a/app/utils.py +++ b/app/utils.py @@ -4,7 +4,6 @@ import random import string from PIL import Image, ImageOps -import markdown import requests @@ -74,7 +73,3 @@ def humanize_ts(timestamp=False, fmt=False): if day_diff < 182: return str(int(day_diff / 30)) + " months ago" return datetm.strftime(fmt or "%b %d %Y") - - -def mkdown(text: str): - return markdown.markdown(text) diff --git a/poetry.lock b/poetry.lock index aec4084..39246d8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -560,6 +560,21 @@ Werkzeug = ">=2.3.7" async = ["asgiref (>=3.2)"] dotenv = ["python-dotenv"] +[[package]] +name = "flask-misaka" +version = "1.0.0" +description = "A pleasant interface between the Flask web framework and the Misaka Markdown parser." +optional = false +python-versions = "*" +files = [ + {file = "Flask-Misaka-1.0.0.tar.gz", hash = "sha256:f423c3beb5502742a57330a272f81d53223f6f99d45cc45b03926e3a3034f589"}, + {file = "Flask_Misaka-1.0.0-py3-none-any.whl", hash = "sha256:d0cfb0efd9e5afacda76defd4a605a68390f4fb1bef283c71534fd3ce0d3efb5"}, +] + +[package.dependencies] +Flask = ">=0.7" +misaka = ">=2.0,<3.0" + [[package]] name = "flask-wtf" version = "1.2.1" @@ -813,21 +828,6 @@ completion = ["shtab"] docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] testing = ["pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-mypy (>=0.9.1)", "pytest-ruff"] -[[package]] -name = "markdown" -version = "3.5" -description = "Python implementation of John Gruber's Markdown." -optional = false -python-versions = ">=3.8" -files = [ - {file = "Markdown-3.5-py3-none-any.whl", hash = "sha256:4afb124395ce5fc34e6d9886dab977fd9ae987fc6e85689f08278cf0c69d4bf3"}, - {file = "Markdown-3.5.tar.gz", hash = "sha256:a807eb2e4778d9156c8f07876c6e4d50b5494c5665c4834f67b06459dfd877b3"}, -] - -[package.extras] -docs = ["mdx-gh-links (>=0.2)", "mkdocs (>=1.5)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"] -testing = ["coverage", "pyyaml"] - [[package]] name = "markupsafe" version = "2.1.3" @@ -887,6 +887,19 @@ files = [ {file = "MarkupSafe-2.1.3.tar.gz", hash = "sha256:af598ed32d6ae86f1b747b82783958b1a4ab8f617b06fe68795c7f026abbdcad"}, ] +[[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 = "more-itertools" version = "10.1.0" @@ -2010,4 +2023,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "abdc6a590a20da8ba3fa2af2084141f676f9003583d33df4dc255f0cf1839d18" +content-hash = "558be51e075b90cb415b1443d8822aef59550d8cbe54b59acd1576f3f9f13d03" diff --git a/pyproject.toml b/pyproject.toml index 3465deb..54c17b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ poetry-dotenv-plugin = "^0.2.0" gunicorn = "^21.2.0" pillow = "^10.0.1" requests = "^2.31.0" -markdown = "^3.4.4" +flask-misaka = "^1.0.0" [tool.flake8] ignore = ["F401", "E402"] diff --git a/templates/note.html b/templates/note.html index 3b9bbbc..94a91fb 100644 --- a/templates/note.html +++ b/templates/note.html @@ -20,5 +20,5 @@

{{note.title}}

{% endif %} -
{{note.content | markdown | safe}}
+
{{note.content | markdown}}
{% endblock %} \ No newline at end of file