2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-28 20:36:44 -08:00
|
|
|
import { addError, nextLinesRe } from "../helpers/helpers.cjs";
|
|
|
|
import { getHtmlTagInfo } from "../helpers/micromark-helpers.cjs";
|
|
|
|
import { filterByTypesCached } from "./cache.mjs";
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2024-12-03 19:58:28 -08:00
|
|
|
/** @type {import("markdownlint").Rule} */
|
2024-11-28 20:36:44 -08:00
|
|
|
export default {
|
2018-01-21 21:44:25 -08:00
|
|
|
"names": [ "MD033", "no-inline-html" ],
|
|
|
|
"description": "Inline HTML",
|
|
|
|
"tags": [ "html" ],
|
2024-03-09 16:17:50 -08:00
|
|
|
"parser": "micromark",
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD033(params, onError) {
|
2020-01-25 18:40:39 -08:00
|
|
|
let allowedElements = params.config.allowed_elements;
|
|
|
|
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
|
|
|
|
allowedElements = allowedElements.map((element) => element.toLowerCase());
|
2024-08-24 22:05:16 -07:00
|
|
|
for (const token of filterByTypesCached([ "htmlText" ], true)) {
|
2023-08-04 20:53:38 -07:00
|
|
|
const htmlTagInfo = getHtmlTagInfo(token);
|
|
|
|
if (
|
|
|
|
htmlTagInfo &&
|
|
|
|
!htmlTagInfo.close &&
|
|
|
|
!allowedElements.includes(htmlTagInfo.name.toLowerCase())
|
|
|
|
) {
|
|
|
|
const range = [
|
|
|
|
token.startColumn,
|
|
|
|
token.text.replace(nextLinesRe, "").length
|
|
|
|
];
|
|
|
|
addError(
|
|
|
|
onError,
|
|
|
|
token.startLine,
|
|
|
|
"Element: " + htmlTagInfo.name,
|
|
|
|
undefined,
|
|
|
|
range
|
|
|
|
);
|
2019-04-29 22:09:03 -07:00
|
|
|
}
|
2023-01-21 15:41:03 -08:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
};
|