markdown-it-abbr
Advanced tools
Comparing version 1.0.4 to 2.0.0
@@ -1,152 +0,140 @@ | ||
/*! markdown-it-abbr 1.0.4 https://github.com//markdown-it/markdown-it-abbr @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitAbbr = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
// Enclose abbreviations in <abbr> tags | ||
// | ||
'use strict'; | ||
module.exports = function sub_plugin(md) { | ||
var escapeRE = md.utils.escapeRE, | ||
arrayReplaceAt = md.utils.arrayReplaceAt; | ||
// ASCII characters in Cc, Sc, Sm, Sk categories we should terminate on; | ||
// you can check character classes here: | ||
// http://www.unicode.org/Public/UNIDATA/UnicodeData.txt | ||
var OTHER_CHARS = ' \r\n$+<=>^`|~'; | ||
var UNICODE_PUNCT_RE = md.utils.lib.ucmicro.P.source; | ||
var UNICODE_SPACE_RE = md.utils.lib.ucmicro.Z.source; | ||
function abbr_def(state, startLine, endLine, silent) { | ||
var label, title, ch, labelStart, labelEnd, | ||
pos = state.bMarks[startLine] + state.tShift[startLine], | ||
max = state.eMarks[startLine]; | ||
if (pos + 2 >= max) { return false; } | ||
if (state.src.charCodeAt(pos++) !== 0x2A/* * */) { return false; } | ||
if (state.src.charCodeAt(pos++) !== 0x5B/* [ */) { return false; } | ||
labelStart = pos; | ||
for (; pos < max; pos++) { | ||
ch = state.src.charCodeAt(pos); | ||
if (ch === 0x5B /* [ */) { | ||
/*! markdown-it-abbr 2.0.0 https://github.com/markdown-it/markdown-it-abbr @license MIT */ | ||
(function(global, factory) { | ||
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, | ||
global.markdownitAbbr = factory()); | ||
})(this, (function() { | ||
"use strict"; | ||
// Enclose abbreviations in <abbr> tags | ||
function abbr_plugin(md) { | ||
const escapeRE = md.utils.escapeRE; | ||
const arrayReplaceAt = md.utils.arrayReplaceAt; | ||
// ASCII characters in Cc, Sc, Sm, Sk categories we should terminate on; | ||
// you can check character classes here: | ||
// http://www.unicode.org/Public/UNIDATA/UnicodeData.txt | ||
const OTHER_CHARS = " \r\n$+<=>^`|~"; | ||
const UNICODE_PUNCT_RE = md.utils.lib.ucmicro.P.source; | ||
const UNICODE_SPACE_RE = md.utils.lib.ucmicro.Z.source; | ||
function abbr_def(state, startLine, endLine, silent) { | ||
let labelEnd; | ||
let pos = state.bMarks[startLine] + state.tShift[startLine]; | ||
const max = state.eMarks[startLine]; | ||
if (pos + 2 >= max) { | ||
return false; | ||
} else if (ch === 0x5D /* ] */) { | ||
labelEnd = pos; | ||
break; | ||
} else if (ch === 0x5C /* \ */) { | ||
pos++; | ||
} | ||
if (state.src.charCodeAt(pos++) !== 42 /* * */) { | ||
return false; | ||
} | ||
if (state.src.charCodeAt(pos++) !== 91 /* [ */) { | ||
return false; | ||
} | ||
const labelStart = pos; | ||
for (;pos < max; pos++) { | ||
const ch = state.src.charCodeAt(pos); | ||
if (ch === 91 /* [ */) { | ||
return false; | ||
} else if (ch === 93 /* ] */) { | ||
labelEnd = pos; | ||
break; | ||
} else if (ch === 92 /* \ */) { | ||
pos++; | ||
} | ||
} | ||
if (labelEnd < 0 || state.src.charCodeAt(labelEnd + 1) !== 58 /* : */) { | ||
return false; | ||
} | ||
if (silent) { | ||
return true; | ||
} | ||
const label = state.src.slice(labelStart, labelEnd).replace(/\\(.)/g, "$1"); | ||
const title = state.src.slice(labelEnd + 2, max).trim(); | ||
if (label.length === 0) { | ||
return false; | ||
} | ||
if (title.length === 0) { | ||
return false; | ||
} | ||
if (!state.env.abbreviations) { | ||
state.env.abbreviations = {}; | ||
} | ||
// prepend ':' to avoid conflict with Object.prototype members | ||
if (typeof state.env.abbreviations[":" + label] === "undefined") { | ||
state.env.abbreviations[":" + label] = title; | ||
} | ||
state.line = startLine + 1; | ||
return true; | ||
} | ||
if (labelEnd < 0 || state.src.charCodeAt(labelEnd + 1) !== 0x3A/* : */) { | ||
return false; | ||
} | ||
if (silent) { return true; } | ||
label = state.src.slice(labelStart, labelEnd).replace(/\\(.)/g, '$1'); | ||
title = state.src.slice(labelEnd + 2, max).trim(); | ||
if (label.length === 0) { return false; } | ||
if (title.length === 0) { return false; } | ||
if (!state.env.abbreviations) { state.env.abbreviations = {}; } | ||
// prepend ':' to avoid conflict with Object.prototype members | ||
if (typeof state.env.abbreviations[':' + label] === 'undefined') { | ||
state.env.abbreviations[':' + label] = title; | ||
} | ||
state.line = startLine + 1; | ||
return true; | ||
} | ||
function abbr_replace(state) { | ||
var i, j, l, tokens, token, text, nodes, pos, reg, m, regText, regSimple, | ||
currentToken, | ||
blockTokens = state.tokens; | ||
if (!state.env.abbreviations) { return; } | ||
regSimple = new RegExp('(?:' + | ||
Object.keys(state.env.abbreviations).map(function (x) { | ||
function abbr_replace(state) { | ||
const blockTokens = state.tokens; | ||
if (!state.env.abbreviations) { | ||
return; | ||
} | ||
const regSimple = new RegExp("(?:" + Object.keys(state.env.abbreviations).map((function(x) { | ||
return x.substr(1); | ||
}).sort(function (a, b) { | ||
})).sort((function(a, b) { | ||
return b.length - a.length; | ||
}).map(escapeRE).join('|') + | ||
')'); | ||
regText = '(^|' + UNICODE_PUNCT_RE + '|' + UNICODE_SPACE_RE + | ||
'|[' + OTHER_CHARS.split('').map(escapeRE).join('') + '])' | ||
+ '(' + Object.keys(state.env.abbreviations).map(function (x) { | ||
return x.substr(1); | ||
}).sort(function (a, b) { | ||
return b.length - a.length; | ||
}).map(escapeRE).join('|') + ')' | ||
+ '($|' + UNICODE_PUNCT_RE + '|' + UNICODE_SPACE_RE + | ||
'|[' + OTHER_CHARS.split('').map(escapeRE).join('') + '])'; | ||
reg = new RegExp(regText, 'g'); | ||
for (j = 0, l = blockTokens.length; j < l; j++) { | ||
if (blockTokens[j].type !== 'inline') { continue; } | ||
tokens = blockTokens[j].children; | ||
// We scan from the end, to keep position when new tags added. | ||
for (i = tokens.length - 1; i >= 0; i--) { | ||
currentToken = tokens[i]; | ||
if (currentToken.type !== 'text') { continue; } | ||
pos = 0; | ||
text = currentToken.content; | ||
reg.lastIndex = 0; | ||
nodes = []; | ||
// fast regexp run to determine whether there are any abbreviated words | ||
// in the current token | ||
if (!regSimple.test(text)) { continue; } | ||
while ((m = reg.exec(text))) { | ||
if (m.index > 0 || m[1].length > 0) { | ||
token = new state.Token('text', '', 0); | ||
token.content = text.slice(pos, m.index + m[1].length); | ||
})).map(escapeRE).join("|") + ")"); | ||
const regText = "(^|" + UNICODE_PUNCT_RE + "|" + UNICODE_SPACE_RE + "|[" + OTHER_CHARS.split("").map(escapeRE).join("") + "])" + "(" + Object.keys(state.env.abbreviations).map((function(x) { | ||
return x.substr(1); | ||
})).sort((function(a, b) { | ||
return b.length - a.length; | ||
})).map(escapeRE).join("|") + ")" + "($|" + UNICODE_PUNCT_RE + "|" + UNICODE_SPACE_RE + "|[" + OTHER_CHARS.split("").map(escapeRE).join("") + "])"; | ||
const reg = new RegExp(regText, "g"); | ||
for (let j = 0, l = blockTokens.length; j < l; j++) { | ||
if (blockTokens[j].type !== "inline") { | ||
continue; | ||
} | ||
let tokens = blockTokens[j].children; | ||
// We scan from the end, to keep position when new tags added. | ||
for (let i = tokens.length - 1; i >= 0; i--) { | ||
const currentToken = tokens[i]; | ||
if (currentToken.type !== "text") { | ||
continue; | ||
} | ||
let pos = 0; | ||
const text = currentToken.content; | ||
reg.lastIndex = 0; | ||
const nodes = []; | ||
// fast regexp run to determine whether there are any abbreviated words | ||
// in the current token | ||
if (!regSimple.test(text)) { | ||
continue; | ||
} | ||
let m; | ||
while (m = reg.exec(text)) { | ||
if (m.index > 0 || m[1].length > 0) { | ||
const token = new state.Token("text", "", 0); | ||
token.content = text.slice(pos, m.index + m[1].length); | ||
nodes.push(token); | ||
} | ||
const token_o = new state.Token("abbr_open", "abbr", 1); | ||
token_o.attrs = [ [ "title", state.env.abbreviations[":" + m[2]] ] ]; | ||
nodes.push(token_o); | ||
const token_t = new state.Token("text", "", 0); | ||
token_t.content = m[2]; | ||
nodes.push(token_t); | ||
const token_c = new state.Token("abbr_close", "abbr", -1); | ||
nodes.push(token_c); | ||
reg.lastIndex -= m[3].length; | ||
pos = reg.lastIndex; | ||
} | ||
if (!nodes.length) { | ||
continue; | ||
} | ||
if (pos < text.length) { | ||
const token = new state.Token("text", "", 0); | ||
token.content = text.slice(pos); | ||
nodes.push(token); | ||
} | ||
token = new state.Token('abbr_open', 'abbr', 1); | ||
token.attrs = [ [ 'title', state.env.abbreviations[':' + m[2]] ] ]; | ||
nodes.push(token); | ||
token = new state.Token('text', '', 0); | ||
token.content = m[2]; | ||
nodes.push(token); | ||
token = new state.Token('abbr_close', 'abbr', -1); | ||
nodes.push(token); | ||
reg.lastIndex -= m[3].length; | ||
pos = reg.lastIndex; | ||
// replace current node | ||
blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes); | ||
} | ||
if (!nodes.length) { continue; } | ||
if (pos < text.length) { | ||
token = new state.Token('text', '', 0); | ||
token.content = text.slice(pos); | ||
nodes.push(token); | ||
} | ||
// replace current node | ||
blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes); | ||
} | ||
} | ||
md.block.ruler.before("reference", "abbr_def", abbr_def, { | ||
alt: [ "paragraph", "reference" ] | ||
}); | ||
md.core.ruler.after("linkify", "abbr_replace", abbr_replace); | ||
} | ||
md.block.ruler.before('reference', 'abbr_def', abbr_def, { alt: [ 'paragraph', 'reference' ] }); | ||
md.core.ruler.after('linkify', 'abbr_replace', abbr_replace); | ||
}; | ||
},{}]},{},[1])(1) | ||
}); | ||
return abbr_plugin; | ||
})); |
@@ -1,2 +0,2 @@ | ||
/*! markdown-it-abbr 1.0.4 https://github.com//markdown-it/markdown-it-abbr @license MIT */ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.markdownitAbbr=e()}}(function(){return function e(n,t,r){function i(a,s){if(!t[a]){if(!n[a]){var f="function"==typeof require&&require;if(!s&&f)return f(a,!0);if(o)return o(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var c=t[a]={exports:{}};n[a][0].call(c.exports,function(e){var t=n[a][1][e];return i(t?t:e)},c,c.exports,e,n,t,r)}return t[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(e,n,t){"use strict";n.exports=function(e){function n(e,n,t,r){var i,o,a,s,f,u=e.bMarks[n]+e.tShift[n],c=e.eMarks[n];if(u+2>=c)return!1;if(42!==e.src.charCodeAt(u++))return!1;if(91!==e.src.charCodeAt(u++))return!1;for(s=u;u<c;u++){if(a=e.src.charCodeAt(u),91===a)return!1;if(93===a){f=u;break}92===a&&u++}return!(f<0||58!==e.src.charCodeAt(f+1))&&(!!r||(i=e.src.slice(s,f).replace(/\\(.)/g,"$1"),o=e.src.slice(f+2,c).trim(),0!==i.length&&(0!==o.length&&(e.env.abbreviations||(e.env.abbreviations={}),"undefined"==typeof e.env.abbreviations[":"+i]&&(e.env.abbreviations[":"+i]=o),e.line=n+1,!0))))}function t(e){var n,t,f,u,c,l,b,p,d,h,v,g,x,y=e.tokens;if(e.env.abbreviations)for(g=new RegExp("(?:"+Object.keys(e.env.abbreviations).map(function(e){return e.substr(1)}).sort(function(e,n){return n.length-e.length}).map(r).join("|")+")"),v="(^|"+a+"|"+s+"|["+o.split("").map(r).join("")+"])("+Object.keys(e.env.abbreviations).map(function(e){return e.substr(1)}).sort(function(e,n){return n.length-e.length}).map(r).join("|")+")($|"+a+"|"+s+"|["+o.split("").map(r).join("")+"])",d=new RegExp(v,"g"),t=0,f=y.length;t<f;t++)if("inline"===y[t].type)for(u=y[t].children,n=u.length-1;n>=0;n--)if(x=u[n],"text"===x.type&&(p=0,l=x.content,d.lastIndex=0,b=[],g.test(l))){for(;h=d.exec(l);)(h.index>0||h[1].length>0)&&(c=new e.Token("text","",0),c.content=l.slice(p,h.index+h[1].length),b.push(c)),c=new e.Token("abbr_open","abbr",1),c.attrs=[["title",e.env.abbreviations[":"+h[2]]]],b.push(c),c=new e.Token("text","",0),c.content=h[2],b.push(c),c=new e.Token("abbr_close","abbr",-1),b.push(c),d.lastIndex-=h[3].length,p=d.lastIndex;b.length&&(p<l.length&&(c=new e.Token("text","",0),c.content=l.slice(p),b.push(c)),y[t].children=u=i(u,n,b))}}var r=e.utils.escapeRE,i=e.utils.arrayReplaceAt,o=" \r\n$+<=>^`|~",a=e.utils.lib.ucmicro.P.source,s=e.utils.lib.ucmicro.Z.source;e.block.ruler.before("reference","abbr_def",n,{alt:["paragraph","reference"]}),e.core.ruler.after("linkify","abbr_replace",t)}},{}]},{},[1])(1)}); | ||
/*! markdown-it-abbr 2.0.0 https://github.com/markdown-it/markdown-it-abbr @license MIT */ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).markdownitAbbr=n()}(this,(function(){"use strict";return function(e){const n=e.utils.escapeRE,t=e.utils.arrayReplaceAt,r=" \r\n$+<=>^`|~",i=e.utils.lib.ucmicro.P.source,o=e.utils.lib.ucmicro.Z.source;e.block.ruler.before("reference","abbr_def",(function(e,n,t,r){let i,o=e.bMarks[n]+e.tShift[n];const s=e.eMarks[n];if(o+2>=s)return!1;if(42!==e.src.charCodeAt(o++))return!1;if(91!==e.src.charCodeAt(o++))return!1;const c=o;for(;o<s;o++){const n=e.src.charCodeAt(o);if(91===n)return!1;if(93===n){i=o;break}92===n&&o++}if(i<0||58!==e.src.charCodeAt(i+1))return!1;if(r)return!0;const l=e.src.slice(c,i).replace(/\\(.)/g,"$1"),a=e.src.slice(i+2,s).trim();return 0!==l.length&&(0!==a.length&&(e.env.abbreviations||(e.env.abbreviations={}),void 0===e.env.abbreviations[":"+l]&&(e.env.abbreviations[":"+l]=a),e.line=n+1,!0))}),{alt:["paragraph","reference"]}),e.core.ruler.after("linkify","abbr_replace",(function(e){const s=e.tokens;if(!e.env.abbreviations)return;const c=new RegExp("(?:"+Object.keys(e.env.abbreviations).map((function(e){return e.substr(1)})).sort((function(e,n){return n.length-e.length})).map(n).join("|")+")"),l="(^|"+i+"|"+o+"|["+r.split("").map(n).join("")+"])("+Object.keys(e.env.abbreviations).map((function(e){return e.substr(1)})).sort((function(e,n){return n.length-e.length})).map(n).join("|")+")($|"+i+"|"+o+"|["+r.split("").map(n).join("")+"])",a=new RegExp(l,"g");for(let n=0,r=s.length;n<r;n++){if("inline"!==s[n].type)continue;let r=s[n].children;for(let i=r.length-1;i>=0;i--){const o=r[i];if("text"!==o.type)continue;let l=0;const u=o.content;a.lastIndex=0;const f=[];if(!c.test(u))continue;let b;for(;b=a.exec(u);){if(b.index>0||b[1].length>0){const n=new e.Token("text","",0);n.content=u.slice(l,b.index+b[1].length),f.push(n)}const n=new e.Token("abbr_open","abbr",1);n.attrs=[["title",e.env.abbreviations[":"+b[2]]]],f.push(n);const t=new e.Token("text","",0);t.content=b[2],f.push(t);const r=new e.Token("abbr_close","abbr",-1);f.push(r),a.lastIndex-=b[3].length,l=a.lastIndex}if(f.length){if(l<u.length){const n=new e.Token("text","",0);n.content=u.slice(l),f.push(n)}s[n].children=r=t(r,i,f)}}}}))}})); |
{ | ||
"name": "markdown-it-abbr", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "<abbr> tag for markdown-it markdown parser.", | ||
@@ -12,26 +12,39 @@ "keywords": [ | ||
], | ||
"homepage": "https://github.com/markdown-it/markdown-it-abbr", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/markdown-it/markdown-it-abbr.git" | ||
"repository": "markdown-it/markdown-it-abbr", | ||
"license": "MIT", | ||
"main": "dist/index.cjs.js", | ||
"module": "index.mjs", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.cjs.js", | ||
"import": "./index.mjs" | ||
}, | ||
"./*": { | ||
"require": "./*", | ||
"import": "./*" | ||
} | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/markdown-it/markdown-it-abbr/issues" | ||
}, | ||
"license": "MIT", | ||
"main": "index.js", | ||
"files": [ | ||
"index.mjs", | ||
"lib/", | ||
"dist/" | ||
], | ||
"scripts": { | ||
"test": "make test" | ||
"lint": "eslint .", | ||
"build": "rollup -c", | ||
"test": "npm run lint && npm run build && c8 --exclude dist --exclude test -r text -r html -r lcov mocha", | ||
"prepublishOnly": "npm run lint && npm run build" | ||
}, | ||
"devDependencies": { | ||
"browserify": "*", | ||
"coveralls": "^2.11.2", | ||
"eslint": "0.10.2", | ||
"eslint-plugin-nodeca": "^1.0.0", | ||
"istanbul": "*", | ||
"markdown-it": "^5.0.3", | ||
"markdown-it-testgen": "~0.1.0", | ||
"mocha": "*", | ||
"uglify-js": "*" | ||
"@rollup/plugin-babel": "^6.0.4", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"c8": "^8.0.1", | ||
"eslint": "^8.55.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"markdown-it": "^13.0.2", | ||
"markdown-it-testgen": "^0.1.6", | ||
"mocha": "^10.2.0", | ||
"rollup": "^4.6.1" | ||
} | ||
} |
# markdown-it-abbr | ||
[![Build Status](https://img.shields.io/travis/markdown-it/markdown-it-abbr/master.svg?style=flat)](https://travis-ci.org/markdown-it/markdown-it-abbr) | ||
[![CI](https://github.com/markdown-it/markdown-it-abbr/actions/workflows/ci.yml/badge.svg)](https://github.com/markdown-it/markdown-it-abbr/actions/workflows/ci.yml) | ||
[![NPM version](https://img.shields.io/npm/v/markdown-it-abbr.svg?style=flat)](https://www.npmjs.org/package/markdown-it-abbr) | ||
@@ -5,0 +5,0 @@ [![Coverage Status](https://img.shields.io/coveralls/markdown-it/markdown-it-abbr/master.svg?style=flat)](https://coveralls.io/r/markdown-it/markdown-it-abbr?branch=master) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
21208
395
1
10
7
2
1