mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Stop nested quotes from crashing the website (#70)
This commit is contained in:
parent
7d8087b228
commit
96d2dc0a0d
1 changed files with 21 additions and 12 deletions
|
@ -15,7 +15,13 @@ rp = Royalprint("wikiview", __name__, url_prefix="/wiki/view", template_folder=t
|
|||
required_tables={Royal, WikiPage, WikiRevision})
|
||||
|
||||
|
||||
class WikiRenderError(Exception):
|
||||
"""An error occurred while trying to render the wiki page."""
|
||||
|
||||
|
||||
def prepare_page_markdown(page):
|
||||
if list(page.content).count(">") > 99:
|
||||
raise WikiRenderError("Too many nested quotes")
|
||||
converted_md = markdown2.markdown(page.content.replace("<", "<"),
|
||||
extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"])
|
||||
converted_md = re.sub(r"{https?://(?:www\.)?(?:youtube\.com/watch\?.*?&?v=|youtu.be/)([0-9A-Za-z-]+).*?}",
|
||||
|
@ -37,6 +43,7 @@ def prepare_page_markdown(page):
|
|||
|
||||
|
||||
def prepare_page(page):
|
||||
try:
|
||||
if page.format == "markdown":
|
||||
return f.render_template("wikiview_page.html",
|
||||
page=page,
|
||||
|
@ -49,6 +56,8 @@ def prepare_page(page):
|
|||
css=page.css)
|
||||
else:
|
||||
return error(500, f"Non esiste nessun handler in grado di preparare pagine con il formato {page.format}.")
|
||||
except WikiRenderError as e:
|
||||
return error(500, f"La pagina Wiki non può essere preparata a causa di un errore: {str(e)}")
|
||||
|
||||
|
||||
@rp.route("/")
|
||||
|
|
Loading…
Reference in a new issue