Skip to content

Commit

Permalink
#365: allow for multiple creator-type overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Oct 9, 2015
1 parent 3056d70 commit e5dd704
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions resource/translators/reference.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class Reference
Translator.debug('particle-parser:', creator)
name = {family: creator.lastName || '', given: creator.firstName || ''}

Zotero.BetterBibTeX.CSL.parseParticles(name)
Zotero.BetterBibTeX.CSL.parseParticles(name)
Translator.debug('particle-parser: parsed to', name)

Expand Down Expand Up @@ -391,6 +392,7 @@ class Reference
when 'url' then @remove('doi')

fields = []
creators = {}
for own name, value of @override
raw = (value.format in ['naive', 'json'])
name = name.toLowerCase()
Expand All @@ -411,10 +413,20 @@ class Reference
remapped = cslvar?[(if Translator.BetterBibLaTeX then 'BibLaTeX' else 'BibTeX')]
remapped = remapped.call(@, name) if typeof remapped == 'function'

# will have to do fancy stuff for cslvar.type != 'string'
if remapped
Translator.debug('CSL override:', name, remapped, value)
fields.push({ name: remapped, value: value.value, raw: raw })
if cslvar.type == 'creator'
creator = value.value.split(/\s*\|\|\s*/)
if creator.length in [1, 2]
creator = {lastName: creator[0] || '', firstName: creator[1] || ''}
else
creator = {lastName: value.value || '', firstName: ''}
creators[remapped] ||= []
creators[remapped].push(creator)

else
fields.push({ name: remapped, value: value.value, enc: cslvar.type, raw: raw })

else
Translator.debug('Unmapped CSL field', name, '=', value.value)

Expand Down Expand Up @@ -444,6 +456,9 @@ class Reference
else
fields.push({ name, value: value.value, raw: raw })

for name, creators of creators
fields.push({name: name, value: creators})

for name in Translator.skipFields
@remove(name)

Expand Down

0 comments on commit e5dd704

Please sign in to comment.