Skip to content

Commit a87fa44

Browse files
committed
fix(no-heading-like-lines): do not flag numbered-list bold/italic when content ends with sentence punctuation
Skip reporting for lines like "3. **This should not be flagged.**" so bolded list items that are full sentences are not treated as heading-like.
1 parent a19e429 commit a87fa44

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

markdownlint-rules/no-heading-like-lines.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ const EXTRACTORS = [
5656
/** Pattern indices that are MD036-style (whole-line emphasis); skip when content ends with punctuation. */
5757
const MD036_STYLE_PATTERN_INDICES = new Set([6, 7]);
5858

59+
/** Pattern indices for numbered-list bold/italic; skip when content ends with sentence punctuation (e.g. "1. **Sentence.**"). */
60+
const NUMBERED_LIST_EMPHASIS_PATTERN_INDICES = new Set([2, 5]);
61+
5962
/**
6063
* Extract plain title from a heading-like line given the pattern index that matched.
6164
* @param {string} trimmedLine - Trimmed line content
@@ -144,6 +147,10 @@ function findHeadingLikeMatch(trimmedLine, punctuationMarks) {
144147
const lastChar = extractedTitle.slice(-1);
145148
if (punctuationMarks.includes(lastChar)) continue;
146149
}
150+
if (NUMBERED_LIST_EMPHASIS_PATTERN_INDICES.has(p) && extractedTitle.length > 0) {
151+
const lastChar = extractedTitle.slice(-1);
152+
if (punctuationMarks.includes(lastChar)) return null;
153+
}
147154
return { p, description, extractedTitle };
148155
}
149156
return null;

md_test_files/expected_errors.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ negative_heading_like.md:
129129
- line: 14
130130
rule: no-heading-like-lines
131131
message_contains: numbered list with bold
132-
- line: 16
132+
- line: 18
133133
rule: MD036/no-emphasis-as-heading
134-
- line: 16
134+
- line: 18
135135
rule: no-heading-like-lines
136136
message_contains: bold only
137-
- line: 18
137+
- line: 20
138138
rule: MD036/no-emphasis-as-heading
139-
- line: 18
139+
- line: 20
140140
rule: no-heading-like-lines
141141
message_contains: italic only
142142

md_test_files/negative_heading_like.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
1. **Numbered list with bold only**
1515

16+
2. **This should not be flagged.**
17+
1618
**Introduction**
1719

1820
*Note*

test/markdownlint-rules/no-heading-like-lines.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ describe("no-heading-like-lines", () => {
4848
assert.ok(errors[0].detail.includes("numbered") || errors[0].detail.includes("bold"), "detail should describe the matched pattern");
4949
});
5050

51+
it("does not report numbered list when bold content ends with sentence punctuation", () => {
52+
const lines = ["3. **This should not be flagged.**", "Content."];
53+
const errors = runRule(rule, lines);
54+
assert.strictEqual(errors.length, 0, "1. **Sentence.** should not be flagged as heading-like");
55+
});
56+
5157
it("reports error for MD036-style **Introduction** (whole line bold)", () => {
5258
const lines = ["**Introduction**", "Content here."];
5359
const errors = runRule(rule, lines);

0 commit comments

Comments
 (0)