Skip to content

Commit

Permalink
Add container support using the official pandoc/latex image (#25)
Browse files Browse the repository at this point in the history
* Add support for running pandoc in a container using the latest official pandoc/latex container https://hub.docker.com/r/pandoc/latex. This includes a new configuration property, pandoc.useDocker, which defaults to false so that the original behavior is preserved.

* version bump
  • Loading branch information
camwheeler authored Jun 21, 2023
1 parent 9a51374 commit fe4ceb3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ _Thanks to the previous work of [@dfinke](https://github.com/dfinke) on this ext

You need to [**install Pandoc**](http://pandoc.org/installing.html) - a universal document converter.

Alternatively you may set the `useDocker` option to true and it will run Pandoc in a container using the latest official [pandoc/latex](https://hub.docker.com/r/pandoc/latex) image. This could result in a delay the first time it runs, or after an update to the container while it pulls down the new image.

## Usage

Two ways to run the extension. You need to have a markdown file open.
Expand Down Expand Up @@ -62,6 +64,9 @@ example:

// path to the pandoc executable. By default gets from PATH variable
"pandoc.executable": ""

// enable running pandoc in a docker container
"pandoc.useDocker": "true"
```

* if necessary to set options for each output format.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-pandoc",
"description": "Renders markdown through pandoc",
"version": "0.4.2",
"version": "0.4.3",
"publisher": "ChrisChinchilla",
"icon": "images/logo.png",
"license": "SEE LICENSE",
Expand Down Expand Up @@ -81,6 +81,11 @@
"type": "boolean",
"default": "true",
"description": "specify if the extension will open the rendered document in it's default viewer"
},
"pandoc.useDocker": {
"type": "boolean",
"default": "false",
"description": "specify if the extension will run pandoc from a docker container"
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ export function activate(context: vscode.ExtensionContext) {
console.log('debug: inFile = ' + outFile);
console.log('debug: pandoc ' + inFile + ' -o ' + outFile + pandocOptions);

var space = '\x20';
var pandocExecutablePath = getPandocExecutablePath();
console.log('debug: pandoc executable path = ' + pandocExecutablePath);

var targetExec = '"' + pandocExecutablePath + '"' + space + inFile + space + '-o' + space + outFile + space + pandocOptions;
var useDocker = vscode.workspace.getConfiguration('pandoc').get('useDocker');
var targetExec = useDocker
? `docker run --rm -v "${filePath}:/data" pandoc/latex:latest "${fileName}" -o "${fileNameOnly}.${qpSelection.label}" ${pandocOptions}`
: `"${pandocExecutablePath}" ${inFile} -o ${outFile} ${pandocOptions}`;
console.log('debug: exec ' + targetExec);

var child = exec(targetExec, { cwd: filePath }, function (error, stdout, stderr) {
Expand Down

0 comments on commit fe4ceb3

Please sign in to comment.