Skip to content
Snippets Groups Projects
Commit bde0cb09 authored by JBorrow's avatar JBorrow
Browse files

Updated renderer to use new versions as of py 3.10

parent 0d573dec
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ import yaml ...@@ -23,7 +23,7 @@ import yaml
def open_meta(filename="about_meta.yaml", data_dir="../data"): def open_meta(filename="about_meta.yaml", data_dir="../data"):
""" Read the meta file and return the associated data """ """ Read the meta file and return the associated data """
with open(f"{data_dir}/{filename}", "r") as handle: with open(f"{data_dir}/{filename}", "r") as handle:
return yaml.load(handle) return yaml.safe_load(handle)
def compile_markdown(data, data_dir="../data"): def compile_markdown(data, data_dir="../data"):
...@@ -50,6 +50,9 @@ class Parser(HTMLParser): ...@@ -50,6 +50,9 @@ class Parser(HTMLParser):
self.waiting_for_data = False self.waiting_for_data = False
def handle_starttag(self, tag, attrs): def handle_starttag(self, tag, attrs):
if len(attrs) == 0:
return
for attr in attrs: for attr in attrs:
if attr[0] == "id": if attr[0] == "id":
this_id = attr[1] this_id = attr[1]
......
...@@ -44,7 +44,7 @@ def get_associated_data(template_names, data_dir="../data"): ...@@ -44,7 +44,7 @@ def get_associated_data(template_names, data_dir="../data"):
# YAML Search # YAML Search
try: try:
with open(f"{data_dir}/{stub}.yaml", "r") as handle: with open(f"{data_dir}/{stub}.yaml", "r") as handle:
this_data = dict(yaml.load(handle), **this_data) this_data = dict(yaml.safe_load(handle), **this_data)
except FileNotFoundError: except FileNotFoundError:
pass pass
...@@ -104,7 +104,7 @@ def global_variables(active, data_dir="../data"): ...@@ -104,7 +104,7 @@ def global_variables(active, data_dir="../data"):
production of the processed navbar. """ production of the processed navbar. """
with open("{}/global.yaml".format(data_dir), "r") as handle: with open("{}/global.yaml".format(data_dir), "r") as handle:
raw = yaml.load(handle) # We need to process the navbar. raw = yaml.safe_load(handle) # We need to process the navbar.
return process_navbar(raw, active) return process_navbar(raw, active)
......
...@@ -32,7 +32,7 @@ except (OSError, ModuleNotFoundError) as e: ...@@ -32,7 +32,7 @@ except (OSError, ModuleNotFoundError) as e:
print("Pandoc not found on your system. Using mistune (python-only)") print("Pandoc not found on your system. Using mistune (python-only)")
import mistune import mistune
class IDRenderer(mistune.Renderer): class IDRenderer(mistune.HTMLRenderer):
def header(self, text, level, raw=None): def header(self, text, level, raw=None):
text = "<h{} id={}>{}</h{}>".format( text = "<h{} id={}>{}</h{}>".format(
level, level,
...@@ -43,8 +43,8 @@ except (OSError, ModuleNotFoundError) as e: ...@@ -43,8 +43,8 @@ except (OSError, ModuleNotFoundError) as e:
return text return text
renderer = IDRenderer() renderer = IDRenderer(escape=False)
markdown = mistune.Markdown(renderer=renderer) markdown = mistune.create_markdown(renderer=renderer)
def convert_text(input_text): def convert_text(input_text):
return markdown(input_text) return markdown(input_text)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment