Skip to content

Feature/fix bare citations script #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CDL: added bare-citation fix to Makefile
  • Loading branch information
Colin Leong committed Jun 28, 2024
commit 2017fbb47f0eb438fa743ab1ad5df564528f88a5
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dst/thesis.pdf: dst/index_shortcode.md src/references.bib

dst/index.md: src/index.md src/markdown_fix.sh src/formats.md dst tmp/datasets.md dst/assets
cat src/index.md > $@
python src/fix_bare_citations.py src/references.bib $@
bash src/markdown_fix.sh $@

dst/style.css: dst src/styles/custom.css
Expand Down
13 changes: 8 additions & 5 deletions src/fix_bare_citations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Find bare citation keys, e.g. shalev2022ham2pose, and add "@" e.g @shalev2022ham2pose
# Does this by reading the citation keys from references.bib and checking the markdown for matches.
# Written with ChatGPT assistance
# https://chatgpt.com/share/8e6057f1-f654-4d04-8528-652fa0392d49
# https://chatgpt.com/share/68cde216-5aeb-41e1-a4b2-93e0855f6b98
import re
import sys

def extract_citation_keys(bib_file_path):
citation_keys = []
Expand Down Expand Up @@ -38,11 +39,13 @@ def update_markdown_with_citations(markdown_file_path, citation_keys):

return issues

if __name__ == '__main__':
if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} <bib_file_path> <markdown_file_path>")
sys.exit(1)

if __name__ == "__main__":
# Example usage
bib_file_path = 'references.bib'
markdown_file_path = 'index.md'
bib_file_path = sys.argv[1]
markdown_file_path = sys.argv[2]

citation_keys = extract_citation_keys(bib_file_path)
issues = update_markdown_with_citations(markdown_file_path, citation_keys)
Expand Down