mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-09 17:13:45 +01:00
parent
c1edea4dc3
commit
32372e8e86
@ -25,18 +25,14 @@ from flask_flatpages import FlatPages
|
||||
from flask_babel import Babel
|
||||
from flask_login import logout_user, current_user, LoginManager
|
||||
import os, redis
|
||||
from app.markdown import init_markdown, MARKDOWN_EXTENSIONS, MARKDOWN_EXTENSION_CONFIG
|
||||
|
||||
|
||||
app = Flask(__name__, static_folder="public/static")
|
||||
app.config["FLATPAGES_ROOT"] = "flatpages"
|
||||
app.config["FLATPAGES_EXTENSION"] = ".md"
|
||||
app.config["FLATPAGES_MARKDOWN_EXTENSIONS"] = ["fenced_code", "tables", "codehilite", 'toc']
|
||||
app.config["FLATPAGES_EXTENSION_CONFIG"] = {
|
||||
"fenced_code": {},
|
||||
"tables": {},
|
||||
"codehilite": {
|
||||
"guess_lang": False,
|
||||
}
|
||||
}
|
||||
app.config["FLATPAGES_MARKDOWN_EXTENSIONS"] = MARKDOWN_EXTENSIONS
|
||||
app.config["FLATPAGES_EXTENSION_CONFIG"] = MARKDOWN_EXTENSION_CONFIG
|
||||
app.config.from_pyfile(os.environ["FLASK_CONFIG"])
|
||||
|
||||
r = redis.Redis.from_url(app.config["REDIS_URL"])
|
||||
@ -55,6 +51,7 @@ gravatar = Gravatar(app,
|
||||
force_lower=False,
|
||||
use_ssl=True,
|
||||
base_url=None)
|
||||
init_markdown(app)
|
||||
|
||||
login_manager = LoginManager()
|
||||
login_manager.init_app(app)
|
||||
@ -69,8 +66,7 @@ if not app.debug and app.config["MAIL_UTILS_ERROR_SEND_TO"]:
|
||||
app.logger.addHandler(build_handler(app))
|
||||
|
||||
|
||||
from app.utils.markdown import init_app
|
||||
init_app(app)
|
||||
|
||||
|
||||
# @babel.localeselector
|
||||
# def get_locale():
|
||||
|
@ -21,7 +21,7 @@ from flask_wtf import FlaskForm
|
||||
from wtforms import *
|
||||
from wtforms.validators import *
|
||||
|
||||
from app.utils.markdown import render_markdown
|
||||
from app.markdown import render_markdown
|
||||
from app.models import *
|
||||
from app.tasks.emails import send_user_email
|
||||
from app.utils import rank_required, addAuditLog
|
||||
|
@ -19,7 +19,7 @@ from flask_login import current_user, login_required
|
||||
from sqlalchemy.sql.expression import func
|
||||
|
||||
from app import csrf
|
||||
from app.utils.markdown import render_markdown
|
||||
from app.markdown import render_markdown
|
||||
from app.models import Tag, PackageState, PackageType, Package, db, PackageRelease, Permission, ForumTopic, MinetestRelease, APIToken, PackageScreenshot, License, ContentWarning, User
|
||||
from app.querybuilder import QueryBuilder
|
||||
from app.utils import is_package_page, get_int_or_abort
|
||||
|
@ -6,6 +6,9 @@ from bleach.linkifier import LinkifyFilter
|
||||
from bs4 import BeautifulSoup
|
||||
from markdown import Markdown
|
||||
from flask import Markup
|
||||
from markdown.extensions import Extension
|
||||
from markdown.inlinepatterns import SimpleTagInlineProcessor
|
||||
|
||||
|
||||
# Based on
|
||||
# https://github.com/Wenzil/mdx_bleach/blob/master/mdx_bleach/whitelist.py
|
||||
@ -25,7 +28,7 @@ ALLOWED_TAGS = [
|
||||
"a",
|
||||
"img",
|
||||
"table", "thead", "tbody", "tr", "th", "td",
|
||||
"div", "span",
|
||||
"div", "span", "del", "s",
|
||||
]
|
||||
|
||||
ALLOWED_CSS = [
|
||||
@ -68,11 +71,30 @@ def render_markdown(source):
|
||||
return cleaner.clean(html)
|
||||
|
||||
|
||||
def init_app(app):
|
||||
class DelInsExtension(Extension):
|
||||
def extendMarkdown(self, md):
|
||||
del_proc = SimpleTagInlineProcessor(r'(\~\~)(.+?)(\~\~)', 'del')
|
||||
md.inlinePatterns.register(del_proc, 'del', 200)
|
||||
|
||||
ins_proc = SimpleTagInlineProcessor(r'(\+\+)(.+?)(\+\+)', 'ins')
|
||||
md.inlinePatterns.register(ins_proc, 'ins', 200)
|
||||
|
||||
|
||||
MARKDOWN_EXTENSIONS = ["fenced_code", "tables", "codehilite", "toc", DelInsExtension()]
|
||||
MARKDOWN_EXTENSION_CONFIG = {
|
||||
"fenced_code": {},
|
||||
"tables": {},
|
||||
"codehilite": {
|
||||
"guess_lang": False,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def init_markdown(app):
|
||||
global md
|
||||
|
||||
md = Markdown(extensions=app.config["FLATPAGES_MARKDOWN_EXTENSIONS"],
|
||||
extension_configs=app.config["FLATPAGES_EXTENSION_CONFIG"],
|
||||
md = Markdown(extensions=MARKDOWN_EXTENSIONS,
|
||||
extension_configs=MARKDOWN_EXTENSION_CONFIG,
|
||||
output_format="html5")
|
||||
|
||||
@app.template_filter()
|
@ -6,7 +6,7 @@ from flask_babel import format_timedelta, gettext
|
||||
from urllib.parse import urlparse
|
||||
from datetime import datetime as dt
|
||||
|
||||
from .utils.markdown import get_headings
|
||||
from app.markdown import get_headings
|
||||
|
||||
|
||||
@app.context_processor
|
||||
|
Loading…
Reference in New Issue
Block a user