Skip to content

Commit

Permalink
fix reference format
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchobben committed Nov 25, 2024
1 parent 57e0567 commit 6419dea
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/eo_datascience/clean_nb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 6419dea

Please sign in to comment.