-
Notifications
You must be signed in to change notification settings - Fork 0
fix(styles): correct article formatting for entries without volume/number #38
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| field, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| join, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optional, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optional_field, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sentence, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -60,6 +60,38 @@ def format_data(self, data: Union[dict, Entry]) -> str: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def gbt_year_vol_pages(children: Node, data: Union[dict, Entry]) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Format year, volume, number and pages per GB/T 7714-2015. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - With volume: ``year, vol(num): pages`` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Without volume: ``year: pages`` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Page ranges are normalized to use a regular hyphen (not en-dash). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if isinstance(data, dict) and "entry" in data: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data = data["entry"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not hasattr(data, "fields"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| year = data.fields.get("year", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| volume = data.fields.get("volume", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| number = data.fields.get("number", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Normalize page-range separators: en-dash / double-hyphen → single hyphen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pages = data.fields.get("pages", "").replace("\u2013", "-").replace("--", "-") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vol_str = "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if volume: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vol_str = f"{volume}({number})" if number else volume | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if vol_str and pages: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{year}, {vol_str}: {pages}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if vol_str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{year}, {vol_str}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if pages: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{year}: {pages}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+87
to
+91
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{year}, {vol_str}: {pages}" | |
| if vol_str: | |
| return f"{year}, {vol_str}" | |
| if pages: | |
| return f"{year}: {pages}" | |
| if year: | |
| return f"{year}, {vol_str}: {pages}" | |
| return f"{vol_str}: {pages}" | |
| if vol_str: | |
| if year: | |
| return f"{year}, {vol_str}" | |
| return vol_str | |
| if pages: | |
| if year: | |
| return f"{year}: {pages}" | |
| return pages |
Copilot
AI
Mar 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When pages is present but year is missing, this returns ": {pages}", which will render malformed output (leading colon). Suggest returning just {pages} in that case, or ensuring year is required before adding the : pages suffix.
| if vol_str and pages: | |
| return f"{year}, {vol_str}: {pages}" | |
| if vol_str: | |
| return f"{year}, {vol_str}" | |
| if pages: | |
| return f"{year}: {pages}" | |
| # Preserve original formatting when year is present, but avoid | |
| # leading commas/colons when year is missing. | |
| if vol_str and pages and year: | |
| return f"{year}, {vol_str}: {pages}" | |
| if vol_str and year: | |
| return f"{year}, {vol_str}" | |
| if pages and year: | |
| return f"{year}: {pages}" | |
| if vol_str and pages: | |
| return f"{vol_str}: {pages}" | |
| if vol_str: | |
| return vol_str | |
| if pages: | |
| return pages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
ChicagoStyle.get_article_template, the no-volume branch no longer referencesfield("number"), so entries that have an issue number but no volume now silently lose that bibliographic detail. This regression is introduced by the newif e.fields.get("volume")split: previously the template still emitted, no. Nwhennumberexisted, but the new branch outputs only journal/date/pages, which can make citations ambiguous for issue-only journals.Useful? React with 👍 / 👎.