Skip to content

Commit 55cf58f

Browse files
committed
fixes #3287
1 parent 16c5ab8 commit 55cf58f

4 files changed

+165
-6
lines changed

test/features/import.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ Feature: Import
1515
And I import 1 reference from "import/*.bib"
1616
Then the library should match "import/*.json"
1717

18+
Scenario: Allow location and address field in imported bibtex entries to be stored in Extra field #3287
19+
When I apply the preferences from "import/*.json"
20+
And I import 1 reference from "import/*.bib"
21+
Then the library should match "import/*.json"
22+
1823
# And the markdown citation for Torre2008 should be '\(Torre & Verducci, 2008\)'
1924
# And the markdown bibliography for Torre2008 should be '<a name="@Torre2008"></a>Torre, J., & Verducci, T. \(2008\). _The Yankee Years_. Doubleday.'
2025
# And the markdown citation for orre2008 should be ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@inproceedings{10.1145/3290605.3300233,
2+
author = {Amershi, Saleema and Weld, Dan and Vorvoreanu, Mihaela and Fourney, Adam and Nushi, Besmira and Collisson, Penny and Suh, Jina and Iqbal, Shamsi and Bennett, Paul N. and Inkpen, Kori and Teevan, Jaime and Kikin-Gil, Ruth and Horvitz, Eric},
3+
title = {Guidelines for Human-AI Interaction},
4+
year = {2019},
5+
isbn = {9781450359702},
6+
publisher = {Association for Computing Machinery},
7+
address = {New York, NY, USA},
8+
url = {https://doi.org/10.1145/3290605.3300233},
9+
doi = {10.1145/3290605.3300233},
10+
booktitle = {Proceedings of the 2019 CHI Conference on Human Factors in Computing Systems},
11+
pages = {1–13},
12+
numpages = {13},
13+
keywords = {ai-infused systems, design guidelines, human-ai interaction},
14+
location = {Glasgow, Scotland Uk},
15+
series = {CHI '19}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"config": {
3+
"id": "36a3b0b5-bad0-4a04-b79b-441c7cef77db",
4+
"label": "BetterBibTeX JSON",
5+
"options": {
6+
"Items": true,
7+
"Preferences": true,
8+
"exportNotes": true,
9+
"worker": true
10+
},
11+
"preferences": {
12+
"bibtexURL": "url",
13+
"citekeyFormat": "auth + year",
14+
"exportBraceProtection": false,
15+
"importCaseProtection": "off",
16+
"importSentenceCase": "off",
17+
"postscript": "// covers both Translator.BetterBibTeX and Translator.BetterBibLaTeX\nif (Translator.BetterTeX) {\n if (zotero.itemType === 'conferencePaper') {\n // For @inproceedings\n const { author, booktitle, title, doi, editor, isbn, location, pages, url, publisher, series, address, articleno, file, issn, keywords, numpages, qualityassured, readstatus, relevance, timestamp, year, ...rest } = tex.has\n\ttex.has = { author, booktitle, title, doi, editor, isbn, location, pages, url, publisher, series, address, articleno, file, issn, keywords, numpages, qualityassured, readstatus, relevance, timestamp, year, ...rest }\n Object.keys(tex.has).forEach(key => tex.has[key] === undefined && delete tex.has[key])\n } else if (zotero.itemType === 'journalArticle') {\n // For @article\n const { author, title, doi, issn, number, pages, volume, address, file, journal, keywords, month, publisher, qualityassured, readstatus, relevance, timestamp, year, ...rest } = tex.has\n\ttex.has = { author, title, doi, issn, number, pages, volume, address, file, journal, keywords, month, publisher, qualityassured, readstatus, relevance, timestamp, year, ...rest }\n Object.keys(tex.has).forEach(key => tex.has[key] === undefined && delete tex.has[key])\n } else if (zotero.itemType === 'bookSection') {\n // For @incollection\n const { author, booktitle, title, doi, edition, editor, isbn, pages, publisher, volume, address, file, issn, year, ...rest } = tex.has\n\ttex.has = { author, booktitle, title, doi, edition, editor, isbn, pages, publisher, volume, address, file, issn, year, ...rest }\n Object.keys(tex.has).forEach(key => tex.has[key] === undefined && delete tex.has[key])\n } else if (zotero.itemType === 'book') {\n // For @book\n const { author, title, doi, isbn, publisher, address, numpages, qualityassured, timestamp, year, ...rest } = tex.has\n\ttex.has = { author, title, doi, isbn, publisher, address, numpages, qualityassured, timestamp, year, ...rest }\n Object.keys(tex.has).forEach(key => tex.has[key] === undefined && delete tex.has[key])\n } else if (zotero.itemType === 'document') {\n // For @misc\n const { author, date, title, url, urldate, file, year, ...rest } = tex.has\n\ttex.has = { author, date, title, url, urldate, file, year, ...rest }\n Object.keys(tex.has).forEach(key => tex.has[key] === undefined && delete tex.has[key])\n } else if (zotero.itemType === 'thesis') {\n // For @phdthesis\n const { author, title, url, file, school, year, ...rest } = tex.has\n\ttex.has = { author, title, url, file, school, year, ...rest }\n Object.keys(tex.has).forEach(key => tex.has[key] === undefined && delete tex.has[key])\n }\n}"
18+
}
19+
},
20+
"items": [
21+
{
22+
"DOI": "10.1145/3290605.3300233",
23+
"ISBN": "978-1-4503-5970-2",
24+
"citationKey": "10.1145/3290605.3300233",
25+
"creators": [
26+
{
27+
"creatorType": "author",
28+
"firstName": "Saleema",
29+
"lastName": "Amershi"
30+
},
31+
{
32+
"creatorType": "author",
33+
"firstName": "Dan",
34+
"lastName": "Weld"
35+
},
36+
{
37+
"creatorType": "author",
38+
"firstName": "Mihaela",
39+
"lastName": "Vorvoreanu"
40+
},
41+
{
42+
"creatorType": "author",
43+
"firstName": "Adam",
44+
"lastName": "Fourney"
45+
},
46+
{
47+
"creatorType": "author",
48+
"firstName": "Besmira",
49+
"lastName": "Nushi"
50+
},
51+
{
52+
"creatorType": "author",
53+
"firstName": "Penny",
54+
"lastName": "Collisson"
55+
},
56+
{
57+
"creatorType": "author",
58+
"firstName": "Jina",
59+
"lastName": "Suh"
60+
},
61+
{
62+
"creatorType": "author",
63+
"firstName": "Shamsi",
64+
"lastName": "Iqbal"
65+
},
66+
{
67+
"creatorType": "author",
68+
"firstName": "Paul N.",
69+
"lastName": "Bennett"
70+
},
71+
{
72+
"creatorType": "author",
73+
"firstName": "Kori",
74+
"lastName": "Inkpen"
75+
},
76+
{
77+
"creatorType": "author",
78+
"firstName": "Jaime",
79+
"lastName": "Teevan"
80+
},
81+
{
82+
"creatorType": "author",
83+
"firstName": "Ruth",
84+
"lastName": "Kikin-Gil"
85+
},
86+
{
87+
"creatorType": "author",
88+
"firstName": "Eric",
89+
"lastName": "Horvitz"
90+
}
91+
],
92+
"date": "2019",
93+
"extra": [
94+
"Citation Key: 10.1145/3290605.3300233",
95+
"Number of pages: 13",
96+
"tex.location: Glasgow, Scotland Uk"
97+
],
98+
"itemID": 1,
99+
"itemType": "conferencePaper",
100+
"pages": "1–13",
101+
"place": "New York, NY, USA",
102+
"publicationTitle": "Proceedings of the 2019 CHI Conference on Human Factors in Computing Systems",
103+
"publisher": "Association for Computing Machinery",
104+
"series": "CHI '19",
105+
"tags": [
106+
{
107+
"tag": "ai-infused systems"
108+
},
109+
{
110+
"tag": "design guidelines"
111+
},
112+
{
113+
"tag": "human-ai interaction"
114+
}
115+
],
116+
"title": "Guidelines for Human-AI Interaction",
117+
"url": "https://doi.org/10.1145/3290605.3300233"
118+
}
119+
]
120+
}

translators/bibtex/bibtex.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,31 @@ class ZoteroItem {
712712
return this.$location(value, field)
713713
}
714714

715-
protected $location(value: string, field: string): boolean {
716-
const location = this.bibtex.fields.location
717-
const address = this.bibtex.fields.address
718-
if (field === 'address' && location?.length && address?.length) return true // handled through location
715+
protected $location(_value: string, _field: string): boolean {
716+
const clean = (a: string[]) => a.map((v: string) => v.replace(/[\n ]+/g, ' ').trim()).filter(_ => _).join(' and ')
717+
const location = {
718+
source: 'location',
719+
value: clean(asarray(this.bibtex.fields.location)),
720+
}
721+
const address = {
722+
source: 'address',
723+
value: clean(asarray(this.bibtex.fields.address)),
724+
}
725+
const place = this.bibtex.type.match(/^(conference|presentation|talk)$/) // #3287
726+
? { field: location, extra: address }
727+
: { extra: location, field: address }
728+
if (!place.field.value) Object.assign(place, { field: place.extra, extra: place.field })
729+
730+
if (place.field.value) {
731+
this.set('place', place.field.value, ['place'])
732+
if (place.extra.value) this.extra.push(`tex.${place.extra.source}: ${place.extra.value}`)
719733

720-
const place = [ ...asarray(location), ...asarray(address) ].map((v: string) => v.replace(/[\n ]+/g, ' ').trim()).filter(_ => _).join(' and ')
721-
return !!place && this.set('place', place, ['place'])
734+
// scrub so they are not double-dipped
735+
delete this.bibtex.fields.location
736+
delete this.bibtex.fields.address
737+
}
738+
739+
return true
722740
}
723741

724742
protected '$call-number'(value: string): boolean {

0 commit comments

Comments
 (0)