From 6419dea811ebf89c8c730639a7eedf7c8b15228d Mon Sep 17 00:00:00 2001 From: Martin Schobben Date: Mon, 25 Nov 2024 15:27:49 +0100 Subject: [PATCH] fix reference format --- src/eo_datascience/clean_nb.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/eo_datascience/clean_nb.py b/src/eo_datascience/clean_nb.py index a62f4ad..5ac348c 100644 --- a/src/eo_datascience/clean_nb.py +++ b/src/eo_datascience/clean_nb.py @@ -38,18 +38,20 @@ def clean_up_frontmatter(dir="./notebooks", save=True): return nb -def convert_bibliography(nb_path="./notebooks/references.ipynb", save=True): - nb = nbformat.read(nb_path, as_version=4) - nb.cells[0].source = """# References +def convert_bibliography(nb_path=Path("./notebooks/references.ipynb"), save=True): + + if nb_path.exists(): + nb = nbformat.read(nb_path, as_version=4) + nb.cells[0].source = """# References -```{bibliography} -``` -""" - # Save the notebook - if save: - nbformat.write(nb, nb_path) - else: - return nb + ```{bibliography} + ``` + """ + # Save the notebook + if save: + nbformat.write(nb, nb_path) + else: + return nb def convert_callout_notes(dir="./notebooks", save=True): @@ -106,14 +108,14 @@ def convert_refs(dir="./notebooks", save=True): def quarto_ref_figure_replace(quarto): bibs = re.findall(r"(?<=\(\@)[^\)]+", quarto) for i in bibs: - quarto = re.sub(r"\(\@" + i + "\)", r"", quarto) + quarto = re.sub(r"\(\@" + i + r"\)", "", quarto) return quarto def quarto_ref_person_replace(quarto): bibs = re.findall(r"(?<=\[\@)[^\]]+", quarto) for i in bibs: - quarto = re.sub(r"\[\@" + i + "\]", r"{cite:p}`" + i + "`", quarto) + quarto = re.sub(r"\[\@" + i + r"\]", r"{cite:p}`" + i + "`", quarto) return quarto