Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5808270
commit 5909f5b
Showing
6 changed files
with
133 additions
and
111 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use strict"; | ||
|
||
const parseFrontMatter = require("../../utils/front-matter/parse.js"); | ||
|
||
function frontMatter() { | ||
const proto = this.Parser.prototype; | ||
proto.blockMethods = ["frontMatter", ...proto.blockMethods]; | ||
proto.blockTokenizers.frontMatter = tokenizer; | ||
|
||
function tokenizer(eat, value) { | ||
const parsed = parseFrontMatter(value); | ||
|
||
if (parsed.frontMatter) { | ||
return eat(parsed.frontMatter.raw)(parsed.frontMatter); | ||
} | ||
} | ||
tokenizer.onlyAtStart = true; | ||
} | ||
|
||
module.exports = frontMatter; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use strict"; | ||
|
||
const mdx = require("../mdx.js"); | ||
const { mapAst, INLINE_NODE_WRAPPER_TYPES } = require("../utils.js"); | ||
|
||
function htmlToJsx() { | ||
return (ast) => | ||
mapAst(ast, (node, _index, [parent]) => { | ||
if ( | ||
node.type !== "html" || | ||
mdx.COMMENT_REGEX.test(node.value) || | ||
INLINE_NODE_WRAPPER_TYPES.includes(parent.type) | ||
) { | ||
return node; | ||
} | ||
return { ...node, type: "jsx" }; | ||
}); | ||
} | ||
|
||
module.exports = htmlToJsx; |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
|
||
function liquid() { | ||
const proto = this.Parser.prototype; | ||
const methods = proto.inlineMethods; | ||
methods.splice(methods.indexOf("text"), 0, "liquid"); | ||
proto.inlineTokenizers.liquid = tokenizer; | ||
|
||
function tokenizer(eat, value) { | ||
const match = value.match(/^({%.*?%}|{{.*?}})/s); | ||
|
||
if (match) { | ||
return eat(match[0])({ | ||
type: "liquidNode", | ||
value: match[0], | ||
}); | ||
} | ||
} | ||
tokenizer.locator = function (value, fromIndex) { | ||
return value.indexOf("{", fromIndex); | ||
}; | ||
} | ||
|
||
module.exports = liquid; |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use strict"; | ||
|
||
function looseItems() { | ||
const proto = this.Parser.prototype; | ||
const originalList = proto.blockTokenizers.list; | ||
|
||
function fixListNodes(value, node, parent) { | ||
if (node.type === "listItem") { | ||
node.loose = node.spread || value.charAt(value.length - 1) === "\n"; | ||
if (node.loose) { | ||
parent.loose = true; | ||
} | ||
} | ||
return node; | ||
} | ||
|
||
proto.blockTokenizers.list = function list(realEat, value, silent) { | ||
function eat(subvalue) { | ||
const realAdd = realEat(subvalue); | ||
|
||
function add(node, parent) { | ||
return realAdd(fixListNodes(subvalue, node, parent), parent); | ||
} | ||
add.reset = function (node, parent) { | ||
return realAdd.reset(fixListNodes(subvalue, node, parent), parent); | ||
}; | ||
|
||
return add; | ||
} | ||
eat.now = realEat.now; | ||
return originalList.call(this, eat, value, silent); | ||
}; | ||
} | ||
|
||
module.exports = looseItems; |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
|
||
function wikiLink() { | ||
const entityType = "wikiLink"; | ||
const wikiLinkRegex = /^\[\[(?<linkContents>.+?)]]/s; | ||
const proto = this.Parser.prototype; | ||
const methods = proto.inlineMethods; | ||
methods.splice(methods.indexOf("link"), 0, entityType); | ||
proto.inlineTokenizers.wikiLink = tokenizer; | ||
|
||
function tokenizer(eat, value) { | ||
const match = wikiLinkRegex.exec(value); | ||
|
||
if (match) { | ||
const linkContents = match.groups.linkContents.trim(); | ||
|
||
return eat(match[0])({ | ||
type: entityType, | ||
value: linkContents, | ||
}); | ||
} | ||
} | ||
|
||
tokenizer.locator = function (value, fromIndex) { | ||
return value.indexOf("[", fromIndex); | ||
}; | ||
} | ||
|
||
module.exports = wikiLink; |