mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Refactor various code to do shallow/constrained search instead of deep search for better performance, make cache key for filterByTypesCached unique.
This commit is contained in:
parent
2fa7730a6b
commit
d22c1f19ef
12 changed files with 171 additions and 220 deletions
|
@ -176,12 +176,12 @@ function getDescendantsByType(parent, typePath) {
|
|||
* @returns {number} Heading level.
|
||||
*/
|
||||
function getHeadingLevel(heading) {
|
||||
const headingSequence = filterByTypes(
|
||||
heading.children,
|
||||
[ "atxHeadingSequence", "setextHeadingLineSequence" ]
|
||||
);
|
||||
let level = 1;
|
||||
const { text } = headingSequence[0];
|
||||
const headingSequence = heading.children.find(
|
||||
(child) => [ "atxHeadingSequence", "setextHeadingLine" ].includes(child.type)
|
||||
);
|
||||
// @ts-ignore
|
||||
const { text } = headingSequence;
|
||||
if (text[0] === "#") {
|
||||
level = Math.min(text.length, 6);
|
||||
} else if (text[0] === "-") {
|
||||
|
@ -200,9 +200,8 @@ function getHeadingStyle(heading) {
|
|||
if (heading.type === "setextHeading") {
|
||||
return "setext";
|
||||
}
|
||||
const atxHeadingSequenceLength = filterByTypes(
|
||||
heading.children,
|
||||
[ "atxHeadingSequence" ]
|
||||
const atxHeadingSequenceLength = heading.children.filter(
|
||||
(child) => child.type === "atxHeadingSequence"
|
||||
).length;
|
||||
if (atxHeadingSequenceLength === 1) {
|
||||
return "atx";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue