From bde0cb09950e7827ddccf22edd24c5b18a5d69b9 Mon Sep 17 00:00:00 2001 From: JBorrow <joshua.borrow@durham.ac.uk> Date: Wed, 27 Jul 2022 14:52:34 +0100 Subject: [PATCH] Updated renderer to use new versions as of py 3.10 --- about.py | 5 ++++- compiler.py | 4 ++-- mdcomp.py | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/about.py b/about.py index db61e91..c5f8a03 100644 --- a/about.py +++ b/about.py @@ -23,7 +23,7 @@ import yaml def open_meta(filename="about_meta.yaml", data_dir="../data"): """ Read the meta file and return the associated data """ 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"): @@ -50,6 +50,9 @@ class Parser(HTMLParser): self.waiting_for_data = False def handle_starttag(self, tag, attrs): + if len(attrs) == 0: + return + for attr in attrs: if attr[0] == "id": this_id = attr[1] diff --git a/compiler.py b/compiler.py index ad5d3e5..c05b8c9 100644 --- a/compiler.py +++ b/compiler.py @@ -44,7 +44,7 @@ def get_associated_data(template_names, data_dir="../data"): # YAML Search try: 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: pass @@ -104,7 +104,7 @@ def global_variables(active, data_dir="../data"): production of the processed navbar. """ 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) diff --git a/mdcomp.py b/mdcomp.py index bc8cbc0..ab3ee79 100644 --- a/mdcomp.py +++ b/mdcomp.py @@ -32,7 +32,7 @@ except (OSError, ModuleNotFoundError) as e: print("Pandoc not found on your system. Using mistune (python-only)") import mistune - class IDRenderer(mistune.Renderer): + class IDRenderer(mistune.HTMLRenderer): def header(self, text, level, raw=None): text = "<h{} id={}>{}</h{}>".format( level, @@ -43,8 +43,8 @@ except (OSError, ModuleNotFoundError) as e: return text - renderer = IDRenderer() - markdown = mistune.Markdown(renderer=renderer) + renderer = IDRenderer(escape=False) + markdown = mistune.create_markdown(renderer=renderer) def convert_text(input_text): return markdown(input_text) -- GitLab