-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update to a micromark parser, defer work to <https://github.com/micromark/micromark-extension-frontmatter>, <https://github.com/syntax-tree/mdast-util-frontmatter> * Frontmatter must now start on the first line Previously, delaying with blank lines first worked. That behavior does not match how GitHub parses YAML, and is thus removed.
- Loading branch information
Showing
39 changed files
with
181 additions
and
587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,19 @@ | ||
'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') | ||
|
||
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) | ||
} | ||
|
||
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) | ||
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] | ||
} | ||
|
||
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) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.