Rename all uses of frontmatter to frontMatter or front-matter (#4519)
parent
553e9bb1ac
commit
9155fe5018
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const createError = require("../common/parser-create-error");
|
const createError = require("../common/parser-create-error");
|
||||||
const parseFrontmatter = require("../utils/front-matter");
|
const parseFrontMatter = require("../utils/front-matter");
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
const utils = require("./utils");
|
const utils = require("./utils");
|
||||||
|
@ -474,8 +474,8 @@ function parseNestedCSS(node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseWithParser(parser, text) {
|
function parseWithParser(parser, text) {
|
||||||
const parsed = parseFrontmatter(text);
|
const parsed = parseFrontMatter(text);
|
||||||
const frontmatter = parsed.frontmatter;
|
const frontMatter = parsed.frontMatter;
|
||||||
text = parsed.content;
|
text = parsed.content;
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
|
@ -491,10 +491,10 @@ function parseWithParser(parser, text) {
|
||||||
|
|
||||||
result = parseNestedCSS(addTypePrefix(result, "css-"));
|
result = parseNestedCSS(addTypePrefix(result, "css-"));
|
||||||
|
|
||||||
if (frontmatter) {
|
if (frontMatter) {
|
||||||
result.nodes.unshift({
|
result.nodes.unshift({
|
||||||
type: "frontmatter",
|
type: "front-matter",
|
||||||
value: frontmatter
|
value: frontMatter
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ function genericPrint(path, options, print) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
case "frontmatter":
|
case "front-matter":
|
||||||
return concat([node.value, hardline]);
|
return concat([node.value, hardline]);
|
||||||
case "css-root": {
|
case "css-root": {
|
||||||
const nodes = printNodeSequence(path, options, print);
|
const nodes = printNodeSequence(path, options, print);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
const remarkParse = require("remark-parse");
|
const remarkParse = require("remark-parse");
|
||||||
const unified = require("unified");
|
const unified = require("unified");
|
||||||
const parseFrontmatter = require("../utils/front-matter");
|
const parseFrontMatter = require("../utils/front-matter");
|
||||||
const util = require("../common/util");
|
const util = require("../common/util");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,7 +22,7 @@ const util = require("../common/util");
|
||||||
function parse(text, parsers, opts) {
|
function parse(text, parsers, opts) {
|
||||||
const processor = unified()
|
const processor = unified()
|
||||||
.use(remarkParse, { footnotes: true, commonmark: true })
|
.use(remarkParse, { footnotes: true, commonmark: true })
|
||||||
.use(frontmatter)
|
.use(frontMatter)
|
||||||
.use(liquid)
|
.use(liquid)
|
||||||
.use(restoreUnescapedCharacter(text))
|
.use(restoreUnescapedCharacter(text))
|
||||||
.use(mergeContinuousTexts)
|
.use(mergeContinuousTexts)
|
||||||
|
@ -128,18 +128,18 @@ function splitText(options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function frontmatter() {
|
function frontMatter() {
|
||||||
const proto = this.Parser.prototype;
|
const proto = this.Parser.prototype;
|
||||||
proto.blockMethods = ["frontmatter"].concat(proto.blockMethods);
|
proto.blockMethods = ["frontMatter"].concat(proto.blockMethods);
|
||||||
proto.blockTokenizers.frontmatter = tokenizer;
|
proto.blockTokenizers.frontMatter = tokenizer;
|
||||||
|
|
||||||
function tokenizer(eat, value) {
|
function tokenizer(eat, value) {
|
||||||
const parsed = parseFrontmatter(value);
|
const parsed = parseFrontMatter(value);
|
||||||
|
|
||||||
if (parsed.frontmatter) {
|
if (parsed.frontMatter) {
|
||||||
return eat(parsed.frontmatter)({
|
return eat(parsed.frontMatter)({
|
||||||
type: "frontmatter",
|
type: "front-matter",
|
||||||
value: parsed.frontmatter
|
value: parsed.frontMatter
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const parseFrontmatter = require("../utils/front-matter");
|
const parseFrontMatter = require("../utils/front-matter");
|
||||||
|
|
||||||
const pragmas = ["format", "prettier"];
|
const pragmas = ["format", "prettier"];
|
||||||
|
|
||||||
|
@ -19,12 +19,12 @@ function startWithPragma(text) {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
startWithPragma,
|
startWithPragma,
|
||||||
hasPragma: text => startWithPragma(parseFrontmatter(text).content.trimLeft()),
|
hasPragma: text => startWithPragma(parseFrontMatter(text).content.trimLeft()),
|
||||||
insertPragma: text => {
|
insertPragma: text => {
|
||||||
const extracted = parseFrontmatter(text);
|
const extracted = parseFrontMatter(text);
|
||||||
const pragma = `<!-- @${pragmas[0]} -->`;
|
const pragma = `<!-- @${pragmas[0]} -->`;
|
||||||
return extracted.frontmatter
|
return extracted.frontMatter
|
||||||
? `${extracted.frontmatter}\n\n${pragma}\n\n${extracted.content}`
|
? `${extracted.frontMatter}\n\n${pragma}\n\n${extracted.content}`
|
||||||
: `${pragma}\n\n${extracted.content}`;
|
: `${pragma}\n\n${extracted.content}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -211,7 +211,7 @@ function genericPrint(path, options, print) {
|
||||||
style
|
style
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
case "frontmatter":
|
case "front-matter":
|
||||||
return node.value;
|
return node.value;
|
||||||
case "html": {
|
case "html": {
|
||||||
const parentNode = path.getParentNode();
|
const parentNode = path.getParentNode();
|
||||||
|
@ -828,7 +828,7 @@ function clean(ast, newObj, parent) {
|
||||||
parent.type === "root" &&
|
parent.type === "root" &&
|
||||||
parent.children.length > 0 &&
|
parent.children.length > 0 &&
|
||||||
(parent.children[0] === ast ||
|
(parent.children[0] === ast ||
|
||||||
(parent.children[0].type === "frontmatter" &&
|
(parent.children[0].type === "front-matter" &&
|
||||||
parent.children[1] === ast)) &&
|
parent.children[1] === ast)) &&
|
||||||
ast.type === "html" &&
|
ast.type === "html" &&
|
||||||
pragma.startWithPragma(ast.value)
|
pragma.startWithPragma(ast.value)
|
||||||
|
|
|
@ -12,13 +12,13 @@ function parse(text) {
|
||||||
let end = -1;
|
let end = -1;
|
||||||
|
|
||||||
if (!delimiter || (end = text.indexOf(`\n${delimiter}`, 3)) === -1) {
|
if (!delimiter || (end = text.indexOf(`\n${delimiter}`, 3)) === -1) {
|
||||||
return { frontmatter: null, content: text };
|
return { frontMatter: null, content: text };
|
||||||
}
|
}
|
||||||
|
|
||||||
end = end + 4;
|
end = end + 4;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
frontmatter: text.slice(0, end),
|
frontMatter: text.slice(0, end),
|
||||||
content: text.slice(end)
|
content: text.slice(end)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue