aboutsummaryrefslogtreecommitdiffstats
path: root/pysite
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-06-08 17:56:15 +0100
committerGravatar Gareth Coles <[email protected]>2018-06-08 17:56:15 +0100
commit60838b789f7e1a307751e13f45e62495dd65bd10 (patch)
tree4d4d86da08c5eb54ba2976d371a7da593311bafa /pysite
parentFix test (diff)
Fix RST table styling and add fira-code text role
Diffstat (limited to 'pysite')
-rw-r--r--pysite/rst/__init__.py9
-rw-r--r--pysite/rst/roles.py13
2 files changed, 20 insertions, 2 deletions
diff --git a/pysite/rst/__init__.py b/pysite/rst/__init__.py
index 54dbba9c..e58fbe8c 100644
--- a/pysite/rst/__init__.py
+++ b/pysite/rst/__init__.py
@@ -5,7 +5,7 @@ from docutils.parsers.rst.directives import register_directive
from docutils.parsers.rst.roles import register_canonical_role
from pysite.rst.directives import ButtonDirective
-from pysite.rst.roles import icon_role, page_role, url_for_role
+from pysite.rst.roles import fira_code_role, icon_role, page_role, url_for_role
RST_TEMPLATE = """.. contents::
@@ -14,6 +14,8 @@ RST_TEMPLATE = """.. contents::
CONTENTS_REGEX = re.compile(r"""<div class=\"contents topic\" id=\"contents\">(.*?)</div>""", re.DOTALL)
HREF_REGEX = re.compile(r"""<a class=\"reference internal\" href=\"(.*?)\".*?>(.*?)</a>""")
+TABLE_FRAGMENT = """<table class="uk-table uk-table-divider table-bordered uk-table-striped">"""
+
def render(rst: str, link_headers=True):
if link_headers:
@@ -35,7 +37,6 @@ def render(rst: str, link_headers=True):
if match:
data["html"] = html.replace(match.group(0), "") # Remove the contents from the document HTML
-
depth = 0
headers = []
current_header = {}
@@ -93,9 +94,13 @@ def render(rst: str, link_headers=True):
current_header["sub_headers"] = sub_headers
data["headers"] = headers
+
+ data["html"] = data["html"].replace("<table>", TABLE_FRAGMENT) # Style the tables properly
+
return data
+register_canonical_role("fira_code", fira_code_role)
register_canonical_role("icon", icon_role)
register_canonical_role("page", page_role)
register_canonical_role("url_for", url_for_role)
diff --git a/pysite/rst/roles.py b/pysite/rst/roles.py
index abade243..d83f07f9 100644
--- a/pysite/rst/roles.py
+++ b/pysite/rst/roles.py
@@ -110,3 +110,16 @@ def page_role(_role: str, rawtext: str, text: str, lineno: int, inliner: Inliner
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"""<span class="fira-code">{text}</span>"""
+ node = nodes.raw(html, html, format="html", **options)
+
+ return [node], []