Skip to content

Commit

Permalink
Allow to customize output format
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jul 29, 2021
1 parent a8e61be commit f3e4cee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -123,6 +124,7 @@ class UnifiedCitationManager implements ICitationManager {

progress: Signal<UnifiedCitationManager, IProgress>;
private currentAdapter: IDocumentAdapter<any> | null = null;
private outputFormat: CiteProc.OutputMode = 'html';

protected createAllReadyPromiseWrapper(): ICancellablePromise<any> {
const REASON_CANCELLED = 'cancelled';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
});
}

Expand Down
13 changes: 13 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -88,6 +99,8 @@ export namespace CiteProc {
): [number, string, CitationID][];

makeBibliography(): Bibliography;

setOutputFormat(mode: OutputMode): void;
}

/**
Expand Down

0 comments on commit f3e4cee

Please sign in to comment.