remark-abbr
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -1,5 +0,11 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var visit = require('unist-util-visit'); | ||
@@ -18,4 +24,4 @@ | ||
var keep = regex.exec(value); | ||
/* istanbul ignore if - never used (yet) */ | ||
/* istanbul ignore if - never used (yet) */ | ||
if (silent) return silent; | ||
@@ -33,3 +39,6 @@ if (!keep || keep.index !== 0) return; | ||
reference: reference, | ||
children: [{ type: 'text', value: abbr }], | ||
children: [{ | ||
type: 'text', | ||
value: abbr | ||
}], | ||
data: { | ||
@@ -47,3 +56,2 @@ hName: 'abbr', | ||
var emptyParagraphsToRemove = new Map(); | ||
visit(tree, 'paragraph', find(abbrs, emptyParagraphsToRemove)); | ||
@@ -56,3 +64,2 @@ emptyParagraphsToRemove.forEach(function (indices, key) { | ||
}); | ||
visit(tree, replace(abbrs)); | ||
@@ -65,9 +72,10 @@ } | ||
var child = node.children[i]; | ||
if (child.type !== 'abbr') continue; | ||
// Store abbr node for later use | ||
if (child.type !== 'abbr') continue; // Store abbr node for later use | ||
abbrs[child.abbr] = child; | ||
node.children.splice(i, 1); | ||
i -= 1; | ||
} | ||
// Keep track of empty paragraphs to remove | ||
} // Keep track of empty paragraphs to remove | ||
if (node.children.length === 0) { | ||
@@ -87,3 +95,3 @@ var indices = emptyParagraphsToRemove.get(parent) || []; | ||
var pattern = Object.keys(abbrs).map(escapeRegExp).join('|'); | ||
var regex = new RegExp('(\\b|\\W)(' + pattern + ')(\\b|\\W)'); | ||
var regex = new RegExp("(\\b|\\W)(".concat(pattern, ")(\\b|\\W)")); | ||
var expanded = {}; | ||
@@ -93,25 +101,23 @@ | ||
if (Object.keys(abbrs).length === 0) return; | ||
if (!node.children) return; | ||
if (!node.children) return; // If a text node is present in child nodes, check if an abbreviation is present | ||
// If a text node is present in child nodes, check if an abbreviation is present | ||
for (var c = 0; c < node.children.length; c++) { | ||
var child = node.children[c]; | ||
if (node.type === 'abbr' || child.type !== 'text') continue; | ||
if (!regex.test(child.value)) continue; | ||
if (!regex.test(child.value)) continue; // Transform node | ||
// Transform node | ||
var newTexts = child.value.split(regex); | ||
var newTexts = child.value.split(regex); // Remove old text node | ||
// Remove old text node | ||
node.children.splice(c, 1); | ||
node.children.splice(c, 1); // Replace abbreviations | ||
// Replace abbreviations | ||
for (var i = 0; i < newTexts.length; i++) { | ||
var content = newTexts[i]; | ||
if (abbrs.hasOwnProperty(content)) { | ||
var abbr = abbrs[content]; | ||
if (expandFirst && !expanded[content]) { | ||
node.children.splice(c + i, 0, { | ||
type: 'text', | ||
value: abbr.reference + ' (' + abbr.abbr + ')' | ||
value: "".concat(abbr.reference, " (").concat(abbr.abbr, ")") | ||
}); | ||
@@ -131,2 +137,3 @@ expanded[content] = true; | ||
} | ||
return one; | ||
@@ -136,6 +143,4 @@ } | ||
inlineTokenizer.locator = locator; | ||
var Parser = this.Parser; // Inject inlineTokenizer | ||
var Parser = this.Parser; | ||
// Inject inlineTokenizer | ||
var inlineTokenizers = Parser.prototype.inlineTokenizers; | ||
@@ -145,21 +150,24 @@ var inlineMethods = Parser.prototype.inlineMethods; | ||
inlineMethods.splice(0, 0, 'abbr'); | ||
var Compiler = this.Compiler; | ||
var Compiler = this.Compiler; | ||
if (Compiler) { | ||
var visitors = Compiler.prototype.visitors; | ||
if (!visitors) return; | ||
var abbrMap = {}; | ||
var abbrMap = {}; | ||
visitors.abbr = function (node) { | ||
if (!abbrMap[node.abbr]) { | ||
abbrMap[node.abbr] = '*[' + node.abbr + ']: ' + node.reference; | ||
abbrMap[node.abbr] = "*[".concat(node.abbr, "]: ").concat(node.reference); | ||
} | ||
return '' + node.abbr; | ||
return "".concat(node.abbr); | ||
}; | ||
var originalRootCompiler = visitors.root; | ||
visitors.root = function (node) { | ||
return originalRootCompiler.apply(this, arguments) + '\n' + Object.values(abbrMap).join('\n'); | ||
return "".concat(originalRootCompiler.apply(this, arguments), "\n").concat(Object.values(abbrMap).join('\n')); | ||
}; | ||
} | ||
return transformer; | ||
@@ -166,0 +174,0 @@ } |
{ | ||
"name": "remark-abbr", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"repository": { | ||
@@ -37,3 +37,3 @@ "url": "https://github.com/zestedesavoir/zmarkdown/tree/master/packages/remark-abbr", | ||
}, | ||
"gitHead": "1dded309a2670689a4a3353f9e38b80624c6df1a" | ||
"gitHead": "7b61723ac4ca1900270d56c7787c08b6887fcb4c" | ||
} |
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
14238
260