mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update fence logic to handle nested fences (per CommonMark spec; no handling of indentation).
http://spec.commonmark.org/0.22/#fenced-code-blocks
This commit is contained in:
parent
5e3d9f8df4
commit
bb0d8a36b3
2 changed files with 79 additions and 1 deletions
|
|
@ -40,12 +40,17 @@ function filterTokens(params, type, callback) {
|
|||
function forEachLine(params, callback) {
|
||||
if (!params.forEachLine) {
|
||||
var lineMetadata = new Array(params.lines.length);
|
||||
var fenceStart = null;
|
||||
var inFence = false;
|
||||
// Find fenced code by pattern (parser ignores "``` close fence")
|
||||
params.lines.forEach(function forLine(line, lineIndex) {
|
||||
var metadata = 0;
|
||||
if (/^(```|~~~)/.test(line)) {
|
||||
var match = /^(`{3,}|~{3,})/.exec(line);
|
||||
var fence = match && match[1];
|
||||
if (fence &&
|
||||
(!inFence || (fence.substr(0, fenceStart.length) === fenceStart))) {
|
||||
metadata = inFence ? -2 : 2;
|
||||
fenceStart = inFence ? null : fence;
|
||||
inFence = !inFence;
|
||||
} else if (inFence) {
|
||||
metadata = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue