mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Tokens inside tables that lack a map should get it from the surrounding table row (which is more scoped than the table body) (fixes #463).
This commit is contained in:
parent
1e82f76596
commit
11806dc5cb
6 changed files with 106 additions and 34 deletions
|
@ -1037,23 +1037,17 @@ function removeFrontMatter(content, frontMatter) {
|
|||
* @returns {void}
|
||||
*/
|
||||
function annotateTokens(tokens, lines) {
|
||||
var tableMap = null;
|
||||
var trMap = null;
|
||||
tokens.forEach(function forToken(token) {
|
||||
// Handle missing maps for table head/body
|
||||
if ((token.type === "thead_open") ||
|
||||
(token.type === "tbody_open")) {
|
||||
tableMap = __spreadArray([], token.map);
|
||||
// Provide missing maps for table content
|
||||
if (token.type === "tr_open") {
|
||||
trMap = token.map;
|
||||
}
|
||||
else if ((token.type === "tr_close") &&
|
||||
tableMap) {
|
||||
tableMap[0]++;
|
||||
else if (token.type === "tr_close") {
|
||||
trMap = null;
|
||||
}
|
||||
else if ((token.type === "thead_close") ||
|
||||
(token.type === "tbody_close")) {
|
||||
tableMap = null;
|
||||
}
|
||||
if (tableMap && !token.map) {
|
||||
token.map = __spreadArray([], tableMap);
|
||||
if (!token.map && trMap) {
|
||||
token.map = __spreadArray([], trMap);
|
||||
}
|
||||
// Update token metadata
|
||||
if (token.map) {
|
||||
|
|
|
@ -181,27 +181,16 @@ function removeFrontMatter(content, frontMatter) {
|
|||
* @returns {void}
|
||||
*/
|
||||
function annotateTokens(tokens, lines) {
|
||||
let tableMap = null;
|
||||
let trMap = null;
|
||||
tokens.forEach(function forToken(token) {
|
||||
// Handle missing maps for table head/body
|
||||
if (
|
||||
(token.type === "thead_open") ||
|
||||
(token.type === "tbody_open")
|
||||
) {
|
||||
tableMap = [ ...token.map ];
|
||||
} else if (
|
||||
(token.type === "tr_close") &&
|
||||
tableMap
|
||||
) {
|
||||
tableMap[0]++;
|
||||
} else if (
|
||||
(token.type === "thead_close") ||
|
||||
(token.type === "tbody_close")
|
||||
) {
|
||||
tableMap = null;
|
||||
// Provide missing maps for table content
|
||||
if (token.type === "tr_open") {
|
||||
trMap = token.map;
|
||||
} else if (token.type === "tr_close") {
|
||||
trMap = null;
|
||||
}
|
||||
if (tableMap && !token.map) {
|
||||
token.map = [ ...tableMap ];
|
||||
if (!token.map && trMap) {
|
||||
token.map = [ ...trMap ];
|
||||
}
|
||||
// Update token metadata
|
||||
if (token.map) {
|
||||
|
|
|
@ -1002,7 +1002,7 @@ test("customRulesOnErrorInvalidHandled", (t) => {
|
|||
"function": function onErrorInvalid(params, onError) {
|
||||
onError({
|
||||
"lineNumber": 13,
|
||||
"details": "N/A"
|
||||
"detail": "N/A"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1717,6 +1717,40 @@ test.cb("texmath test files with texmath plugin", (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("token-map-spans", (t) => {
|
||||
t.plan(38);
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "token-map-spans" ],
|
||||
"description": "token-map-spans",
|
||||
"tags": [ "tms" ],
|
||||
"function": function tokenMapSpans(params) {
|
||||
const tokenLines = [];
|
||||
let lastLineNumber = -1;
|
||||
const inlines = params.tokens.filter((c) => c.type === "inline");
|
||||
for (const token of inlines) {
|
||||
t.truthy(token.map);
|
||||
for (let i = token.map[0]; i < token.map[1]; i++) {
|
||||
if (tokenLines.includes(i)) {
|
||||
t.true(
|
||||
lastLineNumber === token.lineNumber,
|
||||
`Line ${i + 1} is part of token maps from multiple lines.`
|
||||
);
|
||||
} else {
|
||||
tokenLines.push(i);
|
||||
}
|
||||
lastLineNumber = token.lineNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"files": [ "./test/token-map-spans.md" ]
|
||||
};
|
||||
markdownlint.sync(options);
|
||||
});
|
||||
|
||||
test("getVersion", (t) => {
|
||||
t.plan(1);
|
||||
const actual = markdownlint.getVersion();
|
||||
|
|
13
test/table-content-with-issues.md
Normal file
13
test/table-content-with-issues.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Table Content With Issues
|
||||
|
||||
| Content | Issue |
|
||||
|------------------------------|---------|
|
||||
| Text | N/A |
|
||||
| (link)[https://example.com] | {MD011} |
|
||||
| <hr> | {MD033} |
|
||||
| https://example.com | {MD034} |
|
||||
| * emphasis* | {MD037} |
|
||||
| __strong __ | {MD037} |
|
||||
| ` code` | {MD038} |
|
||||
| [link ](https://example.com) | {MD039} |
|
||||
| [link]() | {MD042} |
|
42
test/token-map-spans.md
Normal file
42
test/token-map-spans.md
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Token Map Spans
|
||||
|
||||
Text *emphasis* text __strong__ text `code` text [link](https://example.com).
|
||||
|
||||
Paragraph with *emphasis
|
||||
spanning lines* and __strong
|
||||
spanning lines__ and `code
|
||||
spanning lines` and [link
|
||||
spanning lines](https://example.com).
|
||||
|
||||
> Blockquote
|
||||
> [link](https://example.com)
|
||||
> > Nested
|
||||
> > blockquote
|
||||
> > [link](https://example.com)
|
||||
|
||||
Heading
|
||||
-------
|
||||
|
||||
```lang
|
||||
Fenced
|
||||
code
|
||||
```
|
||||
|
||||
Indented
|
||||
code
|
||||
|
||||
1. List
|
||||
2. List
|
||||
- Sub-list
|
||||
- Sub-list
|
||||
3. List
|
||||
|
||||
| Table | Column 1 | Column 2 | Column 3 | Column 4 |
|
||||
|-------|------------|------------|----------|----------------------------|
|
||||
| Text | *emphasis* | __strong__ | `code` | [link](https://example.com) |
|
||||
| Text | *emphasis* | __strong__ | `code` | [link](https://example.com) |
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"code-block-style": false,
|
||||
"heading-style": false
|
||||
} -->
|
Loading…
Add table
Add a link
Reference in a new issue