Skip to content

Commit

Permalink
Add flask misaka for markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks committed Oct 31, 2023
1 parent 061958c commit 3475d84
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
7 changes: 3 additions & 4 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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"
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import random
import string
from PIL import Image, ImageOps
import markdown
import requests


Expand Down Expand Up @@ -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)
45 changes: 29 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion templates/note.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ <h2 class="font-semibold text-2xl mb-6 pb-4 border-b">{{note.title}}</h2>
<img src="{{ featured_image | safe }}" />
</div>
{% endif %}
<article class="prose">{{note.content | markdown | safe}}</article>
<article class="prose">{{note.content | markdown}}</article>
{% endblock %}

0 comments on commit 3475d84

Please sign in to comment.