walkNoteDom in worker

This commit is contained in:
Emiliano Heyns
2022-05-09 11:57:33 +02:00
parent efd7290ce4
commit ef11ce5ed4
4 changed files with 27 additions and 6 deletions

1
.gitmodules vendored
View File

@@ -21,3 +21,4 @@
[submodule "submodules/zotero-utilities"]
path = submodules/zotero-utilities
url = https://github.com/zotero/utilities.git
branch = master

View File

@@ -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

View File

@@ -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

View File

@@ -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 |