Deprecate magic words
This commit is contained in:
parent
99af43d499
commit
01476fff5d
2 changed files with 22 additions and 11 deletions
24
app.py
24
app.py
|
|
@ -11,12 +11,16 @@ Application is kept compact, with all its core in a single file.
|
||||||
Extensions are supported (?), kept in extensions/ folder.
|
Extensions are supported (?), kept in extensions/ folder.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
#### IMPORTS ####
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Flask, Markup, abort, flash, g, jsonify, make_response, redirect, request,
|
Flask, Markup, abort, flash, g, jsonify, make_response, redirect, request,
|
||||||
render_template, send_from_directory)
|
render_template, send_from_directory)
|
||||||
from werkzeug.routing import BaseConverter
|
from werkzeug.routing import BaseConverter
|
||||||
from peewee import *
|
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 functools import lru_cache, partial
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
@ -398,9 +402,11 @@ def expand_magic_words(text):
|
||||||
Unknown keywords are not replaced. Valid keywords with invalid arguments are replaced with nothing.
|
Unknown keywords are not replaced. Valid keywords with invalid arguments are replaced with nothing.
|
||||||
'''
|
'''
|
||||||
return re.sub(MAGIC_RE, _replace_magic_word, 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:
|
if expand_magic:
|
||||||
|
# DEPRECATED seeking for a better solution.
|
||||||
|
warnings.warn('Magic words are no more supported.', DeprecationWarning)
|
||||||
text = expand_magic_words(text)
|
text = expand_magic_words(text)
|
||||||
extensions = ['tables', 'footnotes', 'fenced_code', 'sane_lists']
|
extensions = ['tables', 'footnotes', 'fenced_code', 'sane_lists']
|
||||||
if markdown_strikethrough:
|
if markdown_strikethrough:
|
||||||
|
|
@ -409,12 +415,6 @@ def md(text, expand_magic=True, toc=True):
|
||||||
extensions.append('toc')
|
extensions.append('toc')
|
||||||
return markdown.Markdown(extensions=extensions).convert(text)
|
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):
|
def remove_tags(text, convert=True, headings=True):
|
||||||
if headings:
|
if headings:
|
||||||
text = re.sub(r'\#[^\n]*', '', text)
|
text = re.sub(r'\#[^\n]*', '', text)
|
||||||
|
|
@ -423,7 +423,7 @@ def remove_tags(text, convert=True, headings=True):
|
||||||
return re.sub(r'<.*?>|\{\{.*?\}\}', '', text)
|
return re.sub(r'<.*?>|\{\{.*?\}\}', '', text)
|
||||||
|
|
||||||
|
|
||||||
### Magic words ###
|
### Magic words (deprecated!) ###
|
||||||
|
|
||||||
def expand_backto(pageid):
|
def expand_backto(pageid):
|
||||||
p = Page[pageid]
|
p = Page[pageid]
|
||||||
|
|
@ -512,7 +512,6 @@ forbidden_urls = [
|
||||||
'stats', 'terms', 'privacy', 'easter', 'search', 'help', 'circles',
|
'stats', 'terms', 'privacy', 'easter', 'search', 'help', 'circles',
|
||||||
'protect', 'kt', 'embed'
|
'protect', 'kt', 'embed'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = 'qrdldCcvamtdcnidmtasegasdsedrdqvtautar'
|
app.secret_key = 'qrdldCcvamtdcnidmtasegasdsedrdqvtautar'
|
||||||
|
|
@ -572,6 +571,9 @@ def error_404(body):
|
||||||
def error_403(body):
|
def error_403(body):
|
||||||
return render_template('forbidden.html'), 403
|
return render_template('forbidden.html'), 403
|
||||||
|
|
||||||
|
@app.errorhandler(500)
|
||||||
|
def error_400(body):
|
||||||
|
return render_template('badrequest.html'), 400
|
||||||
|
|
||||||
# Middle point during page editing.
|
# Middle point during page editing.
|
||||||
def savepoint(form, is_preview=False):
|
def savepoint(form, is_preview=False):
|
||||||
|
|
|
||||||
9
templates/badrequest.html
Normal file
9
templates/badrequest.html
Normal 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 can’t understand. If you entered the URL manually please check your spelling and try again.</p>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue