diff --git a/schema/plugin.json b/schema/plugin.json index 5034611..91b8d15 100644 --- a/schema/plugin.json +++ b/schema/plugin.json @@ -32,6 +32,13 @@ "type": "string", "default": "apa.csl", "description": "The default citation style, one of the styles in the Citation Style Language (CSL) repository." + }, + "outputFormat": { + "title": "Format of citations and bibliography", + "type": "string", + "default": "html", + "description": "One of: html, text, rtf, asciidoc, fo, latex", + "enum": ["html", "text", "rtf", "asciidoc", "fo", "latex"] } }, "additionalProperties": false diff --git a/src/index.ts b/src/index.ts index d264a28..3caa58f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,6 +55,7 @@ import { UpdateProgress } from './components/progressbar'; import { Signal } from '@lumino/signaling'; import { URLExt } from '@jupyterlab/coreutils'; import { refreshIcon } from '@jupyterlab/ui-components'; +import OutputMode = CiteProc.OutputMode; const PLUGIN_ID = 'jupyterlab-citation-manager:plugin'; @@ -123,6 +124,7 @@ class UnifiedCitationManager implements ICitationManager { progress: Signal; private currentAdapter: IDocumentAdapter | null = null; + private outputFormat: CiteProc.OutputMode = 'html'; protected createAllReadyPromiseWrapper(): ICancellablePromise { const REASON_CANCELLED = 'cancelled'; @@ -326,6 +328,7 @@ class UnifiedCitationManager implements ICitationManager { protected updateSettings(settings: ISettingRegistry.ISettings) { this.defaultStyleID = settings.get('defaultStyle').composite as string; + this.outputFormat = settings.get('outputFormat').composite as OutputMode; } public registerReferenceProvider(provider: IReferenceProvider): void { @@ -650,6 +653,10 @@ class UnifiedCitationManager implements ICitationManager { const styleAsText = result.response.responseText; return new CSL.Engine(this, styleAsText); }); + }) + .then((engine: CiteProc.IEngine) => { + engine.setOutputFormat(this.outputFormat); + return engine; }); } diff --git a/src/types.ts b/src/types.ts index b5b396d..6edb063 100644 --- a/src/types.ts +++ b/src/types.ts @@ -69,6 +69,17 @@ export namespace CiteProc { string[] ]; + /** + * https://github.com/Juris-M/citeproc-js/blob/master/src/formats.js + */ + export type OutputMode = + | 'html' + | 'text' + | 'rtf' + | 'asciidoc' + | 'fo' + | 'latex'; + /** * https://citeproc-js.readthedocs.io/en/latest/running.html */ @@ -88,6 +99,8 @@ export namespace CiteProc { ): [number, string, CitationID][]; makeBibliography(): Bibliography; + + setOutputFormat(mode: OutputMode): void; } /**