Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_initProcessor () {
try {
// Load the engine with the current application language. As this citing
// is only for preview purposes, it should follow the language like the
// rest of the interface.
this._engine = new citeproc.Engine(this._sys, this._mainStyle, this._lang)
this._status = READY
this._loadIdHint()
} catch (e) {
console.error(e)
this._status = ERROR
}
}
constructor(style: string) {
const { instance } = Processor;
if (instance) {
if (instance.style !== style) {
instance.style = style;
instance.engine = new Engine(instance.sys, instance.style);
instance.engine.opt.development_extensions.wrap_url_and_doi = true;
}
return instance;
} else {
Processor.instance = this;
this.style = style;
this.engine = new Engine(this.sys, this.style);
this.engine.opt.development_extensions.wrap_url_and_doi = true;
}
}
/* eslint-enable @typescript-eslint/camelcase */
import CSL from 'citeproc'
import {templates} from './styles'
import {locales} from './locales'
// BEGIN add sys function
const getWrapperProxy = (original) => function (state, entry) {
if (state.sys.wrapBibliographyEntry) {
let [prefix, postfix] = state.sys.wrapBibliographyEntry(this.system_id)
entry = [prefix, entry, postfix].join('')
}
return original(state, entry)
}
for (let format in CSL.Output.Formats) {
let original = CSL.Output.Formats[format]['@bibliography/entry']
CSL.Output.Formats[format]['@bibliography/entry'] = getWrapperProxy(original)
}
// END
/**
* Object containing CSL Engines
*
* @access private
* @constant
*/
const engines = {}
/**
* Retrieve CSL parsing engine
*
* @access protected
import CSL from 'citeproc'
import {templates} from './styles'
import {locales} from './locales'
// BEGIN add sys function
const getWrapperProxy = (original) => function (state, entry) {
if (state.sys.wrapBibliographyEntry) {
let [prefix, postfix] = state.sys.wrapBibliographyEntry(this.system_id)
entry = [prefix, entry, postfix].join('')
}
return original(state, entry)
}
for (let format in CSL.Output.Formats) {
let original = CSL.Output.Formats[format]['@bibliography/entry']
CSL.Output.Formats[format]['@bibliography/entry'] = getWrapperProxy(original)
}
// END
/**
* Object containing CSL Engines
*
* @access private
* @constant
*/
const engines = {}
/**
* Retrieve CSL parsing engine
*
const fetchEngine = function (style, lang, template, retrieveItem, retrieveLocale) {
const engineHash = `${style}|${lang}`
let engine
if (engines.hasOwnProperty(engineHash)) {
engine = engines[engineHash]
engine.sys.retrieveItem = retrieveItem
} else {
engine = engines[engineHash] = new CSL.Engine({retrieveLocale, retrieveItem}, template, lang, true)
}
return engine
}
this.data = self.data
}
Cite.prototype = Object.create(core.Cite.prototype)
Cite.async = core.Cite.async
Cite.validateOptions = core.Cite.validateOptions
Cite.validateOutputOptions = core.Cite.validateOutputOptions
Cite.input = core.plugins.input.chain
Cite.inputAsync = core.plugins.input.chainAsync
Cite.util = Object.assign({ attr }, core.util)
Cite.version = {
cite: core.version,
citeproc: citeproc.PROCESSOR_VERSION
}
const CSL = core.plugins.config.get('@csl')
Cite.CSL = {
engine: require('@citation-js/plugin-csl/lib/engines').fetchEngine,
item (data) {
return id => data.find(entry => entry.id === id)
},
locale (lang) {
return CSL.styles.get(CSL.styles.has(lang) ? lang : 'en-US')
},
style (style) {
return CSL.templates.get(CSL.templates.has(style) ? style : 'apa')
},
register: {
get: function get() {
return _citeproc.PROCESSOR_VERSION;
}
});