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

Support configuration file #9

Merged
merged 11 commits into from
Sep 5, 2018
Merged

Support configuration file #9

merged 11 commits into from
Sep 5, 2018

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented Sep 2, 2018

This PR will support configuration file like marp.config.js or .marprc (+ with extensions .json, .yml, .yaml, and .js), powered by cosmiconfig.

You can specify CLI options through config file declaratively. For example, a below .marprc file will instruct to output pdf with using uncover theme.

{
  "theme": "uncover",
  "pdf": true
}

The biggest benefit is a customization of Marp Core's constructor option by options. These are too complex to be config through CLI, so you must use configuration file.

# .marprc.yml

options:
  markdown:
    breaks: false
  emoji:
    shortcode: false
    unicode: false

html: # Setting HTML whitelist (Marp core's feature)
  a:
    - href
    - target
    - title
  br: []

Some flags may not be able to use because they will override by marp-cli.

If you are using configuration file with .js extension, you can swap the conversion engine to Marpit based engines. The below example is using pure Marpit framework.

// marp.config.js
const { Marpit } = require('@marp-team/marpit')

module.exports = {
  engine: Marpit,
  options: {
    lazyYAML: true,
  },
}

Of course you can specify the path to configuration file by CLI --config (-c) option.

# Convert markdown in "~/slideshow" with specifed configuration
marp ~/slideshow -c ~/slideshow/config.json

ToDo

  • Add tests

@yhatt
Copy link
Member Author

yhatt commented Sep 3, 2018

Update engine support to be able to specify module name by string. In addition, it becomes to be able to parse marpBrowser section of package.json as browser context JS. (= Marp.ready(), that has already defined in @marp-team/marp-core)

It means that you can use CLI directly while developing Marpit based engine. cosmiconfig will read marp section on package.json, so you can develop an original engine with this config:

{
  "private": true,
  "scripts": {
    "build": "marp"
  },
  "devDependencies": {
    "@marp-team/marpit": "^0.0.14",
    "@marp-team/marp-cli": "^0.0.5"
  },
  "marpBrowser": "lib/browser-context.js",
  "marp": {
    "engine": "./lib/marpit-based-engine.js"
  }
}
export default class MarpitBasedEngine extends Marpit {
  // ...
}

@yhatt yhatt changed the title [Work in progress] Support configuration file Support configuration file Sep 5, 2018
@yhatt yhatt merged commit 0b41ca8 into master Sep 5, 2018
@yhatt yhatt deleted the config-file branch September 5, 2018 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant