Restructure markdown plugin (#18479)
This commit is contained in:
1 parent
f16e059640
commit
9541af3087
20 files changed
+95
-78
No files matched your search
@@ -1,8 +1,4 @@
|
||||
import printer from "./printer-markdown.js";
|
||||
|
||||
export const printers = {
|
||||
mdast: printer,
|
||||
};
|
||||
export { default as languages } from "./languages.evaluate.js";
|
||||
export { default as options } from "./options.js";
|
||||
export * as parsers from "./parser-markdown.js";
|
||||
export * as parsers from "./parsers.js";
|
||||
export * as printers from "./printers.js";
|
||||
@@ -0,0 +1 @@
|
||||
export { parseMarkdown, parseMdx } from "./parse.js";
|
||||
File renamed without changes.
@@ -2,9 +2,7 @@ import footnotes from "remark-footnotes";
|
||||
import remarkMath from "remark-math";
|
||||
import remarkParse from "remark-parse";
|
||||
import unified from "unified";
|
||||
import { locEnd, locStart } from "./loc.js";
|
||||
import { BLOCKS_REGEX, esSyntax } from "./mdx.js";
|
||||
import { hasIgnorePragma, hasPragma } from "./pragma.js";
|
||||
import frontMatter from "./unified-plugins/front-matter.js";
|
||||
import htmlToJsx from "./unified-plugins/html-to-jsx.js";
|
||||
import liquid from "./unified-plugins/liquid.js";
|
||||
@@ -44,14 +42,7 @@ function createParse({ isMDX }) {
|
||||
|
||||
function noop() {}
|
||||
|
||||
const baseParser = {
|
||||
astFormat: "mdast",
|
||||
hasPragma,
|
||||
hasIgnorePragma,
|
||||
locStart,
|
||||
locEnd,
|
||||
};
|
||||
const parseMarkdown = /* @__PURE__ */ createParse({ isMDX: false });
|
||||
const parseMdx = /* @__PURE__ */ createParse({ isMDX: true });
|
||||
|
||||
export const markdown = { ...baseParser, parse: createParse({ isMDX: false }) };
|
||||
export const mdx = { ...baseParser, parse: createParse({ isMDX: true }) };
|
||||
export { markdown as remark };
|
||||
export { parseMarkdown, parseMdx };
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { parseFrontMatter } from "../../main/front-matter/index.js";
|
||||
import { parseFrontMatter } from "../../../main/front-matter/index.js";
|
||||
|
||||
/** @import {Plugin, Settings} from "unified" */
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { INLINE_NODE_WRAPPER_TYPES, mapAst } from "../../utilities.js";
|
||||
import { COMMENT_REGEX } from "../mdx.js";
|
||||
import { INLINE_NODE_WRAPPER_TYPES, mapAst } from "../utilities.js";
|
||||
|
||||
function htmlToJsx() {
|
||||
return (ast) =>
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,23 @@
|
||||
import { locEnd, locStart } from "./loc.js";
|
||||
import { parseMarkdown, parseMdx } from "./parse/index.js";
|
||||
import { hasIgnorePragma, hasPragma } from "./pragma.js";
|
||||
|
||||
function createParser(parse) {
|
||||
return {
|
||||
astFormat: "mdast",
|
||||
hasPragma,
|
||||
hasIgnorePragma,
|
||||
locStart,
|
||||
locEnd,
|
||||
parse,
|
||||
};
|
||||
}
|
||||
|
||||
const markdownParser = /* @__PURE__ */ createParser(parseMarkdown);
|
||||
const mdxParser = /* @__PURE__ */ createParser(parseMdx);
|
||||
|
||||
export {
|
||||
markdownParser as markdown,
|
||||
mdxParser as mdx,
|
||||
markdownParser as remark,
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { printMdast } from "./mdast.js";
|
||||
@@ -13,34 +13,29 @@ import {
|
||||
markAsRoot,
|
||||
replaceEndOfLine,
|
||||
softline,
|
||||
} from "../document/index.js";
|
||||
import getMaxContinuousCount from "../utilities/get-max-continuous-count.js";
|
||||
import getMinNotPresentContinuousCount from "../utilities/get-min-not-present-continuous-count.js";
|
||||
import getPreferredQuote from "../utilities/get-preferred-quote.js";
|
||||
import UnexpectedNodeError from "../utilities/unexpected-node-error.js";
|
||||
import clean from "./clean.js";
|
||||
import embed from "./embed.js";
|
||||
import getVisitorKeys from "./get-visitor-keys.js";
|
||||
import { locEnd, locStart } from "./loc.js";
|
||||
import { insertPragma } from "./pragma.js";
|
||||
import { printChildren } from "./print/children.js";
|
||||
import { printList } from "./print/list.js";
|
||||
import { printTable } from "./print/table.js";
|
||||
import { printWord } from "./print/word.js";
|
||||
import { printParagraph } from "./print-paragraph.js";
|
||||
import preprocess from "./print-preprocess.js";
|
||||
import { printSentence } from "./print-sentence.js";
|
||||
import { printWhitespace } from "./print-whitespace.js";
|
||||
} from "../../document/index.js";
|
||||
import getMaxContinuousCount from "../../utilities/get-max-continuous-count.js";
|
||||
import getMinNotPresentContinuousCount from "../../utilities/get-min-not-present-continuous-count.js";
|
||||
import getPreferredQuote from "../../utilities/get-preferred-quote.js";
|
||||
import UnexpectedNodeError from "../../utilities/unexpected-node-error.js";
|
||||
import { locEnd, locStart } from "../loc.js";
|
||||
import { printChildren } from "../print/children.js";
|
||||
import { printList } from "../print/list.js";
|
||||
import { printParagraph } from "../print/paragraph.js";
|
||||
import { printSentence } from "../print/sentence.js";
|
||||
import { printTable } from "../print/table.js";
|
||||
import { printWhitespace } from "../print/whitespace.js";
|
||||
import { printWord } from "../print/word.js";
|
||||
import {
|
||||
getFencedCodeBlockValue,
|
||||
getNthListSiblingIndex,
|
||||
isAutolink,
|
||||
isPrettierIgnore,
|
||||
splitText,
|
||||
} from "./utilities.js";
|
||||
} from "../utilities.js";
|
||||
|
||||
/**
|
||||
* @import {Doc} from "../document/index.js"
|
||||
* @import {Doc} from "../../document/index.js"
|
||||
*/
|
||||
|
||||
function prevOrNextWord(path) {
|
||||
@@ -55,7 +50,7 @@ function prevOrNextWord(path) {
|
||||
return hasPrevOrNextWord;
|
||||
}
|
||||
|
||||
function genericPrint(path, options, print) {
|
||||
function printMdast(path, options, print) {
|
||||
const { node } = path;
|
||||
|
||||
if (shouldRemainTheSameContent(path)) {
|
||||
@@ -502,10 +497,6 @@ function printTitle(title, options, printSpace = true) {
|
||||
return `${quote}${title}${quote}`;
|
||||
}
|
||||
|
||||
function hasPrettierIgnore(path) {
|
||||
return path.index > 0 && isPrettierIgnore(path.previous) === "next";
|
||||
}
|
||||
|
||||
// `remark-parse` lowercase the `label` as `identifier`, we don't want do that
|
||||
// https://github.com/remarkjs/remark/blob/daddcb463af2d5b2115496c395d0571c0ff87d15/packages/remark-parse/lib/tokenize/reference.js
|
||||
function printLinkReference(node) {
|
||||
@@ -516,21 +507,4 @@ function printFootnoteReference(node) {
|
||||
return `[^${node.label}]`;
|
||||
}
|
||||
|
||||
const printer = {
|
||||
features: {
|
||||
experimental_frontMatterSupport: {
|
||||
massageAstNode: true,
|
||||
embed: true,
|
||||
print: true,
|
||||
},
|
||||
},
|
||||
preprocess,
|
||||
print: genericPrint,
|
||||
embed,
|
||||
massageAstNode: clean,
|
||||
hasPrettierIgnore,
|
||||
insertPragma,
|
||||
getVisitorKeys,
|
||||
};
|
||||
|
||||
export default printer;
|
||||
export { printMdast };
|
||||
@@ -3,11 +3,11 @@ import {
|
||||
DOC_TYPE_FILL,
|
||||
fill,
|
||||
getDocType,
|
||||
} from "../document/index.js";
|
||||
} from "../../document/index.js";
|
||||
|
||||
/**
|
||||
* @import AstPath from "../common/ast-path.js"
|
||||
* @import {Doc} from "../document/index.js"
|
||||
* @import AstPath from "../../common/ast-path.js"
|
||||
* @import {Doc} from "../../document/index.js"
|
||||
*/
|
||||
|
||||
/**
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import htmlWhitespace from "../utilities/html-whitespace.js";
|
||||
import { getOrderedListItemInfo, mapAst, splitText } from "./utilities.js";
|
||||
import htmlWhitespace from "../../utilities/html-whitespace.js";
|
||||
import { getOrderedListItemInfo, mapAst, splitText } from "../utilities.js";
|
||||
|
||||
// 0x0 ~ 0x10ffff
|
||||
const isSingleCharRegex = /^\\?.$/su;
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* @import AstPath from "../common/ast-path.js"
|
||||
* @import {Doc} from "../document/index.js"
|
||||
* @import AstPath from "../../common/ast-path.js"
|
||||
* @import {Doc} from "../../document/index.js"
|
||||
*/
|
||||
|
||||
import { DOC_TYPE_STRING, fill, getDocType } from "../document/index.js";
|
||||
import { DOC_TYPE_STRING, fill, getDocType } from "../../document/index.js";
|
||||
|
||||
/**
|
||||
* @param {AstPath} path
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
import { hardline, line, softline } from "../document/index.js";
|
||||
import { hardline, line, softline } from "../../document/index.js";
|
||||
import {
|
||||
KIND_CJ_LETTER,
|
||||
KIND_CJK_PUNCTUATION,
|
||||
KIND_K_LETTER,
|
||||
KIND_NON_CJK,
|
||||
} from "./utilities.js";
|
||||
} from "../utilities.js";
|
||||
|
||||
/**
|
||||
* @import {WordNode, WhitespaceValue, WordKind} from "./utilities.js"
|
||||
* @import AstPath from "../common/ast-path.js"
|
||||
* @import {WordNode, WhitespaceValue, WordKind} from "../utilities.js"
|
||||
* @import AstPath from "../../common/ast-path.js"
|
||||
* @typedef {"always" | "never" | "preserve"} ProseWrap
|
||||
* @typedef {{ next?: WordNode | null, previous?: WordNode | null }}
|
||||
* AdjacentNodes Nodes adjacent to a `whitespace` node. Are always of type
|
||||
@@ -0,0 +1,26 @@
|
||||
import clean from "./clean.js";
|
||||
import embed from "./embed.js";
|
||||
import { insertPragma } from "./pragma.js";
|
||||
import { printMdast } from "./print/index.js";
|
||||
import preprocess from "./print/preprocess.js";
|
||||
import getVisitorKeys from "./traverse/get-visitor-keys.js";
|
||||
import { hasPrettierIgnore } from "./utilities.js";
|
||||
|
||||
const printer = {
|
||||
features: {
|
||||
experimental_frontMatterSupport: {
|
||||
massageAstNode: true,
|
||||
embed: true,
|
||||
print: true,
|
||||
},
|
||||
},
|
||||
preprocess,
|
||||
print: printMdast,
|
||||
embed,
|
||||
massageAstNode: clean,
|
||||
hasPrettierIgnore,
|
||||
insertPragma,
|
||||
getVisitorKeys,
|
||||
};
|
||||
|
||||
export { printer as mdast };
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import createGetVisitorKeys from "../utilities/create-get-visitor-keys.js";
|
||||
import createGetVisitorKeys from "../../utilities/create-get-visitor-keys.js";
|
||||
import visitorKeys from "./visitor-keys.evaluate.js";
|
||||
|
||||
const getVisitorKeys = createGetVisitorKeys(visitorKeys);
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { generateReferenceSharedVisitorKeys } from "../utilities/visitor-keys.js";
|
||||
import { generateReferenceSharedVisitorKeys } from "../../utilities/visitor-keys.js";
|
||||
|
||||
const visitorKeys = generateReferenceSharedVisitorKeys({
|
||||
root: ["children"],
|
||||
@@ -305,11 +305,16 @@ function getNthListSiblingIndex(node, parentNode) {
|
||||
}
|
||||
}
|
||||
|
||||
function hasPrettierIgnore(path) {
|
||||
return path.index > 0 && isPrettierIgnore(path.previous) === "next";
|
||||
}
|
||||
|
||||
export {
|
||||
getFencedCodeBlockValue,
|
||||
getNthListSiblingIndex,
|
||||
getOrderedListItemInfo,
|
||||
hasGitDiffFriendlyOrderedList,
|
||||
hasPrettierIgnore,
|
||||
INLINE_NODE_TYPES,
|
||||
INLINE_NODE_WRAPPER_TYPES,
|
||||
isAutolink,
|
||||
|
||||
@@ -4,7 +4,7 @@ import glimmerVisitorKeys from "../../src/language-handlebars/visitor-keys.js";
|
||||
import htmlVisitorKeys from "../../src/language-html/visitor-keys.evaluate.js";
|
||||
import estreeVisitorKeys from "../../src/language-js/traverse/visitor-keys.evaluate.js";
|
||||
import jsonVisitorKeys from "../../src/language-json/visitor-keys.evaluate.js";
|
||||
import remarkVisitorKeys from "../../src/language-markdown/visitor-keys.evaluate.js";
|
||||
import remarkVisitorKeys from "../../src/language-markdown/traverse/visitor-keys.evaluate.js";
|
||||
import yamlVisitorKeys from "../../src/language-yaml/visitor-keys.evaluate.js";
|
||||
|
||||
// Keep eye on package change
|
||||
|
||||
Reference in new issue
Block a user