mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 05:50:13 +01:00
This commit is contained in:
parent
5be7104dab
commit
6c57203ae5
4 changed files with 72 additions and 21 deletions
|
|
@ -136,32 +136,26 @@ function makeTokenCache(params) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Populate line metadata array
|
||||
// Initialize line metadata array
|
||||
// 0x7: inCode
|
||||
// 0x6: onFence (start)
|
||||
// 0x2: onFence (end)
|
||||
// 0x1: code body
|
||||
// 0x8: inTable
|
||||
const lineMetadata = new Array(params.lines.length);
|
||||
let fenceStart = null;
|
||||
let inFence = false;
|
||||
// Find fenced code by pattern (parser ignores "``` close fence")
|
||||
params.lines.forEach(function forLine(line, lineIndex) {
|
||||
let metadata = 0;
|
||||
const match = /^[ ]{0,3}(`{3,}|~{3,})/.exec(line);
|
||||
const fence = match && match[1];
|
||||
if (fence &&
|
||||
(!inFence || (fence.substr(0, fenceStart.length) === fenceStart))) {
|
||||
metadata = inFence ? 2 : 6;
|
||||
fenceStart = inFence ? null : fence;
|
||||
inFence = !inFence;
|
||||
} else if (inFence) {
|
||||
metadata = 1;
|
||||
lineMetadata.fill(0);
|
||||
filterTokens(params, "fence", function forToken(token) {
|
||||
lineMetadata[token.map[0]] = 6;
|
||||
lineMetadata[token.map[1] - 1] = 2;
|
||||
for (let i = token.map[0] + 1; i < token.map[1] - 1; i++) {
|
||||
lineMetadata[i] = 1;
|
||||
}
|
||||
lineMetadata[lineIndex] = metadata;
|
||||
});
|
||||
// Find code blocks normally
|
||||
filterTokens(params, "code_block", function forToken(token) {
|
||||
for (let i = token.map[0]; i < token.map[1]; i++) {
|
||||
lineMetadata[i] = 1;
|
||||
}
|
||||
});
|
||||
// Find tables normally
|
||||
filterTokens(params, "table_open", function forToken(token) {
|
||||
for (let i = token.map[0]; i < token.map[1]; i++) {
|
||||
lineMetadata[i] += 8;
|
||||
|
|
@ -220,12 +214,15 @@ module.exports.forEachLine = function forEachLine(callback) {
|
|||
// Invoke callback
|
||||
tokenCache.params.lines.forEach(function forLine(line, lineIndex) {
|
||||
const metadata = tokenCache.lineMetadata[lineIndex];
|
||||
const inCode = !!(metadata & 7);
|
||||
const onFence = (((metadata & 6) >> 1) || 2) - 2;
|
||||
const inTable = !!(metadata & 8);
|
||||
callback(
|
||||
line,
|
||||
lineIndex,
|
||||
!!(metadata & 7),
|
||||
(((metadata & 6) >> 1) || 2) - 2,
|
||||
!!(metadata & 8));
|
||||
inCode,
|
||||
onFence,
|
||||
inTable);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
6
test/fenced-code-in-list.json
Normal file
6
test/fenced-code-in-list.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD013": {
|
||||
"code_blocks": false
|
||||
}
|
||||
}
|
||||
35
test/fenced-code-in-list.md
Normal file
35
test/fenced-code-in-list.md
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Heading
|
||||
|
||||
- Item
|
||||
|
||||
```javascript
|
||||
debugger;
|
||||
|
||||
|
||||
debugger;
|
||||
```
|
||||
|
||||
text
|
||||
|
||||
- Item
|
||||
|
||||
- Subitem
|
||||
|
||||
```javascript
|
||||
debugger;
|
||||
|
||||
|
||||
debugger;
|
||||
```
|
||||
|
||||
text
|
||||
|
||||
- Subitem
|
||||
|
||||
- Item
|
||||
|
||||
- Subitem
|
||||
|
||||
```javascript
|
||||
debugger; debugger; debugger; debugger; debugger; debugger; debugger; debugger; debugger; debugger;
|
||||
```
|
||||
13
test/fenced-code-unmatched.md
Normal file
13
test/fenced-code-unmatched.md
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Heading
|
||||
|
||||
Text
|
||||
|
||||
```code```
|
||||
|
||||
Text
|
||||
|
||||
```javascript
|
||||
var x = 5;
|
||||
```
|
||||
|
||||
Text
|
||||
Loading…
Add table
Add a link
Reference in a new issue