linkify-element
Advanced tools
Comparing version 4.0.0-beta.3 to 4.0.0-beta.4
var linkifyElement = (function (linkifyjs) { | ||
'use strict'; | ||
/** | ||
Linkify a HTML DOM node | ||
*/ | ||
var HTML_NODE = 1, | ||
@@ -11,3 +8,3 @@ TXT_NODE = 3; | ||
* @param {HTMLElement} parent | ||
* @param {Text | HTMLElement} oldChild | ||
* @param {Text | HTMLElement | ChildNode} oldChild | ||
* @param {Array<Text | HTMLElement>} newChildren | ||
@@ -26,5 +23,5 @@ */ | ||
/** | ||
* @param {MultiToken[]} tokens | ||
* @param {Object} opts | ||
* @param {Document} doc A | ||
* @param {import('linkifyjs').MultiToken[]} tokens | ||
* @param {import('linkifyjs').Options} options | ||
* @param {Document} doc Document implementation | ||
* @returns {Array<Text | HTMLElement>} | ||
@@ -34,3 +31,3 @@ */ | ||
function tokensToNodes(tokens, opts, doc) { | ||
function tokensToNodes(tokens, options, doc) { | ||
var result = []; | ||
@@ -41,8 +38,8 @@ | ||
if (token.t === 'nl' && opts.get('nl2br')) { | ||
if (token.t === 'nl' && options.get('nl2br')) { | ||
result.push(doc.createElement('br')); | ||
} else if (!token.isLink || !opts.check(token)) { | ||
} else if (!token.isLink || !options.check(token)) { | ||
result.push(doc.createTextNode(token.toString())); | ||
} else { | ||
result.push(opts.render(token)); | ||
result.push(options.render(token)); | ||
} | ||
@@ -55,4 +52,4 @@ } | ||
* Requires document.createElement | ||
* @param {HTMLElement} element | ||
* @param {Options} opts | ||
* @param {HTMLElement | ChildNode} element | ||
* @param {import('linkifyjs').Options} options | ||
* @param {Document} doc | ||
@@ -63,3 +60,3 @@ * @returns {HTMLElement} | ||
function linkifyElementHelper(element, opts, doc) { | ||
function linkifyElementHelper(element, options, doc) { | ||
// Can the element be linkified? | ||
@@ -71,3 +68,3 @@ if (!element || element.nodeType !== HTML_NODE) { | ||
if (element.tagName === 'A' || opts.ignoreTags.indexOf(element.tagName) >= 0) { | ||
if (element.tagName === 'A' || options.ignoreTags.indexOf(element.tagName) >= 0) { | ||
// No need to linkify | ||
@@ -86,3 +83,3 @@ return element; | ||
case HTML_NODE: | ||
linkifyElementHelper(childElement, opts, doc); | ||
linkifyElementHelper(childElement, options, doc); | ||
break; | ||
@@ -100,3 +97,3 @@ | ||
nodes = tokensToNodes(tokens, opts, doc); // Swap out the current child for the set of nodes | ||
nodes = tokensToNodes(tokens, options, doc); // Swap out the current child for the set of nodes | ||
@@ -147,3 +144,3 @@ replaceChildWithChildren(element, childElement, nodes); // so that the correct sibling is selected next | ||
* @param {HTMLElement} element A DOM node to linkify | ||
* @param {Object} opts linkify options | ||
* @param {import('linkifyjs').Opts} [opts] linkify options | ||
* @param {Document} [doc] (optional) window.document implementation, if differs from global | ||
@@ -155,2 +152,6 @@ * @returns {HTMLElement} | ||
function linkifyElement(element, opts, doc) { | ||
if (opts === void 0) { | ||
opts = null; | ||
} | ||
if (doc === void 0) { | ||
@@ -170,8 +171,13 @@ doc = null; | ||
opts = new linkifyjs.Options(opts, getDefaultRender(doc)); | ||
return linkifyElementHelper(element, opts, doc); | ||
} // Maintain reference to the recursive helper to cache option-normalization | ||
var options = new linkifyjs.Options(opts, getDefaultRender(doc)); | ||
return linkifyElementHelper(element, options, doc); | ||
} // Maintain reference to the recursive helper and option-normalization for use | ||
// in linkify-jquery | ||
linkifyElement.helper = linkifyElementHelper; | ||
linkifyElement.getDefaultRender = getDefaultRender; | ||
/** | ||
* @param {import('linkifyjs').Opts | import('linkifyjs').Options} opts | ||
* @param {Document} doc | ||
*/ | ||
@@ -178,0 +184,0 @@ linkifyElement.normalize = function (opts, doc) { |
@@ -1,1 +0,1 @@ | ||
var linkifyElement=function(e){"use strict";function n(e,n,t){var r=t[t.length-1];e.replaceChild(r,n);for(var i=t.length-2;i>=0;i--)e.insertBefore(t[i],r),r=t[i]}function t(e,n,t){for(var r=[],i=0;i<e.length;i++){var o=e[i];"nl"===o.t&&n.get("nl2br")?r.push(t.createElement("br")):o.isLink&&n.check(o)?r.push(n.render(o)):r.push(t.createTextNode(o.toString()))}return r}function r(i,o,a){if(!i||1!==i.nodeType)throw new Error("Cannot linkify "+i+" - Invalid DOM Node type");if("A"===i.tagName||o.ignoreTags.indexOf(i.tagName)>=0)return i;for(var l=i.firstChild;l;){var d=void 0,u=void 0,f=void 0;switch(l.nodeType){case 1:r(l,o,a);break;case 3:if(d=l.nodeValue,0===(u=e.tokenize(d)).length||1===u.length&&"text"===u[0].t)break;n(i,l,f=t(u,o,a)),l=f[f.length-1]}l=l.nextSibling}return i}function i(e){return function(n){var t=n.tagName,r=n.attributes,i=n.content,o=n.eventListeners,a=e.createElement(t);for(var l in r)a.setAttribute(l,r[l]);if(o&&a.addEventListener)for(var d in o)a.addEventListener(d,o[d]);return a.appendChild(e.createTextNode(i)),a}}function o(n,t,o){void 0===o&&(o=null);try{o=o||document||window&&window.document||global&&global.document}catch(e){}if(!o)throw new Error("Cannot find document implementation. If you are in a non-browser environment like Node.js, pass the document implementation as the third argument to linkifyElement.");return r(n,t=new e.Options(t,i(o)),o)}return o.helper=r,o.getDefaultRender=i,o.normalize=function(n,t){return new e.Options(n,i(t))},o}(linkify); | ||
var linkifyElement=function(e){"use strict";function n(e,n,t){var r=t[t.length-1];e.replaceChild(r,n);for(var i=t.length-2;i>=0;i--)e.insertBefore(t[i],r),r=t[i]}function t(e,n,t){for(var r=[],i=0;i<e.length;i++){var o=e[i];"nl"===o.t&&n.get("nl2br")?r.push(t.createElement("br")):o.isLink&&n.check(o)?r.push(n.render(o)):r.push(t.createTextNode(o.toString()))}return r}function r(i,o,a){if(!i||1!==i.nodeType)throw new Error("Cannot linkify "+i+" - Invalid DOM Node type");if("A"===i.tagName||o.ignoreTags.indexOf(i.tagName)>=0)return i;for(var l=i.firstChild;l;){var d=void 0,u=void 0,f=void 0;switch(l.nodeType){case 1:r(l,o,a);break;case 3:if(d=l.nodeValue,0===(u=e.tokenize(d)).length||1===u.length&&"text"===u[0].t)break;n(i,l,f=t(u,o,a)),l=f[f.length-1]}l=l.nextSibling}return i}function i(e){return function(n){var t=n.tagName,r=n.attributes,i=n.content,o=n.eventListeners,a=e.createElement(t);for(var l in r)a.setAttribute(l,r[l]);if(o&&a.addEventListener)for(var d in o)a.addEventListener(d,o[d]);return a.appendChild(e.createTextNode(i)),a}}function o(n,t,o){void 0===t&&(t=null),void 0===o&&(o=null);try{o=o||document||window&&window.document||global&&global.document}catch(e){}if(!o)throw new Error("Cannot find document implementation. If you are in a non-browser environment like Node.js, pass the document implementation as the third argument to linkifyElement.");return r(n,new e.Options(t,i(o)),o)}return o.helper=r,o.getDefaultRender=i,o.normalize=function(n,t){return new e.Options(n,i(t))},o}(linkify); |
@@ -7,20 +7,24 @@ export { linkifyElement as default }; | ||
* @param {HTMLElement} element A DOM node to linkify | ||
* @param {Object} opts linkify options | ||
* @param {import('linkifyjs').Opts} [opts] linkify options | ||
* @param {Document} [doc] (optional) window.document implementation, if differs from global | ||
* @returns {HTMLElement} | ||
*/ | ||
declare function linkifyElement(element: HTMLElement, opts: any, doc?: Document): HTMLElement; | ||
declare function linkifyElement(element: HTMLElement, opts?: import('linkifyjs').Opts, doc?: Document): HTMLElement; | ||
declare namespace linkifyElement { | ||
export { linkifyElementHelper as helper }; | ||
export { getDefaultRender }; | ||
export function normalize(opts: any, doc: any): Options; | ||
/** | ||
* @param {import('linkifyjs').Opts | import('linkifyjs').Options} opts | ||
* @param {Document} doc | ||
*/ | ||
export function normalize(opts: import("linkifyjs").Opts | Options, doc: Document): Options; | ||
} | ||
/** | ||
* Requires document.createElement | ||
* @param {HTMLElement} element | ||
* @param {Options} opts | ||
* @param {HTMLElement | ChildNode} element | ||
* @param {import('linkifyjs').Options} options | ||
* @param {Document} doc | ||
* @returns {HTMLElement} | ||
*/ | ||
declare function linkifyElementHelper(element: HTMLElement, opts: Options, doc: Document): HTMLElement; | ||
declare function linkifyElementHelper(element: HTMLElement | ChildNode, options: import('linkifyjs').Options, doc: Document): HTMLElement; | ||
/** | ||
@@ -27,0 +31,0 @@ * @param {Document} doc The document implementaiton |
import { Options, tokenize } from 'linkifyjs'; | ||
/** | ||
Linkify a HTML DOM node | ||
*/ | ||
var HTML_NODE = 1, | ||
@@ -10,3 +7,3 @@ TXT_NODE = 3; | ||
* @param {HTMLElement} parent | ||
* @param {Text | HTMLElement} oldChild | ||
* @param {Text | HTMLElement | ChildNode} oldChild | ||
* @param {Array<Text | HTMLElement>} newChildren | ||
@@ -25,5 +22,5 @@ */ | ||
/** | ||
* @param {MultiToken[]} tokens | ||
* @param {Object} opts | ||
* @param {Document} doc A | ||
* @param {import('linkifyjs').MultiToken[]} tokens | ||
* @param {import('linkifyjs').Options} options | ||
* @param {Document} doc Document implementation | ||
* @returns {Array<Text | HTMLElement>} | ||
@@ -33,3 +30,3 @@ */ | ||
function tokensToNodes(tokens, opts, doc) { | ||
function tokensToNodes(tokens, options, doc) { | ||
var result = []; | ||
@@ -40,8 +37,8 @@ | ||
if (token.t === 'nl' && opts.get('nl2br')) { | ||
if (token.t === 'nl' && options.get('nl2br')) { | ||
result.push(doc.createElement('br')); | ||
} else if (!token.isLink || !opts.check(token)) { | ||
} else if (!token.isLink || !options.check(token)) { | ||
result.push(doc.createTextNode(token.toString())); | ||
} else { | ||
result.push(opts.render(token)); | ||
result.push(options.render(token)); | ||
} | ||
@@ -54,4 +51,4 @@ } | ||
* Requires document.createElement | ||
* @param {HTMLElement} element | ||
* @param {Options} opts | ||
* @param {HTMLElement | ChildNode} element | ||
* @param {import('linkifyjs').Options} options | ||
* @param {Document} doc | ||
@@ -62,3 +59,3 @@ * @returns {HTMLElement} | ||
function linkifyElementHelper(element, opts, doc) { | ||
function linkifyElementHelper(element, options, doc) { | ||
// Can the element be linkified? | ||
@@ -70,3 +67,3 @@ if (!element || element.nodeType !== HTML_NODE) { | ||
if (element.tagName === 'A' || opts.ignoreTags.indexOf(element.tagName) >= 0) { | ||
if (element.tagName === 'A' || options.ignoreTags.indexOf(element.tagName) >= 0) { | ||
// No need to linkify | ||
@@ -85,3 +82,3 @@ return element; | ||
case HTML_NODE: | ||
linkifyElementHelper(childElement, opts, doc); | ||
linkifyElementHelper(childElement, options, doc); | ||
break; | ||
@@ -99,3 +96,3 @@ | ||
nodes = tokensToNodes(tokens, opts, doc); // Swap out the current child for the set of nodes | ||
nodes = tokensToNodes(tokens, options, doc); // Swap out the current child for the set of nodes | ||
@@ -146,3 +143,3 @@ replaceChildWithChildren(element, childElement, nodes); // so that the correct sibling is selected next | ||
* @param {HTMLElement} element A DOM node to linkify | ||
* @param {Object} opts linkify options | ||
* @param {import('linkifyjs').Opts} [opts] linkify options | ||
* @param {Document} [doc] (optional) window.document implementation, if differs from global | ||
@@ -154,2 +151,6 @@ * @returns {HTMLElement} | ||
function linkifyElement(element, opts, doc) { | ||
if (opts === void 0) { | ||
opts = null; | ||
} | ||
if (doc === void 0) { | ||
@@ -169,8 +170,13 @@ doc = null; | ||
opts = new Options(opts, getDefaultRender(doc)); | ||
return linkifyElementHelper(element, opts, doc); | ||
} // Maintain reference to the recursive helper to cache option-normalization | ||
var options = new Options(opts, getDefaultRender(doc)); | ||
return linkifyElementHelper(element, options, doc); | ||
} // Maintain reference to the recursive helper and option-normalization for use | ||
// in linkify-jquery | ||
linkifyElement.helper = linkifyElementHelper; | ||
linkifyElement.getDefaultRender = getDefaultRender; | ||
/** | ||
* @param {import('linkifyjs').Opts | import('linkifyjs').Options} opts | ||
* @param {Document} doc | ||
*/ | ||
@@ -177,0 +183,0 @@ linkifyElement.normalize = function (opts, doc) { |
@@ -7,20 +7,24 @@ export = linkifyElement; | ||
* @param {HTMLElement} element A DOM node to linkify | ||
* @param {Object} opts linkify options | ||
* @param {import('linkifyjs').Opts} [opts] linkify options | ||
* @param {Document} [doc] (optional) window.document implementation, if differs from global | ||
* @returns {HTMLElement} | ||
*/ | ||
declare function linkifyElement(element: HTMLElement, opts: any, doc?: Document): HTMLElement; | ||
declare function linkifyElement(element: HTMLElement, opts?: import('linkifyjs').Opts, doc?: Document): HTMLElement; | ||
declare namespace linkifyElement { | ||
export { linkifyElementHelper as helper }; | ||
export { getDefaultRender }; | ||
export function normalize(opts: any, doc: any): linkifyjs.Options; | ||
/** | ||
* @param {import('linkifyjs').Opts | import('linkifyjs').Options} opts | ||
* @param {Document} doc | ||
*/ | ||
export function normalize(opts: linkifyjs.Opts | linkifyjs.Options, doc: Document): linkifyjs.Options; | ||
} | ||
/** | ||
* Requires document.createElement | ||
* @param {HTMLElement} element | ||
* @param {Options} opts | ||
* @param {HTMLElement | ChildNode} element | ||
* @param {import('linkifyjs').Options} options | ||
* @param {Document} doc | ||
* @returns {HTMLElement} | ||
*/ | ||
declare function linkifyElementHelper(element: HTMLElement, opts: Options, doc: Document): HTMLElement; | ||
declare function linkifyElementHelper(element: HTMLElement | ChildNode, options: import('linkifyjs').Options, doc: Document): HTMLElement; | ||
/** | ||
@@ -27,0 +31,0 @@ * @param {Document} doc The document implementaiton |
48
index.js
@@ -5,5 +5,2 @@ 'use strict'; | ||
/** | ||
Linkify a HTML DOM node | ||
*/ | ||
var HTML_NODE = 1, | ||
@@ -13,3 +10,3 @@ TXT_NODE = 3; | ||
* @param {HTMLElement} parent | ||
* @param {Text | HTMLElement} oldChild | ||
* @param {Text | HTMLElement | ChildNode} oldChild | ||
* @param {Array<Text | HTMLElement>} newChildren | ||
@@ -28,5 +25,5 @@ */ | ||
/** | ||
* @param {MultiToken[]} tokens | ||
* @param {Object} opts | ||
* @param {Document} doc A | ||
* @param {import('linkifyjs').MultiToken[]} tokens | ||
* @param {import('linkifyjs').Options} options | ||
* @param {Document} doc Document implementation | ||
* @returns {Array<Text | HTMLElement>} | ||
@@ -36,3 +33,3 @@ */ | ||
function tokensToNodes(tokens, opts, doc) { | ||
function tokensToNodes(tokens, options, doc) { | ||
var result = []; | ||
@@ -43,8 +40,8 @@ | ||
if (token.t === 'nl' && opts.get('nl2br')) { | ||
if (token.t === 'nl' && options.get('nl2br')) { | ||
result.push(doc.createElement('br')); | ||
} else if (!token.isLink || !opts.check(token)) { | ||
} else if (!token.isLink || !options.check(token)) { | ||
result.push(doc.createTextNode(token.toString())); | ||
} else { | ||
result.push(opts.render(token)); | ||
result.push(options.render(token)); | ||
} | ||
@@ -57,4 +54,4 @@ } | ||
* Requires document.createElement | ||
* @param {HTMLElement} element | ||
* @param {Options} opts | ||
* @param {HTMLElement | ChildNode} element | ||
* @param {import('linkifyjs').Options} options | ||
* @param {Document} doc | ||
@@ -65,3 +62,3 @@ * @returns {HTMLElement} | ||
function linkifyElementHelper(element, opts, doc) { | ||
function linkifyElementHelper(element, options, doc) { | ||
// Can the element be linkified? | ||
@@ -73,3 +70,3 @@ if (!element || element.nodeType !== HTML_NODE) { | ||
if (element.tagName === 'A' || opts.ignoreTags.indexOf(element.tagName) >= 0) { | ||
if (element.tagName === 'A' || options.ignoreTags.indexOf(element.tagName) >= 0) { | ||
// No need to linkify | ||
@@ -88,3 +85,3 @@ return element; | ||
case HTML_NODE: | ||
linkifyElementHelper(childElement, opts, doc); | ||
linkifyElementHelper(childElement, options, doc); | ||
break; | ||
@@ -102,3 +99,3 @@ | ||
nodes = tokensToNodes(tokens, opts, doc); // Swap out the current child for the set of nodes | ||
nodes = tokensToNodes(tokens, options, doc); // Swap out the current child for the set of nodes | ||
@@ -149,3 +146,3 @@ replaceChildWithChildren(element, childElement, nodes); // so that the correct sibling is selected next | ||
* @param {HTMLElement} element A DOM node to linkify | ||
* @param {Object} opts linkify options | ||
* @param {import('linkifyjs').Opts} [opts] linkify options | ||
* @param {Document} [doc] (optional) window.document implementation, if differs from global | ||
@@ -157,2 +154,6 @@ * @returns {HTMLElement} | ||
function linkifyElement(element, opts, doc) { | ||
if (opts === void 0) { | ||
opts = null; | ||
} | ||
if (doc === void 0) { | ||
@@ -172,8 +173,13 @@ doc = null; | ||
opts = new linkifyjs.Options(opts, getDefaultRender(doc)); | ||
return linkifyElementHelper(element, opts, doc); | ||
} // Maintain reference to the recursive helper to cache option-normalization | ||
var options = new linkifyjs.Options(opts, getDefaultRender(doc)); | ||
return linkifyElementHelper(element, options, doc); | ||
} // Maintain reference to the recursive helper and option-normalization for use | ||
// in linkify-jquery | ||
linkifyElement.helper = linkifyElementHelper; | ||
linkifyElement.getDefaultRender = getDefaultRender; | ||
/** | ||
* @param {import('linkifyjs').Opts | import('linkifyjs').Options} opts | ||
* @param {Document} doc | ||
*/ | ||
@@ -180,0 +186,0 @@ linkifyElement.normalize = function (opts, doc) { |
{ | ||
"name": "linkify-element", | ||
"version": "4.0.0-beta.3", | ||
"version": "4.0.0-beta.4", | ||
"description": "Browser DOM element interface for linkifyjs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
21300
492