Rename all uses of frontmatter to frontMatter or front-matter (#4519)

master
Jed Fox 2018-05-21 10:02:09 -04:00 committed by GitHub
parent 553e9bb1ac
commit 9155fe5018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 26 deletions

View File

@ -1,7 +1,7 @@
"use strict";
const createError = require("../common/parser-create-error");
const parseFrontmatter = require("../utils/front-matter");
const parseFrontMatter = require("../utils/front-matter");
// utils
const utils = require("./utils");
@ -474,8 +474,8 @@ function parseNestedCSS(node) {
}
function parseWithParser(parser, text) {
const parsed = parseFrontmatter(text);
const frontmatter = parsed.frontmatter;
const parsed = parseFrontMatter(text);
const frontMatter = parsed.frontMatter;
text = parsed.content;
let result;
@ -491,10 +491,10 @@ function parseWithParser(parser, text) {
result = parseNestedCSS(addTypePrefix(result, "css-"));
if (frontmatter) {
if (frontMatter) {
result.nodes.unshift({
type: "frontmatter",
value: frontmatter
type: "front-matter",
value: frontMatter
});
}

View File

@ -77,7 +77,7 @@ function genericPrint(path, options, print) {
}
switch (node.type) {
case "frontmatter":
case "front-matter":
return concat([node.value, hardline]);
case "css-root": {
const nodes = printNodeSequence(path, options, print);

View File

@ -2,7 +2,7 @@
const remarkParse = require("remark-parse");
const unified = require("unified");
const parseFrontmatter = require("../utils/front-matter");
const parseFrontMatter = require("../utils/front-matter");
const util = require("../common/util");
/**
@ -22,7 +22,7 @@ const util = require("../common/util");
function parse(text, parsers, opts) {
const processor = unified()
.use(remarkParse, { footnotes: true, commonmark: true })
.use(frontmatter)
.use(frontMatter)
.use(liquid)
.use(restoreUnescapedCharacter(text))
.use(mergeContinuousTexts)
@ -128,18 +128,18 @@ function splitText(options) {
});
}
function frontmatter() {
function frontMatter() {
const proto = this.Parser.prototype;
proto.blockMethods = ["frontmatter"].concat(proto.blockMethods);
proto.blockTokenizers.frontmatter = tokenizer;
proto.blockMethods = ["frontMatter"].concat(proto.blockMethods);
proto.blockTokenizers.frontMatter = tokenizer;
function tokenizer(eat, value) {
const parsed = parseFrontmatter(value);
const parsed = parseFrontMatter(value);
if (parsed.frontmatter) {
return eat(parsed.frontmatter)({
type: "frontmatter",
value: parsed.frontmatter
if (parsed.frontMatter) {
return eat(parsed.frontMatter)({
type: "front-matter",
value: parsed.frontMatter
});
}
}

View File

@ -1,6 +1,6 @@
"use strict";
const parseFrontmatter = require("../utils/front-matter");
const parseFrontMatter = require("../utils/front-matter");
const pragmas = ["format", "prettier"];
@ -19,12 +19,12 @@ function startWithPragma(text) {
module.exports = {
startWithPragma,
hasPragma: text => startWithPragma(parseFrontmatter(text).content.trimLeft()),
hasPragma: text => startWithPragma(parseFrontMatter(text).content.trimLeft()),
insertPragma: text => {
const extracted = parseFrontmatter(text);
const extracted = parseFrontMatter(text);
const pragma = `<!-- @${pragmas[0]} -->`;
return extracted.frontmatter
? `${extracted.frontmatter}\n\n${pragma}\n\n${extracted.content}`
return extracted.frontMatter
? `${extracted.frontMatter}\n\n${pragma}\n\n${extracted.content}`
: `${pragma}\n\n${extracted.content}`;
}
};

View File

@ -211,7 +211,7 @@ function genericPrint(path, options, print) {
style
]);
}
case "frontmatter":
case "front-matter":
return node.value;
case "html": {
const parentNode = path.getParentNode();
@ -828,7 +828,7 @@ function clean(ast, newObj, parent) {
parent.type === "root" &&
parent.children.length > 0 &&
(parent.children[0] === ast ||
(parent.children[0].type === "frontmatter" &&
(parent.children[0].type === "front-matter" &&
parent.children[1] === ast)) &&
ast.type === "html" &&
pragma.startWithPragma(ast.value)

View File

@ -12,13 +12,13 @@ function parse(text) {
let end = -1;
if (!delimiter || (end = text.indexOf(`\n${delimiter}`, 3)) === -1) {
return { frontmatter: null, content: text };
return { frontMatter: null, content: text };
}
end = end + 4;
return {
frontmatter: text.slice(0, end),
frontMatter: text.slice(0, end),
content: text.slice(end)
};
}