Skip to content

Commit

Permalink
Markdownlint TOP007 bug: Account for non-codepen closing </p> tags (#…
Browse files Browse the repository at this point in the history
…27876)

* Fix bug with non-codepen closing </p> tags

Bug affected files with </p> tags somewhere before (or without) any
codepen embeds, due to trying to push to undefined.

* Add example of </p> exception fixed by this change to test file
  • Loading branch information
MaoShizhong committed May 10, 2024
1 parent 9243f25 commit e21f215
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions markdownlint/TOP007_useMarkdownLinks/TOP007_useMarkdownLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ module.exports = {
.map((token) => token.map);

const codepenLineRanges = params.lines.reduce((lineRanges, currentLine, index) => {
const range = [];
const lineNumber = index + 1;
if (currentLine.includes('class="codepen"')) {
range.push(lineNumber);
lineRanges.push(range);
} else if (currentLine.trim().startsWith("</p>")) {
const isCodepenOpeningTag = currentLine.includes('class="codepen"');
const isCodepenClosingTag =
currentLine.trim().startsWith("</p>") && lineRanges.at(-1)?.length < 2;

if (isCodepenOpeningTag) {
lineRanges.push([lineNumber]);
} else if (isCodepenClosingTag) {
lineRanges.at(-1).push(lineNumber);
}

Expand Down
6 changes: 6 additions & 0 deletions markdownlint/TOP007_useMarkdownLinks/tests/TOP007_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Assignment section

#### Custom section

```html
<p>
The following &lt;/p&gt; should be ignored by this rule as it does not belong to a codepen embed.
</p>
```

[Markdown links are desired in most cases](#custom-section)

<a href="#custom-section">Link should flag as we should be using a markdown link instead</a>.
Expand Down

0 comments on commit e21f215

Please sign in to comment.