UNPKG

quill2-smart-links

Version:

Autodetects links with format "http(s)://..." that were entered or pasted into Quill 2.0 and converts them into <a> elements.

3 lines (2 loc) 768 B
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=/https?:\/\/[^\s]+/;class y{constructor(n,x){n.on("text-change",function(c){var u,d;const f=n.getSelection(!1),t=f==null?void 0:f.index;if(t===null||typeof t>"u")return;const[r]=n.getLeaf(t);if(r==null)return;const[g]=((d=(u=c==null?void 0:c.ops)==null?void 0:u.filter(s=>s.insert))==null?void 0:d.map(s=>s.insert))??[null],o=r.value();if(!o||typeof o!="string"||r.parent.domNode.localName==="a")return;const p=[` `," "].find(s=>s===g),m=x.linkRegex??I,[e]=o.match(m)??[null];if(e===null)return;const i=o.indexOf(e);if(i===null)return;const l=n.getIndex(r),a=l+i,k=a+e.length;!p&&t<=k&&t>a||(n.deleteText(l+i,e.length,"api"),n.insertText(l+i,e,"link",e))})}}exports.SmartLinks=y;