Skip to content

Commit

Permalink
[style] Improve nationality support on patent entries
Browse files Browse the repository at this point in the history
  • Loading branch information
anjos committed Nov 6, 2024
1 parent 025daeb commit 43f8096
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/pelican/plugins/pybtex/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
types.
"""

import pybtex.database
from pybtex.style.formatting import toplevel
import pybtex.style.formatting.unsrt
from pybtex.style.template import field, node, optional, sentence, tag, words
Expand Down Expand Up @@ -54,7 +55,7 @@ def decorator(func):


@_monkeypatch_method(pybtex.style.formatting.unsrt.Style)
def get_patent_template(self, e):
def get_patent_template(self, e: pybtex.database.Entry):
"""Format patent bibtex entry.
Parameters
Expand All @@ -66,11 +67,19 @@ def get_patent_template(self, e):
-------
The formatted entry object.
"""
assert e.fields is not None

nationality = e.fields.get("nationality", "")

if nationality.lower() == "united states":
nationality = "U.S."

return toplevel[
sentence[self.format_names("author")],
self.format_title(e, "title"),
sentence(capfirst=False)[
tag("em")[field("number")], pybtex.style.formatting.unsrt.date
tag("em")[optional[nationality, " "], "Patent ", field("number")],
pybtex.style.formatting.unsrt.date,
],
optional[self.format_url(e), optional[" (visited on ", field("urldate"), ")"]],
]
1 change: 0 additions & 1 deletion tests/data/biblio-patent/content/article.bib
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ @patent{pat
@patent{pat2,
author = "A. G. Bell",
title = "Improvement in telegraphy",
nationality = "United States",
number = "174465",
day = "7",
month = "3",
Expand Down
2 changes: 2 additions & 0 deletions tests/test_pybtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ def test_biblio_patent(setup_pelican: tuple[list[logging.LogRecord], pathlib.Pat

# assert that the month number was correctly translated in both entries
assert "March 1876" in details[0].find_all("summary")[0].text
assert "Patent" in details[0].find_all("summary")[0].text
assert "March 1876" in details[1].find_all("summary")[0].text
assert "U.S. Patent" in details[1].find_all("summary")[0].text

_assert_log_no_errors(records)
_assert_log_contains(
Expand Down

0 comments on commit 43f8096

Please sign in to comment.