Skip to content

Commit

Permalink
detect style
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Mar 9, 2024
1 parent d7425c7 commit 896d5d4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions content/json-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ type Query
= Record<string, Record<'in', QueryPrimitive[]>>
| Record<string, QueryPrimitive>

function getStyle(id: string): any {
const style = Zotero.Styles.get(id)
if (!style) throw new Error(`CSL style ${JSON.stringify(id)} not found`)
return style
}

class NSCollection {
/**
* Scan an AUX file for citekeys and populate a Zotero collection from them. The target collection will be cleared if it exists.
Expand Down Expand Up @@ -380,6 +386,7 @@ class NSItem {

if (!format.id) throw new Error('no style specified')
if (!format.id.includes('/')) format.id = `http://www.zotero.org/styles/${format.id}`
getStyle(format.id)

if (((format as any).mode || 'bibliography') !== 'bibliography') throw new Error(`mode must be bibliograpy, not ${(format as any).mode}`)

Expand Down Expand Up @@ -530,14 +537,7 @@ class NSItem {
style = style || 'apa'
if (!style.includes('/')) style = `http://www.zotero.org/styles/${style}`
locale = locale || Zotero.Prefs.get('export.quickCopy.locale')

let citeproc
try {
citeproc = Zotero.Styles.get(style).getCiteProc(locale)
}
catch (err) {
throw new Error(`Could not load citation style ${style}`)
}
const citeproc = getStyle(style).getCiteProc(locale)

for (const item of csl) {
result.items[item['citation-key']] = item
Expand Down

0 comments on commit 896d5d4

Please sign in to comment.