remark-stringify
Advanced tools
Comparing version 8.1.1 to 9.0.0-alpha.0
26
index.js
'use strict' | ||
var unherit = require('unherit') | ||
var xtend = require('xtend') | ||
var Compiler = require('./lib/compiler.js') | ||
module.exports = stringify | ||
stringify.Compiler = Compiler | ||
var toMarkdown = require('mdast-util-to-markdown') | ||
function stringify(options) { | ||
var Local = unherit(Compiler) | ||
Local.prototype.options = xtend( | ||
Local.prototype.options, | ||
this.data('settings'), | ||
options | ||
) | ||
this.Compiler = Local | ||
var self = this | ||
this.Compiler = compile | ||
function compile(tree) { | ||
var settings = Object.assign({}, self.data('settings'), options) | ||
// Note: this option is not in the readme. | ||
// The goal is for it to be set by plugins on `data` instead of being | ||
// passed by users. | ||
settings.extensions = settings.toMarkdownExtensions | ||
return toMarkdown(tree, settings) | ||
} | ||
} |
{ | ||
"name": "remark-stringify", | ||
"version": "8.1.1", | ||
"version": "9.0.0-alpha.0", | ||
"description": "remark plugin to compile Markdown", | ||
@@ -36,3 +36,2 @@ "license": "MIT", | ||
"index.js", | ||
"lib", | ||
"types/index.d.ts" | ||
@@ -42,16 +41,3 @@ ], | ||
"dependencies": { | ||
"ccount": "^1.0.0", | ||
"is-alphanumeric": "^1.0.0", | ||
"is-decimal": "^1.0.0", | ||
"is-whitespace-character": "^1.0.0", | ||
"longest-streak": "^2.0.1", | ||
"markdown-escapes": "^1.0.0", | ||
"markdown-table": "^2.0.0", | ||
"mdast-util-compact": "^2.0.0", | ||
"parse-entities": "^2.0.0", | ||
"repeat-string": "^1.5.4", | ||
"state-toggle": "^1.0.0", | ||
"stringify-entities": "^3.0.0", | ||
"unherit": "^1.0.4", | ||
"xtend": "^4.0.1" | ||
"mdast-util-to-markdown": "^0.4.0" | ||
}, | ||
@@ -58,0 +44,0 @@ "scripts": { |
312
readme.md
@@ -16,47 +16,2 @@ # remark-stringify | ||
## Sponsors | ||
<!--lint ignore no-html--> | ||
<table> | ||
<tr valign="top"> | ||
<td width="33.33%" align="center" colspan="2"> | ||
<a href="https://www.gatsbyjs.org">Gatsby</a><br>🥇<br><br> | ||
<a href="https://www.gatsbyjs.org"><img src="https://avatars1.githubusercontent.com/u/12551863?s=900&v=4"></a> | ||
</td> | ||
<td width="33.33%" align="center" colspan="2"> | ||
<a href="https://vercel.com">Vercel</a><br>🥇<br><br> | ||
<!--OC has a sharper image--> | ||
<a href="https://vercel.com"><img src="https://images.opencollective.com/vercel/d8a5bee/logo/512.png"></a> | ||
</td> | ||
<td width="33.33%" align="center" colspan="2"> | ||
<a href="https://www.netlify.com">Netlify</a><br><br><br> | ||
<!--OC has a sharper image--> | ||
<a href="https://www.netlify.com"><img src="https://images.opencollective.com/netlify/4087de2/logo/512.png"></a> | ||
</td> | ||
</tr> | ||
<tr valign="top"> | ||
<td width="16.67%" align="center"> | ||
<a href="https://www.holloway.com">Holloway</a><br><br><br> | ||
<a href="https://www.holloway.com"><img src="https://avatars1.githubusercontent.com/u/35904294?s=300&v=4"></a> | ||
</td> | ||
<td width="16.67%" align="center"> | ||
<a href="https://themeisle.com">ThemeIsle</a><br>🥉<br><br> | ||
<a href="https://themeisle.com"><img src="https://twitter-avatar.now.sh/themeisle"></a> | ||
</td> | ||
<td width="16.67%" align="center"> | ||
<a href="https://boostio.co">BoostIO</a><br>🥉<br><br> | ||
<a href="https://boostio.co"><img src="https://avatars1.githubusercontent.com/u/13612118?s=300&v=4"></a> | ||
</td> | ||
<td width="16.67%" align="center"> | ||
<a href="https://expo.io">Expo</a><br>🥉<br><br> | ||
<a href="https://expo.io"><img src="https://avatars1.githubusercontent.com/u/12504344?s=300&v=4"></a> | ||
</td> | ||
<td width="50%" align="center" colspan="2"> | ||
<br><br><br><br> | ||
<a href="https://opencollective.com/unified"><strong>You?</strong></a> | ||
</td> | ||
</tr> | ||
</table> | ||
## Install | ||
@@ -79,11 +34,8 @@ | ||
var processor = unified() | ||
.use(html) | ||
.use(rehype2remark) | ||
.use(stringify, { | ||
bullet: '*', | ||
fence: '~', | ||
fences: true, | ||
incrementListMarker: false | ||
}) | ||
var processor = unified().use(html).use(rehype2remark).use(stringify, { | ||
bullet: '*', | ||
fence: '~', | ||
fences: true, | ||
incrementListMarker: false | ||
}) | ||
@@ -95,14 +47,2 @@ process.stdin.pipe(createStream(processor)).pipe(process.stdout) | ||
## Contents | ||
* [API](#api) | ||
* [`processor().use(stringify[, options])`](#processorusestringify-options) | ||
* [`stringify.Compiler`](#stringifycompiler) | ||
* [Extending the `Compiler`](#extending-the-compiler) | ||
* [`Compiler#visitors`](#compilervisitors) | ||
* [`function visitor(node[, parent])`](#function-visitornode-parent) | ||
* [Security](#security) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## API | ||
@@ -117,3 +57,3 @@ | ||
##### `options` | ||
###### `options` | ||
@@ -123,169 +63,10 @@ Options can be passed directly, or passed later through | ||
###### `options.gfm` | ||
All the formatting options of [`mdast-util-to-markdown`][to-markdown-options] | ||
are supported and will be passed through. | ||
Serialize with the required escapes for GFM compatible Markdown (`boolean`, | ||
default: `true`). | ||
## Extending the compiler | ||
* Escape pipes (`|`, for tables) | ||
* Escape colons (`:`, for literal URLs) | ||
* Escape tildes (`~`, for strike-through) | ||
See [`mdast-util-to-markdown`][to-markdown]. | ||
Then create a wrapper plugin such as `remark-gfm`. | ||
###### `options.commonmark` | ||
Serialize for CommonMark compatible Markdown (`boolean`, default: `false`). | ||
* Serialize adjacent block quotes separately | ||
* Escape more characters using slashes, instead of as entities | ||
###### `options.pedantic` | ||
⚠️ Pedantic was previously used to mimic old-style Markdown mode: no tables, no | ||
fenced code, and with many bugs. | ||
It’s currently still “working”, but please do not use it, it’ll be removed in | ||
the future. | ||
###### `options.entities` | ||
⚠️ `entities` was previously used, but included bugs. | ||
It’s currently still “working”, but please do not use it, it’ll be removed in | ||
the future. | ||
###### `options.setext` | ||
Serialize headings, when possible, in Setext-style (`boolean`, default: `false`). | ||
Uses `=` for level one headings and `-` for level two headings. | ||
Other heading levels are serialized as ATX (respecting `closeAtx`). | ||
###### `options.closeAtx` | ||
Serialize ATX headings with the same amount of closing hashes as opening hashes | ||
(`boolean`, default: `false`). | ||
###### `options.tableCellPadding` | ||
Create tables with a space between cell delimiters (`|`) and content (`boolean`, | ||
default: `true`). | ||
###### `options.tablePipeAlign` | ||
Align the delimiters (`|`) between table cells so that they all align nicely and | ||
form a grid (`boolean`, default: `true`). | ||
###### `options.stringLength` | ||
Function passed to [`markdown-table`][markdown-table] to detect the length of a | ||
table cell (`Function`, default: [`s => s.length`][string-length]). | ||
Used to pad tables. | ||
###### `options.fence` | ||
Marker to use for fenced code blocks (`'~'` or ``'`'``, default: ``'`'``). | ||
###### `options.fences` | ||
Create code blocks with a fence instead of indentation if they have no info | ||
string (`boolean`, default: `false`). | ||
When `false`, code blocks are indented. | ||
Code blocks with an info string are always fenced. | ||
###### `options.bullet` | ||
Marker to use for the bullet of unordered list items (`'-'`, `'*'`, or `'+'`, | ||
default: `'-'`). | ||
###### `options.listItemIndent` | ||
Style of indentation for list items (`'tab'`, `'mixed'` or `'1'`, default: | ||
`'tab'`). | ||
* `'tab'`: use a tab stops (4 spaces) | ||
* `'1'`: use one space | ||
* `'mixed'`: use `1` for tight and `tab` for loose list items | ||
###### `options.incrementListMarker` | ||
Increment ordered list item numbers (`boolean`, default: `true`). | ||
When `false`, all list item numbers will be the same. | ||
###### `options.tightDefinitions` | ||
Separate definitions with a single line feed (`boolean`, default: `false`). | ||
When `false`, definitions will have blank lines between them, similar to other | ||
blocks. | ||
###### `options.rule` | ||
Marker to use for thematic breaks / horizontal rules (`'-'`, `'*'`, or `'_'`, | ||
default: `'*'`). | ||
###### `options.ruleRepetition` | ||
Number of markers to use for thematic breaks / horizontal rules (`number`, | ||
default: `3`). | ||
Musts be `3` or more. | ||
###### `options.ruleSpaces` | ||
Place a space between thematic break (horizontal rule) markers (`boolean`, | ||
default `true`). | ||
###### `options.strong` | ||
Marker to use for importance (`'_'` or `'*'`, default `'*'`). | ||
###### `options.emphasis` | ||
Marker to use for emphasis (`'_'` or `'*'`, default `'_'`). | ||
### `stringify.Compiler` | ||
Access to the [compiler][], if you need it. | ||
## Extending the `Compiler` | ||
If the `remark-stringify` plugin is used, it adds a [`Compiler`][compiler] | ||
constructor function to the `processor`. | ||
Other plugins can add visitors to its prototype to change how Markdown is | ||
serialized. | ||
The below plugin modifies a [visitor][] to add an extra blank line before | ||
headings with a rank of `2`. | ||
```js | ||
module.exports = gap | ||
function gap() { | ||
var Compiler = this.Compiler | ||
var visitors = Compiler.prototype.visitors | ||
var original = visitors.heading | ||
visitors.heading = heading | ||
function heading(node) { | ||
return (node.depth === 2 ? '\n' : '') + original.apply(this, arguments) | ||
} | ||
} | ||
``` | ||
### `Compiler#visitors` | ||
Map of types to [visitor][]s (`Object.<Function>`). | ||
### `function visitor(node[, parent])` | ||
Serialize `node`. | ||
###### Parameters | ||
* `node` ([`Node`][node]) — Node to compile | ||
* `parent` ([`Parent`][parent], optional) — Parent of `node`. | ||
Not available on the root node | ||
###### Returns | ||
`string` — Serialized given `node`. | ||
## Security | ||
@@ -315,2 +96,49 @@ | ||
## Sponsor | ||
Support this effort and give back by sponsoring on [OpenCollective][collective]! | ||
<!--lint ignore no-html--> | ||
<table> | ||
<tr valign="middle"> | ||
<td width="20%" align="center" colspan="2"> | ||
<a href="https://www.gatsbyjs.org">Gatsby</a> 🥇<br><br> | ||
<a href="https://www.gatsbyjs.org"><img src="https://avatars1.githubusercontent.com/u/12551863?s=256&v=4" width="128"></a> | ||
</td> | ||
<td width="20%" align="center" colspan="2"> | ||
<a href="https://vercel.com">Vercel</a> 🥇<br><br> | ||
<a href="https://vercel.com"><img src="https://avatars1.githubusercontent.com/u/14985020?s=256&v=4" width="128"></a> | ||
</td> | ||
<td width="20%" align="center" colspan="2"> | ||
<a href="https://www.netlify.com">Netlify</a><br><br> | ||
<!--OC has a sharper image--> | ||
<a href="https://www.netlify.com"><img src="https://images.opencollective.com/netlify/4087de2/logo/256.png" width="128"></a> | ||
</td> | ||
<td width="10%" align="center"> | ||
<a href="https://www.holloway.com">Holloway</a><br><br> | ||
<a href="https://www.holloway.com"><img src="https://avatars1.githubusercontent.com/u/35904294?s=128&v=4" width="64"></a> | ||
</td> | ||
<td width="10%" align="center"> | ||
<a href="https://themeisle.com">ThemeIsle</a><br><br> | ||
<a href="https://themeisle.com"><img src="https://avatars1.githubusercontent.com/u/58979018?s=128&v=4" width="64"></a> | ||
</td> | ||
<td width="10%" align="center"> | ||
<a href="https://boostio.co">BoostIO</a><br><br> | ||
<a href="https://boostio.co"><img src="https://avatars1.githubusercontent.com/u/13612118?s=128&v=4" width="64"></a> | ||
</td> | ||
<td width="10%" align="center"> | ||
<a href="https://expo.io">Expo</a><br><br> | ||
<a href="https://expo.io"><img src="https://avatars1.githubusercontent.com/u/12504344?s=128&v=4" width="64"></a> | ||
</td> | ||
</tr> | ||
<tr valign="middle"> | ||
<td width="100%" align="center" colspan="10"> | ||
<br> | ||
<a href="https://opencollective.com/unified"><strong>You?</strong></a> | ||
<br><br> | ||
</td> | ||
</tr> | ||
</table> | ||
## License | ||
@@ -344,5 +172,5 @@ | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/remark | ||
[chat]: https://github.com/remarkjs/remark/discussions | ||
@@ -377,18 +205,12 @@ [health]: https://github.com/remarkjs/.github | ||
[node]: https://github.com/syntax-tree/unist#node | ||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
[parent]: https://github.com/syntax-tree/unist#parent | ||
[rehype]: https://github.com/rehypejs/rehype | ||
[extend]: #extending-the-compiler | ||
[sanitize]: https://github.com/rehypejs/rehype-sanitize | ||
[visitor]: #function-visitornode-parent | ||
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown | ||
[markdown-table]: https://github.com/wooorm/markdown-table | ||
[to-markdown-options]: https://github.com/syntax-tree/mdast-util-to-markdown#formatting-options | ||
[string-length]: https://github.com/wooorm/markdown-table#stringlengthcell | ||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
[rehype]: https://github.com/rehypejs/rehype | ||
[sanitize]: https://github.com/rehypejs/rehype-sanitize | ||
[extend]: #extending-the-compiler |
@@ -14,5 +14,5 @@ // TypeScript Version: 3.0 | ||
declare namespace remarkStringify { | ||
interface Stringify extends Plugin<[PartialRemarkStringifyOptions?]> { | ||
interface Stringify extends Plugin<[RemarkStringifyOptions?]> { | ||
Compiler: typeof RemarkCompiler | ||
(this: Processor, options?: PartialRemarkStringifyOptions): void | ||
(this: Processor, options?: RemarkStringifyOptions): void | ||
} | ||
@@ -23,24 +23,27 @@ | ||
interface RemarkStringifyOptions { | ||
gfm: boolean | ||
commonmark: boolean | ||
entities: boolean | 'numbers' | 'escape' | ||
setext: boolean | ||
closeAtx: boolean | ||
tableCellPadding: boolean | ||
tablePipeAlign: boolean | ||
stringLength: (s: string) => number | ||
fence: '~' | '`' | ||
fences: boolean | ||
bullet: '-' | '*' | '+' | ||
listItemIndent: 'tab' | '1' | 'mixed' | ||
incrementListMarker: boolean | ||
tightDefinitions: boolean | ||
rule: '-' | '_' | '*' | ||
ruleRepetition: number | ||
ruleSpaces: boolean | ||
strong: '_' | '*' | ||
emphasis: '_' | '*' | ||
gfm?: boolean | ||
commonmark?: boolean | ||
entities?: boolean | 'numbers' | 'escape' | ||
setext?: boolean | ||
closeAtx?: boolean | ||
tableCellPadding?: boolean | ||
tablePipeAlign?: boolean | ||
stringLength?: (s: string) => number | ||
fence?: '~' | '`' | ||
fences?: boolean | ||
bullet?: '-' | '*' | '+' | ||
listItemIndent?: 'tab' | '1' | 'mixed' | ||
incrementListMarker?: boolean | ||
tightDefinitions?: boolean | ||
rule?: '-' | '_' | '*' | ||
ruleRepetition?: number | ||
ruleSpaces?: boolean | ||
strong?: '_' | '*' | ||
emphasis?: '_' | '*' | ||
} | ||
type PartialRemarkStringifyOptions = Partial<RemarkStringifyOptions> | ||
/** | ||
* @deprecated Use `RemarkStringifyOptions` instead. | ||
*/ | ||
type PartialRemarkStringifyOptions = RemarkStringifyOptions | ||
@@ -47,0 +50,0 @@ type Visitor = (node: Node, parent?: Parent) => string |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
9435
4
59
1
209
1
+ Addedmdast-util-to-markdown@0.4.3(transitive)
+ Addedmdast-util-to-string@1.1.0(transitive)
+ Addedzwitch@1.0.5(transitive)
- Removedccount@^1.0.0
- Removedis-alphanumeric@^1.0.0
- Removedis-decimal@^1.0.0
- Removedis-whitespace-character@^1.0.0
- Removedlongest-streak@^2.0.1
- Removedmarkdown-escapes@^1.0.0
- Removedmarkdown-table@^2.0.0
- Removedmdast-util-compact@^2.0.0
- Removedparse-entities@^2.0.0
- Removedrepeat-string@^1.5.4
- Removedstate-toggle@^1.0.0
- Removedstringify-entities@^3.0.0
- Removedunherit@^1.0.4
- Removedxtend@^4.0.1
- Removed@types/unist@2.0.11(transitive)
- Removedccount@1.1.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-alphanumeric@1.0.0(transitive)
- Removedis-whitespace-character@1.0.4(transitive)
- Removedmarkdown-escapes@1.0.4(transitive)
- Removedmarkdown-table@2.0.0(transitive)
- Removedmdast-util-compact@2.0.1(transitive)
- Removedstate-toggle@1.0.3(transitive)
- Removedunherit@1.1.3(transitive)
- Removedunist-util-is@4.1.0(transitive)
- Removedunist-util-visit@2.0.3(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)