mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run
46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
// @ts-check
|
|
|
|
import { addError, nextLinesRe } from "../helpers/helpers.cjs";
|
|
import { getHtmlTagInfo, getParentOfType } from "../helpers/micromark-helpers.cjs";
|
|
import { filterByTypesCached } from "./cache.mjs";
|
|
|
|
/** @typedef {import("micromark-extension-gfm-table")} */
|
|
|
|
// eslint-disable-next-line jsdoc/reject-any-type
|
|
const toLowerCaseStringArray = (/** @type {any} */ arr) => Array.isArray(arr) ? arr.map((elm) => String(elm).toLowerCase()) : [];
|
|
|
|
/** @type {import("markdownlint").Rule} */
|
|
export default {
|
|
"names": [ "MD033", "no-inline-html" ],
|
|
"description": "Inline HTML",
|
|
"tags": [ "html" ],
|
|
"parser": "micromark",
|
|
"function": function MD033(params, onError) {
|
|
const allowedElements = toLowerCaseStringArray(params.config.allowed_elements);
|
|
// If not defined, use allowedElements for backward compatibility
|
|
const tableAllowedElements = toLowerCaseStringArray(params.config.table_allowed_elements || params.config.allowed_elements);
|
|
for (const token of filterByTypesCached([ "htmlText" ], true)) {
|
|
const htmlTagInfo = getHtmlTagInfo(token);
|
|
if (htmlTagInfo && !htmlTagInfo.close) {
|
|
const elementName = htmlTagInfo?.name.toLowerCase();
|
|
const inTable = !!getParentOfType(token, [ "table" ]);
|
|
if (
|
|
(inTable || !allowedElements.includes(elementName)) &&
|
|
(!inTable || !tableAllowedElements.includes(elementName))
|
|
) {
|
|
const range = [
|
|
token.startColumn,
|
|
token.text.replace(nextLinesRe, "").length
|
|
];
|
|
addError(
|
|
onError,
|
|
token.startLine,
|
|
"Element: " + htmlTagInfo.name,
|
|
undefined,
|
|
range
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|