From ad9e290b60e8f2b58bbae34b6c9721f3a485b8af Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 18 Jan 2018 16:02:11 +0100 Subject: [PATCH] remark: add examples on how to configure Closes GH-314. --- packages/remark/readme.md | 65 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/packages/remark/readme.md b/packages/remark/readme.md index ba24469d5..5ec215ccb 100644 --- a/packages/remark/readme.md +++ b/packages/remark/readme.md @@ -1,13 +1,13 @@ # remark [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat] -The [**remark**][remark] processor is a markdown processor powered by +The [`remark`][remark] processor is a markdown processor powered by [plugins][]. -* Interface by [**unified**][unified] +* Interface by [`unified`][unified] * [**MDAST**][mdast] syntax tree -* Parses markdown to the tree with [**remark-parse**][parse] +* Parses markdown to the tree with [`remark-parse`][parse] * [Plugins][] transform the tree -* Compiles the tree to markdown using [**remark-stringify**][stringify] +* Compiles the tree to markdown using [`remark-stringify`][stringify] Don’t need the parser? Or the compiler? [That’s OK][unified-usage]. @@ -21,6 +21,10 @@ npm install remark ## Usage +###### Common example + +This example lints markdown and turns it into HTML. + ```js var remark = require('remark'); var recommended = require('remark-preset-lint-recommended'); @@ -42,9 +46,58 @@ Yields: 1:1 warning Missing newline character at end of file final-newline remark-lint ⚠ 1 warning +``` + +```html

Hello world!

``` +###### Settings through data + +This example prettifies markdown and configures [`remark-parse`][parse] and +[`remark-stringify`][stringify] through [data][]. + +```js +var remark = require('remark'); + +remark() + .data('settings', {commonmark: true, emphasis: '*', strong: '*'}) + .process('_Emphasis_ and __importance__', function (err, file) { + if (err) throw err; + console.log(String(file)); + }); +``` + +Yields: + +```markdown +*Emphasis* and **importance** +``` + +###### Settings through a preset + +This example prettifies markdown and configures [`remark-parse`][parse] and +[`remark-stringify`][stringify] through a [preset][]. + +```js +var remark = require('remark'); + +remark() + .use({ + settings: {commonmark: true, emphasis: '*', strong: '*'} + }) + .process('_Emphasis_ and __importance__', function (err, file) { + if (err) throw err; + console.log(String(file)); + }); +``` + +Yields: + +```markdown +*Emphasis* and **importance** +``` + ## License [MIT][license] © [Titus Wormer][author] @@ -82,3 +135,7 @@ Yields: [plugins]: https://github.com/remarkjs/remark/blob/master/doc/plugins.md [unified-usage]: https://github.com/unifiedjs/unified#usage + +[preset]: https://github.com/unifiedjs/unified#preset + +[data]: https://github.com/unifiedjs/unified#processordatakey-value