mirror of
https://github.com/retorquere/zotero-better-bibtex.git
synced 2022-05-23 09:36:29 +03:00
walkNoteDom in worker
This commit is contained in:
1
.gitmodules
vendored
1
.gitmodules
vendored
@@ -21,3 +21,4 @@
|
||||
[submodule "submodules/zotero-utilities"]
|
||||
path = submodules/zotero-utilities
|
||||
url = https://github.com/zotero/utilities.git
|
||||
branch = master
|
||||
|
||||
@@ -4,8 +4,29 @@ importScripts('resource://gre/modules/osfile.jsm')
|
||||
|
||||
import type { ITranslator } from '../../translators/lib/translator'
|
||||
import type { Translators } from '../../typings/translators'
|
||||
export const { DOMParser, XMLSerializer } = require('@xmldom/xmldom')
|
||||
import { Utilities as ZU } from '../../submodules/zotero-utilities/utilities.js'
|
||||
|
||||
import { DOMParser as XMLDOMParser } from '@xmldom/xmldom'
|
||||
|
||||
function hasAttribute(attr: string): boolean {
|
||||
return !!(this.getAttribute?.(attr))
|
||||
}
|
||||
function upgrade(node) {
|
||||
if (!node.children) {
|
||||
node.children = Array.from(node.childNodes || [])
|
||||
for (const child of node.children) {
|
||||
upgrade(child)
|
||||
}
|
||||
}
|
||||
if (!node.hasAttribute) node.hasAttribute = hasAttribute
|
||||
}
|
||||
export class DOMParser extends XMLDOMParser {
|
||||
parseFromString(text: string, contentType: string) { // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
|
||||
const doc = super.parseFromString(text, contentType)
|
||||
upgrade(doc)
|
||||
return doc
|
||||
}
|
||||
}
|
||||
const ZU = require('../../submodules/zotero-utilities/utilities.js')
|
||||
|
||||
declare const doExport: () => void
|
||||
declare const Translator: ITranslator
|
||||
|
||||
@@ -76,7 +76,7 @@ async function rebuild() {
|
||||
})
|
||||
|
||||
// worker code
|
||||
const vars = [ 'Zotero', 'workerContext', 'DOMParser', 'XMLSerializer' ]
|
||||
const vars = [ 'Zotero', 'workerContext', 'DOMParser' ]
|
||||
const globalName = vars.join('__')
|
||||
await bundle({
|
||||
entryPoints: [ 'content/worker/zotero.ts' ],
|
||||
@@ -102,9 +102,7 @@ async function rebuild() {
|
||||
].join('\n'),
|
||||
},
|
||||
metafile: 'gen/worker.json',
|
||||
external: [
|
||||
'jsdom',
|
||||
]
|
||||
external: [ 'jsdom' ],
|
||||
})
|
||||
|
||||
// translators
|
||||
|
||||
@@ -13,6 +13,7 @@ Feature: Export
|
||||
|
||||
Examples:
|
||||
| file | references |
|
||||
| Make DOMParser available in background export #2094 | 1 |
|
||||
| Authors export looks like this prefix=von useprefix=true... #2138 | 1 |
|
||||
| Zotero's Manuscript 'Type' is mapped to both biblatex's 'type' and 'howpublished' #2114 | 1 |
|
||||
| Configurable journal abbreviation for citekey #2097 | 1 |
|
||||
|
||||
Reference in New Issue
Block a user