Socket
Socket
Sign inDemoInstall

remark-frontmatter

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-frontmatter - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

65

index.js
'use strict'
var matters = require('./lib/matters')
var parse = require('./lib/parse')
var compile = require('./lib/compile')
var syntax = require('micromark-extension-frontmatter')
var fromMarkdown = require('mdast-util-frontmatter/from-markdown')
var toMarkdown = require('mdast-util-frontmatter/to-markdown')

@@ -10,54 +10,11 @@ module.exports = frontmatter

function frontmatter(options) {
var parser = this.Parser
var compiler = this.Compiler
var config = matters(options || ['yaml'])
if (isRemarkParser(parser)) {
attachParser(parser, config)
var data = this.data()
add('micromarkExtensions', syntax(options))
add('fromMarkdownExtensions', fromMarkdown(options))
add('toMarkdownExtensions', toMarkdown(options))
function add(field, value) {
/* istanbul ignore if - other extensions. */
if (data[field]) data[field].push(value)
else data[field] = [value]
}
if (isRemarkCompiler(compiler)) {
attachCompiler(compiler, config)
}
}
function attachParser(parser, matters) {
var proto = parser.prototype
var tokenizers = wrap(parse, matters)
var names = []
var key
for (key in tokenizers) {
names.push(key)
}
proto.blockMethods = names.concat(proto.blockMethods)
proto.blockTokenizers = Object.assign({}, tokenizers, proto.blockTokenizers)
}
function attachCompiler(compiler, matters) {
var proto = compiler.prototype
proto.visitors = Object.assign({}, wrap(compile, matters), proto.visitors)
}
function wrap(func, matters) {
var result = {}
var length = matters.length
var index = -1
var tuple
while (++index < length) {
tuple = func(matters[index])
result[tuple[0]] = tuple[1]
}
return result
}
function isRemarkParser(parser) {
return Boolean(parser && parser.prototype && parser.prototype.blockTokenizers)
}
function isRemarkCompiler(compiler) {
return Boolean(compiler && compiler.prototype && compiler.prototype.visitors)
}

24

package.json
{
"name": "remark-frontmatter",
"version": "2.0.0",
"version": "3.0.0",
"description": "remark plugin to support frontmatter (yaml, toml, and more)",

@@ -31,3 +31,2 @@ "license": "MIT",

"index.js",
"lib",
"types/index.d.ts"

@@ -37,7 +36,8 @@ ],

"dependencies": {
"fault": "^1.0.1"
"mdast-util-frontmatter": "^0.2.0",
"micromark-extension-frontmatter": "^0.2.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"dtslint": "^3.4.1",
"dtslint": "^4.0.0",
"is-hidden": "^1.0.0",

@@ -47,13 +47,13 @@ "not": "^0.1.0",

"prettier": "^2.0.0",
"remark": "^12.0.0",
"remark": "^13.0.0-alpha.1",
"remark-cli": "^8.0.0",
"remark-preset-wooorm": "^7.0.0",
"tape": "^4.0.0",
"tinyify": "^2.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"to-vfile": "^6.0.0",
"unified": "^9.0.0",
"xo": "^0.28.0"
"xo": "^0.33.0"
},
"scripts": {
"format": "remark *.md -qfo && prettier --write . && xo --fix",
"format": "remark . -qfo --ignore-pattern test/ && prettier . --write && xo --fix",
"build-bundle": "browserify . -s remarkFrontmatter > remark-frontmatter.js",

@@ -85,7 +85,9 @@ "build-mangle": "browserify . -s remarkFrontmatter -p tinyify > remark-frontmatter.min.js",

"rules": {
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-optional-catch-binding": "off",
"guard-for-in": "off"
},
"ignores": [
"remark-frontmatter.js",
"**/*.ts"
"types/",
"remark-frontmatter.js"
]

@@ -92,0 +94,0 @@ },

@@ -13,2 +13,10 @@ # remark-frontmatter

## Important!
This plugin is affected by the new parser in remark
([`micromark`](https://github.com/micromark/micromark),
see [`remarkjs/remark#536`](https://github.com/remarkjs/remark/pull/536)).
Use version 2 while you’re still on remark 12.
Use version 3 for remark 13+.
## Install

@@ -49,5 +57,5 @@

.use(logger)
.process(vfile.readSync('example.md'), function(err, file) {
.process(vfile.readSync('example.md'), function (err, file) {
console.error(report(err || file))
console.log(String(file))
console.error(report(err || file))
})

@@ -63,12 +71,13 @@

```js
{ type: 'root',
children:
[ { type: 'toml',
value: 'title = "New Website"',
position: [Object] },
{ type: 'heading',
depth: 1,
children: [Array],
position: [Object] } ],
position: [Object] }
{
type: 'root',
children: [
{type: 'toml', value: 'title = "New Website"', position: [Object]},
{type: 'heading', depth: 1, children: [Array], position: [Object]}
],
position: {
start: {line: 1, column: 1, offset: 0},
end: {line: 6, column: 1, offset: 48}
}
}
```

@@ -89,114 +98,9 @@

Support frontmatter (YAML, TOML, and more).
Adds [tokenizers][] if the [processor][] is configured with
[`remark-parse`][parse], and [visitors][] if configured with
[`remark-stringify`][stringify].
Configures remark so that it can parse and serialize frontmatter (YAML, TOML,
and more).
If you are parsing from a different syntax, or compiling to a different syntax
(such as, [`remark-man`][man]) your custom nodes may not be supported.
##### `options`
One [`preset`][preset] or [`Matter`][matter], or an array of them, defining all
the supported frontmatters (default: `'yaml'`).
See [`micromark-extension-frontmatter`][options] for a description of `options`.
##### `preset`
Either `'yaml'` or `'toml'`:
* `'yaml'` — [`matter`][matter] defined as `{type: 'yaml', marker: '-'}`
* `'toml'` — [`matter`][matter] defined as `{type: 'toml', marker: '+'}`
##### `Matter`
An object with a `type` and either a `marker` or a `fence`:
* `type` (`string`)
— Node type to parse to in [mdast][] and compile from
* `marker` (`string` or `{open: string, close: string}`)
— Character used to construct fences.
By providing an object with `open` and `close`.
different characters can be used for opening and closing fences.
For example the character `'-'` will result in `'---'` being used as the
fence
* `fence` (`string` or `{open: string, close: string}`)
— String used as the complete fence.
By providing an object with `open` and `close` different values can be used
for opening and closing fences.
This can be used too if fences contain different characters or lengths other
than 3
* `anywhere` (`boolean`, default: `false`)
– if `true`, matter can be found anywhere in the document.
If `false` (default), only matter at the start of the document is recognized
###### Example
For `{type: 'yaml', marker: '-'}`:
```yaml
---
key: value
---
```
Yields:
```json
{
"type": "yaml",
"value": "key: value"
}
```
For `{type: 'custom', marker: {open: '<', close: '>'}}`:
```text
<<<
data
>>>
```
Yields:
```json
{
"type": "custom",
"value": "data"
}
```
For `{type: 'custom', fence: '+=+=+=+'}`:
```text
+=+=+=+
data
+=+=+=+
```
Yields:
```json
{
"type": "custom",
"value": "data"
}
```
For `{type: 'json', fence: {open: '{', close: '}'}}`:
```json
{
"key": "value"
}
```
Yields:
```json
{
"type": "json",
"value": "\"key\": \"value\""
}
```
## Security

@@ -210,6 +114,10 @@

* [`remark-gfm`](https://github.com/remarkjs/remark-gfm)
— GitHub Flavored Markdown
* [`remark-footnotes`](https://github.com/remarkjs/remark-footnotes)
— Footnotes
* [`remark-math`](https://github.com/remarkjs/remark-math)
— Math
* [`remark-github`](https://github.com/remarkjs/remark-github)
— Auto-link references like in GitHub issues, PRs, and comments
* [`remark-math`](https://github.com/rokt33r/remark-math)
— Math support
* [`remark-yaml-config`](https://github.com/remarkjs/remark-yaml-config)

@@ -234,3 +142,3 @@ — Configure remark from YAML configuration

[build-badge]: https://img.shields.io/travis/remarkjs/remark-frontmatter/master.svg
[build-badge]: https://img.shields.io/travis/remarkjs/remark-frontmatter/main.svg

@@ -257,5 +165,5 @@ [build]: https://travis-ci.org/remarkjs/remark-frontmatter

[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

@@ -266,7 +174,7 @@ [npm]: https://docs.npmjs.com/cli/install

[contributing]: https://github.com/remarkjs/.github/blob/master/contributing.md
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
[support]: https://github.com/remarkjs/.github/blob/master/support.md
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
[coc]: https://github.com/remarkjs/.github/blob/master/code-of-conduct.md
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md

@@ -279,20 +187,2 @@ [license]: license

[parse]: https://github.com/remarkjs/remark/tree/master/packages/remark-parse
[tokenizers]: https://github.com/remarkjs/remark/tree/master/packages/remark-parse#parserblocktokenizers
[stringify]: https://github.com/remarkjs/remark/tree/master/packages/remark-stringify
[visitors]: https://github.com/remarkjs/remark/tree/master/packages/remark-stringify#compilervisitors
[processor]: https://github.com/unifiedjs/unified#processor
[mdast]: https://github.com/syntax-tree/mdast
[man]: https://github.com/remarkjs/remark-man
[preset]: #preset
[matter]: #matter
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

@@ -303,1 +193,3 @@

[hast]: https://github.com/syntax-tree/hast
[options]: https://github.com/micromark/micromark-extension-frontmatter#options

@@ -40,3 +40,3 @@ // Minimum TypeScript Version: 3.2

/**
* if `true`, matter can be found anywhere in the document.
* If `true`, matter can be found anywhere in the document.
* If `false` (default), only matter at the start of the document is recognized

@@ -43,0 +43,0 @@ *

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