From aab5833166dbfdf9e9be54af2f75634fae88c413 Mon Sep 17 00:00:00 2001 From: David Anson Date: Tue, 25 Nov 2025 16:20:19 -0800 Subject: [PATCH] wip --- lib/md013.mjs | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/lib/md013.mjs b/lib/md013.mjs index 0d1b24ea..1bb21aed 100644 --- a/lib/md013.mjs +++ b/lib/md013.mjs @@ -4,10 +4,8 @@ import { addErrorDetailIf } from "../helpers/helpers.cjs"; import { filterByTypesCached, getReferenceLinkImageData } from "./cache.mjs"; import { addRangeToSet, getDescendantsByType } from "../helpers/micromark-helpers.cjs"; -const longLineRePrefix = "^.{"; -const longLineRePostfixRelaxed = "}.*\\s.*$"; -const longLineRePostfixStrict = "}.+$"; -const sternModeRe = /^(?:[#>\s]*\s)?\S*$/; +// Regular expression for a line that is not wrappable +const notWrappableRe = /^(?:[#>\s]*\s)?\S*$/; /** @typedef {import("micromark-extension-gfm-autolink-literal")} */ /** @typedef {import("micromark-extension-gfm-table")} */ @@ -20,20 +18,10 @@ export default { "parser": "micromark", "function": function MD013(params, onError) { const lineLength = Number(params.config.line_length || 80); - const headingLineLength = - Number(params.config.heading_line_length || lineLength); - const codeLineLength = - Number(params.config.code_block_line_length || lineLength); + const headingLineLength = Number(params.config.heading_line_length || lineLength); + const codeLineLength = Number(params.config.code_block_line_length || lineLength); const strict = !!params.config.strict; const stern = !!params.config.stern; - const longLineRePostfix = - (strict || stern) ? longLineRePostfixStrict : longLineRePostfixRelaxed; - const longLineRe = - new RegExp(longLineRePrefix + lineLength + longLineRePostfix); - const longHeadingLineRe = - new RegExp(longLineRePrefix + headingLineLength + longLineRePostfix); - const longCodeLineRe = - new RegExp(longLineRePrefix + codeLineLength + longLineRePostfix); const codeBlocks = params.config.code_blocks; const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks; const tables = params.config.tables; @@ -75,28 +63,25 @@ export default { const isHeading = headingLineNumbers.has(lineNumber); const inCode = codeBlockLineNumbers.has(lineNumber); const inTable = tableLineNumbers.has(lineNumber); - const length = inCode ? - codeLineLength : - (isHeading ? headingLineLength : lineLength); - const lengthRe = inCode ? - longCodeLineRe : - (isHeading ? longHeadingLineRe : longLineRe); - if ((includeCodeBlocks || !inCode) && + const maxLength = inCode ? codeLineLength : (isHeading ? headingLineLength : lineLength); + const text = (strict || stern) ? line : line.replace(/\S*$/u, ""); + if ((maxLength > 0) && + (includeCodeBlocks || !inCode) && (includeTables || !inTable) && (includeHeadings || !isHeading) && !definitionLineIndices.has(lineIndex) && (strict || - (!(stern && sternModeRe.test(line)) && + (!(stern && notWrappableRe.test(line)) && !linkOnlyLineNumbers.has(lineNumber))) && - lengthRe.test(line)) { + (text.length > maxLength)) { addErrorDetailIf( onError, lineNumber, - length, + maxLength, line.length, undefined, undefined, - [ length + 1, line.length - length ] + [ maxLength + 1, line.length - maxLength ] ); } }