Skip to content

Commit

Permalink
bug-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFern2 committed Oct 21, 2020
1 parent 4dae264 commit 05c7d8b
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@ All notable changes to the "vscode-markdown-pandoc" extension will be documented

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## 1.0.1

Bug Fixes:
- Fixed issue with spaces in path
- Added cmd arguments to configuration
- Tested on Windows and Linux

## 1.0.0
- Initial release
48 changes: 37 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,43 @@ pandoc someFile.md -o book.html

> NB: The first time you use pandoc, you'll get popups for installing MiKTeX packages, or you can choose in settings to install on the fly without popups. Also the first time you convert a document it takes a while, the next time will be fast as all the packages are already downloaded.
## Book Structure

There are two ways you can structure your book. If you're like me chances are you want some folder structure, keeping in mind, that there should be no nesting within those folders, basically from root folder you can have one nested level of folders or chapters. I thought about gathering files recursively, but that would complicate things a bit with ordering while is certainly doable, I think it isn't worth the trouble for now.

Folder structured book:
```
├── book
│ ├── Chapter1
│ │ ├── Scene1.md
│ │ └── Scene2.md
│ └── Chapter2
│ └── Scene1.md
├── images
│ └── lostbook.jpg
```

Files in root path:
```
├── book_2
│ ├── Scene1.md
│ ├── Scene2.md
│ └── Scene3.md
├── images
│ └── lostbook.jpg
```

## Extension Settings

This extension contributes the following settings:

* `gutenberg.defaultPandocCommand`: Default pandoc command, and output file name. Use this if you need to include a template, or other command flag
* `gutenberg.defaultPdfEngine`: Default pdf engine
* `gutenberg.useDifferentRootPath`: By default gutenberg reads workspace rootPath, if your book is within a folder, specify the path to be used
* `gutenberg.inputExtension`: Input file extension, if you're using something other than md
* `gutenberg.outputExtension`: Output file extension
* `gutenberg.ignoreRootPathFolders`: Root path folders ignored from the book print
* `gutenberg.ignoreFiles`: Files to be ignored from the book print
* `gutenberg.pandocCmdArgs`: Variables that are passed to the default pandoc command.
* `gutenberg.pandocCommandExtra`: If any extra flags are needed, they go here, i.e. --template=, --toc, etc.
* `gutenberg.useDifferentRootPath`: By default gutenberg reads workspace rootPath, if your book is within a folder, specify the path to be used.
* `gutenberg.inputExtension`: Input file extension, if you're using something other than md.
* `gutenberg.outputExtension`: Output file extension.
* `gutenberg.ignoreRootPathFolders`: Root path folders ignored from the book print.
* `gutenberg.ignoreFiles`: Files to be ignored from the book print.

### ignoreRootPathFolders

Expand All @@ -59,11 +85,11 @@ None

Users appreciate release notes as you update your extension.

### 1.0.0
### 1.0.1

Initial release of gutenberg:
- Print a book
- Print a single file
Bug Fixes:
- Fixed issue with spaces in path
- Added cmd arguments to configuration

## Credits

Expand Down
24 changes: 20 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const vscode = require('vscode');
const path = require('path');
const { exec } = require("child_process");
const process = require("process")
const fs = require('fs-extra')

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
Expand All @@ -20,14 +21,17 @@ function activate(context) {
var gutenbergOutputChannel = vscode.window.createOutputChannel('Gutenberg')

// Options
defaultPandocCommandOption = vscode.workspace.getConfiguration('gutenberg').get('defaultPandocCommand');
pandocCmdArgsOption = vscode.workspace.getConfiguration('gutenberg').get('pandocCmdArgs');
pandocCommandExtraOption = vscode.workspace.getConfiguration('gutenberg').get('pandocCommandExtra');
defaultPdfEngineOption = vscode.workspace.getConfiguration('gutenberg').get('defaultPdfEngine');
rootFolderOption = vscode.workspace.getConfiguration('gutenberg').get('useDifferentRootPath');
ignoreRootFoldersOption = vscode.workspace.getConfiguration('gutenberg').get('ignoreRootPathFolders');
ignoreFilesOption = vscode.workspace.getConfiguration('gutenberg').get('ignoreFiles');
inputExtensionOption = vscode.workspace.getConfiguration('gutenberg').get('inputExtension');
outputExtensionOption = vscode.workspace.getConfiguration('gutenberg').get('outputExtension');

console.log(pandocCmdArgsOption)

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
Expand Down Expand Up @@ -88,14 +92,26 @@ function activate(context) {
} else {
vscode.window.showErrorMessage('No files found!');
return
}
}

// Ensure output folder exists
const outputFolderExists = await fs.pathExists(`${rootPathFull}/${pandocCmdArgsOption.outputFolder}`)
if(!outputFolderExists){
try {
await fs.ensureDir(`${rootPathFull}/${pandocCmdArgsOption.outputFolder}`)
console.log('success!')
} catch (err) {
console.error(err)
vscode.window.showErrorMessage(err);
}
}

let pandocCmdTest = `cd "${rootPathFull}" && ls`
let pandocCmd = ''
if(outputExtensionOption !== "pdf"){
pandocCmd = `cd "${rootPathFull}" && ${defaultPandocCommandOption}.${outputExtensionOption} ${filesString}`
pandocCmd = `cd "${rootPathFull}" && pandoc -o ./${pandocCmdArgsOption.outputFolder}/${pandocCmdArgsOption.bookName}.${outputExtensionOption} ${filesString} ${pandocCommandExtraOption}`
} else {
pandocCmd = `cd "${rootPathFull}" && ${defaultPandocCommandOption}.${outputExtensionOption} --pdf-engine=${defaultPdfEngineOption} ${filesString}`
pandocCmd = `cd "${rootPathFull}" && pandoc -o ./${pandocCmdArgsOption.outputFolder}/${pandocCmdArgsOption.bookName}.${outputExtensionOption} --pdf-engine=${pandocCmdArgsOption.pdfEngine} ${filesString} ${pandocCommandExtraOption}`
}

exec(pandocCmd, (error, stdout, stderr) => {
Expand Down
63 changes: 63 additions & 0 deletions package-lock.json

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

23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-gutenberg",
"displayName": "Gutenberg",
"description": "Print a markdown book to pdf, doc, or html",
"version": "1.0.0",
"version": "1.0.1",
"publisher": "TheFern",
"icon": "images/printed.png",
"license": "MIT",
Expand Down Expand Up @@ -45,15 +45,19 @@
"configuration": {
"title": "Gutenberg",
"properties": {
"gutenberg.defaultPandocCommand": {
"type": "string",
"default": "pandoc -o ./output/book",
"description": "Default Pandoc Command for advanced users, the book extension comes from outputExtension"
"gutenberg.pandocCmdArgs": {
"type": "object",
"default": {
"outputFolder": "output",
"bookName": "book",
"pdfEngine": "xelatex"
},
"description": "Pandoc cmd line options"
},
"gutenberg.defaultPdfEngine": {
"gutenberg.pandocCommandExtra": {
"type": "string",
"default": "xelatex",
"description": "Default pdf engine"
"default": "",
"description": "If any extra flags are needed, they go here, i.e. template, toc, etc."
},
"gutenberg.useDifferentRootPath": {
"type": "string",
Expand Down Expand Up @@ -101,5 +105,8 @@
"mocha": "^8.1.3",
"typescript": "^4.0.2",
"vscode-test": "^1.4.0"
},
"dependencies": {
"fs-extra": "^9.0.1"
}
}

0 comments on commit 05c7d8b

Please sign in to comment.