Skip to content

Commit

Permalink
Merge branch 'gh-2849'
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Apr 29, 2024
2 parents 1b139c3 + be0d8f6 commit e0688cf
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions test/features/export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Feature: Export

Examples:
| file | references |
| Three dashes in extra field for generating markdown files from bibtex #2849 | 1 |
| Export of Contributor to WITH #2837 | 1 |
| Better BibTeX export from Zotero missing Extra fields eg issued #2816 | 1 |
| Support for Chinese Quotation Marks When Exporting with Export unicode as plaintext latex commands #2810 | 1 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
journal = {Pacific Journal of Mathematics},
volume = {41},
pages = {247--261},
annotation = {\{biblatex\{ editortype: "translated and edited under the supervision of", referencetype: mvlexicon \}\}\{\}},
annotation = {\{biblatex\{\\
editortype: "translated and edited under the supervision of",\\
referencetype: mvlexicon\\
\}\}\\
\\
\{\}},
note = {MR 46:7018}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@inproceedings{castillo_authoritarianism_2011,
title = {Authoritarianism, social dominance, and trust in public institutions.},
author = {Castillo, J. and Miranda, D. and Torres, P.},
date = {2011-07},
location = {Bilgi University, Istambul},
eventtitle = {Annual Scientific Meeting of the International Society of Political Psychology ISPP},
keywords = {legitimacy ideology Chile},
annotation = {url\_slides: "lisa-coes.github.io/"\\
---\\
This is a presentation funded by ANID}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"config": {
"id": "36a3b0b5-bad0-4a04-b79b-441c7cef77db",
"label": "BetterBibTeX JSON",
"preferences": {
"asciiBibTeX": false,
"bibtexParticleNoOp": true,
"bibtexURL": "url",
"citekeyFormat": "auth(n=0,m=1,creator=\"*\",initials=false).fold.lower + \"_\" + shorttitle(1).lower + \"_\" + year",
"exportBraceProtection": false,
"exportTitleCase": false,
"importSentenceCase": "off",
"keyScope": "global"
}
},
"items": [
{
"citationKey": "castillo_authoritarianism_2011a",
"conferenceName": "Annual Scientific Meeting of the International Society of Political Psychology ISPP",
"creators": [
{
"creatorType": "author",
"firstName": "J.",
"lastName": "Castillo"
},
{
"creatorType": "author",
"firstName": "D.",
"lastName": "Miranda"
},
{
"creatorType": "author",
"firstName": "P.",
"lastName": "Torres"
}
],
"date": "July, 2011",
"extra": [
"url_slides: \"lisa-coes.github.io/\"",
"---",
"This is a presentation funded by ANID"
],
"itemID": 1,
"itemType": "conferencePaper",
"place": "Bilgi University, Istambul",
"tags": [
{
"tag": "legitimacy ideology Chile"
}
],
"title": "Authoritarianism, social dominance, and trust in public institutions."
}
]
}
25 changes: 21 additions & 4 deletions translators/bibtex/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const enc_creators_marker = {
const isBibString = /^[a-z][-a-z0-9_]*$/i

export type Config = {
fieldEncoding: Record<string, 'raw' | 'url' | 'verbatim' | 'creators' | 'literal' | 'literal_list' | 'tags' | 'attachments' | 'date'>
fieldEncoding: Record<string, 'raw' | 'url' | 'verbatim' | 'creators' | 'literal' | 'literal_list' | 'tags' | 'attachments' | 'date' | 'extra'>
caseConversion: Record<string, boolean>
typeMap: {
csl: Record<string, string | { type: string, subtype?: string }>
Expand Down Expand Up @@ -515,6 +515,10 @@ export class Entry {
else {
let value
switch (field.enc) {
case 'extra':
value = this.enc_extra(field)
break

case 'literal_list':
value = this.enc_literal_list(field, { raw: this.item.raw })
break
Expand Down Expand Up @@ -776,7 +780,7 @@ export class Entry {
}
}

this.add({ name: 'annotation', value: this.item.extra?.replace(/\n+/g, newlines => (newlines.length > 1 ? '\n\n' : ' ')).trim() })
this.add({ name: 'annotation', value: this.item.extra, enc: 'extra' })

if (this.translation.options.exportNotes) {
// if bibtexURL === 'note' is active, the note field will have been filled with an URL. In all other cases, if this is attempting to overwrite the 'note' field, I want the test suite to throw an error
Expand Down Expand Up @@ -1033,12 +1037,25 @@ export class Entry {
}

/*
* Encode text to LaTeX
* Encode extra field to LaTeX
*
* This encoding supports plaintext with newlines
*
* @param {field} field to encode.
* @return {String} field.value encoded as latex
*/
protected enc_extra(f) {
return this.enc_literal({ value: f.value.replace(/\n/g, '\x0E') }).replace(/\x0E/g, newlines => newlines.length === 1 ? '\\\\\n' : '\n\n') // eslint-disable-line no-control-regex
}

/*
/*
* Encode list to LaTeX
*
* This encoding supports simple HTML markup.
*
* @param {field} field to encode.
* @return {String} field.value encoded as author-style value
* @return {String} field.value encoded as list of literals
*/
protected enc_literal_list(f, options: { raw?: boolean } = {}) {
const list = Array.isArray(f.value) ? f.value : [ f.value ]
Expand Down
2 changes: 1 addition & 1 deletion typings/translators.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export namespace Translators {
name: string
verbatim?: string
value: string | string[] | number | null | Attachment[] | Tag[]
enc?: 'raw' | 'url' | 'verbatim' | 'creators' | 'literal' | 'literal_list' | 'latex' | 'tags' | 'attachments' | 'date' | 'minimal' | 'bibtex' | 'biblatex'
enc?: 'raw' | 'url' | 'verbatim' | 'creators' | 'literal' | 'literal_list' | 'latex' | 'tags' | 'attachments' | 'date' | 'minimal' | 'bibtex' | 'biblatex' | 'extra'
orig?: { name?: string, verbatim?: string, inherit?: boolean }
bibtexStrings?: boolean
bare?: boolean
Expand Down

0 comments on commit e0688cf

Please sign in to comment.