mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01: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}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function annotateTokens(tokens, lines) {
|
function annotateTokens(tokens, lines) {
|
||||||
var tableMap = null;
|
var trMap = null;
|
||||||
tokens.forEach(function forToken(token) {
|
tokens.forEach(function forToken(token) {
|
||||||
// Handle missing maps for table head/body
|
// Provide missing maps for table content
|
||||||
if ((token.type === "thead_open") ||
|
if (token.type === "tr_open") {
|
||||||
(token.type === "tbody_open")) {
|
trMap = token.map;
|
||||||
tableMap = __spreadArray([], token.map);
|
|
||||||
}
|
}
|
||||||
else if ((token.type === "tr_close") &&
|
else if (token.type === "tr_close") {
|
||||||
tableMap) {
|
trMap = null;
|
||||||
tableMap[0]++;
|
|
||||||
}
|
}
|
||||||
else if ((token.type === "thead_close") ||
|
if (!token.map && trMap) {
|
||||||
(token.type === "tbody_close")) {
|
token.map = __spreadArray([], trMap);
|
||||||
tableMap = null;
|
|
||||||
}
|
|
||||||
if (tableMap && !token.map) {
|
|
||||||
token.map = __spreadArray([], tableMap);
|
|
||||||
}
|
}
|
||||||
// Update token metadata
|
// Update token metadata
|
||||||
if (token.map) {
|
if (token.map) {
|
||||||
|
|
|
||||||
|
|
@ -181,27 +181,16 @@ function removeFrontMatter(content, frontMatter) {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function annotateTokens(tokens, lines) {
|
function annotateTokens(tokens, lines) {
|
||||||
let tableMap = null;
|
let trMap = null;
|
||||||
tokens.forEach(function forToken(token) {
|
tokens.forEach(function forToken(token) {
|
||||||
// Handle missing maps for table head/body
|
// Provide missing maps for table content
|
||||||
if (
|
if (token.type === "tr_open") {
|
||||||
(token.type === "thead_open") ||
|
trMap = token.map;
|
||||||
(token.type === "tbody_open")
|
} else if (token.type === "tr_close") {
|
||||||
) {
|
trMap = null;
|
||||||
tableMap = [ ...token.map ];
|
|
||||||
} else if (
|
|
||||||
(token.type === "tr_close") &&
|
|
||||||
tableMap
|
|
||||||
) {
|
|
||||||
tableMap[0]++;
|
|
||||||
} else if (
|
|
||||||
(token.type === "thead_close") ||
|
|
||||||
(token.type === "tbody_close")
|
|
||||||
) {
|
|
||||||
tableMap = null;
|
|
||||||
}
|
}
|
||||||
if (tableMap && !token.map) {
|
if (!token.map && trMap) {
|
||||||
token.map = [ ...tableMap ];
|
token.map = [ ...trMap ];
|
||||||
}
|
}
|
||||||
// Update token metadata
|
// Update token metadata
|
||||||
if (token.map) {
|
if (token.map) {
|
||||||
|
|
|
||||||
|
|
@ -1002,7 +1002,7 @@ test("customRulesOnErrorInvalidHandled", (t) => {
|
||||||
"function": function onErrorInvalid(params, onError) {
|
"function": function onErrorInvalid(params, onError) {
|
||||||
onError({
|
onError({
|
||||||
"lineNumber": 13,
|
"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) => {
|
test("getVersion", (t) => {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
const actual = markdownlint.getVersion();
|
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