Extract inferParserByLanguage to seperate file (#13483)
This commit is contained in:
1 parent
da4f6071c2
commit
5b962d6f14
5 files changed
+22
-22
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import escapeStringRegexp from "escape-string-regexp";
|
||||
import { getSupportInfo } from "../main/support.js";
|
||||
import {
|
||||
skipWhitespace,
|
||||
skipSpaces,
|
||||
@@ -423,20 +422,6 @@ function addTrailingComment(node, comment) {
|
||||
addCommentHelper(node, comment);
|
||||
}
|
||||
|
||||
function inferParserByLanguage(language, options) {
|
||||
const { languages } = getSupportInfo({ plugins: options.plugins });
|
||||
const matched =
|
||||
languages.find(({ name }) => name.toLowerCase() === language) ||
|
||||
languages.find(
|
||||
({ aliases }) => Array.isArray(aliases) && aliases.includes(language)
|
||||
) ||
|
||||
languages.find(
|
||||
({ extensions }) =>
|
||||
Array.isArray(extensions) && extensions.includes(`.${language}`)
|
||||
);
|
||||
return matched && matched.parsers[0];
|
||||
}
|
||||
|
||||
function isFrontMatterNode(node) {
|
||||
return node && node.type === "front-matter";
|
||||
}
|
||||
@@ -473,7 +458,6 @@ function describeNodeForDebugging(node) {
|
||||
}
|
||||
|
||||
export {
|
||||
inferParserByLanguage,
|
||||
getMaxContinuousCount,
|
||||
getMinNotPresentContinuousCount,
|
||||
getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import parseFrontMatter from "../utils/front-matter/parse.js";
|
||||
import inferParserByLanguage from "../utils/infer-parser-by-language.js";
|
||||
import createError from "../common/parser-create-error.js";
|
||||
import { inferParserByLanguage } from "../common/util.js";
|
||||
import HTML_TAGS from "./utils/html-tag-names.js";
|
||||
import HTML_ELEMENT_ATTRIBUTES from "./utils/html-elements-attributes.js";
|
||||
import isUnknownNamespace from "./utils/is-unknown-namespace.js";
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* @typedef {import("../../common/ast-path.js").default} AstPath
|
||||
*/
|
||||
|
||||
import { inferParserByLanguage, isFrontMatterNode } from "../../common/util.js";
|
||||
import { isFrontMatterNode } from "../../common/util.js";
|
||||
import inferParserByLanguage from "../../utils/infer-parser-by-language.js";
|
||||
import { line, hardline, join } from "../../document/builders.js";
|
||||
import { replaceEndOfLine } from "../../document/utils.js";
|
||||
import {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import {
|
||||
inferParserByLanguage,
|
||||
getMaxContinuousCount,
|
||||
} from "../common/util.js";
|
||||
import { getMaxContinuousCount } from "../common/util.js";
|
||||
import { hardline, markAsRoot } from "../document/builders.js";
|
||||
import { replaceEndOfLine } from "../document/utils.js";
|
||||
import printFrontMatter from "../utils/front-matter/print.js";
|
||||
import inferParserByLanguage from "../utils/infer-parser-by-language.js";
|
||||
import { getFencedCodeBlockValue } from "./utils.js";
|
||||
|
||||
function embed(path, options) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { getSupportInfo } from "../main/support.js";
|
||||
|
||||
function inferParserByLanguage(language, options) {
|
||||
const { languages } = getSupportInfo({ plugins: options.plugins });
|
||||
const matched =
|
||||
languages.find(({ name }) => name.toLowerCase() === language) ||
|
||||
languages.find(
|
||||
({ aliases }) => Array.isArray(aliases) && aliases.includes(language)
|
||||
) ||
|
||||
languages.find(
|
||||
({ extensions }) =>
|
||||
Array.isArray(extensions) && extensions.includes(`.${language}`)
|
||||
);
|
||||
return matched && matched.parsers[0];
|
||||
}
|
||||
|
||||
export default inferParserByLanguage;
|
||||
Reference in new issue
Block a user