From af54db6c136138c66cf5ca72419989525a0baa5c Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Tue, 7 Aug 2018 15:09:08 +0100 Subject: Initial project layout for django --- pysite/rst/roles.py | 125 ---------------------------------------------------- 1 file changed, 125 deletions(-) delete mode 100644 pysite/rst/roles.py (limited to 'pysite/rst/roles.py') diff --git a/pysite/rst/roles.py b/pysite/rst/roles.py deleted file mode 100644 index d83f07f9..00000000 --- a/pysite/rst/roles.py +++ /dev/null @@ -1,125 +0,0 @@ -from docutils import nodes -from docutils.parsers.rst.roles import set_classes -from docutils.parsers.rst.states import Inliner -from flask import url_for -from jinja2 import escape - - -def icon_role(_role: str, rawtext: str, text: str, lineno: int, inliner: Inliner, - options: dict = None, _content: dict = None): - if options is None: - options = {} - - set_classes(options) - - if "/" in text: - parts = [escape(x) for x in text.split("/")] - else: - msg = inliner.reporter.error("Icon specification must be in the form /", line=lineno) - prb = inliner.problematic(text, rawtext, msg) - - return [prb], [msg] - - if len(parts) != 2: - msg = inliner.reporter.error("Icon specification must be in the form /", line=lineno) - prb = inliner.problematic(text, rawtext, msg) - - return [prb], [msg] - else: - if parts[0] == "light": - weight = "fal" - elif parts[0] == "regular": - weight = "far" - elif parts[0] == "solid": - weight = "fas" - elif parts[0] == "branding": - weight = "fab" - else: - msg = inliner.reporter.error("Icon type must be one of light, regular, solid or branding", line=lineno) - prb = inliner.problematic(text, rawtext, msg) - - return [prb], [msg] - - html = f"""""" - - node = nodes.raw(html, html, format="html", **options) - return [node], [] - - -def url_for_role(_role: str, rawtext: str, text: str, lineno: int, inliner: Inliner, - options: dict = None, _content: dict = None): - if options is None: - options = {} - - set_classes(options) - - if "/" in text: - parts = [escape(x) for x in text.split("/")] - else: - msg = inliner.reporter.error("URL specification must be in the form /", line=lineno) - prb = inliner.problematic(text, rawtext, msg) - - return [prb], [msg] - - if len(parts) != 2: - msg = inliner.reporter.error("URL specification must be in the form /", line=lineno) - prb = inliner.problematic(text, rawtext, msg) - - return [prb], [msg] - else: - try: - url = url_for(parts[0]) - name = parts[1] - - html = f"""{name}""" - - node = nodes.raw(html, html, format="html", **options) - return [node], [] - except Exception as e: - msg = inliner.reporter.error(str(e), line=lineno) - prb = inliner.problematic(text, rawtext, msg) - - return [prb], [msg] - - -def page_role(_role: str, rawtext: str, text: str, lineno: int, inliner: Inliner, - options: dict = None, _content: dict = None): - if options is None: - options = {} - - set_classes(options) - - if "/" in text: - parts = [escape(x) for x in text.rsplit("/", 1)] - else: - msg = inliner.reporter.error("Page specification must be in the form /", line=lineno) - prb = inliner.problematic(text, rawtext, msg) - - return [prb], [msg] - - try: - url = url_for("wiki.page", page=parts[0]) - name = parts[1] - - html = f"""{name}""" - - node = nodes.raw(html, html, format="html", **options) - return [node], [] - except Exception as e: - msg = inliner.reporter.error(str(e), line=lineno) - prb = inliner.problematic(text, rawtext, msg) - - return [prb], [msg] - - -def fira_code_role(_role: str, rawtext: str, text: str, lineno: int, inliner: Inliner, - options: dict = None, _content: dict = None): - if options is None: - options = {} - - set_classes(options) - - html = f"""{text}""" - node = nodes.raw(html, html, format="html", **options) - - return [node], [] -- cgit v1.2.3