mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-18 15:00:13 +01:00
Address new TypeScript warnings in core files, improve type definitions.
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
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
This commit is contained in:
parent
bd02390014
commit
7beb9fc9d0
32 changed files with 354 additions and 170 deletions
|
|
@ -4,6 +4,11 @@ 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" ],
|
||||
|
|
@ -11,35 +16,30 @@ export default {
|
|||
"tags": [ "html" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD033(params, onError) {
|
||||
let allowedElements = params.config.allowed_elements;
|
||||
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
|
||||
allowedElements = allowedElements.map((element) => element.toLowerCase());
|
||||
let tableAllowedElements = params.config.table_allowed_elements;
|
||||
// if not defined, use allowedElements for backward compatibility
|
||||
tableAllowedElements = Array.isArray(tableAllowedElements) ? tableAllowedElements : allowedElements;
|
||||
tableAllowedElements = tableAllowedElements.map((element) => element.toLowerCase());
|
||||
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);
|
||||
const elementName = htmlTagInfo?.name.toLowerCase();
|
||||
const inTable = !!getParentOfType(token, [ "table" ]);
|
||||
if (
|
||||
htmlTagInfo &&
|
||||
!htmlTagInfo.close && !(
|
||||
(!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
|
||||
);
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue