Skip to content

Commit

Permalink
Hopefully fix #15, adds a setting to specify the Pandoc executable lo…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
OliverBalfour committed Apr 27, 2021
1 parent 613e4d4 commit fd4bc13
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
3 changes: 3 additions & 0 deletions global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface PandocPluginSettings {
linkStrippingBehaviour: 'strip' | 'text' | 'link',
// Do we render SVGs at 2x the size?
highDPIDiagrams: boolean,
// Custom Pandoc binary path (useful for PATH variable issues)
pandoc: string | null,
}

export const DEFAULT_SETTINGS: PandocPluginSettings = {
Expand All @@ -34,6 +36,7 @@ export const DEFAULT_SETTINGS: PandocPluginSettings = {
displayYAMLFrontmatter: false,
linkStrippingBehaviour: 'text',
highDPIDiagrams: true,
pandoc: null,
}

export function replaceFileExtension(file: string, ext: string): string {
Expand Down
22 changes: 17 additions & 5 deletions main.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class PandocPlugin extends Plugin {
checkCallback: (checking: boolean) => {
let leaf = this.app.workspace.activeLeaf;
if (!leaf) return false;
if (!this.features.pandoc && pandocFormat !== 'html') return false;
if (!this.features.pandoc && pandocFormat !== 'html' && !this.settings.pandoc) return false;
if (!this.currentFileCanBeExported()) return false;
if (!checking) {
this.startPandocExport(this.getCurrentFile(), pandocFormat as OutputFormat, extension, shortName);
Expand Down Expand Up @@ -102,7 +102,11 @@ export default class PandocPlugin extends Plugin {
new Notice('Successfully exported via Pandoc to ' + outputFile);
} else {
// Spawn Pandoc
const { error, command } = await pandoc({ file: 'STDIN', contents: html, format: 'html', title }, { file: outputFile, format });
const { error, command } = await pandoc(
{ file: 'STDIN', contents: html, format: 'html', title,
pandoc: this.settings.pandoc },
{ file: outputFile, format }
);
// Never give warnings for plain-text exports
if (error.length && format !== 'plain') {
new Notice('Exported via Pandoc to ' + outputFile + ' with warnings');
Expand Down
3 changes: 2 additions & 1 deletion pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface PandocInput {
format?: InputFormat, // -f/--from format, if left blank it's inferred by Pandoc
contents?: string,
title?: string, // used as metadata for HTML <title>, etc. defaults to the file base name
pandoc?: string, // optional path to Pandoc if it's not in the current PATH variable
}

export interface PandocOutput {
Expand Down Expand Up @@ -133,7 +134,7 @@ export const pandoc = async (input: PandocInput, output: PandocOutput, extraPara
// Spawn a Pandoc child process
// Assumes Pandoc is installed and that the arguments are valid
// The arguments aren't sanitised, so be careful!
pandoc = spawn('pandoc', args);
pandoc = spawn(input.pandoc || 'pandoc', args);

if (stdin) {
const contents = input.contents;
Expand Down
13 changes: 12 additions & 1 deletion settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class PandocPluginSettingTab extends PluginSettingTab {

for (const binary of this.plugin.programs) {
const path = this.plugin.features[binary];
if (path === undefined) {
if (path === undefined && (binary !== 'pandoc' || !this.plugin.settings.pandoc)) {
createError(this.errorMessages[binary]);
}
}
Expand Down Expand Up @@ -134,5 +134,16 @@ export default class PandocPluginSettingTab extends PluginSettingTab {
this.plugin.settings.addExtensionsToInternalLinks = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName("Pandoc path")
.setDesc("Optional override for Pandoc's path if you have command not found issues. On Mac/Linux use the output of 'which pandoc' in a terminal; on Windows use the output of 'Get-Command pandoc' in powershell.")
.addText(text => text
.setPlaceholder('pandoc')
.setValue(this.plugin.settings.pandoc)
.onChange(async (value: string) => {
this.plugin.settings.pandoc = value;
await this.plugin.saveSettings();
}));
}
}

0 comments on commit fd4bc13

Please sign in to comment.