Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for using a custom Marp CLI config #123

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
"type": "boolean",
"default": true,
"description": "Shows editor toolbar button to Markdown document, for accessing quick pick of Marp commands."
},
"markdown.marp.customConfig": {
"type": "boolean",
"default": false,
"description": "Enable using a custom Marp CLI config file for exporting (does not affect preview in VS Code). Custom config file must be placed in the root of the workspace."
}
}
},
Expand Down
15 changes: 13 additions & 2 deletions src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,19 @@ export const doExport = async (uri: Uri, document: TextDocument) => {
const conf = await createConfigFile(document)

try {
await marpCli('-c', conf.path, input.path, '-o', uri.fsPath)
env.openExternal(uri)
if (!marpConfiguration().get<boolean>('customConfig')) {
await marpCli('-c', conf.path, input.path, '-o', uri.fsPath)
} else {
/* If we are using the custom config, set the working directory
* allow Marp CLI to search the document's workspace for a
* config file.
*/
const currentDir = path.cwd()
process.chdir(path.dirname(document.uri.fsPath))
await marpCli(input.path, '-o', uri.fsPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some options might have to override in CLI arguments for export the document as VS Code user expected. For example:

  • Disable extra conversion modes such as watch, server, and preview mode (These bring looking like hang up conversion process in VS Code UI). --no-server, --no-watch and --no-preview will work.
  • Prefer export type selected in the save dialog rather than specified in configuration file. (Require to pass specific flag: --pdf, --pptx, and --image [png|jpeg])

process.chdir(currentDir)
}
env.openExternal(uri)
} finally {
conf.cleanup()
}
Expand Down