Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-parse

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-parse - npm Package Compare versions

Comparing version 8.0.3 to 9.0.0-alpha.0

22

index.js
'use strict'
var unherit = require('unherit')
var xtend = require('xtend')
var Parser = require('./lib/parser.js')
module.exports = parse
parse.Parser = Parser
var fromMarkdown = require('mdast-util-from-markdown')
function parse(options) {
var settings = this.data('settings')
var Local = unherit(Parser)
var self = this
Local.prototype.options = xtend(Local.prototype.options, settings, options)
this.Parser = parse
this.Parser = Local
function parse(doc) {
var settings = Object.assign({}, self.data('settings'), options)
// Note: these options are not in the readme.
// The goal is for them to be set by plugins on `data` instead of being
// passed by users.
settings.extensions = settings.micromarkExtensions
settings.mdastExtensions = settings.fromMarkdownExtensions
return fromMarkdown(doc, settings)
}
}
{
"name": "remark-parse",
"version": "8.0.3",
"version": "9.0.0-alpha.0",
"description": "remark plugin to parse Markdown",

@@ -37,22 +37,6 @@ "license": "MIT",

"index.js",
"lib",
"types/index.d.ts"
],
"dependencies": {
"ccount": "^1.0.0",
"collapse-white-space": "^1.0.2",
"is-alphabetical": "^1.0.0",
"is-decimal": "^1.0.0",
"is-whitespace-character": "^1.0.0",
"is-word-character": "^1.0.0",
"markdown-escapes": "^1.0.0",
"parse-entities": "^2.0.0",
"repeat-string": "^1.5.4",
"state-toggle": "^1.0.0",
"trim": "0.0.1",
"trim-trailing-lines": "^1.0.0",
"unherit": "^1.0.4",
"unist-util-remove-position": "^2.0.0",
"vfile-location": "^3.0.0",
"xtend": "^4.0.1"
"mdast-util-from-markdown": "^0.7.0"
},

@@ -59,0 +43,0 @@ "scripts": {

@@ -13,50 +13,6 @@ # remark-parse

Parses Markdown to [**mdast**][mdast] syntax trees.
Built on [micromark][].
Used in the [**remark** processor][remark] but can be used on its own as well.
Can be [extended][extend] to change how Markdown is parsed.
## 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

@@ -80,3 +36,3 @@

var processor = unified()
.use(markdown, {commonmark: true})
.use(markdown)
.use(remark2rehype)

@@ -90,23 +46,2 @@ .use(html)

## Contents
* [API](#api)
* [`processor().use(parse[, options])`](#processoruseparse-options)
* [`parse.Parser`](#parseparser)
* [Extending the `Parser`](#extending-the-parser)
* [`Parser#blockTokenizers`](#parserblocktokenizers)
* [`Parser#blockMethods`](#parserblockmethods)
* [`Parser#inlineTokenizers`](#parserinlinetokenizers)
* [`Parser#inlineMethods`](#parserinlinemethods)
* [`function tokenizer(eat, value, silent)`](#function-tokenizereat-value-silent)
* [`tokenizer.locator(value, fromIndex)`](#tokenizerlocatorvalue-fromindex)
* [`eat(subvalue)`](#eatsubvalue)
* [`add(node[, parent])`](#addnode-parent)
* [`add.test()`](#addtest)
* [`add.reset(node[, parent])`](#addresetnode-parent)
* [Turning off a tokenizer](#turning-off-a-tokenizer)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## API

@@ -116,3 +51,3 @@

### `processor().use(parse[, options])`
### `processor().use(parse)`

@@ -122,348 +57,7 @@ Configure the `processor` to read Markdown as input and process

##### `options`
## Extending the parser
Options can be passed directly, or passed later through
[`processor.data()`][data].
See [`micromark`][micromark] and [`mdast-util-from-markdown`][from-markdown].
Then create a wrapper plugin such as `remark-gfm`.
###### `options.gfm`
GFM mode (`boolean`, default: `true`).
```markdown
hello ~~hi~~ world
```
Turns on:
* [Fenced code blocks](https://help.github.com/articles/creating-and-highlighting-code-blocks#fenced-code-blocks)
* [Autolinking of URLs](https://help.github.com/articles/autolinked-references-and-urls)
* [Deletions (strikethrough)](https://help.github.com/articles/basic-writing-and-formatting-syntax#styling-text)
* [Task lists](https://help.github.com/articles/basic-writing-and-formatting-syntax#task-lists)
* [Tables](https://help.github.com/articles/organizing-information-with-tables)
###### `options.commonmark`
CommonMark mode (`boolean`, default: `false`).
```markdown
This is a paragraph
and this is also part of the preceding paragraph.
```
Allows:
* Empty lines to split block quotes
* Parentheses (`(` and `)`) around link and image titles
* Any escaped [ASCII punctuation][escapes] character
* Closing parenthesis (`)`) as an ordered list marker
* URL definitions in block quotes
Disallows:
* Indented code blocks directly following a paragraph
* ATX headings (`# Hash headings`) without spacing after opening hashes or and
before closing hashes
* Setext headings (`Underline headings\n---`) when following a paragraph
* Newlines in link and image titles
* White space in link and image URLs in auto-links (links in brackets, `<` and
`>`)
* Lazy block quote continuation, lines not preceded by a greater than
character (`>`), for lists, code, and thematic breaks
###### `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.blocks`
Blocks (`Array.<string>`, default: list of [block HTML elements][blocks]).
```markdown
<block>foo
</block>
```
Defines which HTML elements are seen as block level.
### `parse.Parser`
Access to the [parser][], if you need it.
## Extending the `Parser`
Typically, using [*transformers*][transformer] to manipulate a syntax tree
produces the desired output.
Sometimes, such as when introducing new syntactic entities with a certain
precedence, interfacing with the parser is necessary.
If the `remark-parse` plugin is used, it adds a [`Parser`][parser] constructor
function to the `processor`.
Other plugins can add tokenizers to its prototype to change how Markdown is
parsed.
The below plugin adds a [tokenizer][] for at-mentions.
```js
module.exports = mentions
function mentions() {
var Parser = this.Parser
var tokenizers = Parser.prototype.inlineTokenizers
var methods = Parser.prototype.inlineMethods
// Add an inline tokenizer (defined in the following example).
tokenizers.mention = tokenizeMention
// Run it just before `text`.
methods.splice(methods.indexOf('text'), 0, 'mention')
}
```
### `Parser#blockTokenizers`
Map of names to [tokenizer][]s (`Object.<Function>`).
These tokenizers (such as `fencedCode`, `table`, and `paragraph`) eat from the
start of a value to a line ending.
See `#blockMethods` below for a list of methods that are included by default.
### `Parser#blockMethods`
List of `blockTokenizers` names (`Array.<string>`).
Specifies the order in which tokenizers run.
Precedence of default block methods is as follows:
<!--methods-block start-->
* `blankLine`
* `indentedCode`
* `fencedCode`
* `blockquote`
* `atxHeading`
* `thematicBreak`
* `list`
* `setextHeading`
* `html`
* `definition`
* `table`
* `paragraph`
<!--methods-block end-->
### `Parser#inlineTokenizers`
Map of names to [tokenizer][]s (`Object.<Function>`).
These tokenizers (such as `url`, `reference`, and `emphasis`) eat from the start
of a value.
To increase performance, they depend on [locator][]s.
See `#inlineMethods` below for a list of methods that are included by default.
### `Parser#inlineMethods`
List of `inlineTokenizers` names (`Array.<string>`).
Specifies the order in which tokenizers run.
Precedence of default inline methods is as follows:
<!--methods-inline start-->
* `escape`
* `autoLink`
* `url`
* `email`
* `html`
* `link`
* `reference`
* `strong`
* `emphasis`
* `deletion`
* `code`
* `break`
* `text`
<!--methods-inline end-->
### `function tokenizer(eat, value, silent)`
There are two types of tokenizers: block level and inline level.
Both are functions, and work the same, but inline tokenizers must have a
[locator][].
The following example shows an inline tokenizer that is added by the mentions
plugin above.
```js
tokenizeMention.notInLink = true
tokenizeMention.locator = locateMention
function tokenizeMention(eat, value, silent) {
var match = /^@(\w+)/.exec(value)
if (match) {
if (silent) {
return true
}
return eat(match[0])({
type: 'link',
url: 'https://social-network/' + match[1],
children: [{type: 'text', value: match[0]}]
})
}
}
```
Tokenizers *test* whether a document starts with a certain syntactic entity.
In *silent* mode, they return whether that test passes.
In *normal* mode, they consume that token, a process which is called “eating”.
Locators enable inline tokenizers to function faster by providing where the next
entity may occur.
###### Signatures
* `Node? = tokenizer(eat, value)`
* `boolean? = tokenizer(eat, value, silent)`
###### Parameters
* `eat` ([`Function`][eat]) — Eat, when applicable, an entity
* `value` (`string`) — Value which may start an entity
* `silent` (`boolean`, optional) — Whether to detect or consume
###### Properties
* `locator` ([`Function`][locator]) — Required for inline tokenizers
* `onlyAtStart` (`boolean`) — Whether nodes can only be found at the beginning
of the document
* `notInBlock` (`boolean`) — Whether nodes cannot be in block quotes or lists
* `notInList` (`boolean`) — Whether nodes cannot be in lists
* `notInLink` (`boolean`) — Whether nodes cannot be in links
###### Returns
* `boolean?`, in *silent* mode — whether a node can be found at the start of
`value`
* [`Node?`][node], In *normal* mode — If it can be found at the start of
`value`
### `tokenizer.locator(value, fromIndex)`
Locators are required for inline tokenizers.
Their role is to keep parsing performant.
The following example shows a locator that is added by the mentions tokenizer
above.
```js
function locateMention(value, fromIndex) {
return value.indexOf('@', fromIndex)
}
```
Locators enable inline tokenizers to function faster by providing information on
where the next entity *may* occur.
Locators may be wrong, it’s OK if there actually isn’t a node to be found at the
index they return.
###### Parameters
* `value` (`string`) — Value which may contain an entity
* `fromIndex` (`number`) — Position to start searching at
###### Returns
`number` — Index at which an entity may start, and `-1` otherwise.
### `eat(subvalue)`
```js
var add = eat('foo')
```
Eat `subvalue`, which is a string at the start of the [tokenized][tokenizer]
`value`.
###### Parameters
* `subvalue` (`string`) - Value to eat
###### Returns
[`add`][add].
### `add(node[, parent])`
```js
var add = eat('foo')
add({type: 'text', value: 'foo'})
```
Add [positional information][position] to `node` and add `node` to `parent`.
###### Parameters
* `node` ([`Node`][node]) - Node to patch position on and to add
* `parent` ([`Parent`][parent], optional) - Place to add `node` to in the
syntax tree.
Defaults to the currently processed node
###### Returns
[`Node`][node] — The given `node`.
### `add.test()`
Get the [positional information][position] that would be patched on `node` by
`add`.
###### Returns
[`Position`][position].
### `add.reset(node[, parent])`
`add`, but resets the internal position.
Useful for example in lists, where the same content is first eaten for a list,
and later for list items.
###### Parameters
* `node` ([`Node`][node]) - Node to patch position on and insert
* `parent` ([`Node`][node], optional) - Place to add `node` to in
the syntax tree.
Defaults to the currently processed node
###### Returns
[`Node`][node] — The given node.
### Turning off a tokenizer
In some situations, you may want to turn off a tokenizer to avoid parsing that
syntactic feature.
Preferably, use the [`remark-disable-tokenizers`][remark-disable-tokenizers]
plugin to turn off tokenizers.
Alternatively, this can be done by replacing the tokenizer from
`blockTokenizers` (or `blockMethods`) or `inlineTokenizers` (or
`inlineMethods`).
The following example turns off indented code blocks:
```js
remarkParse.Parser.prototype.blockTokenizers.indentedCode = indentedCode
function indentedCode() {
return true
}
```
## Security

@@ -493,2 +87,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

@@ -522,5 +163,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

@@ -547,34 +188,10 @@ [health]: https://github.com/remarkjs/.github

[data]: https://github.com/unifiedjs/unified#processordatakey-value
[remark]: https://github.com/remarkjs/remark/tree/main/packages/remark
[blocks]: https://github.com/remarkjs/remark/blob/main/packages/remark-parse/lib/block-elements.js
[mdast]: https://github.com/syntax-tree/mdast
[escapes]: https://spec.commonmark.org/0.29/#backslash-escapes
[node]: https://github.com/syntax-tree/unist#node
[parent]: https://github.com/syntax-tree/unist#parent
[position]: https://github.com/syntax-tree/unist#position
[parser]: https://github.com/unifiedjs/unified#processorparser
[transformer]: https://github.com/unifiedjs/unified#function-transformernode-file-next
[extend]: #extending-the-parser
[tokenizer]: #function-tokenizereat-value-silent
[locator]: #tokenizerlocatorvalue-fromindex
[eat]: #eatsubvalue
[add]: #addnode-parent
[remark-disable-tokenizers]: https://github.com/zestedesavoir/zmarkdown/tree/HEAD/packages/remark-disable-tokenizers
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

@@ -585,1 +202,5 @@

[sanitize]: https://github.com/rehypejs/rehype-sanitize
[micromark]: https://github.com/micromark/micromark
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown

@@ -12,2 +12,5 @@ // TypeScript Version: 3.0

}
blockTokenizers: {
[key: string]: remarkParse.Tokenizer
}

@@ -18,4 +21,4 @@ inlineMethods: string[]

declare namespace remarkParse {
interface Parse extends Plugin<[PartialRemarkParseOptions?]> {
(options: PartialRemarkParseOptions): void
interface Parse extends Plugin<[RemarkParseOptions?]> {
(options: RemarkParseOptions): void
Parser: typeof RemarkParser

@@ -39,3 +42,3 @@ }

*/
gfm: boolean
gfm?: boolean

@@ -62,3 +65,3 @@ /**

*/
commonmark: boolean
commonmark?: boolean

@@ -70,3 +73,3 @@ /**

*/
blocks: string[]
blocks?: string[]

@@ -85,6 +88,9 @@ /**

*/
pedantic: boolean
pedantic?: boolean
}
type PartialRemarkParseOptions = Partial<RemarkParseOptions>
/**
* @deprecated Use `RemarkParseOptions` instead.
*/
type PartialRemarkParseOptions = RemarkParseOptions

@@ -91,0 +97,0 @@ interface Add {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc