Skip to content

Commit

Permalink
fix full bibliography
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed Jan 15, 2025
1 parent d10106d commit aa559bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/mkdocs_bibtex/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
import time
import validators
from collections import OrderedDict
Expand Down Expand Up @@ -129,21 +128,19 @@ def on_page_markdown(self, markdown, page, config, files):
except Exception as e:
log.warning(f"Error formatting citation {citation.key}: {e}")
bibliography = "\n".join(bibliography)
markdown = re.sub(
re.escape(bib_command),
bibliography,
markdown,
)
markdown = markdown.replace(bib_command, bibliography)


# 5. Build the full Bibliography and insert into the text
full_bib_command = self.config.full_bib_command
all_citations = [Citation(key=key) for key in self.registry.bib_data.entries]
full_bibliography = []
for citation in all_citations:
full_bibliography.append("[^{}]: {}".format(citation.key, self.registry.reference_text(citation)))
full_bibliography = "\n".join(full_bibliography)
if markdown.count(full_bib_command) > 0:
all_citations = [Citation(key=key) for key in self.registry.bib_data.entries]
full_bibliography = []
for citation in all_citations:
full_bibliography.append("[^{}]: {}".format(citation.key, self.registry.reference_text(citation)))
full_bibliography = "\n".join(full_bibliography)
markdown = markdown.replace(full_bib_command, full_bibliography)


markdown = markdown.replace(bib_command, bibliography)
markdown = markdown.replace(full_bib_command, full_bibliography)

return markdown
12 changes: 12 additions & 0 deletions test_files/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,15 @@ def test_invalid_citations(plugin):
result = plugin.on_page_markdown(markdown, None, None, None)
# assert "[@nonexistent]" in result # Invalid citation should remain unchanged
assert "[^nonexistent]" not in result


def test_full_bib_command(plugin):
"""Test full bibliography command"""
markdown = "Full bibliography [@test]\n\n\\full_bibliography"
result = plugin.on_page_markdown(markdown, None, None, None)
print(result)
assert "Full bibliography [^test]" in result
assert "[^test]:" in result
assert "[^test2]:" in result
assert "[^Bivort2016]:" in result
assert "[^test_citavi]:" in result

0 comments on commit aa559bc

Please sign in to comment.