remark-abbr
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -41,7 +41,16 @@ 'use strict'; | ||
var abbrs = {}; | ||
visit(tree, 'paragraph', find(abbrs)); | ||
var emptyParagraphsToRemove = new Map(); | ||
visit(tree, 'paragraph', find(abbrs, emptyParagraphsToRemove)); | ||
emptyParagraphsToRemove.forEach(function (indices, key) { | ||
indices.reverse(); | ||
indices.forEach(function (index) { | ||
key.children.splice(index, 1); | ||
}); | ||
}); | ||
visit(tree, replace(abbrs)); | ||
} | ||
function find(abbrs) { | ||
function find(abbrs, emptyParagraphsToRemove) { | ||
return function one(node, index, parent) { | ||
@@ -56,4 +65,8 @@ for (var i = 0; i < node.children.length; i++) { | ||
} | ||
// Remove paragraph if there is no child | ||
if (node.children.length === 0) parent.children.splice(index, 1); | ||
// Keep track of empty paragraphs to remove | ||
if (node.children.length === 0) { | ||
var indices = emptyParagraphsToRemove.get(parent) || []; | ||
indices.push(index); | ||
emptyParagraphsToRemove.set(parent, indices); | ||
} | ||
}; | ||
@@ -60,0 +73,0 @@ } |
{ | ||
"name": "remark-abbr", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"repository": { | ||
@@ -37,3 +37,3 @@ "url": "https://github.com/zestedesavoir/zmarkdown/tree/master/packages/remark-abbr", | ||
}, | ||
"gitHead": "bfff52b7e7a248004b81525f54354f1acceba898" | ||
"gitHead": "47164411c9e3ae0d7d29ebb7ab0d112569e83f01" | ||
} |
@@ -36,7 +36,16 @@ const visit = require('unist-util-visit') | ||
const abbrs = {} | ||
visit(tree, 'paragraph', find(abbrs)) | ||
const emptyParagraphsToRemove = new Map() | ||
visit(tree, 'paragraph', find(abbrs, emptyParagraphsToRemove)) | ||
emptyParagraphsToRemove.forEach((indices, key) => { | ||
indices.reverse() | ||
indices.forEach((index) => { | ||
key.children.splice(index, 1) | ||
}) | ||
}) | ||
visit(tree, replace(abbrs)) | ||
} | ||
function find (abbrs) { | ||
function find (abbrs, emptyParagraphsToRemove) { | ||
return function one (node, index, parent) { | ||
@@ -51,4 +60,8 @@ for (let i = 0; i < node.children.length; i++) { | ||
} | ||
// Remove paragraph if there is no child | ||
if (node.children.length === 0) parent.children.splice(index, 1) | ||
// Keep track of empty paragraphs to remove | ||
if (node.children.length === 0) { | ||
const indices = emptyParagraphsToRemove.get(parent) || [] | ||
indices.push(index) | ||
emptyParagraphsToRemove.set(parent, indices) | ||
} | ||
} | ||
@@ -55,0 +68,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12666
238