Deprecate magic words

This commit is contained in:
Yusur 2021-10-17 18:02:29 +02:00
parent 99af43d499
commit 01476fff5d
2 changed files with 22 additions and 11 deletions

22
app.py
View file

@ -11,12 +11,16 @@ Application is kept compact, with all its core in a single file.
Extensions are supported (?), kept in extensions/ folder.
'''
#### IMPORTS ####
from flask import (
Flask, Markup, abort, flash, g, jsonify, make_response, redirect, request,
render_template, send_from_directory)
from werkzeug.routing import BaseConverter
from peewee import *
import datetime, re, markdown, uuid, json, importlib, sys, hashlib, html, os, csv, random
import (
csv, datetime, hashlib, html, importlib, json, markdown, os, random, re,
sys, uuid, warnings)
from functools import lru_cache, partial
from urllib.parse import quote
from configparser import ConfigParser
@ -399,8 +403,10 @@ def expand_magic_words(text):
'''
return re.sub(MAGIC_RE, _replace_magic_word, text)
def md(text, expand_magic=True, toc=True):
def md(text, expand_magic=False, toc=True):
if expand_magic:
# DEPRECATED seeking for a better solution.
warnings.warn('Magic words are no more supported.', DeprecationWarning)
text = expand_magic_words(text)
extensions = ['tables', 'footnotes', 'fenced_code', 'sane_lists']
if markdown_strikethrough:
@ -409,12 +415,6 @@ def md(text, expand_magic=True, toc=True):
extensions.append('toc')
return markdown.Markdown(extensions=extensions).convert(text)
# unused, MD already adds anchors by itself
#def make_header_anchor(match):
# tagname, tagattrs, text = match.group(1), match.group(2), match.group(3)
# anchor = quote(remove_tags(text, False)).replace('.', '.2E').replace('%', '.')
# return '<{0} id="{3}"{1}>{2}</{0}>'.format(tagname, tagattrs, text, anchor)
def remove_tags(text, convert=True, headings=True):
if headings:
text = re.sub(r'\#[^\n]*', '', text)
@ -423,7 +423,7 @@ def remove_tags(text, convert=True, headings=True):
return re.sub(r'<.*?>|\{\{.*?\}\}', '', text)
### Magic words ###
### Magic words (deprecated!) ###
def expand_backto(pageid):
p = Page[pageid]
@ -513,7 +513,6 @@ forbidden_urls = [
'protect', 'kt', 'embed'
]
app = Flask(__name__)
app.secret_key = 'qrdldCcvamtdcnidmtasegasdsedrdqvtautar'
app.url_map.converters['slug'] = SlugConverter
@ -572,6 +571,9 @@ def error_404(body):
def error_403(body):
return render_template('forbidden.html'), 403
@app.errorhandler(500)
def error_400(body):
return render_template('badrequest.html'), 400
# Middle point during page editing.
def savepoint(form, is_preview=False):

View file

@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block title %}Bad Request - {{ app_name }}{% endblock %}
{% block content %}
<h1>Bad request</h1>
<p>You sent a request the server cant understand. If you entered the URL manually please check your spelling and try again.</p>
{% endblock %}