@ni/nimble-components 20.2.14 → 20.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/all-components-bundle.js +2310 -37
- package/dist/all-components-bundle.js.map +1 -1
- package/dist/all-components-bundle.min.js +2478 -2281
- package/dist/all-components-bundle.min.js.map +1 -1
- package/dist/esm/anchor/template.d.ts +1 -1
- package/dist/esm/anchor/template.js +34 -19
- package/dist/esm/anchor/template.js.map +1 -1
- package/dist/esm/rich-text/editor/index.d.ts +9 -0
- package/dist/esm/rich-text/editor/index.js +48 -0
- package/dist/esm/rich-text/editor/index.js.map +1 -1
- package/dist/esm/rich-text/editor/styles.js +30 -1
- package/dist/esm/rich-text/editor/styles.js.map +1 -1
- package/dist/esm/rich-text/editor/testing/rich-text-editor.pageobject.d.ts +3 -0
- package/dist/esm/rich-text/editor/testing/rich-text-editor.pageobject.js +24 -5
- package/dist/esm/rich-text/editor/testing/rich-text-editor.pageobject.js.map +1 -1
- package/dist/esm/rich-text/models/markdown-parser.d.ts +2 -0
- package/dist/esm/rich-text/models/markdown-parser.js +45 -3
- package/dist/esm/rich-text/models/markdown-parser.js.map +1 -1
- package/dist/esm/rich-text/models/markdown-serializer.js +22 -1
- package/dist/esm/rich-text/models/markdown-serializer.js.map +1 -1
- package/dist/esm/rich-text/models/testing/markdown-parser-utils.d.ts +2 -0
- package/dist/esm/rich-text/models/testing/markdown-parser-utils.js +10 -0
- package/dist/esm/rich-text/models/testing/markdown-parser-utils.js.map +1 -1
- package/dist/esm/rich-text/viewer/styles.js +1 -10
- package/dist/esm/rich-text/viewer/styles.js.map +1 -1
- package/dist/esm/src/anchor/template.d.ts +1 -1
- package/dist/esm/src/rich-text/editor/index.d.ts +9 -0
- package/dist/esm/src/rich-text/editor/testing/rich-text-editor.pageobject.d.ts +3 -0
- package/dist/esm/src/rich-text/models/markdown-parser.d.ts +2 -0
- package/dist/esm/src/rich-text/models/testing/markdown-parser-utils.d.ts +2 -0
- package/package.json +2 -1
|
@@ -16288,7 +16288,7 @@
|
|
|
16288
16288
|
|
|
16289
16289
|
/**
|
|
16290
16290
|
* Do not edit directly
|
|
16291
|
-
* Generated on Thu, 14 Sep 2023
|
|
16291
|
+
* Generated on Thu, 14 Sep 2023 19:33:47 GMT
|
|
16292
16292
|
*/
|
|
16293
16293
|
|
|
16294
16294
|
const Information100DarkUi = "#a46eff";
|
|
@@ -17067,8 +17067,7 @@
|
|
|
17067
17067
|
`;
|
|
17068
17068
|
|
|
17069
17069
|
// prettier-ignore
|
|
17070
|
-
const template$z = (
|
|
17071
|
-
<a
|
|
17070
|
+
const template$z = (_context, definition) => html `<a
|
|
17072
17071
|
class="control"
|
|
17073
17072
|
part="control"
|
|
17074
17073
|
download="${x => x.download}"
|
|
@@ -17100,22 +17099,39 @@
|
|
|
17100
17099
|
aria-relevant="${x => x.ariaRelevant}"
|
|
17101
17100
|
aria-roledescription="${x => x.ariaRoledescription}"
|
|
17102
17101
|
${ref('control')}
|
|
17103
|
-
|
|
17104
|
-
|
|
17105
|
-
|
|
17106
|
-
|
|
17107
|
-
|
|
17108
|
-
|
|
17109
|
-
|
|
17110
|
-
|
|
17111
|
-
|
|
17112
|
-
|
|
17113
|
-
|
|
17114
|
-
|
|
17115
|
-
|
|
17116
|
-
|
|
17117
|
-
|
|
17118
|
-
|
|
17102
|
+
>${
|
|
17103
|
+
/* Start and End slot templates inlined to avoid extra whitespace.
|
|
17104
|
+
See https://github.com/microsoft/fast/issues/6557
|
|
17105
|
+
|
|
17106
|
+
Whitespace intentionally avoided between tags for inline styles */ ''}<span
|
|
17107
|
+
part="start"
|
|
17108
|
+
${ref('startContainer')}
|
|
17109
|
+
class="${_x => (definition.start ? 'start' : null)}"
|
|
17110
|
+
><slot
|
|
17111
|
+
name="start"
|
|
17112
|
+
${ref('start')}
|
|
17113
|
+
@slotchange="${x => x.handleStartContentChange()}">
|
|
17114
|
+
${definition.start || ''}
|
|
17115
|
+
</slot
|
|
17116
|
+
></span
|
|
17117
|
+
><span
|
|
17118
|
+
class="content"
|
|
17119
|
+
part="content"
|
|
17120
|
+
><slot
|
|
17121
|
+
${slotted('defaultSlottedContent')}
|
|
17122
|
+
></slot
|
|
17123
|
+
></span
|
|
17124
|
+
><span
|
|
17125
|
+
part="end"
|
|
17126
|
+
${ref('endContainer')}
|
|
17127
|
+
class=${_x => (definition.end ? 'end' : null)}
|
|
17128
|
+
><slot
|
|
17129
|
+
name="end"
|
|
17130
|
+
${ref('end')}
|
|
17131
|
+
@slotchange="${x => x.handleEndContentChange()}">
|
|
17132
|
+
${definition.end || ''}
|
|
17133
|
+
</slot
|
|
17134
|
+
></span></a>`;
|
|
17119
17135
|
|
|
17120
17136
|
/**
|
|
17121
17137
|
* A nimble-styled anchor
|
|
@@ -38362,7 +38378,7 @@
|
|
|
38362
38378
|
}
|
|
38363
38379
|
return result;
|
|
38364
38380
|
};
|
|
38365
|
-
function run$1(config) {
|
|
38381
|
+
function run$1$1(config) {
|
|
38366
38382
|
var _a;
|
|
38367
38383
|
const { editor, from, to, text, rules, plugin, } = config;
|
|
38368
38384
|
const { view } = editor;
|
|
@@ -38447,7 +38463,7 @@
|
|
|
38447
38463
|
},
|
|
38448
38464
|
props: {
|
|
38449
38465
|
handleTextInput(view, from, to, text) {
|
|
38450
|
-
return run$1({
|
|
38466
|
+
return run$1$1({
|
|
38451
38467
|
editor,
|
|
38452
38468
|
from,
|
|
38453
38469
|
to,
|
|
@@ -38461,7 +38477,7 @@
|
|
|
38461
38477
|
setTimeout(() => {
|
|
38462
38478
|
const { $cursor } = view.state.selection;
|
|
38463
38479
|
if ($cursor) {
|
|
38464
|
-
run$1({
|
|
38480
|
+
run$1$1({
|
|
38465
38481
|
editor,
|
|
38466
38482
|
from: $cursor.pos,
|
|
38467
38483
|
to: $cursor.pos,
|
|
@@ -38482,7 +38498,7 @@
|
|
|
38482
38498
|
}
|
|
38483
38499
|
const { $cursor } = view.state.selection;
|
|
38484
38500
|
if ($cursor) {
|
|
38485
|
-
return run$1({
|
|
38501
|
+
return run$1$1({
|
|
38486
38502
|
editor,
|
|
38487
38503
|
from: $cursor.pos,
|
|
38488
38504
|
to: $cursor.pos,
|
|
@@ -38532,7 +38548,7 @@
|
|
|
38532
38548
|
return result;
|
|
38533
38549
|
});
|
|
38534
38550
|
};
|
|
38535
|
-
function run(config) {
|
|
38551
|
+
function run$2(config) {
|
|
38536
38552
|
const { editor, state, from, to, rule, } = config;
|
|
38537
38553
|
const { commands, chain, can } = new CommandManager({
|
|
38538
38554
|
editor,
|
|
@@ -38632,7 +38648,7 @@
|
|
|
38632
38648
|
state,
|
|
38633
38649
|
transaction: tr,
|
|
38634
38650
|
});
|
|
38635
|
-
const handler = run({
|
|
38651
|
+
const handler = run$2({
|
|
38636
38652
|
editor,
|
|
38637
38653
|
state: chainableState,
|
|
38638
38654
|
from: Math.max(from - 1, 0),
|
|
@@ -39791,6 +39807,19 @@
|
|
|
39791
39807
|
return { ...mark.attrs };
|
|
39792
39808
|
}
|
|
39793
39809
|
|
|
39810
|
+
/**
|
|
39811
|
+
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
39812
|
+
*/
|
|
39813
|
+
function combineTransactionSteps(oldDoc, transactions) {
|
|
39814
|
+
const transform = new Transform$1(oldDoc);
|
|
39815
|
+
transactions.forEach(transaction => {
|
|
39816
|
+
transaction.steps.forEach(step => {
|
|
39817
|
+
transform.step(step);
|
|
39818
|
+
});
|
|
39819
|
+
});
|
|
39820
|
+
return transform;
|
|
39821
|
+
}
|
|
39822
|
+
|
|
39794
39823
|
function defaultBlockAt(match) {
|
|
39795
39824
|
for (let i = 0; i < match.edgeCount; i += 1) {
|
|
39796
39825
|
const { type } = match.edge(i);
|
|
@@ -39801,6 +39830,31 @@
|
|
|
39801
39830
|
return null;
|
|
39802
39831
|
}
|
|
39803
39832
|
|
|
39833
|
+
/**
|
|
39834
|
+
* Same as `findChildren` but searches only within a `range`.
|
|
39835
|
+
*/
|
|
39836
|
+
function findChildrenInRange(node, range, predicate) {
|
|
39837
|
+
const nodesWithPos = [];
|
|
39838
|
+
// if (range.from === range.to) {
|
|
39839
|
+
// const nodeAt = node.nodeAt(range.from)
|
|
39840
|
+
// if (nodeAt) {
|
|
39841
|
+
// nodesWithPos.push({
|
|
39842
|
+
// node: nodeAt,
|
|
39843
|
+
// pos: range.from,
|
|
39844
|
+
// })
|
|
39845
|
+
// }
|
|
39846
|
+
// }
|
|
39847
|
+
node.nodesBetween(range.from, range.to, (child, pos) => {
|
|
39848
|
+
if (predicate(child)) {
|
|
39849
|
+
nodesWithPos.push({
|
|
39850
|
+
node: child,
|
|
39851
|
+
pos,
|
|
39852
|
+
});
|
|
39853
|
+
}
|
|
39854
|
+
});
|
|
39855
|
+
return nodesWithPos;
|
|
39856
|
+
}
|
|
39857
|
+
|
|
39804
39858
|
function findParentNodeClosestToPos($pos, predicate) {
|
|
39805
39859
|
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
39806
39860
|
const node = $pos.node(i);
|
|
@@ -39860,6 +39914,82 @@
|
|
|
39860
39914
|
return {};
|
|
39861
39915
|
}
|
|
39862
39916
|
|
|
39917
|
+
/**
|
|
39918
|
+
* Removes duplicated values within an array.
|
|
39919
|
+
* Supports numbers, strings and objects.
|
|
39920
|
+
*/
|
|
39921
|
+
function removeDuplicates(array, by = JSON.stringify) {
|
|
39922
|
+
const seen = {};
|
|
39923
|
+
return array.filter(item => {
|
|
39924
|
+
const key = by(item);
|
|
39925
|
+
return Object.prototype.hasOwnProperty.call(seen, key)
|
|
39926
|
+
? false
|
|
39927
|
+
: (seen[key] = true);
|
|
39928
|
+
});
|
|
39929
|
+
}
|
|
39930
|
+
|
|
39931
|
+
/**
|
|
39932
|
+
* Removes duplicated ranges and ranges that are
|
|
39933
|
+
* fully captured by other ranges.
|
|
39934
|
+
*/
|
|
39935
|
+
function simplifyChangedRanges(changes) {
|
|
39936
|
+
const uniqueChanges = removeDuplicates(changes);
|
|
39937
|
+
return uniqueChanges.length === 1
|
|
39938
|
+
? uniqueChanges
|
|
39939
|
+
: uniqueChanges.filter((change, index) => {
|
|
39940
|
+
const rest = uniqueChanges.filter((_, i) => i !== index);
|
|
39941
|
+
return !rest.some(otherChange => {
|
|
39942
|
+
return change.oldRange.from >= otherChange.oldRange.from
|
|
39943
|
+
&& change.oldRange.to <= otherChange.oldRange.to
|
|
39944
|
+
&& change.newRange.from >= otherChange.newRange.from
|
|
39945
|
+
&& change.newRange.to <= otherChange.newRange.to;
|
|
39946
|
+
});
|
|
39947
|
+
});
|
|
39948
|
+
}
|
|
39949
|
+
/**
|
|
39950
|
+
* Returns a list of changed ranges
|
|
39951
|
+
* based on the first and last state of all steps.
|
|
39952
|
+
*/
|
|
39953
|
+
function getChangedRanges(transform) {
|
|
39954
|
+
const { mapping, steps } = transform;
|
|
39955
|
+
const changes = [];
|
|
39956
|
+
mapping.maps.forEach((stepMap, index) => {
|
|
39957
|
+
const ranges = [];
|
|
39958
|
+
// This accounts for step changes where no range was actually altered
|
|
39959
|
+
// e.g. when setting a mark, node attribute, etc.
|
|
39960
|
+
// @ts-ignore
|
|
39961
|
+
if (!stepMap.ranges.length) {
|
|
39962
|
+
const { from, to } = steps[index];
|
|
39963
|
+
if (from === undefined || to === undefined) {
|
|
39964
|
+
return;
|
|
39965
|
+
}
|
|
39966
|
+
ranges.push({ from, to });
|
|
39967
|
+
}
|
|
39968
|
+
else {
|
|
39969
|
+
stepMap.forEach((from, to) => {
|
|
39970
|
+
ranges.push({ from, to });
|
|
39971
|
+
});
|
|
39972
|
+
}
|
|
39973
|
+
ranges.forEach(({ from, to }) => {
|
|
39974
|
+
const newStart = mapping.slice(index).map(from, -1);
|
|
39975
|
+
const newEnd = mapping.slice(index).map(to);
|
|
39976
|
+
const oldStart = mapping.invert().map(newStart, -1);
|
|
39977
|
+
const oldEnd = mapping.invert().map(newEnd);
|
|
39978
|
+
changes.push({
|
|
39979
|
+
oldRange: {
|
|
39980
|
+
from: oldStart,
|
|
39981
|
+
to: oldEnd,
|
|
39982
|
+
},
|
|
39983
|
+
newRange: {
|
|
39984
|
+
from: newStart,
|
|
39985
|
+
to: newEnd,
|
|
39986
|
+
},
|
|
39987
|
+
});
|
|
39988
|
+
});
|
|
39989
|
+
});
|
|
39990
|
+
return simplifyChangedRanges(changes);
|
|
39991
|
+
}
|
|
39992
|
+
|
|
39863
39993
|
function getMarksBetween(from, to, doc) {
|
|
39864
39994
|
const marks = [];
|
|
39865
39995
|
// get all inclusive marks on empty selection
|
|
@@ -42462,6 +42592,2021 @@ img.ProseMirror-separator {
|
|
|
42462
42592
|
},
|
|
42463
42593
|
});
|
|
42464
42594
|
|
|
42595
|
+
// THIS FILE IS AUTOMATICALLY GENERATED DO NOT EDIT DIRECTLY
|
|
42596
|
+
// See update-tlds.js for encoding/decoding format
|
|
42597
|
+
// https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
|
42598
|
+
const encodedTlds = 'aaa1rp3barth4b0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0faromeo7ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4vianca6w0s2x0a2z0ure5ba0by2idu3namex3narepublic11d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2ntley5rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re2s2c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y0eats7k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0cast4mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking0channel11l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dabur3d1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t0isalat7u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0at2delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d0network8tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntdoor4ier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0ardian6cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5gtv3iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0eles2s3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6logistics9properties14fh2g1h1i0a1ds2m1nder2le4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3ncaster5ia3d0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4de2k2psy3ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0cys3drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7serati6ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic3tual5v1w1x1y1z2na0b1goya4me2tura4vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rthwesternmutual14on4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9dnavy5lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3ssagens7y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0america6xi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cher3ks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0a1b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp2w2ell3ia1ksha5oes2p0ping5uji3w0time7i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ffany5ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0channel7ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lkswagen7vo3te1ing3o2yage5u0elos6wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4finity6ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2';
|
|
42599
|
+
// Internationalized domain names containing non-ASCII
|
|
42600
|
+
const encodedUtlds = 'ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5تصالات6رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2';
|
|
42601
|
+
|
|
42602
|
+
/**
|
|
42603
|
+
* @template A
|
|
42604
|
+
* @template B
|
|
42605
|
+
* @param {A} target
|
|
42606
|
+
* @param {B} properties
|
|
42607
|
+
* @return {A & B}
|
|
42608
|
+
*/
|
|
42609
|
+
const assign$2 = (target, properties) => {
|
|
42610
|
+
for (const key in properties) {
|
|
42611
|
+
target[key] = properties[key];
|
|
42612
|
+
}
|
|
42613
|
+
return target;
|
|
42614
|
+
};
|
|
42615
|
+
|
|
42616
|
+
/**
|
|
42617
|
+
* Finite State Machine generation utilities
|
|
42618
|
+
*/
|
|
42619
|
+
|
|
42620
|
+
/**
|
|
42621
|
+
* @template T
|
|
42622
|
+
* @typedef {{ [group: string]: T[] }} Collections
|
|
42623
|
+
*/
|
|
42624
|
+
|
|
42625
|
+
/**
|
|
42626
|
+
* @typedef {{ [group: string]: true }} Flags
|
|
42627
|
+
*/
|
|
42628
|
+
|
|
42629
|
+
// Keys in scanner Collections instances
|
|
42630
|
+
const numeric = 'numeric';
|
|
42631
|
+
const ascii = 'ascii';
|
|
42632
|
+
const alpha$1 = 'alpha';
|
|
42633
|
+
const asciinumeric = 'asciinumeric';
|
|
42634
|
+
const alphanumeric$1 = 'alphanumeric';
|
|
42635
|
+
const domain = 'domain';
|
|
42636
|
+
const emoji = 'emoji';
|
|
42637
|
+
const scheme = 'scheme';
|
|
42638
|
+
const slashscheme = 'slashscheme';
|
|
42639
|
+
const whitespace = 'whitespace';
|
|
42640
|
+
|
|
42641
|
+
/**
|
|
42642
|
+
* @template T
|
|
42643
|
+
* @param {string} name
|
|
42644
|
+
* @param {Collections<T>} groups to register in
|
|
42645
|
+
* @returns {T[]} Current list of tokens in the given collection
|
|
42646
|
+
*/
|
|
42647
|
+
function registerGroup(name, groups) {
|
|
42648
|
+
if (!(name in groups)) {
|
|
42649
|
+
groups[name] = [];
|
|
42650
|
+
}
|
|
42651
|
+
return groups[name];
|
|
42652
|
+
}
|
|
42653
|
+
|
|
42654
|
+
/**
|
|
42655
|
+
* @template T
|
|
42656
|
+
* @param {T} t token to add
|
|
42657
|
+
* @param {Collections<T>} groups
|
|
42658
|
+
* @param {Flags} flags
|
|
42659
|
+
*/
|
|
42660
|
+
function addToGroups(t, flags, groups) {
|
|
42661
|
+
if (flags[numeric]) {
|
|
42662
|
+
flags[asciinumeric] = true;
|
|
42663
|
+
flags[alphanumeric$1] = true;
|
|
42664
|
+
}
|
|
42665
|
+
if (flags[ascii]) {
|
|
42666
|
+
flags[asciinumeric] = true;
|
|
42667
|
+
flags[alpha$1] = true;
|
|
42668
|
+
}
|
|
42669
|
+
if (flags[asciinumeric]) {
|
|
42670
|
+
flags[alphanumeric$1] = true;
|
|
42671
|
+
}
|
|
42672
|
+
if (flags[alpha$1]) {
|
|
42673
|
+
flags[alphanumeric$1] = true;
|
|
42674
|
+
}
|
|
42675
|
+
if (flags[alphanumeric$1]) {
|
|
42676
|
+
flags[domain] = true;
|
|
42677
|
+
}
|
|
42678
|
+
if (flags[emoji]) {
|
|
42679
|
+
flags[domain] = true;
|
|
42680
|
+
}
|
|
42681
|
+
for (const k in flags) {
|
|
42682
|
+
const group = registerGroup(k, groups);
|
|
42683
|
+
if (group.indexOf(t) < 0) {
|
|
42684
|
+
group.push(t);
|
|
42685
|
+
}
|
|
42686
|
+
}
|
|
42687
|
+
}
|
|
42688
|
+
|
|
42689
|
+
/**
|
|
42690
|
+
* @template T
|
|
42691
|
+
* @param {T} t token to check
|
|
42692
|
+
* @param {Collections<T>} groups
|
|
42693
|
+
* @returns {Flags} group flags that contain this token
|
|
42694
|
+
*/
|
|
42695
|
+
function flagsForToken(t, groups) {
|
|
42696
|
+
const result = {};
|
|
42697
|
+
for (const c in groups) {
|
|
42698
|
+
if (groups[c].indexOf(t) >= 0) {
|
|
42699
|
+
result[c] = true;
|
|
42700
|
+
}
|
|
42701
|
+
}
|
|
42702
|
+
return result;
|
|
42703
|
+
}
|
|
42704
|
+
|
|
42705
|
+
/**
|
|
42706
|
+
* @template T
|
|
42707
|
+
* @typedef {null | T } Transition
|
|
42708
|
+
*/
|
|
42709
|
+
|
|
42710
|
+
/**
|
|
42711
|
+
* Define a basic state machine state. j is the list of character transitions,
|
|
42712
|
+
* jr is the list of regex-match transitions, jd is the default state to
|
|
42713
|
+
* transition to t is the accepting token type, if any. If this is the terminal
|
|
42714
|
+
* state, then it does not emit a token.
|
|
42715
|
+
*
|
|
42716
|
+
* The template type T represents the type of the token this state accepts. This
|
|
42717
|
+
* should be a string (such as of the token exports in `text.js`) or a
|
|
42718
|
+
* MultiToken subclass (from `multi.js`)
|
|
42719
|
+
*
|
|
42720
|
+
* @template T
|
|
42721
|
+
* @param {T} [token] Token that this state emits
|
|
42722
|
+
*/
|
|
42723
|
+
function State(token) {
|
|
42724
|
+
if (token === void 0) {
|
|
42725
|
+
token = null;
|
|
42726
|
+
}
|
|
42727
|
+
// this.n = null; // DEBUG: State name
|
|
42728
|
+
/** @type {{ [input: string]: State<T> }} j */
|
|
42729
|
+
this.j = {}; // IMPLEMENTATION 1
|
|
42730
|
+
// this.j = []; // IMPLEMENTATION 2
|
|
42731
|
+
/** @type {[RegExp, State<T>][]} jr */
|
|
42732
|
+
this.jr = [];
|
|
42733
|
+
/** @type {?State<T>} jd */
|
|
42734
|
+
this.jd = null;
|
|
42735
|
+
/** @type {?T} t */
|
|
42736
|
+
this.t = token;
|
|
42737
|
+
}
|
|
42738
|
+
|
|
42739
|
+
/**
|
|
42740
|
+
* Scanner token groups
|
|
42741
|
+
* @type Collections<string>
|
|
42742
|
+
*/
|
|
42743
|
+
State.groups = {};
|
|
42744
|
+
State.prototype = {
|
|
42745
|
+
accepts() {
|
|
42746
|
+
return !!this.t;
|
|
42747
|
+
},
|
|
42748
|
+
/**
|
|
42749
|
+
* Follow an existing transition from the given input to the next state.
|
|
42750
|
+
* Does not mutate.
|
|
42751
|
+
* @param {string} input character or token type to transition on
|
|
42752
|
+
* @returns {?State<T>} the next state, if any
|
|
42753
|
+
*/
|
|
42754
|
+
go(input) {
|
|
42755
|
+
const state = this;
|
|
42756
|
+
const nextState = state.j[input];
|
|
42757
|
+
if (nextState) {
|
|
42758
|
+
return nextState;
|
|
42759
|
+
}
|
|
42760
|
+
for (let i = 0; i < state.jr.length; i++) {
|
|
42761
|
+
const regex = state.jr[i][0];
|
|
42762
|
+
const nextState = state.jr[i][1]; // note: might be empty to prevent default jump
|
|
42763
|
+
if (nextState && regex.test(input)) {
|
|
42764
|
+
return nextState;
|
|
42765
|
+
}
|
|
42766
|
+
}
|
|
42767
|
+
// Nowhere left to jump! Return default, if any
|
|
42768
|
+
return state.jd;
|
|
42769
|
+
},
|
|
42770
|
+
/**
|
|
42771
|
+
* Whether the state has a transition for the given input. Set the second
|
|
42772
|
+
* argument to true to only look for an exact match (and not a default or
|
|
42773
|
+
* regular-expression-based transition)
|
|
42774
|
+
* @param {string} input
|
|
42775
|
+
* @param {boolean} exactOnly
|
|
42776
|
+
*/
|
|
42777
|
+
has(input, exactOnly) {
|
|
42778
|
+
if (exactOnly === void 0) {
|
|
42779
|
+
exactOnly = false;
|
|
42780
|
+
}
|
|
42781
|
+
return exactOnly ? input in this.j : !!this.go(input);
|
|
42782
|
+
},
|
|
42783
|
+
/**
|
|
42784
|
+
* Short for "transition all"; create a transition from the array of items
|
|
42785
|
+
* in the given list to the same final resulting state.
|
|
42786
|
+
* @param {string | string[]} inputs Group of inputs to transition on
|
|
42787
|
+
* @param {Transition<T> | State<T>} [next] Transition options
|
|
42788
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
42789
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
42790
|
+
*/
|
|
42791
|
+
ta(inputs, next, flags, groups) {
|
|
42792
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
42793
|
+
this.tt(inputs[i], next, flags, groups);
|
|
42794
|
+
}
|
|
42795
|
+
},
|
|
42796
|
+
/**
|
|
42797
|
+
* Short for "take regexp transition"; defines a transition for this state
|
|
42798
|
+
* when it encounters a token which matches the given regular expression
|
|
42799
|
+
* @param {RegExp} regexp Regular expression transition (populate first)
|
|
42800
|
+
* @param {T | State<T>} [next] Transition options
|
|
42801
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
42802
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
42803
|
+
* @returns {State<T>} taken after the given input
|
|
42804
|
+
*/
|
|
42805
|
+
tr(regexp, next, flags, groups) {
|
|
42806
|
+
groups = groups || State.groups;
|
|
42807
|
+
let nextState;
|
|
42808
|
+
if (next && next.j) {
|
|
42809
|
+
nextState = next;
|
|
42810
|
+
} else {
|
|
42811
|
+
// Token with maybe token groups
|
|
42812
|
+
nextState = new State(next);
|
|
42813
|
+
if (flags && groups) {
|
|
42814
|
+
addToGroups(next, flags, groups);
|
|
42815
|
+
}
|
|
42816
|
+
}
|
|
42817
|
+
this.jr.push([regexp, nextState]);
|
|
42818
|
+
return nextState;
|
|
42819
|
+
},
|
|
42820
|
+
/**
|
|
42821
|
+
* Short for "take transitions", will take as many sequential transitions as
|
|
42822
|
+
* the length of the given input and returns the
|
|
42823
|
+
* resulting final state.
|
|
42824
|
+
* @param {string | string[]} input
|
|
42825
|
+
* @param {T | State<T>} [next] Transition options
|
|
42826
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
42827
|
+
* @param {Collections<T>} [groups] Master list of token groups
|
|
42828
|
+
* @returns {State<T>} taken after the given input
|
|
42829
|
+
*/
|
|
42830
|
+
ts(input, next, flags, groups) {
|
|
42831
|
+
let state = this;
|
|
42832
|
+
const len = input.length;
|
|
42833
|
+
if (!len) {
|
|
42834
|
+
return state;
|
|
42835
|
+
}
|
|
42836
|
+
for (let i = 0; i < len - 1; i++) {
|
|
42837
|
+
state = state.tt(input[i]);
|
|
42838
|
+
}
|
|
42839
|
+
return state.tt(input[len - 1], next, flags, groups);
|
|
42840
|
+
},
|
|
42841
|
+
/**
|
|
42842
|
+
* Short for "take transition", this is a method for building/working with
|
|
42843
|
+
* state machines.
|
|
42844
|
+
*
|
|
42845
|
+
* If a state already exists for the given input, returns it.
|
|
42846
|
+
*
|
|
42847
|
+
* If a token is specified, that state will emit that token when reached by
|
|
42848
|
+
* the linkify engine.
|
|
42849
|
+
*
|
|
42850
|
+
* If no state exists, it will be initialized with some default transitions
|
|
42851
|
+
* that resemble existing default transitions.
|
|
42852
|
+
*
|
|
42853
|
+
* If a state is given for the second argument, that state will be
|
|
42854
|
+
* transitioned to on the given input regardless of what that input
|
|
42855
|
+
* previously did.
|
|
42856
|
+
*
|
|
42857
|
+
* Specify a token group flags to define groups that this token belongs to.
|
|
42858
|
+
* The token will be added to corresponding entires in the given groups
|
|
42859
|
+
* object.
|
|
42860
|
+
*
|
|
42861
|
+
* @param {string} input character, token type to transition on
|
|
42862
|
+
* @param {T | State<T>} [next] Transition options
|
|
42863
|
+
* @param {Flags} [flags] Collections flags to add token to
|
|
42864
|
+
* @param {Collections<T>} [groups] Master list of groups
|
|
42865
|
+
* @returns {State<T>} taken after the given input
|
|
42866
|
+
*/
|
|
42867
|
+
tt(input, next, flags, groups) {
|
|
42868
|
+
groups = groups || State.groups;
|
|
42869
|
+
const state = this;
|
|
42870
|
+
|
|
42871
|
+
// Check if existing state given, just a basic transition
|
|
42872
|
+
if (next && next.j) {
|
|
42873
|
+
state.j[input] = next;
|
|
42874
|
+
return next;
|
|
42875
|
+
}
|
|
42876
|
+
const t = next;
|
|
42877
|
+
|
|
42878
|
+
// Take the transition with the usual default mechanisms and use that as
|
|
42879
|
+
// a template for creating the next state
|
|
42880
|
+
let nextState,
|
|
42881
|
+
templateState = state.go(input);
|
|
42882
|
+
if (templateState) {
|
|
42883
|
+
nextState = new State();
|
|
42884
|
+
assign$2(nextState.j, templateState.j);
|
|
42885
|
+
nextState.jr.push.apply(nextState.jr, templateState.jr);
|
|
42886
|
+
nextState.jd = templateState.jd;
|
|
42887
|
+
nextState.t = templateState.t;
|
|
42888
|
+
} else {
|
|
42889
|
+
nextState = new State();
|
|
42890
|
+
}
|
|
42891
|
+
if (t) {
|
|
42892
|
+
// Ensure newly token is in the same groups as the old token
|
|
42893
|
+
if (groups) {
|
|
42894
|
+
if (nextState.t && typeof nextState.t === 'string') {
|
|
42895
|
+
const allFlags = assign$2(flagsForToken(nextState.t, groups), flags);
|
|
42896
|
+
addToGroups(t, allFlags, groups);
|
|
42897
|
+
} else if (flags) {
|
|
42898
|
+
addToGroups(t, flags, groups);
|
|
42899
|
+
}
|
|
42900
|
+
}
|
|
42901
|
+
nextState.t = t; // overwrite anything that was previously there
|
|
42902
|
+
}
|
|
42903
|
+
|
|
42904
|
+
state.j[input] = nextState;
|
|
42905
|
+
return nextState;
|
|
42906
|
+
}
|
|
42907
|
+
};
|
|
42908
|
+
|
|
42909
|
+
// Helper functions to improve minification (not exported outside linkifyjs module)
|
|
42910
|
+
|
|
42911
|
+
/**
|
|
42912
|
+
* @template T
|
|
42913
|
+
* @param {State<T>} state
|
|
42914
|
+
* @param {string | string[]} input
|
|
42915
|
+
* @param {Flags} [flags]
|
|
42916
|
+
* @param {Collections<T>} [groups]
|
|
42917
|
+
*/
|
|
42918
|
+
const ta = (state, input, next, flags, groups) => state.ta(input, next, flags, groups);
|
|
42919
|
+
|
|
42920
|
+
/**
|
|
42921
|
+
* @template T
|
|
42922
|
+
* @param {State<T>} state
|
|
42923
|
+
* @param {RegExp} regexp
|
|
42924
|
+
* @param {T | State<T>} [next]
|
|
42925
|
+
* @param {Flags} [flags]
|
|
42926
|
+
* @param {Collections<T>} [groups]
|
|
42927
|
+
*/
|
|
42928
|
+
const tr = (state, regexp, next, flags, groups) => state.tr(regexp, next, flags, groups);
|
|
42929
|
+
|
|
42930
|
+
/**
|
|
42931
|
+
* @template T
|
|
42932
|
+
* @param {State<T>} state
|
|
42933
|
+
* @param {string | string[]} input
|
|
42934
|
+
* @param {T | State<T>} [next]
|
|
42935
|
+
* @param {Flags} [flags]
|
|
42936
|
+
* @param {Collections<T>} [groups]
|
|
42937
|
+
*/
|
|
42938
|
+
const ts = (state, input, next, flags, groups) => state.ts(input, next, flags, groups);
|
|
42939
|
+
|
|
42940
|
+
/**
|
|
42941
|
+
* @template T
|
|
42942
|
+
* @param {State<T>} state
|
|
42943
|
+
* @param {string} input
|
|
42944
|
+
* @param {T | State<T>} [next]
|
|
42945
|
+
* @param {Collections<T>} [groups]
|
|
42946
|
+
* @param {Flags} [flags]
|
|
42947
|
+
*/
|
|
42948
|
+
const tt = (state, input, next, flags, groups) => state.tt(input, next, flags, groups);
|
|
42949
|
+
|
|
42950
|
+
/******************************************************************************
|
|
42951
|
+
Text Tokens
|
|
42952
|
+
Identifiers for token outputs from the regexp scanner
|
|
42953
|
+
******************************************************************************/
|
|
42954
|
+
|
|
42955
|
+
// A valid web domain token
|
|
42956
|
+
const WORD = 'WORD'; // only contains a-z
|
|
42957
|
+
const UWORD = 'UWORD'; // contains letters other than a-z, used for IDN
|
|
42958
|
+
|
|
42959
|
+
// Special case of word
|
|
42960
|
+
const LOCALHOST = 'LOCALHOST';
|
|
42961
|
+
|
|
42962
|
+
// Valid top-level domain, special case of WORD (see tlds.js)
|
|
42963
|
+
const TLD = 'TLD';
|
|
42964
|
+
|
|
42965
|
+
// Valid IDN TLD, special case of UWORD (see tlds.js)
|
|
42966
|
+
const UTLD = 'UTLD';
|
|
42967
|
+
|
|
42968
|
+
// The scheme portion of a web URI protocol. Supported types include: `mailto`,
|
|
42969
|
+
// `file`, and user-defined custom protocols. Limited to schemes that contain
|
|
42970
|
+
// only letters
|
|
42971
|
+
const SCHEME = 'SCHEME';
|
|
42972
|
+
|
|
42973
|
+
// Similar to SCHEME, except makes distinction for schemes that must always be
|
|
42974
|
+
// followed by `://`, not just `:`. Supported types include `http`, `https`,
|
|
42975
|
+
// `ftp`, `ftps`
|
|
42976
|
+
const SLASH_SCHEME = 'SLASH_SCHEME';
|
|
42977
|
+
|
|
42978
|
+
// Any sequence of digits 0-9
|
|
42979
|
+
const NUM = 'NUM';
|
|
42980
|
+
|
|
42981
|
+
// Any number of consecutive whitespace characters that are not newline
|
|
42982
|
+
const WS = 'WS';
|
|
42983
|
+
|
|
42984
|
+
// New line (unix style)
|
|
42985
|
+
const NL$1 = 'NL'; // \n
|
|
42986
|
+
|
|
42987
|
+
// Opening/closing bracket classes
|
|
42988
|
+
const OPENBRACE = 'OPENBRACE'; // {
|
|
42989
|
+
const OPENBRACKET = 'OPENBRACKET'; // [
|
|
42990
|
+
const OPENANGLEBRACKET = 'OPENANGLEBRACKET'; // <
|
|
42991
|
+
const OPENPAREN = 'OPENPAREN'; // (
|
|
42992
|
+
const CLOSEBRACE = 'CLOSEBRACE'; // }
|
|
42993
|
+
const CLOSEBRACKET = 'CLOSEBRACKET'; // ]
|
|
42994
|
+
const CLOSEANGLEBRACKET = 'CLOSEANGLEBRACKET'; // >
|
|
42995
|
+
const CLOSEPAREN = 'CLOSEPAREN'; // )
|
|
42996
|
+
|
|
42997
|
+
// Various symbols
|
|
42998
|
+
const AMPERSAND = 'AMPERSAND'; // &
|
|
42999
|
+
const APOSTROPHE$1 = 'APOSTROPHE'; // '
|
|
43000
|
+
const ASTERISK = 'ASTERISK'; // *
|
|
43001
|
+
const AT = 'AT'; // @
|
|
43002
|
+
const BACKSLASH = 'BACKSLASH'; // \
|
|
43003
|
+
const BACKTICK = 'BACKTICK'; // `
|
|
43004
|
+
const CARET = 'CARET'; // ^
|
|
43005
|
+
const COLON = 'COLON'; // :
|
|
43006
|
+
const COMMA = 'COMMA'; // ,
|
|
43007
|
+
const DOLLAR = 'DOLLAR'; // $
|
|
43008
|
+
const DOT = 'DOT'; // .
|
|
43009
|
+
const EQUALS = 'EQUALS'; // =
|
|
43010
|
+
const EXCLAMATION = 'EXCLAMATION'; // !
|
|
43011
|
+
const HYPHEN = 'HYPHEN'; // -
|
|
43012
|
+
const PERCENT = 'PERCENT'; // %
|
|
43013
|
+
const PIPE = 'PIPE'; // |
|
|
43014
|
+
const PLUS = 'PLUS'; // +
|
|
43015
|
+
const POUND = 'POUND'; // #
|
|
43016
|
+
const QUERY = 'QUERY'; // ?
|
|
43017
|
+
const QUOTE = 'QUOTE'; // "
|
|
43018
|
+
|
|
43019
|
+
const SEMI = 'SEMI'; // ;
|
|
43020
|
+
const SLASH = 'SLASH'; // /
|
|
43021
|
+
const TILDE = 'TILDE'; // ~
|
|
43022
|
+
const UNDERSCORE = 'UNDERSCORE'; // _
|
|
43023
|
+
|
|
43024
|
+
// Emoji symbol
|
|
43025
|
+
const EMOJI$1 = 'EMOJI';
|
|
43026
|
+
|
|
43027
|
+
// Default token - anything that is not one of the above
|
|
43028
|
+
const SYM = 'SYM';
|
|
43029
|
+
|
|
43030
|
+
var tk = /*#__PURE__*/Object.freeze({
|
|
43031
|
+
__proto__: null,
|
|
43032
|
+
WORD: WORD,
|
|
43033
|
+
UWORD: UWORD,
|
|
43034
|
+
LOCALHOST: LOCALHOST,
|
|
43035
|
+
TLD: TLD,
|
|
43036
|
+
UTLD: UTLD,
|
|
43037
|
+
SCHEME: SCHEME,
|
|
43038
|
+
SLASH_SCHEME: SLASH_SCHEME,
|
|
43039
|
+
NUM: NUM,
|
|
43040
|
+
WS: WS,
|
|
43041
|
+
NL: NL$1,
|
|
43042
|
+
OPENBRACE: OPENBRACE,
|
|
43043
|
+
OPENBRACKET: OPENBRACKET,
|
|
43044
|
+
OPENANGLEBRACKET: OPENANGLEBRACKET,
|
|
43045
|
+
OPENPAREN: OPENPAREN,
|
|
43046
|
+
CLOSEBRACE: CLOSEBRACE,
|
|
43047
|
+
CLOSEBRACKET: CLOSEBRACKET,
|
|
43048
|
+
CLOSEANGLEBRACKET: CLOSEANGLEBRACKET,
|
|
43049
|
+
CLOSEPAREN: CLOSEPAREN,
|
|
43050
|
+
AMPERSAND: AMPERSAND,
|
|
43051
|
+
APOSTROPHE: APOSTROPHE$1,
|
|
43052
|
+
ASTERISK: ASTERISK,
|
|
43053
|
+
AT: AT,
|
|
43054
|
+
BACKSLASH: BACKSLASH,
|
|
43055
|
+
BACKTICK: BACKTICK,
|
|
43056
|
+
CARET: CARET,
|
|
43057
|
+
COLON: COLON,
|
|
43058
|
+
COMMA: COMMA,
|
|
43059
|
+
DOLLAR: DOLLAR,
|
|
43060
|
+
DOT: DOT,
|
|
43061
|
+
EQUALS: EQUALS,
|
|
43062
|
+
EXCLAMATION: EXCLAMATION,
|
|
43063
|
+
HYPHEN: HYPHEN,
|
|
43064
|
+
PERCENT: PERCENT,
|
|
43065
|
+
PIPE: PIPE,
|
|
43066
|
+
PLUS: PLUS,
|
|
43067
|
+
POUND: POUND,
|
|
43068
|
+
QUERY: QUERY,
|
|
43069
|
+
QUOTE: QUOTE,
|
|
43070
|
+
SEMI: SEMI,
|
|
43071
|
+
SLASH: SLASH,
|
|
43072
|
+
TILDE: TILDE,
|
|
43073
|
+
UNDERSCORE: UNDERSCORE,
|
|
43074
|
+
EMOJI: EMOJI$1,
|
|
43075
|
+
SYM: SYM
|
|
43076
|
+
});
|
|
43077
|
+
|
|
43078
|
+
// Note that these two Unicode ones expand into a really big one with Babel
|
|
43079
|
+
const ASCII_LETTER = /[a-z]/;
|
|
43080
|
+
const LETTER = /\p{L}/u; // Any Unicode character with letter data type
|
|
43081
|
+
const EMOJI = /\p{Emoji}/u; // Any Unicode emoji character
|
|
43082
|
+
const DIGIT = /\d/;
|
|
43083
|
+
const SPACE = /\s/;
|
|
43084
|
+
|
|
43085
|
+
/**
|
|
43086
|
+
The scanner provides an interface that takes a string of text as input, and
|
|
43087
|
+
outputs an array of tokens instances that can be used for easy URL parsing.
|
|
43088
|
+
*/
|
|
43089
|
+
const NL = '\n'; // New line character
|
|
43090
|
+
const EMOJI_VARIATION = '\ufe0f'; // Variation selector, follows heart and others
|
|
43091
|
+
const EMOJI_JOINER = '\u200d'; // zero-width joiner
|
|
43092
|
+
|
|
43093
|
+
let tlds = null,
|
|
43094
|
+
utlds = null; // don't change so only have to be computed once
|
|
43095
|
+
|
|
43096
|
+
/**
|
|
43097
|
+
* Scanner output token:
|
|
43098
|
+
* - `t` is the token name (e.g., 'NUM', 'EMOJI', 'TLD')
|
|
43099
|
+
* - `v` is the value of the token (e.g., '123', '❤️', 'com')
|
|
43100
|
+
* - `s` is the start index of the token in the original string
|
|
43101
|
+
* - `e` is the end index of the token in the original string
|
|
43102
|
+
* @typedef {{t: string, v: string, s: number, e: number}} Token
|
|
43103
|
+
*/
|
|
43104
|
+
|
|
43105
|
+
/**
|
|
43106
|
+
* @template T
|
|
43107
|
+
* @typedef {{ [collection: string]: T[] }} Collections
|
|
43108
|
+
*/
|
|
43109
|
+
|
|
43110
|
+
/**
|
|
43111
|
+
* Initialize the scanner character-based state machine for the given start
|
|
43112
|
+
* state
|
|
43113
|
+
* @param {[string, boolean][]} customSchemes List of custom schemes, where each
|
|
43114
|
+
* item is a length-2 tuple with the first element set to the string scheme, and
|
|
43115
|
+
* the second element set to `true` if the `://` after the scheme is optional
|
|
43116
|
+
*/
|
|
43117
|
+
function init$2(customSchemes) {
|
|
43118
|
+
if (customSchemes === void 0) {
|
|
43119
|
+
customSchemes = [];
|
|
43120
|
+
}
|
|
43121
|
+
// Frequently used states (name argument removed during minification)
|
|
43122
|
+
/** @type Collections<string> */
|
|
43123
|
+
const groups = {}; // of tokens
|
|
43124
|
+
State.groups = groups;
|
|
43125
|
+
/** @type State<string> */
|
|
43126
|
+
const Start = new State();
|
|
43127
|
+
if (tlds == null) {
|
|
43128
|
+
tlds = decodeTlds(encodedTlds);
|
|
43129
|
+
}
|
|
43130
|
+
if (utlds == null) {
|
|
43131
|
+
utlds = decodeTlds(encodedUtlds);
|
|
43132
|
+
}
|
|
43133
|
+
|
|
43134
|
+
// States for special URL symbols that accept immediately after start
|
|
43135
|
+
tt(Start, "'", APOSTROPHE$1);
|
|
43136
|
+
tt(Start, '{', OPENBRACE);
|
|
43137
|
+
tt(Start, '[', OPENBRACKET);
|
|
43138
|
+
tt(Start, '<', OPENANGLEBRACKET);
|
|
43139
|
+
tt(Start, '(', OPENPAREN);
|
|
43140
|
+
tt(Start, '}', CLOSEBRACE);
|
|
43141
|
+
tt(Start, ']', CLOSEBRACKET);
|
|
43142
|
+
tt(Start, '>', CLOSEANGLEBRACKET);
|
|
43143
|
+
tt(Start, ')', CLOSEPAREN);
|
|
43144
|
+
tt(Start, '&', AMPERSAND);
|
|
43145
|
+
tt(Start, '*', ASTERISK);
|
|
43146
|
+
tt(Start, '@', AT);
|
|
43147
|
+
tt(Start, '`', BACKTICK);
|
|
43148
|
+
tt(Start, '^', CARET);
|
|
43149
|
+
tt(Start, ':', COLON);
|
|
43150
|
+
tt(Start, ',', COMMA);
|
|
43151
|
+
tt(Start, '$', DOLLAR);
|
|
43152
|
+
tt(Start, '.', DOT);
|
|
43153
|
+
tt(Start, '=', EQUALS);
|
|
43154
|
+
tt(Start, '!', EXCLAMATION);
|
|
43155
|
+
tt(Start, '-', HYPHEN);
|
|
43156
|
+
tt(Start, '%', PERCENT);
|
|
43157
|
+
tt(Start, '|', PIPE);
|
|
43158
|
+
tt(Start, '+', PLUS);
|
|
43159
|
+
tt(Start, '#', POUND);
|
|
43160
|
+
tt(Start, '?', QUERY);
|
|
43161
|
+
tt(Start, '"', QUOTE);
|
|
43162
|
+
tt(Start, '/', SLASH);
|
|
43163
|
+
tt(Start, ';', SEMI);
|
|
43164
|
+
tt(Start, '~', TILDE);
|
|
43165
|
+
tt(Start, '_', UNDERSCORE);
|
|
43166
|
+
tt(Start, '\\', BACKSLASH);
|
|
43167
|
+
const Num = tr(Start, DIGIT, NUM, {
|
|
43168
|
+
[numeric]: true
|
|
43169
|
+
});
|
|
43170
|
+
tr(Num, DIGIT, Num);
|
|
43171
|
+
|
|
43172
|
+
// State which emits a word token
|
|
43173
|
+
const Word = tr(Start, ASCII_LETTER, WORD, {
|
|
43174
|
+
[ascii]: true
|
|
43175
|
+
});
|
|
43176
|
+
tr(Word, ASCII_LETTER, Word);
|
|
43177
|
+
|
|
43178
|
+
// Same as previous, but specific to non-fsm.ascii alphabet words
|
|
43179
|
+
const UWord = tr(Start, LETTER, UWORD, {
|
|
43180
|
+
[alpha$1]: true
|
|
43181
|
+
});
|
|
43182
|
+
tr(UWord, ASCII_LETTER); // Non-accepting
|
|
43183
|
+
tr(UWord, LETTER, UWord);
|
|
43184
|
+
|
|
43185
|
+
// Whitespace jumps
|
|
43186
|
+
// Tokens of only non-newline whitespace are arbitrarily long
|
|
43187
|
+
// If any whitespace except newline, more whitespace!
|
|
43188
|
+
const Ws = tr(Start, SPACE, WS, {
|
|
43189
|
+
[whitespace]: true
|
|
43190
|
+
});
|
|
43191
|
+
tt(Start, NL, NL$1, {
|
|
43192
|
+
[whitespace]: true
|
|
43193
|
+
});
|
|
43194
|
+
tt(Ws, NL); // non-accepting state to avoid mixing whitespaces
|
|
43195
|
+
tr(Ws, SPACE, Ws);
|
|
43196
|
+
|
|
43197
|
+
// Emoji tokens. They are not grouped by the scanner except in cases where a
|
|
43198
|
+
// zero-width joiner is present
|
|
43199
|
+
const Emoji = tr(Start, EMOJI, EMOJI$1, {
|
|
43200
|
+
[emoji]: true
|
|
43201
|
+
});
|
|
43202
|
+
tr(Emoji, EMOJI, Emoji);
|
|
43203
|
+
tt(Emoji, EMOJI_VARIATION, Emoji);
|
|
43204
|
+
// tt(Start, EMOJI_VARIATION, Emoji); // This one is sketchy
|
|
43205
|
+
|
|
43206
|
+
const EmojiJoiner = tt(Emoji, EMOJI_JOINER);
|
|
43207
|
+
tr(EmojiJoiner, EMOJI, Emoji);
|
|
43208
|
+
// tt(EmojiJoiner, EMOJI_VARIATION, Emoji); // also sketchy
|
|
43209
|
+
|
|
43210
|
+
// Generates states for top-level domains
|
|
43211
|
+
// Note that this is most accurate when tlds are in alphabetical order
|
|
43212
|
+
const wordjr = [[ASCII_LETTER, Word]];
|
|
43213
|
+
const uwordjr = [[ASCII_LETTER, null], [LETTER, UWord]];
|
|
43214
|
+
for (let i = 0; i < tlds.length; i++) {
|
|
43215
|
+
fastts(Start, tlds[i], TLD, WORD, wordjr);
|
|
43216
|
+
}
|
|
43217
|
+
for (let i = 0; i < utlds.length; i++) {
|
|
43218
|
+
fastts(Start, utlds[i], UTLD, UWORD, uwordjr);
|
|
43219
|
+
}
|
|
43220
|
+
addToGroups(TLD, {
|
|
43221
|
+
tld: true,
|
|
43222
|
+
ascii: true
|
|
43223
|
+
}, groups);
|
|
43224
|
+
addToGroups(UTLD, {
|
|
43225
|
+
utld: true,
|
|
43226
|
+
alpha: true
|
|
43227
|
+
}, groups);
|
|
43228
|
+
|
|
43229
|
+
// Collect the states generated by different protocols. NOTE: If any new TLDs
|
|
43230
|
+
// get added that are also protocols, set the token to be the same as the
|
|
43231
|
+
// protocol to ensure parsing works as expected.
|
|
43232
|
+
fastts(Start, 'file', SCHEME, WORD, wordjr);
|
|
43233
|
+
fastts(Start, 'mailto', SCHEME, WORD, wordjr);
|
|
43234
|
+
fastts(Start, 'http', SLASH_SCHEME, WORD, wordjr);
|
|
43235
|
+
fastts(Start, 'https', SLASH_SCHEME, WORD, wordjr);
|
|
43236
|
+
fastts(Start, 'ftp', SLASH_SCHEME, WORD, wordjr);
|
|
43237
|
+
fastts(Start, 'ftps', SLASH_SCHEME, WORD, wordjr);
|
|
43238
|
+
addToGroups(SCHEME, {
|
|
43239
|
+
scheme: true,
|
|
43240
|
+
ascii: true
|
|
43241
|
+
}, groups);
|
|
43242
|
+
addToGroups(SLASH_SCHEME, {
|
|
43243
|
+
slashscheme: true,
|
|
43244
|
+
ascii: true
|
|
43245
|
+
}, groups);
|
|
43246
|
+
|
|
43247
|
+
// Register custom schemes. Assumes each scheme is asciinumeric with hyphens
|
|
43248
|
+
customSchemes = customSchemes.sort((a, b) => a[0] > b[0] ? 1 : -1);
|
|
43249
|
+
for (let i = 0; i < customSchemes.length; i++) {
|
|
43250
|
+
const sch = customSchemes[i][0];
|
|
43251
|
+
const optionalSlashSlash = customSchemes[i][1];
|
|
43252
|
+
const flags = optionalSlashSlash ? {
|
|
43253
|
+
[scheme]: true
|
|
43254
|
+
} : {
|
|
43255
|
+
[slashscheme]: true
|
|
43256
|
+
};
|
|
43257
|
+
if (sch.indexOf('-') >= 0) {
|
|
43258
|
+
flags[domain] = true;
|
|
43259
|
+
} else if (!ASCII_LETTER.test(sch)) {
|
|
43260
|
+
flags[numeric] = true; // numbers only
|
|
43261
|
+
} else if (DIGIT.test(sch)) {
|
|
43262
|
+
flags[asciinumeric] = true;
|
|
43263
|
+
} else {
|
|
43264
|
+
flags[ascii] = true;
|
|
43265
|
+
}
|
|
43266
|
+
ts(Start, sch, sch, flags);
|
|
43267
|
+
}
|
|
43268
|
+
|
|
43269
|
+
// Localhost token
|
|
43270
|
+
ts(Start, 'localhost', LOCALHOST, {
|
|
43271
|
+
ascii: true
|
|
43272
|
+
});
|
|
43273
|
+
|
|
43274
|
+
// Set default transition for start state (some symbol)
|
|
43275
|
+
Start.jd = new State(SYM);
|
|
43276
|
+
return {
|
|
43277
|
+
start: Start,
|
|
43278
|
+
tokens: assign$2({
|
|
43279
|
+
groups
|
|
43280
|
+
}, tk)
|
|
43281
|
+
};
|
|
43282
|
+
}
|
|
43283
|
+
|
|
43284
|
+
/**
|
|
43285
|
+
Given a string, returns an array of TOKEN instances representing the
|
|
43286
|
+
composition of that string.
|
|
43287
|
+
|
|
43288
|
+
@method run
|
|
43289
|
+
@param {State<string>} start scanner starting state
|
|
43290
|
+
@param {string} str input string to scan
|
|
43291
|
+
@return {Token[]} list of tokens, each with a type and value
|
|
43292
|
+
*/
|
|
43293
|
+
function run$1(start, str) {
|
|
43294
|
+
// State machine is not case sensitive, so input is tokenized in lowercased
|
|
43295
|
+
// form (still returns regular case). Uses selective `toLowerCase` because
|
|
43296
|
+
// lowercasing the entire string causes the length and character position to
|
|
43297
|
+
// vary in some non-English strings with V8-based runtimes.
|
|
43298
|
+
const iterable = stringToArray(str.replace(/[A-Z]/g, c => c.toLowerCase()));
|
|
43299
|
+
const charCount = iterable.length; // <= len if there are emojis, etc
|
|
43300
|
+
const tokens = []; // return value
|
|
43301
|
+
|
|
43302
|
+
// cursor through the string itself, accounting for characters that have
|
|
43303
|
+
// width with length 2 such as emojis
|
|
43304
|
+
let cursor = 0;
|
|
43305
|
+
|
|
43306
|
+
// Cursor through the array-representation of the string
|
|
43307
|
+
let charCursor = 0;
|
|
43308
|
+
|
|
43309
|
+
// Tokenize the string
|
|
43310
|
+
while (charCursor < charCount) {
|
|
43311
|
+
let state = start;
|
|
43312
|
+
let nextState = null;
|
|
43313
|
+
let tokenLength = 0;
|
|
43314
|
+
let latestAccepting = null;
|
|
43315
|
+
let sinceAccepts = -1;
|
|
43316
|
+
let charsSinceAccepts = -1;
|
|
43317
|
+
while (charCursor < charCount && (nextState = state.go(iterable[charCursor]))) {
|
|
43318
|
+
state = nextState;
|
|
43319
|
+
|
|
43320
|
+
// Keep track of the latest accepting state
|
|
43321
|
+
if (state.accepts()) {
|
|
43322
|
+
sinceAccepts = 0;
|
|
43323
|
+
charsSinceAccepts = 0;
|
|
43324
|
+
latestAccepting = state;
|
|
43325
|
+
} else if (sinceAccepts >= 0) {
|
|
43326
|
+
sinceAccepts += iterable[charCursor].length;
|
|
43327
|
+
charsSinceAccepts++;
|
|
43328
|
+
}
|
|
43329
|
+
tokenLength += iterable[charCursor].length;
|
|
43330
|
+
cursor += iterable[charCursor].length;
|
|
43331
|
+
charCursor++;
|
|
43332
|
+
}
|
|
43333
|
+
|
|
43334
|
+
// Roll back to the latest accepting state
|
|
43335
|
+
cursor -= sinceAccepts;
|
|
43336
|
+
charCursor -= charsSinceAccepts;
|
|
43337
|
+
tokenLength -= sinceAccepts;
|
|
43338
|
+
|
|
43339
|
+
// No more jumps, just make a new token from the last accepting one
|
|
43340
|
+
tokens.push({
|
|
43341
|
+
t: latestAccepting.t,
|
|
43342
|
+
// token type/name
|
|
43343
|
+
v: str.slice(cursor - tokenLength, cursor),
|
|
43344
|
+
// string value
|
|
43345
|
+
s: cursor - tokenLength,
|
|
43346
|
+
// start index
|
|
43347
|
+
e: cursor // end index (excluding)
|
|
43348
|
+
});
|
|
43349
|
+
}
|
|
43350
|
+
|
|
43351
|
+
return tokens;
|
|
43352
|
+
}
|
|
43353
|
+
|
|
43354
|
+
/**
|
|
43355
|
+
* Convert a String to an Array of characters, taking into account that some
|
|
43356
|
+
* characters like emojis take up two string indexes.
|
|
43357
|
+
*
|
|
43358
|
+
* Adapted from core-js (MIT license)
|
|
43359
|
+
* https://github.com/zloirock/core-js/blob/2d69cf5f99ab3ea3463c395df81e5a15b68f49d9/packages/core-js/internals/string-multibyte.js
|
|
43360
|
+
*
|
|
43361
|
+
* @function stringToArray
|
|
43362
|
+
* @param {string} str
|
|
43363
|
+
* @returns {string[]}
|
|
43364
|
+
*/
|
|
43365
|
+
function stringToArray(str) {
|
|
43366
|
+
const result = [];
|
|
43367
|
+
const len = str.length;
|
|
43368
|
+
let index = 0;
|
|
43369
|
+
while (index < len) {
|
|
43370
|
+
let first = str.charCodeAt(index);
|
|
43371
|
+
let second;
|
|
43372
|
+
let char = first < 0xd800 || first > 0xdbff || index + 1 === len || (second = str.charCodeAt(index + 1)) < 0xdc00 || second > 0xdfff ? str[index] // single character
|
|
43373
|
+
: str.slice(index, index + 2); // two-index characters
|
|
43374
|
+
result.push(char);
|
|
43375
|
+
index += char.length;
|
|
43376
|
+
}
|
|
43377
|
+
return result;
|
|
43378
|
+
}
|
|
43379
|
+
|
|
43380
|
+
/**
|
|
43381
|
+
* Fast version of ts function for when transition defaults are well known
|
|
43382
|
+
* @param {State<string>} state
|
|
43383
|
+
* @param {string} input
|
|
43384
|
+
* @param {string} t
|
|
43385
|
+
* @param {string} defaultt
|
|
43386
|
+
* @param {[RegExp, State<string>][]} jr
|
|
43387
|
+
* @returns {State<string>}
|
|
43388
|
+
*/
|
|
43389
|
+
function fastts(state, input, t, defaultt, jr) {
|
|
43390
|
+
let next;
|
|
43391
|
+
const len = input.length;
|
|
43392
|
+
for (let i = 0; i < len - 1; i++) {
|
|
43393
|
+
const char = input[i];
|
|
43394
|
+
if (state.j[char]) {
|
|
43395
|
+
next = state.j[char];
|
|
43396
|
+
} else {
|
|
43397
|
+
next = new State(defaultt);
|
|
43398
|
+
next.jr = jr.slice();
|
|
43399
|
+
state.j[char] = next;
|
|
43400
|
+
}
|
|
43401
|
+
state = next;
|
|
43402
|
+
}
|
|
43403
|
+
next = new State(t);
|
|
43404
|
+
next.jr = jr.slice();
|
|
43405
|
+
state.j[input[len - 1]] = next;
|
|
43406
|
+
return next;
|
|
43407
|
+
}
|
|
43408
|
+
|
|
43409
|
+
/**
|
|
43410
|
+
* Converts a string of Top-Level Domain names encoded in update-tlds.js back
|
|
43411
|
+
* into a list of strings.
|
|
43412
|
+
* @param {str} encoded encoded TLDs string
|
|
43413
|
+
* @returns {str[]} original TLDs list
|
|
43414
|
+
*/
|
|
43415
|
+
function decodeTlds(encoded) {
|
|
43416
|
+
const words = [];
|
|
43417
|
+
const stack = [];
|
|
43418
|
+
let i = 0;
|
|
43419
|
+
let digits = '0123456789';
|
|
43420
|
+
while (i < encoded.length) {
|
|
43421
|
+
let popDigitCount = 0;
|
|
43422
|
+
while (digits.indexOf(encoded[i + popDigitCount]) >= 0) {
|
|
43423
|
+
popDigitCount++; // encountered some digits, have to pop to go one level up trie
|
|
43424
|
+
}
|
|
43425
|
+
|
|
43426
|
+
if (popDigitCount > 0) {
|
|
43427
|
+
words.push(stack.join('')); // whatever preceded the pop digits must be a word
|
|
43428
|
+
for (let popCount = parseInt(encoded.substring(i, i + popDigitCount), 10); popCount > 0; popCount--) {
|
|
43429
|
+
stack.pop();
|
|
43430
|
+
}
|
|
43431
|
+
i += popDigitCount;
|
|
43432
|
+
} else {
|
|
43433
|
+
stack.push(encoded[i]); // drop down a level into the trie
|
|
43434
|
+
i++;
|
|
43435
|
+
}
|
|
43436
|
+
}
|
|
43437
|
+
return words;
|
|
43438
|
+
}
|
|
43439
|
+
|
|
43440
|
+
/**
|
|
43441
|
+
* An object where each key is a valid DOM Event Name such as `click` or `focus`
|
|
43442
|
+
* and each value is an event handler function.
|
|
43443
|
+
*
|
|
43444
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Element#events
|
|
43445
|
+
* @typedef {?{ [event: string]: Function }} EventListeners
|
|
43446
|
+
*/
|
|
43447
|
+
|
|
43448
|
+
/**
|
|
43449
|
+
* All formatted properties required to render a link, including `tagName`,
|
|
43450
|
+
* `attributes`, `content` and `eventListeners`.
|
|
43451
|
+
* @typedef {{ tagName: any, attributes: {[attr: string]: any}, content: string,
|
|
43452
|
+
* eventListeners: EventListeners }} IntermediateRepresentation
|
|
43453
|
+
*/
|
|
43454
|
+
|
|
43455
|
+
/**
|
|
43456
|
+
* Specify either an object described by the template type `O` or a function.
|
|
43457
|
+
*
|
|
43458
|
+
* The function takes a string value (usually the link's href attribute), the
|
|
43459
|
+
* link type (`'url'`, `'hashtag`', etc.) and an internal token representation
|
|
43460
|
+
* of the link. It should return an object of the template type `O`
|
|
43461
|
+
* @template O
|
|
43462
|
+
* @typedef {O | ((value: string, type: string, token: MultiToken) => O)} OptObj
|
|
43463
|
+
*/
|
|
43464
|
+
|
|
43465
|
+
/**
|
|
43466
|
+
* Specify either a function described by template type `F` or an object.
|
|
43467
|
+
*
|
|
43468
|
+
* Each key in the object should be a link type (`'url'`, `'hashtag`', etc.). Each
|
|
43469
|
+
* value should be a function with template type `F` that is called when the
|
|
43470
|
+
* corresponding link type is encountered.
|
|
43471
|
+
* @template F
|
|
43472
|
+
* @typedef {F | { [type: string]: F}} OptFn
|
|
43473
|
+
*/
|
|
43474
|
+
|
|
43475
|
+
/**
|
|
43476
|
+
* Specify either a value with template type `V`, a function that returns `V` or
|
|
43477
|
+
* an object where each value resolves to `V`.
|
|
43478
|
+
*
|
|
43479
|
+
* The function takes a string value (usually the link's href attribute), the
|
|
43480
|
+
* link type (`'url'`, `'hashtag`', etc.) and an internal token representation
|
|
43481
|
+
* of the link. It should return an object of the template type `V`
|
|
43482
|
+
*
|
|
43483
|
+
* For the object, each key should be a link type (`'url'`, `'hashtag`', etc.).
|
|
43484
|
+
* Each value should either have type `V` or a function that returns V. This
|
|
43485
|
+
* function similarly takes a string value and a token.
|
|
43486
|
+
*
|
|
43487
|
+
* Example valid types for `Opt<string>`:
|
|
43488
|
+
*
|
|
43489
|
+
* ```js
|
|
43490
|
+
* 'hello'
|
|
43491
|
+
* (value, type, token) => 'world'
|
|
43492
|
+
* { url: 'hello', email: (value, token) => 'world'}
|
|
43493
|
+
* ```
|
|
43494
|
+
* @template V
|
|
43495
|
+
* @typedef {V | ((value: string, type: string, token: MultiToken) => V) | { [type: string]: V | ((value: string, token: MultiToken) => V) }} Opt
|
|
43496
|
+
*/
|
|
43497
|
+
|
|
43498
|
+
/**
|
|
43499
|
+
* See available options: https://linkify.js.org/docs/options.html
|
|
43500
|
+
* @typedef {{
|
|
43501
|
+
* defaultProtocol?: string,
|
|
43502
|
+
* events?: OptObj<EventListeners>,
|
|
43503
|
+
* format?: Opt<string>,
|
|
43504
|
+
* formatHref?: Opt<string>,
|
|
43505
|
+
* nl2br?: boolean,
|
|
43506
|
+
* tagName?: Opt<any>,
|
|
43507
|
+
* target?: Opt<string>,
|
|
43508
|
+
* rel?: Opt<string>,
|
|
43509
|
+
* validate?: Opt<boolean>,
|
|
43510
|
+
* truncate?: Opt<number>,
|
|
43511
|
+
* className?: Opt<string>,
|
|
43512
|
+
* attributes?: OptObj<({ [attr: string]: any })>,
|
|
43513
|
+
* ignoreTags?: string[],
|
|
43514
|
+
* render?: OptFn<((ir: IntermediateRepresentation) => any)>
|
|
43515
|
+
* }} Opts
|
|
43516
|
+
*/
|
|
43517
|
+
|
|
43518
|
+
/**
|
|
43519
|
+
* @type Required<Opts>
|
|
43520
|
+
*/
|
|
43521
|
+
const defaults = {
|
|
43522
|
+
defaultProtocol: 'http',
|
|
43523
|
+
events: null,
|
|
43524
|
+
format: noop$1,
|
|
43525
|
+
formatHref: noop$1,
|
|
43526
|
+
nl2br: false,
|
|
43527
|
+
tagName: 'a',
|
|
43528
|
+
target: null,
|
|
43529
|
+
rel: null,
|
|
43530
|
+
validate: true,
|
|
43531
|
+
truncate: Infinity,
|
|
43532
|
+
className: null,
|
|
43533
|
+
attributes: null,
|
|
43534
|
+
ignoreTags: [],
|
|
43535
|
+
render: null
|
|
43536
|
+
};
|
|
43537
|
+
|
|
43538
|
+
/**
|
|
43539
|
+
* Utility class for linkify interfaces to apply specified
|
|
43540
|
+
* {@link Opts formatting and rendering options}.
|
|
43541
|
+
*
|
|
43542
|
+
* @param {Opts | Options} [opts] Option value overrides.
|
|
43543
|
+
* @param {(ir: IntermediateRepresentation) => any} [defaultRender] (For
|
|
43544
|
+
* internal use) default render function that determines how to generate an
|
|
43545
|
+
* HTML element based on a link token's derived tagName, attributes and HTML.
|
|
43546
|
+
* Similar to render option
|
|
43547
|
+
*/
|
|
43548
|
+
function Options(opts, defaultRender) {
|
|
43549
|
+
if (defaultRender === void 0) {
|
|
43550
|
+
defaultRender = null;
|
|
43551
|
+
}
|
|
43552
|
+
let o = assign$2({}, defaults);
|
|
43553
|
+
if (opts) {
|
|
43554
|
+
o = assign$2(o, opts instanceof Options ? opts.o : opts);
|
|
43555
|
+
}
|
|
43556
|
+
|
|
43557
|
+
// Ensure all ignored tags are uppercase
|
|
43558
|
+
const ignoredTags = o.ignoreTags;
|
|
43559
|
+
const uppercaseIgnoredTags = [];
|
|
43560
|
+
for (let i = 0; i < ignoredTags.length; i++) {
|
|
43561
|
+
uppercaseIgnoredTags.push(ignoredTags[i].toUpperCase());
|
|
43562
|
+
}
|
|
43563
|
+
/** @protected */
|
|
43564
|
+
this.o = o;
|
|
43565
|
+
if (defaultRender) {
|
|
43566
|
+
this.defaultRender = defaultRender;
|
|
43567
|
+
}
|
|
43568
|
+
this.ignoreTags = uppercaseIgnoredTags;
|
|
43569
|
+
}
|
|
43570
|
+
Options.prototype = {
|
|
43571
|
+
o: defaults,
|
|
43572
|
+
/**
|
|
43573
|
+
* @type string[]
|
|
43574
|
+
*/
|
|
43575
|
+
ignoreTags: [],
|
|
43576
|
+
/**
|
|
43577
|
+
* @param {IntermediateRepresentation} ir
|
|
43578
|
+
* @returns {any}
|
|
43579
|
+
*/
|
|
43580
|
+
defaultRender(ir) {
|
|
43581
|
+
return ir;
|
|
43582
|
+
},
|
|
43583
|
+
/**
|
|
43584
|
+
* Returns true or false based on whether a token should be displayed as a
|
|
43585
|
+
* link based on the user options.
|
|
43586
|
+
* @param {MultiToken} token
|
|
43587
|
+
* @returns {boolean}
|
|
43588
|
+
*/
|
|
43589
|
+
check(token) {
|
|
43590
|
+
return this.get('validate', token.toString(), token);
|
|
43591
|
+
},
|
|
43592
|
+
// Private methods
|
|
43593
|
+
|
|
43594
|
+
/**
|
|
43595
|
+
* Resolve an option's value based on the value of the option and the given
|
|
43596
|
+
* params. If operator and token are specified and the target option is
|
|
43597
|
+
* callable, automatically calls the function with the given argument.
|
|
43598
|
+
* @template {keyof Opts} K
|
|
43599
|
+
* @param {K} key Name of option to use
|
|
43600
|
+
* @param {string} [operator] will be passed to the target option if it's a
|
|
43601
|
+
* function. If not specified, RAW function value gets returned
|
|
43602
|
+
* @param {MultiToken} [token] The token from linkify.tokenize
|
|
43603
|
+
* @returns {Opts[K] | any}
|
|
43604
|
+
*/
|
|
43605
|
+
get(key, operator, token) {
|
|
43606
|
+
const isCallable = operator != null;
|
|
43607
|
+
let option = this.o[key];
|
|
43608
|
+
if (!option) {
|
|
43609
|
+
return option;
|
|
43610
|
+
}
|
|
43611
|
+
if (typeof option === 'object') {
|
|
43612
|
+
option = token.t in option ? option[token.t] : defaults[key];
|
|
43613
|
+
if (typeof option === 'function' && isCallable) {
|
|
43614
|
+
option = option(operator, token);
|
|
43615
|
+
}
|
|
43616
|
+
} else if (typeof option === 'function' && isCallable) {
|
|
43617
|
+
option = option(operator, token.t, token);
|
|
43618
|
+
}
|
|
43619
|
+
return option;
|
|
43620
|
+
},
|
|
43621
|
+
/**
|
|
43622
|
+
* @template {keyof Opts} L
|
|
43623
|
+
* @param {L} key Name of options object to use
|
|
43624
|
+
* @param {string} [operator]
|
|
43625
|
+
* @param {MultiToken} [token]
|
|
43626
|
+
* @returns {Opts[L] | any}
|
|
43627
|
+
*/
|
|
43628
|
+
getObj(key, operator, token) {
|
|
43629
|
+
let obj = this.o[key];
|
|
43630
|
+
if (typeof obj === 'function' && operator != null) {
|
|
43631
|
+
obj = obj(operator, token.t, token);
|
|
43632
|
+
}
|
|
43633
|
+
return obj;
|
|
43634
|
+
},
|
|
43635
|
+
/**
|
|
43636
|
+
* Convert the given token to a rendered element that may be added to the
|
|
43637
|
+
* calling-interface's DOM
|
|
43638
|
+
* @param {MultiToken} token Token to render to an HTML element
|
|
43639
|
+
* @returns {any} Render result; e.g., HTML string, DOM element, React
|
|
43640
|
+
* Component, etc.
|
|
43641
|
+
*/
|
|
43642
|
+
render(token) {
|
|
43643
|
+
const ir = token.render(this); // intermediate representation
|
|
43644
|
+
const renderFn = this.get('render', null, token) || this.defaultRender;
|
|
43645
|
+
return renderFn(ir, token.t, token);
|
|
43646
|
+
}
|
|
43647
|
+
};
|
|
43648
|
+
function noop$1(val) {
|
|
43649
|
+
return val;
|
|
43650
|
+
}
|
|
43651
|
+
|
|
43652
|
+
/******************************************************************************
|
|
43653
|
+
Multi-Tokens
|
|
43654
|
+
Tokens composed of arrays of TextTokens
|
|
43655
|
+
******************************************************************************/
|
|
43656
|
+
|
|
43657
|
+
/**
|
|
43658
|
+
* @param {string} value
|
|
43659
|
+
* @param {Token[]} tokens
|
|
43660
|
+
*/
|
|
43661
|
+
function MultiToken(value, tokens) {
|
|
43662
|
+
this.t = 'token';
|
|
43663
|
+
this.v = value;
|
|
43664
|
+
this.tk = tokens;
|
|
43665
|
+
}
|
|
43666
|
+
|
|
43667
|
+
/**
|
|
43668
|
+
* Abstract class used for manufacturing tokens of text tokens. That is rather
|
|
43669
|
+
* than the value for a token being a small string of text, it's value an array
|
|
43670
|
+
* of text tokens.
|
|
43671
|
+
*
|
|
43672
|
+
* Used for grouping together URLs, emails, hashtags, and other potential
|
|
43673
|
+
* creations.
|
|
43674
|
+
* @class MultiToken
|
|
43675
|
+
* @property {string} t
|
|
43676
|
+
* @property {string} v
|
|
43677
|
+
* @property {Token[]} tk
|
|
43678
|
+
* @abstract
|
|
43679
|
+
*/
|
|
43680
|
+
MultiToken.prototype = {
|
|
43681
|
+
isLink: false,
|
|
43682
|
+
/**
|
|
43683
|
+
* Return the string this token represents.
|
|
43684
|
+
* @return {string}
|
|
43685
|
+
*/
|
|
43686
|
+
toString() {
|
|
43687
|
+
return this.v;
|
|
43688
|
+
},
|
|
43689
|
+
/**
|
|
43690
|
+
* What should the value for this token be in the `href` HTML attribute?
|
|
43691
|
+
* Returns the `.toString` value by default.
|
|
43692
|
+
* @param {string} [scheme]
|
|
43693
|
+
* @return {string}
|
|
43694
|
+
*/
|
|
43695
|
+
toHref(scheme) {
|
|
43696
|
+
return this.toString();
|
|
43697
|
+
},
|
|
43698
|
+
/**
|
|
43699
|
+
* @param {Options} options Formatting options
|
|
43700
|
+
* @returns {string}
|
|
43701
|
+
*/
|
|
43702
|
+
toFormattedString(options) {
|
|
43703
|
+
const val = this.toString();
|
|
43704
|
+
const truncate = options.get('truncate', val, this);
|
|
43705
|
+
const formatted = options.get('format', val, this);
|
|
43706
|
+
return truncate && formatted.length > truncate ? formatted.substring(0, truncate) + '…' : formatted;
|
|
43707
|
+
},
|
|
43708
|
+
/**
|
|
43709
|
+
*
|
|
43710
|
+
* @param {Options} options
|
|
43711
|
+
* @returns {string}
|
|
43712
|
+
*/
|
|
43713
|
+
toFormattedHref(options) {
|
|
43714
|
+
return options.get('formatHref', this.toHref(options.get('defaultProtocol')), this);
|
|
43715
|
+
},
|
|
43716
|
+
/**
|
|
43717
|
+
* The start index of this token in the original input string
|
|
43718
|
+
* @returns {number}
|
|
43719
|
+
*/
|
|
43720
|
+
startIndex() {
|
|
43721
|
+
return this.tk[0].s;
|
|
43722
|
+
},
|
|
43723
|
+
/**
|
|
43724
|
+
* The end index of this token in the original input string (up to this
|
|
43725
|
+
* index but not including it)
|
|
43726
|
+
* @returns {number}
|
|
43727
|
+
*/
|
|
43728
|
+
endIndex() {
|
|
43729
|
+
return this.tk[this.tk.length - 1].e;
|
|
43730
|
+
},
|
|
43731
|
+
/**
|
|
43732
|
+
Returns an object of relevant values for this token, which includes keys
|
|
43733
|
+
* type - Kind of token ('url', 'email', etc.)
|
|
43734
|
+
* value - Original text
|
|
43735
|
+
* href - The value that should be added to the anchor tag's href
|
|
43736
|
+
attribute
|
|
43737
|
+
@method toObject
|
|
43738
|
+
@param {string} [protocol] `'http'` by default
|
|
43739
|
+
*/
|
|
43740
|
+
toObject(protocol) {
|
|
43741
|
+
if (protocol === void 0) {
|
|
43742
|
+
protocol = defaults.defaultProtocol;
|
|
43743
|
+
}
|
|
43744
|
+
return {
|
|
43745
|
+
type: this.t,
|
|
43746
|
+
value: this.toString(),
|
|
43747
|
+
isLink: this.isLink,
|
|
43748
|
+
href: this.toHref(protocol),
|
|
43749
|
+
start: this.startIndex(),
|
|
43750
|
+
end: this.endIndex()
|
|
43751
|
+
};
|
|
43752
|
+
},
|
|
43753
|
+
/**
|
|
43754
|
+
*
|
|
43755
|
+
* @param {Options} options Formatting option
|
|
43756
|
+
*/
|
|
43757
|
+
toFormattedObject(options) {
|
|
43758
|
+
return {
|
|
43759
|
+
type: this.t,
|
|
43760
|
+
value: this.toFormattedString(options),
|
|
43761
|
+
isLink: this.isLink,
|
|
43762
|
+
href: this.toFormattedHref(options),
|
|
43763
|
+
start: this.startIndex(),
|
|
43764
|
+
end: this.endIndex()
|
|
43765
|
+
};
|
|
43766
|
+
},
|
|
43767
|
+
/**
|
|
43768
|
+
* Whether this token should be rendered as a link according to the given options
|
|
43769
|
+
* @param {Options} options
|
|
43770
|
+
* @returns {boolean}
|
|
43771
|
+
*/
|
|
43772
|
+
validate(options) {
|
|
43773
|
+
return options.get('validate', this.toString(), this);
|
|
43774
|
+
},
|
|
43775
|
+
/**
|
|
43776
|
+
* Return an object that represents how this link should be rendered.
|
|
43777
|
+
* @param {Options} options Formattinng options
|
|
43778
|
+
*/
|
|
43779
|
+
render(options) {
|
|
43780
|
+
const token = this;
|
|
43781
|
+
const href = this.toHref(options.get('defaultProtocol'));
|
|
43782
|
+
const formattedHref = options.get('formatHref', href, this);
|
|
43783
|
+
const tagName = options.get('tagName', href, token);
|
|
43784
|
+
const content = this.toFormattedString(options);
|
|
43785
|
+
const attributes = {};
|
|
43786
|
+
const className = options.get('className', href, token);
|
|
43787
|
+
const target = options.get('target', href, token);
|
|
43788
|
+
const rel = options.get('rel', href, token);
|
|
43789
|
+
const attrs = options.getObj('attributes', href, token);
|
|
43790
|
+
const eventListeners = options.getObj('events', href, token);
|
|
43791
|
+
attributes.href = formattedHref;
|
|
43792
|
+
if (className) {
|
|
43793
|
+
attributes.class = className;
|
|
43794
|
+
}
|
|
43795
|
+
if (target) {
|
|
43796
|
+
attributes.target = target;
|
|
43797
|
+
}
|
|
43798
|
+
if (rel) {
|
|
43799
|
+
attributes.rel = rel;
|
|
43800
|
+
}
|
|
43801
|
+
if (attrs) {
|
|
43802
|
+
assign$2(attributes, attrs);
|
|
43803
|
+
}
|
|
43804
|
+
return {
|
|
43805
|
+
tagName,
|
|
43806
|
+
attributes,
|
|
43807
|
+
content,
|
|
43808
|
+
eventListeners
|
|
43809
|
+
};
|
|
43810
|
+
}
|
|
43811
|
+
};
|
|
43812
|
+
|
|
43813
|
+
/**
|
|
43814
|
+
* Create a new token that can be emitted by the parser state machine
|
|
43815
|
+
* @param {string} type readable type of the token
|
|
43816
|
+
* @param {object} props properties to assign or override, including isLink = true or false
|
|
43817
|
+
* @returns {new (value: string, tokens: Token[]) => MultiToken} new token class
|
|
43818
|
+
*/
|
|
43819
|
+
function createTokenClass(type, props) {
|
|
43820
|
+
class Token extends MultiToken {
|
|
43821
|
+
constructor(value, tokens) {
|
|
43822
|
+
super(value, tokens);
|
|
43823
|
+
this.t = type;
|
|
43824
|
+
}
|
|
43825
|
+
}
|
|
43826
|
+
for (const p in props) {
|
|
43827
|
+
Token.prototype[p] = props[p];
|
|
43828
|
+
}
|
|
43829
|
+
Token.t = type;
|
|
43830
|
+
return Token;
|
|
43831
|
+
}
|
|
43832
|
+
|
|
43833
|
+
/**
|
|
43834
|
+
Represents a list of tokens making up a valid email address
|
|
43835
|
+
*/
|
|
43836
|
+
const Email = createTokenClass('email', {
|
|
43837
|
+
isLink: true,
|
|
43838
|
+
toHref() {
|
|
43839
|
+
return 'mailto:' + this.toString();
|
|
43840
|
+
}
|
|
43841
|
+
});
|
|
43842
|
+
|
|
43843
|
+
/**
|
|
43844
|
+
Represents some plain text
|
|
43845
|
+
*/
|
|
43846
|
+
const Text$1 = createTokenClass('text');
|
|
43847
|
+
|
|
43848
|
+
/**
|
|
43849
|
+
Multi-linebreak token - represents a line break
|
|
43850
|
+
@class Nl
|
|
43851
|
+
*/
|
|
43852
|
+
const Nl = createTokenClass('nl');
|
|
43853
|
+
|
|
43854
|
+
/**
|
|
43855
|
+
Represents a list of text tokens making up a valid URL
|
|
43856
|
+
@class Url
|
|
43857
|
+
*/
|
|
43858
|
+
const Url$1 = createTokenClass('url', {
|
|
43859
|
+
isLink: true,
|
|
43860
|
+
/**
|
|
43861
|
+
Lowercases relevant parts of the domain and adds the protocol if
|
|
43862
|
+
required. Note that this will not escape unsafe HTML characters in the
|
|
43863
|
+
URL.
|
|
43864
|
+
@param {string} [scheme] default scheme (e.g., 'https')
|
|
43865
|
+
@return {string} the full href
|
|
43866
|
+
*/
|
|
43867
|
+
toHref(scheme) {
|
|
43868
|
+
if (scheme === void 0) {
|
|
43869
|
+
scheme = defaults.defaultProtocol;
|
|
43870
|
+
}
|
|
43871
|
+
// Check if already has a prefix scheme
|
|
43872
|
+
return this.hasProtocol() ? this.v : `${scheme}://${this.v}`;
|
|
43873
|
+
},
|
|
43874
|
+
/**
|
|
43875
|
+
* Check whether this URL token has a protocol
|
|
43876
|
+
* @return {boolean}
|
|
43877
|
+
*/
|
|
43878
|
+
hasProtocol() {
|
|
43879
|
+
const tokens = this.tk;
|
|
43880
|
+
return tokens.length >= 2 && tokens[0].t !== LOCALHOST && tokens[1].t === COLON;
|
|
43881
|
+
}
|
|
43882
|
+
});
|
|
43883
|
+
|
|
43884
|
+
/**
|
|
43885
|
+
Not exactly parser, more like the second-stage scanner (although we can
|
|
43886
|
+
theoretically hotswap the code here with a real parser in the future... but
|
|
43887
|
+
for a little URL-finding utility abstract syntax trees may be a little
|
|
43888
|
+
overkill).
|
|
43889
|
+
|
|
43890
|
+
URL format: http://en.wikipedia.org/wiki/URI_scheme
|
|
43891
|
+
Email format: http://en.wikipedia.org/wiki/EmailAddress (links to RFC in
|
|
43892
|
+
reference)
|
|
43893
|
+
|
|
43894
|
+
@module linkify
|
|
43895
|
+
@submodule parser
|
|
43896
|
+
@main run
|
|
43897
|
+
*/
|
|
43898
|
+
const makeState = arg => new State(arg);
|
|
43899
|
+
|
|
43900
|
+
/**
|
|
43901
|
+
* Generate the parser multi token-based state machine
|
|
43902
|
+
* @param {{ groups: Collections<string> }} tokens
|
|
43903
|
+
*/
|
|
43904
|
+
function init$1(_ref) {
|
|
43905
|
+
let {
|
|
43906
|
+
groups
|
|
43907
|
+
} = _ref;
|
|
43908
|
+
// Types of characters the URL can definitely end in
|
|
43909
|
+
const qsAccepting = groups.domain.concat([AMPERSAND, ASTERISK, AT, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, NUM, PERCENT, PIPE, PLUS, POUND, SLASH, SYM, TILDE, UNDERSCORE]);
|
|
43910
|
+
|
|
43911
|
+
// Types of tokens that can follow a URL and be part of the query string
|
|
43912
|
+
// but cannot be the very last characters
|
|
43913
|
+
// Characters that cannot appear in the URL at all should be excluded
|
|
43914
|
+
const qsNonAccepting = [APOSTROPHE$1, CLOSEANGLEBRACKET, CLOSEBRACE, CLOSEBRACKET, CLOSEPAREN, COLON, COMMA, DOT, EXCLAMATION, OPENANGLEBRACKET, OPENBRACE, OPENBRACKET, OPENPAREN, QUERY, QUOTE, SEMI];
|
|
43915
|
+
|
|
43916
|
+
// For addresses without the mailto prefix
|
|
43917
|
+
// Tokens allowed in the localpart of the email
|
|
43918
|
+
const localpartAccepting = [AMPERSAND, APOSTROPHE$1, ASTERISK, BACKSLASH, BACKTICK, CARET, CLOSEBRACE, DOLLAR, EQUALS, HYPHEN, OPENBRACE, PERCENT, PIPE, PLUS, POUND, QUERY, SLASH, SYM, TILDE, UNDERSCORE];
|
|
43919
|
+
|
|
43920
|
+
// The universal starting state.
|
|
43921
|
+
/**
|
|
43922
|
+
* @type State<Token>
|
|
43923
|
+
*/
|
|
43924
|
+
const Start = makeState();
|
|
43925
|
+
const Localpart = tt(Start, TILDE); // Local part of the email address
|
|
43926
|
+
ta(Localpart, localpartAccepting, Localpart);
|
|
43927
|
+
ta(Localpart, groups.domain, Localpart);
|
|
43928
|
+
const Domain = makeState(),
|
|
43929
|
+
Scheme = makeState(),
|
|
43930
|
+
SlashScheme = makeState();
|
|
43931
|
+
ta(Start, groups.domain, Domain); // parsed string ends with a potential domain name (A)
|
|
43932
|
+
ta(Start, groups.scheme, Scheme); // e.g., 'mailto'
|
|
43933
|
+
ta(Start, groups.slashscheme, SlashScheme); // e.g., 'http'
|
|
43934
|
+
|
|
43935
|
+
ta(Domain, localpartAccepting, Localpart);
|
|
43936
|
+
ta(Domain, groups.domain, Domain);
|
|
43937
|
+
const LocalpartAt = tt(Domain, AT); // Local part of the email address plus @
|
|
43938
|
+
|
|
43939
|
+
tt(Localpart, AT, LocalpartAt); // close to an email address now
|
|
43940
|
+
|
|
43941
|
+
// Local part of an email address can be e.g. 'http' or 'mailto'
|
|
43942
|
+
tt(Scheme, AT, LocalpartAt);
|
|
43943
|
+
tt(SlashScheme, AT, LocalpartAt);
|
|
43944
|
+
const LocalpartDot = tt(Localpart, DOT); // Local part of the email address plus '.' (localpart cannot end in .)
|
|
43945
|
+
ta(LocalpartDot, localpartAccepting, Localpart);
|
|
43946
|
+
ta(LocalpartDot, groups.domain, Localpart);
|
|
43947
|
+
const EmailDomain = makeState();
|
|
43948
|
+
ta(LocalpartAt, groups.domain, EmailDomain); // parsed string starts with local email info + @ with a potential domain name
|
|
43949
|
+
ta(EmailDomain, groups.domain, EmailDomain);
|
|
43950
|
+
const EmailDomainDot = tt(EmailDomain, DOT); // domain followed by DOT
|
|
43951
|
+
ta(EmailDomainDot, groups.domain, EmailDomain);
|
|
43952
|
+
const Email$1 = makeState(Email); // Possible email address (could have more tlds)
|
|
43953
|
+
ta(EmailDomainDot, groups.tld, Email$1);
|
|
43954
|
+
ta(EmailDomainDot, groups.utld, Email$1);
|
|
43955
|
+
tt(LocalpartAt, LOCALHOST, Email$1);
|
|
43956
|
+
|
|
43957
|
+
// Hyphen can jump back to a domain name
|
|
43958
|
+
const EmailDomainHyphen = tt(EmailDomain, HYPHEN); // parsed string starts with local email info + @ with a potential domain name
|
|
43959
|
+
ta(EmailDomainHyphen, groups.domain, EmailDomain);
|
|
43960
|
+
ta(Email$1, groups.domain, EmailDomain);
|
|
43961
|
+
tt(Email$1, DOT, EmailDomainDot);
|
|
43962
|
+
tt(Email$1, HYPHEN, EmailDomainHyphen);
|
|
43963
|
+
|
|
43964
|
+
// Final possible email states
|
|
43965
|
+
const EmailColon = tt(Email$1, COLON); // URL followed by colon (potential port number here)
|
|
43966
|
+
/*const EmailColonPort = */
|
|
43967
|
+
ta(EmailColon, groups.numeric, Email); // URL followed by colon and port numner
|
|
43968
|
+
|
|
43969
|
+
// Account for dots and hyphens. Hyphens are usually parts of domain names
|
|
43970
|
+
// (but not TLDs)
|
|
43971
|
+
const DomainHyphen = tt(Domain, HYPHEN); // domain followed by hyphen
|
|
43972
|
+
const DomainDot = tt(Domain, DOT); // domain followed by DOT
|
|
43973
|
+
ta(DomainHyphen, groups.domain, Domain);
|
|
43974
|
+
ta(DomainDot, localpartAccepting, Localpart);
|
|
43975
|
+
ta(DomainDot, groups.domain, Domain);
|
|
43976
|
+
const DomainDotTld = makeState(Url$1); // Simplest possible URL with no query string
|
|
43977
|
+
ta(DomainDot, groups.tld, DomainDotTld);
|
|
43978
|
+
ta(DomainDot, groups.utld, DomainDotTld);
|
|
43979
|
+
ta(DomainDotTld, groups.domain, Domain);
|
|
43980
|
+
ta(DomainDotTld, localpartAccepting, Localpart);
|
|
43981
|
+
tt(DomainDotTld, DOT, DomainDot);
|
|
43982
|
+
tt(DomainDotTld, HYPHEN, DomainHyphen);
|
|
43983
|
+
tt(DomainDotTld, AT, LocalpartAt);
|
|
43984
|
+
const DomainDotTldColon = tt(DomainDotTld, COLON); // URL followed by colon (potential port number here)
|
|
43985
|
+
const DomainDotTldColonPort = makeState(Url$1); // TLD followed by a port number
|
|
43986
|
+
ta(DomainDotTldColon, groups.numeric, DomainDotTldColonPort);
|
|
43987
|
+
|
|
43988
|
+
// Long URL with optional port and maybe query string
|
|
43989
|
+
const Url$1$1 = makeState(Url$1);
|
|
43990
|
+
|
|
43991
|
+
// URL with extra symbols at the end, followed by an opening bracket
|
|
43992
|
+
const UrlNonaccept = makeState(); // URL followed by some symbols (will not be part of the final URL)
|
|
43993
|
+
|
|
43994
|
+
// Query strings
|
|
43995
|
+
ta(Url$1$1, qsAccepting, Url$1$1);
|
|
43996
|
+
ta(Url$1$1, qsNonAccepting, UrlNonaccept);
|
|
43997
|
+
ta(UrlNonaccept, qsAccepting, Url$1$1);
|
|
43998
|
+
ta(UrlNonaccept, qsNonAccepting, UrlNonaccept);
|
|
43999
|
+
|
|
44000
|
+
// Become real URLs after `SLASH` or `COLON NUM SLASH`
|
|
44001
|
+
// Here works with or without scheme:// prefix
|
|
44002
|
+
tt(DomainDotTld, SLASH, Url$1$1);
|
|
44003
|
+
tt(DomainDotTldColonPort, SLASH, Url$1$1);
|
|
44004
|
+
|
|
44005
|
+
// Note that domains that begin with schemes are treated slighly differently
|
|
44006
|
+
const SchemeColon = tt(Scheme, COLON); // e.g., 'mailto:'
|
|
44007
|
+
const SlashSchemeColon = tt(SlashScheme, COLON); // e.g., 'http:'
|
|
44008
|
+
const SlashSchemeColonSlash = tt(SlashSchemeColon, SLASH); // e.g., 'http:/'
|
|
44009
|
+
|
|
44010
|
+
const UriPrefix = tt(SlashSchemeColonSlash, SLASH); // e.g., 'http://'
|
|
44011
|
+
|
|
44012
|
+
// Scheme states can transition to domain states
|
|
44013
|
+
ta(Scheme, groups.domain, Domain);
|
|
44014
|
+
tt(Scheme, DOT, DomainDot);
|
|
44015
|
+
tt(Scheme, HYPHEN, DomainHyphen);
|
|
44016
|
+
ta(SlashScheme, groups.domain, Domain);
|
|
44017
|
+
tt(SlashScheme, DOT, DomainDot);
|
|
44018
|
+
tt(SlashScheme, HYPHEN, DomainHyphen);
|
|
44019
|
+
|
|
44020
|
+
// Force URL with scheme prefix followed by anything sane
|
|
44021
|
+
ta(SchemeColon, groups.domain, Url$1$1);
|
|
44022
|
+
tt(SchemeColon, SLASH, Url$1$1);
|
|
44023
|
+
ta(UriPrefix, groups.domain, Url$1$1);
|
|
44024
|
+
ta(UriPrefix, qsAccepting, Url$1$1);
|
|
44025
|
+
tt(UriPrefix, SLASH, Url$1$1);
|
|
44026
|
+
|
|
44027
|
+
// URL, followed by an opening bracket
|
|
44028
|
+
const UrlOpenbrace = tt(Url$1$1, OPENBRACE); // URL followed by {
|
|
44029
|
+
const UrlOpenbracket = tt(Url$1$1, OPENBRACKET); // URL followed by [
|
|
44030
|
+
const UrlOpenanglebracket = tt(Url$1$1, OPENANGLEBRACKET); // URL followed by <
|
|
44031
|
+
const UrlOpenparen = tt(Url$1$1, OPENPAREN); // URL followed by (
|
|
44032
|
+
|
|
44033
|
+
tt(UrlNonaccept, OPENBRACE, UrlOpenbrace);
|
|
44034
|
+
tt(UrlNonaccept, OPENBRACKET, UrlOpenbracket);
|
|
44035
|
+
tt(UrlNonaccept, OPENANGLEBRACKET, UrlOpenanglebracket);
|
|
44036
|
+
tt(UrlNonaccept, OPENPAREN, UrlOpenparen);
|
|
44037
|
+
|
|
44038
|
+
// Closing bracket component. This character WILL be included in the URL
|
|
44039
|
+
tt(UrlOpenbrace, CLOSEBRACE, Url$1$1);
|
|
44040
|
+
tt(UrlOpenbracket, CLOSEBRACKET, Url$1$1);
|
|
44041
|
+
tt(UrlOpenanglebracket, CLOSEANGLEBRACKET, Url$1$1);
|
|
44042
|
+
tt(UrlOpenparen, CLOSEPAREN, Url$1$1);
|
|
44043
|
+
tt(UrlOpenbrace, CLOSEBRACE, Url$1$1);
|
|
44044
|
+
|
|
44045
|
+
// URL that beings with an opening bracket, followed by a symbols.
|
|
44046
|
+
// Note that the final state can still be `UrlOpenbrace` (if the URL only
|
|
44047
|
+
// has a single opening bracket for some reason).
|
|
44048
|
+
const UrlOpenbraceQ = makeState(Url$1); // URL followed by { and some symbols that the URL can end it
|
|
44049
|
+
const UrlOpenbracketQ = makeState(Url$1); // URL followed by [ and some symbols that the URL can end it
|
|
44050
|
+
const UrlOpenanglebracketQ = makeState(Url$1); // URL followed by < and some symbols that the URL can end it
|
|
44051
|
+
const UrlOpenparenQ = makeState(Url$1); // URL followed by ( and some symbols that the URL can end it
|
|
44052
|
+
ta(UrlOpenbrace, qsAccepting, UrlOpenbraceQ);
|
|
44053
|
+
ta(UrlOpenbracket, qsAccepting, UrlOpenbracketQ);
|
|
44054
|
+
ta(UrlOpenanglebracket, qsAccepting, UrlOpenanglebracketQ);
|
|
44055
|
+
ta(UrlOpenparen, qsAccepting, UrlOpenparenQ);
|
|
44056
|
+
const UrlOpenbraceSyms = makeState(); // UrlOpenbrace followed by some symbols it cannot end it
|
|
44057
|
+
const UrlOpenbracketSyms = makeState(); // UrlOpenbracketQ followed by some symbols it cannot end it
|
|
44058
|
+
const UrlOpenanglebracketSyms = makeState(); // UrlOpenanglebracketQ followed by some symbols it cannot end it
|
|
44059
|
+
const UrlOpenparenSyms = makeState(); // UrlOpenparenQ followed by some symbols it cannot end it
|
|
44060
|
+
ta(UrlOpenbrace, qsNonAccepting);
|
|
44061
|
+
ta(UrlOpenbracket, qsNonAccepting);
|
|
44062
|
+
ta(UrlOpenanglebracket, qsNonAccepting);
|
|
44063
|
+
ta(UrlOpenparen, qsNonAccepting);
|
|
44064
|
+
|
|
44065
|
+
// URL that begins with an opening bracket, followed by some symbols
|
|
44066
|
+
ta(UrlOpenbraceQ, qsAccepting, UrlOpenbraceQ);
|
|
44067
|
+
ta(UrlOpenbracketQ, qsAccepting, UrlOpenbracketQ);
|
|
44068
|
+
ta(UrlOpenanglebracketQ, qsAccepting, UrlOpenanglebracketQ);
|
|
44069
|
+
ta(UrlOpenparenQ, qsAccepting, UrlOpenparenQ);
|
|
44070
|
+
ta(UrlOpenbraceQ, qsNonAccepting, UrlOpenbraceQ);
|
|
44071
|
+
ta(UrlOpenbracketQ, qsNonAccepting, UrlOpenbracketQ);
|
|
44072
|
+
ta(UrlOpenanglebracketQ, qsNonAccepting, UrlOpenanglebracketQ);
|
|
44073
|
+
ta(UrlOpenparenQ, qsNonAccepting, UrlOpenparenQ);
|
|
44074
|
+
ta(UrlOpenbraceSyms, qsAccepting, UrlOpenbraceSyms);
|
|
44075
|
+
ta(UrlOpenbracketSyms, qsAccepting, UrlOpenbracketQ);
|
|
44076
|
+
ta(UrlOpenanglebracketSyms, qsAccepting, UrlOpenanglebracketQ);
|
|
44077
|
+
ta(UrlOpenparenSyms, qsAccepting, UrlOpenparenQ);
|
|
44078
|
+
ta(UrlOpenbraceSyms, qsNonAccepting, UrlOpenbraceSyms);
|
|
44079
|
+
ta(UrlOpenbracketSyms, qsNonAccepting, UrlOpenbracketSyms);
|
|
44080
|
+
ta(UrlOpenanglebracketSyms, qsNonAccepting, UrlOpenanglebracketSyms);
|
|
44081
|
+
ta(UrlOpenparenSyms, qsNonAccepting, UrlOpenparenSyms);
|
|
44082
|
+
|
|
44083
|
+
// Close brace/bracket to become regular URL
|
|
44084
|
+
tt(UrlOpenbracketQ, CLOSEBRACKET, Url$1$1);
|
|
44085
|
+
tt(UrlOpenanglebracketQ, CLOSEANGLEBRACKET, Url$1$1);
|
|
44086
|
+
tt(UrlOpenparenQ, CLOSEPAREN, Url$1$1);
|
|
44087
|
+
tt(UrlOpenbraceQ, CLOSEBRACE, Url$1$1);
|
|
44088
|
+
tt(UrlOpenbracketSyms, CLOSEBRACKET, Url$1$1);
|
|
44089
|
+
tt(UrlOpenanglebracketSyms, CLOSEANGLEBRACKET, Url$1$1);
|
|
44090
|
+
tt(UrlOpenparenSyms, CLOSEPAREN, Url$1$1);
|
|
44091
|
+
tt(UrlOpenbraceSyms, CLOSEPAREN, Url$1$1);
|
|
44092
|
+
tt(Start, LOCALHOST, DomainDotTld); // localhost is a valid URL state
|
|
44093
|
+
tt(Start, NL$1, Nl); // single new line
|
|
44094
|
+
|
|
44095
|
+
return {
|
|
44096
|
+
start: Start,
|
|
44097
|
+
tokens: tk
|
|
44098
|
+
};
|
|
44099
|
+
}
|
|
44100
|
+
|
|
44101
|
+
/**
|
|
44102
|
+
* Run the parser state machine on a list of scanned string-based tokens to
|
|
44103
|
+
* create a list of multi tokens, each of which represents a URL, email address,
|
|
44104
|
+
* plain text, etc.
|
|
44105
|
+
*
|
|
44106
|
+
* @param {State<MultiToken>} start parser start state
|
|
44107
|
+
* @param {string} input the original input used to generate the given tokens
|
|
44108
|
+
* @param {Token[]} tokens list of scanned tokens
|
|
44109
|
+
* @returns {MultiToken[]}
|
|
44110
|
+
*/
|
|
44111
|
+
function run(start, input, tokens) {
|
|
44112
|
+
let len = tokens.length;
|
|
44113
|
+
let cursor = 0;
|
|
44114
|
+
let multis = [];
|
|
44115
|
+
let textTokens = [];
|
|
44116
|
+
while (cursor < len) {
|
|
44117
|
+
let state = start;
|
|
44118
|
+
let secondState = null;
|
|
44119
|
+
let nextState = null;
|
|
44120
|
+
let multiLength = 0;
|
|
44121
|
+
let latestAccepting = null;
|
|
44122
|
+
let sinceAccepts = -1;
|
|
44123
|
+
while (cursor < len && !(secondState = state.go(tokens[cursor].t))) {
|
|
44124
|
+
// Starting tokens with nowhere to jump to.
|
|
44125
|
+
// Consider these to be just plain text
|
|
44126
|
+
textTokens.push(tokens[cursor++]);
|
|
44127
|
+
}
|
|
44128
|
+
while (cursor < len && (nextState = secondState || state.go(tokens[cursor].t))) {
|
|
44129
|
+
// Get the next state
|
|
44130
|
+
secondState = null;
|
|
44131
|
+
state = nextState;
|
|
44132
|
+
|
|
44133
|
+
// Keep track of the latest accepting state
|
|
44134
|
+
if (state.accepts()) {
|
|
44135
|
+
sinceAccepts = 0;
|
|
44136
|
+
latestAccepting = state;
|
|
44137
|
+
} else if (sinceAccepts >= 0) {
|
|
44138
|
+
sinceAccepts++;
|
|
44139
|
+
}
|
|
44140
|
+
cursor++;
|
|
44141
|
+
multiLength++;
|
|
44142
|
+
}
|
|
44143
|
+
if (sinceAccepts < 0) {
|
|
44144
|
+
// No accepting state was found, part of a regular text token add
|
|
44145
|
+
// the first text token to the text tokens array and try again from
|
|
44146
|
+
// the next
|
|
44147
|
+
cursor -= multiLength;
|
|
44148
|
+
if (cursor < len) {
|
|
44149
|
+
textTokens.push(tokens[cursor]);
|
|
44150
|
+
cursor++;
|
|
44151
|
+
}
|
|
44152
|
+
} else {
|
|
44153
|
+
// Accepting state!
|
|
44154
|
+
// First close off the textTokens (if available)
|
|
44155
|
+
if (textTokens.length > 0) {
|
|
44156
|
+
multis.push(initMultiToken(Text$1, input, textTokens));
|
|
44157
|
+
textTokens = [];
|
|
44158
|
+
}
|
|
44159
|
+
|
|
44160
|
+
// Roll back to the latest accepting state
|
|
44161
|
+
cursor -= sinceAccepts;
|
|
44162
|
+
multiLength -= sinceAccepts;
|
|
44163
|
+
|
|
44164
|
+
// Create a new multitoken
|
|
44165
|
+
const Multi = latestAccepting.t;
|
|
44166
|
+
const subtokens = tokens.slice(cursor - multiLength, cursor);
|
|
44167
|
+
multis.push(initMultiToken(Multi, input, subtokens));
|
|
44168
|
+
}
|
|
44169
|
+
}
|
|
44170
|
+
|
|
44171
|
+
// Finally close off the textTokens (if available)
|
|
44172
|
+
if (textTokens.length > 0) {
|
|
44173
|
+
multis.push(initMultiToken(Text$1, input, textTokens));
|
|
44174
|
+
}
|
|
44175
|
+
return multis;
|
|
44176
|
+
}
|
|
44177
|
+
|
|
44178
|
+
/**
|
|
44179
|
+
* Utility function for instantiating a new multitoken with all the relevant
|
|
44180
|
+
* fields during parsing.
|
|
44181
|
+
* @param {new (value: string, tokens: Token[]) => MultiToken} Multi class to instantiate
|
|
44182
|
+
* @param {string} input original input string
|
|
44183
|
+
* @param {Token[]} tokens consecutive tokens scanned from input string
|
|
44184
|
+
* @returns {MultiToken}
|
|
44185
|
+
*/
|
|
44186
|
+
function initMultiToken(Multi, input, tokens) {
|
|
44187
|
+
const startIdx = tokens[0].s;
|
|
44188
|
+
const endIdx = tokens[tokens.length - 1].e;
|
|
44189
|
+
const value = input.slice(startIdx, endIdx);
|
|
44190
|
+
return new Multi(value, tokens);
|
|
44191
|
+
}
|
|
44192
|
+
|
|
44193
|
+
const warn = typeof console !== 'undefined' && console && console.warn || (() => {});
|
|
44194
|
+
const warnAdvice = 'until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.';
|
|
44195
|
+
|
|
44196
|
+
// Side-effect initialization state
|
|
44197
|
+
const INIT = {
|
|
44198
|
+
scanner: null,
|
|
44199
|
+
parser: null,
|
|
44200
|
+
tokenQueue: [],
|
|
44201
|
+
pluginQueue: [],
|
|
44202
|
+
customSchemes: [],
|
|
44203
|
+
initialized: false
|
|
44204
|
+
};
|
|
44205
|
+
|
|
44206
|
+
/**
|
|
44207
|
+
* @typedef {{
|
|
44208
|
+
* start: State<string>,
|
|
44209
|
+
* tokens: { groups: Collections<string> } & typeof tk
|
|
44210
|
+
* }} ScannerInit
|
|
44211
|
+
*/
|
|
44212
|
+
|
|
44213
|
+
/**
|
|
44214
|
+
* @typedef {{
|
|
44215
|
+
* start: State<MultiToken>,
|
|
44216
|
+
* tokens: typeof multi
|
|
44217
|
+
* }} ParserInit
|
|
44218
|
+
*/
|
|
44219
|
+
|
|
44220
|
+
/**
|
|
44221
|
+
* @typedef {(arg: { scanner: ScannerInit }) => void} TokenPlugin
|
|
44222
|
+
*/
|
|
44223
|
+
|
|
44224
|
+
/**
|
|
44225
|
+
* @typedef {(arg: { scanner: ScannerInit, parser: ParserInit }) => void} Plugin
|
|
44226
|
+
*/
|
|
44227
|
+
|
|
44228
|
+
/**
|
|
44229
|
+
* De-register all plugins and reset the internal state-machine. Used for
|
|
44230
|
+
* testing; not required in practice.
|
|
44231
|
+
* @private
|
|
44232
|
+
*/
|
|
44233
|
+
function reset() {
|
|
44234
|
+
State.groups = {};
|
|
44235
|
+
INIT.scanner = null;
|
|
44236
|
+
INIT.parser = null;
|
|
44237
|
+
INIT.tokenQueue = [];
|
|
44238
|
+
INIT.pluginQueue = [];
|
|
44239
|
+
INIT.customSchemes = [];
|
|
44240
|
+
INIT.initialized = false;
|
|
44241
|
+
}
|
|
44242
|
+
|
|
44243
|
+
/**
|
|
44244
|
+
* Detect URLs with the following additional protocol. Anything with format
|
|
44245
|
+
* "protocol://..." will be considered a link. If `optionalSlashSlash` is set to
|
|
44246
|
+
* `true`, anything with format "protocol:..." will be considered a link.
|
|
44247
|
+
* @param {string} protocol
|
|
44248
|
+
* @param {boolean} [optionalSlashSlash]
|
|
44249
|
+
*/
|
|
44250
|
+
function registerCustomProtocol(scheme, optionalSlashSlash) {
|
|
44251
|
+
if (optionalSlashSlash === void 0) {
|
|
44252
|
+
optionalSlashSlash = false;
|
|
44253
|
+
}
|
|
44254
|
+
if (INIT.initialized) {
|
|
44255
|
+
warn(`linkifyjs: already initialized - will not register custom scheme "${scheme}" ${warnAdvice}`);
|
|
44256
|
+
}
|
|
44257
|
+
if (!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(scheme)) {
|
|
44258
|
+
throw new Error('linkifyjs: incorrect scheme format.\n 1. Must only contain digits, lowercase ASCII letters or "-"\n 2. Cannot start or end with "-"\n 3. "-" cannot repeat');
|
|
44259
|
+
}
|
|
44260
|
+
INIT.customSchemes.push([scheme, optionalSlashSlash]);
|
|
44261
|
+
}
|
|
44262
|
+
|
|
44263
|
+
/**
|
|
44264
|
+
* Initialize the linkify state machine. Called automatically the first time
|
|
44265
|
+
* linkify is called on a string, but may be called manually as well.
|
|
44266
|
+
*/
|
|
44267
|
+
function init$3() {
|
|
44268
|
+
// Initialize scanner state machine and plugins
|
|
44269
|
+
INIT.scanner = init$2(INIT.customSchemes);
|
|
44270
|
+
for (let i = 0; i < INIT.tokenQueue.length; i++) {
|
|
44271
|
+
INIT.tokenQueue[i][1]({
|
|
44272
|
+
scanner: INIT.scanner
|
|
44273
|
+
});
|
|
44274
|
+
}
|
|
44275
|
+
|
|
44276
|
+
// Initialize parser state machine and plugins
|
|
44277
|
+
INIT.parser = init$1(INIT.scanner.tokens);
|
|
44278
|
+
for (let i = 0; i < INIT.pluginQueue.length; i++) {
|
|
44279
|
+
INIT.pluginQueue[i][1]({
|
|
44280
|
+
scanner: INIT.scanner,
|
|
44281
|
+
parser: INIT.parser
|
|
44282
|
+
});
|
|
44283
|
+
}
|
|
44284
|
+
INIT.initialized = true;
|
|
44285
|
+
}
|
|
44286
|
+
|
|
44287
|
+
/**
|
|
44288
|
+
* Parse a string into tokens that represent linkable and non-linkable sub-components
|
|
44289
|
+
* @param {string} str
|
|
44290
|
+
* @return {MultiToken[]} tokens
|
|
44291
|
+
*/
|
|
44292
|
+
function tokenize(str) {
|
|
44293
|
+
if (!INIT.initialized) {
|
|
44294
|
+
init$3();
|
|
44295
|
+
}
|
|
44296
|
+
return run(INIT.parser.start, str, run$1(INIT.scanner.start, str));
|
|
44297
|
+
}
|
|
44298
|
+
|
|
44299
|
+
/**
|
|
44300
|
+
* Find a list of linkable items in the given string.
|
|
44301
|
+
* @param {string} str string to find links in
|
|
44302
|
+
* @param {string | Opts} [type] either formatting options or specific type of
|
|
44303
|
+
* links to find, e.g., 'url' or 'email'
|
|
44304
|
+
* @param {Opts} [opts] formatting options for final output. Cannot be specified
|
|
44305
|
+
* if opts already provided in `type` argument
|
|
44306
|
+
*/
|
|
44307
|
+
function find$1(str, type, opts) {
|
|
44308
|
+
if (type === void 0) {
|
|
44309
|
+
type = null;
|
|
44310
|
+
}
|
|
44311
|
+
if (opts === void 0) {
|
|
44312
|
+
opts = null;
|
|
44313
|
+
}
|
|
44314
|
+
if (type && typeof type === 'object') {
|
|
44315
|
+
if (opts) {
|
|
44316
|
+
throw Error(`linkifyjs: Invalid link type ${type}; must be a string`);
|
|
44317
|
+
}
|
|
44318
|
+
opts = type;
|
|
44319
|
+
type = null;
|
|
44320
|
+
}
|
|
44321
|
+
const options = new Options(opts);
|
|
44322
|
+
const tokens = tokenize(str);
|
|
44323
|
+
const filtered = [];
|
|
44324
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
44325
|
+
const token = tokens[i];
|
|
44326
|
+
if (token.isLink && (!type || token.t === type)) {
|
|
44327
|
+
filtered.push(token.toFormattedObject(options));
|
|
44328
|
+
}
|
|
44329
|
+
}
|
|
44330
|
+
return filtered;
|
|
44331
|
+
}
|
|
44332
|
+
|
|
44333
|
+
function autolink$1(options) {
|
|
44334
|
+
return new Plugin({
|
|
44335
|
+
key: new PluginKey('autolink'),
|
|
44336
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
44337
|
+
const docChanges = transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc);
|
|
44338
|
+
const preventAutolink = transactions.some(transaction => transaction.getMeta('preventAutolink'));
|
|
44339
|
+
if (!docChanges || preventAutolink) {
|
|
44340
|
+
return;
|
|
44341
|
+
}
|
|
44342
|
+
const { tr } = newState;
|
|
44343
|
+
const transform = combineTransactionSteps(oldState.doc, [...transactions]);
|
|
44344
|
+
const changes = getChangedRanges(transform);
|
|
44345
|
+
changes.forEach(({ newRange }) => {
|
|
44346
|
+
// Now let’s see if we can add new links.
|
|
44347
|
+
const nodesInChangedRanges = findChildrenInRange(newState.doc, newRange, node => node.isTextblock);
|
|
44348
|
+
let textBlock;
|
|
44349
|
+
let textBeforeWhitespace;
|
|
44350
|
+
if (nodesInChangedRanges.length > 1) {
|
|
44351
|
+
// Grab the first node within the changed ranges (ex. the first of two paragraphs when hitting enter).
|
|
44352
|
+
textBlock = nodesInChangedRanges[0];
|
|
44353
|
+
textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, textBlock.pos + textBlock.node.nodeSize, undefined, ' ');
|
|
44354
|
+
}
|
|
44355
|
+
else if (nodesInChangedRanges.length
|
|
44356
|
+
// We want to make sure to include the block seperator argument to treat hard breaks like spaces.
|
|
44357
|
+
&& newState.doc.textBetween(newRange.from, newRange.to, ' ', ' ').endsWith(' ')) {
|
|
44358
|
+
textBlock = nodesInChangedRanges[0];
|
|
44359
|
+
textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, newRange.to, undefined, ' ');
|
|
44360
|
+
}
|
|
44361
|
+
if (textBlock && textBeforeWhitespace) {
|
|
44362
|
+
const wordsBeforeWhitespace = textBeforeWhitespace.split(' ').filter(s => s !== '');
|
|
44363
|
+
if (wordsBeforeWhitespace.length <= 0) {
|
|
44364
|
+
return false;
|
|
44365
|
+
}
|
|
44366
|
+
const lastWordBeforeSpace = wordsBeforeWhitespace[wordsBeforeWhitespace.length - 1];
|
|
44367
|
+
const lastWordAndBlockOffset = textBlock.pos + textBeforeWhitespace.lastIndexOf(lastWordBeforeSpace);
|
|
44368
|
+
if (!lastWordBeforeSpace) {
|
|
44369
|
+
return false;
|
|
44370
|
+
}
|
|
44371
|
+
find$1(lastWordBeforeSpace)
|
|
44372
|
+
.filter(link => link.isLink)
|
|
44373
|
+
// Calculate link position.
|
|
44374
|
+
.map(link => ({
|
|
44375
|
+
...link,
|
|
44376
|
+
from: lastWordAndBlockOffset + link.start + 1,
|
|
44377
|
+
to: lastWordAndBlockOffset + link.end + 1,
|
|
44378
|
+
}))
|
|
44379
|
+
// ignore link inside code mark
|
|
44380
|
+
.filter(link => {
|
|
44381
|
+
if (!newState.schema.marks.code) {
|
|
44382
|
+
return true;
|
|
44383
|
+
}
|
|
44384
|
+
return !newState.doc.rangeHasMark(link.from, link.to, newState.schema.marks.code);
|
|
44385
|
+
})
|
|
44386
|
+
// validate link
|
|
44387
|
+
.filter(link => {
|
|
44388
|
+
if (options.validate) {
|
|
44389
|
+
return options.validate(link.value);
|
|
44390
|
+
}
|
|
44391
|
+
return true;
|
|
44392
|
+
})
|
|
44393
|
+
// Add link mark.
|
|
44394
|
+
.forEach(link => {
|
|
44395
|
+
if (getMarksBetween(link.from, link.to, newState.doc).some(item => item.mark.type === options.type)) {
|
|
44396
|
+
return;
|
|
44397
|
+
}
|
|
44398
|
+
tr.addMark(link.from, link.to, options.type.create({
|
|
44399
|
+
href: link.href,
|
|
44400
|
+
}));
|
|
44401
|
+
});
|
|
44402
|
+
}
|
|
44403
|
+
});
|
|
44404
|
+
if (!tr.steps.length) {
|
|
44405
|
+
return;
|
|
44406
|
+
}
|
|
44407
|
+
return tr;
|
|
44408
|
+
},
|
|
44409
|
+
});
|
|
44410
|
+
}
|
|
44411
|
+
|
|
44412
|
+
function clickHandler(options) {
|
|
44413
|
+
return new Plugin({
|
|
44414
|
+
key: new PluginKey('handleClickLink'),
|
|
44415
|
+
props: {
|
|
44416
|
+
handleClick: (view, pos, event) => {
|
|
44417
|
+
var _a, _b;
|
|
44418
|
+
if (event.button !== 0) {
|
|
44419
|
+
return false;
|
|
44420
|
+
}
|
|
44421
|
+
const attrs = getAttributes(view.state, options.type.name);
|
|
44422
|
+
const link = event.target;
|
|
44423
|
+
const href = (_a = link === null || link === void 0 ? void 0 : link.href) !== null && _a !== void 0 ? _a : attrs.href;
|
|
44424
|
+
const target = (_b = link === null || link === void 0 ? void 0 : link.target) !== null && _b !== void 0 ? _b : attrs.target;
|
|
44425
|
+
if (link && href) {
|
|
44426
|
+
if (view.editable) {
|
|
44427
|
+
window.open(href, target);
|
|
44428
|
+
}
|
|
44429
|
+
return true;
|
|
44430
|
+
}
|
|
44431
|
+
return false;
|
|
44432
|
+
},
|
|
44433
|
+
},
|
|
44434
|
+
});
|
|
44435
|
+
}
|
|
44436
|
+
|
|
44437
|
+
function pasteHandler(options) {
|
|
44438
|
+
return new Plugin({
|
|
44439
|
+
key: new PluginKey('handlePasteLink'),
|
|
44440
|
+
props: {
|
|
44441
|
+
handlePaste: (view, event, slice) => {
|
|
44442
|
+
var _a, _b;
|
|
44443
|
+
const { state } = view;
|
|
44444
|
+
const { selection } = state;
|
|
44445
|
+
// Do not proceed if in code block.
|
|
44446
|
+
if (state.doc.resolve(selection.from).parent.type.spec.code) {
|
|
44447
|
+
return false;
|
|
44448
|
+
}
|
|
44449
|
+
let textContent = '';
|
|
44450
|
+
slice.content.forEach(node => {
|
|
44451
|
+
textContent += node.textContent;
|
|
44452
|
+
});
|
|
44453
|
+
let isAlreadyLink = false;
|
|
44454
|
+
slice.content.descendants(node => {
|
|
44455
|
+
if (node.marks.some(mark => mark.type.name === options.type.name)) {
|
|
44456
|
+
isAlreadyLink = true;
|
|
44457
|
+
}
|
|
44458
|
+
});
|
|
44459
|
+
if (isAlreadyLink) {
|
|
44460
|
+
return;
|
|
44461
|
+
}
|
|
44462
|
+
const link = find$1(textContent).find(item => item.isLink && item.value === textContent);
|
|
44463
|
+
if (!selection.empty && options.linkOnPaste) {
|
|
44464
|
+
const pastedLink = (link === null || link === void 0 ? void 0 : link.href) || null;
|
|
44465
|
+
if (pastedLink) {
|
|
44466
|
+
options.editor.commands.setMark(options.type, { href: pastedLink });
|
|
44467
|
+
return true;
|
|
44468
|
+
}
|
|
44469
|
+
}
|
|
44470
|
+
const firstChildIsText = ((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type.name) === 'text';
|
|
44471
|
+
const firstChildContainsLinkMark = (_b = slice.content.firstChild) === null || _b === void 0 ? void 0 : _b.marks.some(mark => mark.type.name === options.type.name);
|
|
44472
|
+
if ((firstChildIsText && firstChildContainsLinkMark) || !options.linkOnPaste) {
|
|
44473
|
+
return false;
|
|
44474
|
+
}
|
|
44475
|
+
if (link && selection.empty) {
|
|
44476
|
+
options.editor.commands.insertContent(`<a href="${link.href}">${link.href}</a>`);
|
|
44477
|
+
return true;
|
|
44478
|
+
}
|
|
44479
|
+
const { tr } = state;
|
|
44480
|
+
let deleteOnly = false;
|
|
44481
|
+
if (!selection.empty) {
|
|
44482
|
+
deleteOnly = true;
|
|
44483
|
+
tr.delete(selection.from, selection.to);
|
|
44484
|
+
}
|
|
44485
|
+
let currentPos = selection.from;
|
|
44486
|
+
let fragmentLinks = [];
|
|
44487
|
+
slice.content.forEach(node => {
|
|
44488
|
+
fragmentLinks = find$1(node.textContent);
|
|
44489
|
+
tr.insert(currentPos - 1, node);
|
|
44490
|
+
if (fragmentLinks.length > 0) {
|
|
44491
|
+
deleteOnly = false;
|
|
44492
|
+
fragmentLinks.forEach(fragmentLink => {
|
|
44493
|
+
const linkStart = currentPos + fragmentLink.start;
|
|
44494
|
+
const linkEnd = currentPos + fragmentLink.end;
|
|
44495
|
+
const hasMark = tr.doc.rangeHasMark(linkStart, linkEnd, options.type);
|
|
44496
|
+
if (!hasMark) {
|
|
44497
|
+
tr.addMark(linkStart, linkEnd, options.type.create({ href: fragmentLink.href }));
|
|
44498
|
+
}
|
|
44499
|
+
});
|
|
44500
|
+
}
|
|
44501
|
+
currentPos += node.nodeSize;
|
|
44502
|
+
});
|
|
44503
|
+
const hasFragmentLinks = fragmentLinks.length > 0;
|
|
44504
|
+
if (tr.docChanged && !deleteOnly && hasFragmentLinks) {
|
|
44505
|
+
options.editor.view.dispatch(tr);
|
|
44506
|
+
return true;
|
|
44507
|
+
}
|
|
44508
|
+
return false;
|
|
44509
|
+
},
|
|
44510
|
+
},
|
|
44511
|
+
});
|
|
44512
|
+
}
|
|
44513
|
+
|
|
44514
|
+
const Link = Mark.create({
|
|
44515
|
+
name: 'link',
|
|
44516
|
+
priority: 1000,
|
|
44517
|
+
keepOnSplit: false,
|
|
44518
|
+
onCreate() {
|
|
44519
|
+
this.options.protocols.forEach(protocol => {
|
|
44520
|
+
if (typeof protocol === 'string') {
|
|
44521
|
+
registerCustomProtocol(protocol);
|
|
44522
|
+
return;
|
|
44523
|
+
}
|
|
44524
|
+
registerCustomProtocol(protocol.scheme, protocol.optionalSlashes);
|
|
44525
|
+
});
|
|
44526
|
+
},
|
|
44527
|
+
onDestroy() {
|
|
44528
|
+
reset();
|
|
44529
|
+
},
|
|
44530
|
+
inclusive() {
|
|
44531
|
+
return this.options.autolink;
|
|
44532
|
+
},
|
|
44533
|
+
addOptions() {
|
|
44534
|
+
return {
|
|
44535
|
+
openOnClick: true,
|
|
44536
|
+
linkOnPaste: true,
|
|
44537
|
+
autolink: true,
|
|
44538
|
+
protocols: [],
|
|
44539
|
+
HTMLAttributes: {
|
|
44540
|
+
target: '_blank',
|
|
44541
|
+
rel: 'noopener noreferrer nofollow',
|
|
44542
|
+
class: null,
|
|
44543
|
+
},
|
|
44544
|
+
validate: undefined,
|
|
44545
|
+
};
|
|
44546
|
+
},
|
|
44547
|
+
addAttributes() {
|
|
44548
|
+
return {
|
|
44549
|
+
href: {
|
|
44550
|
+
default: null,
|
|
44551
|
+
},
|
|
44552
|
+
target: {
|
|
44553
|
+
default: this.options.HTMLAttributes.target,
|
|
44554
|
+
},
|
|
44555
|
+
rel: {
|
|
44556
|
+
default: this.options.HTMLAttributes.rel,
|
|
44557
|
+
},
|
|
44558
|
+
class: {
|
|
44559
|
+
default: this.options.HTMLAttributes.class,
|
|
44560
|
+
},
|
|
44561
|
+
};
|
|
44562
|
+
},
|
|
44563
|
+
parseHTML() {
|
|
44564
|
+
return [{ tag: 'a[href]:not([href *= "javascript:" i])' }];
|
|
44565
|
+
},
|
|
44566
|
+
renderHTML({ HTMLAttributes }) {
|
|
44567
|
+
return ['a', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
44568
|
+
},
|
|
44569
|
+
addCommands() {
|
|
44570
|
+
return {
|
|
44571
|
+
setLink: attributes => ({ chain }) => {
|
|
44572
|
+
return chain().setMark(this.name, attributes).setMeta('preventAutolink', true).run();
|
|
44573
|
+
},
|
|
44574
|
+
toggleLink: attributes => ({ chain }) => {
|
|
44575
|
+
return chain()
|
|
44576
|
+
.toggleMark(this.name, attributes, { extendEmptyMarkRange: true })
|
|
44577
|
+
.setMeta('preventAutolink', true)
|
|
44578
|
+
.run();
|
|
44579
|
+
},
|
|
44580
|
+
unsetLink: () => ({ chain }) => {
|
|
44581
|
+
return chain()
|
|
44582
|
+
.unsetMark(this.name, { extendEmptyMarkRange: true })
|
|
44583
|
+
.setMeta('preventAutolink', true)
|
|
44584
|
+
.run();
|
|
44585
|
+
},
|
|
44586
|
+
};
|
|
44587
|
+
},
|
|
44588
|
+
addProseMirrorPlugins() {
|
|
44589
|
+
const plugins = [];
|
|
44590
|
+
if (this.options.autolink) {
|
|
44591
|
+
plugins.push(autolink$1({
|
|
44592
|
+
type: this.type,
|
|
44593
|
+
validate: this.options.validate,
|
|
44594
|
+
}));
|
|
44595
|
+
}
|
|
44596
|
+
if (this.options.openOnClick) {
|
|
44597
|
+
plugins.push(clickHandler({
|
|
44598
|
+
type: this.type,
|
|
44599
|
+
}));
|
|
44600
|
+
}
|
|
44601
|
+
plugins.push(pasteHandler({
|
|
44602
|
+
editor: this.editor,
|
|
44603
|
+
type: this.type,
|
|
44604
|
+
linkOnPaste: this.options.linkOnPaste,
|
|
44605
|
+
}));
|
|
44606
|
+
return plugins;
|
|
44607
|
+
},
|
|
44608
|
+
});
|
|
44609
|
+
|
|
42465
44610
|
const ListItem$1 = Node$1.create({
|
|
42466
44611
|
name: 'listItem',
|
|
42467
44612
|
addOptions() {
|
|
@@ -43048,6 +45193,35 @@ img.ProseMirror-separator {
|
|
|
43048
45193
|
color: ${controlLabelDisabledFontColor};
|
|
43049
45194
|
}
|
|
43050
45195
|
|
|
45196
|
+
${
|
|
45197
|
+
/**
|
|
45198
|
+
* Custom anchor stylings can be removed once leveraging 'nimble-anchor' is supported.
|
|
45199
|
+
* See: https://github.com/ni/nimble/issues/1516
|
|
45200
|
+
*/ ''}
|
|
45201
|
+
.ProseMirror a {
|
|
45202
|
+
color: ${linkFontColor};
|
|
45203
|
+
white-space: normal;
|
|
45204
|
+
${
|
|
45205
|
+
/**
|
|
45206
|
+
* Setting 'pointer-events: none;' to restrict the user from opening a link using the right-click context menu: If the user manually edits
|
|
45207
|
+
* the link's text content, the 'href' attribute of the anchor tag will not be updated. If they attempt to open it using
|
|
45208
|
+
* the right-click context menu with 'Open in new tab/window,' it will still navigate to the link specified
|
|
45209
|
+
* in the 'href' attribute, which may create unnecessary confusion while trying to open the link.
|
|
45210
|
+
*
|
|
45211
|
+
* Using pointer-events: none to disable link interactions can be removed when hyperlink support is added.
|
|
45212
|
+
* see: https://github.com/ni/nimble/issues/1527
|
|
45213
|
+
*/ ''}
|
|
45214
|
+
pointer-events: none;
|
|
45215
|
+
}
|
|
45216
|
+
|
|
45217
|
+
:host([disabled]) .ProseMirror a {
|
|
45218
|
+
color: ${bodyDisabledFontColor};
|
|
45219
|
+
fill: currentcolor;
|
|
45220
|
+
cursor: default;
|
|
45221
|
+
}
|
|
45222
|
+
|
|
45223
|
+
${ /** End of anchor styles */''}
|
|
45224
|
+
|
|
43051
45225
|
.footer-section {
|
|
43052
45226
|
display: flex;
|
|
43053
45227
|
justify-content: space-between;
|
|
@@ -56335,12 +58509,53 @@ img.ProseMirror-separator {
|
|
|
56335
58509
|
'autolink',
|
|
56336
58510
|
'escape'
|
|
56337
58511
|
]);
|
|
56338
|
-
|
|
58512
|
+
supportedTokenizerRules.validateLink = href => /^https?:\/\//i.test(href);
|
|
58513
|
+
/**
|
|
58514
|
+
* In order to display encoded characters, non-ASCII characters, emojis, and other special characters in their original form,
|
|
58515
|
+
* we bypass the default normalization of link text in markdown-it. This is done because we support only "AutoLink" feature in CommonMark flavor.
|
|
58516
|
+
* "normalizeLinkText" method reference in markdown-it: https://github.com/markdown-it/markdown-it/blob/2b6cac25823af011ff3bc7628bc9b06e483c5a08/lib/index.js#L67C1-L86C2
|
|
58517
|
+
*
|
|
58518
|
+
* We can use the default normalization once hyperlink support is added.
|
|
58519
|
+
* See: https://github.com/ni/nimble/issues/1527
|
|
58520
|
+
*/
|
|
58521
|
+
supportedTokenizerRules.normalizeLinkText = url => url;
|
|
58522
|
+
return new MarkdownParser(this.updatedSchema, supportedTokenizerRules, defaultMarkdownParser.tokens);
|
|
58523
|
+
}
|
|
58524
|
+
static getSchemaWithLinkConfiguration() {
|
|
58525
|
+
return new Schema({
|
|
58526
|
+
nodes: schema.spec.nodes,
|
|
58527
|
+
marks: {
|
|
58528
|
+
link: {
|
|
58529
|
+
attrs: {
|
|
58530
|
+
href: {},
|
|
58531
|
+
rel: { default: 'noopener noreferrer' }
|
|
58532
|
+
},
|
|
58533
|
+
// Inclusive can be updated when hyperlink support added
|
|
58534
|
+
// See: https://github.com/ni/nimble/issues/1527
|
|
58535
|
+
inclusive: false,
|
|
58536
|
+
// Excludes can be removed/enabled when hyperlink support added
|
|
58537
|
+
// See: https://github.com/ni/nimble/issues/1527
|
|
58538
|
+
excludes: '_',
|
|
58539
|
+
toDOM(node) {
|
|
58540
|
+
return [
|
|
58541
|
+
anchorTag,
|
|
58542
|
+
{
|
|
58543
|
+
href: node.attrs.href,
|
|
58544
|
+
rel: node.attrs.rel
|
|
58545
|
+
}
|
|
58546
|
+
];
|
|
58547
|
+
}
|
|
58548
|
+
},
|
|
58549
|
+
em: schema.spec.marks.get('em'),
|
|
58550
|
+
strong: schema.spec.marks.get('strong')
|
|
58551
|
+
}
|
|
58552
|
+
});
|
|
56339
58553
|
}
|
|
56340
58554
|
}
|
|
56341
58555
|
_a$1 = RichTextMarkdownParser;
|
|
58556
|
+
RichTextMarkdownParser.updatedSchema = _a$1.getSchemaWithLinkConfiguration();
|
|
56342
58557
|
RichTextMarkdownParser.markdownParser = _a$1.initializeMarkdownParser();
|
|
56343
|
-
RichTextMarkdownParser.domSerializer = DOMSerializer.fromSchema(
|
|
58558
|
+
RichTextMarkdownParser.domSerializer = DOMSerializer.fromSchema(_a$1.updatedSchema);
|
|
56344
58559
|
|
|
56345
58560
|
var _a;
|
|
56346
58561
|
/**
|
|
@@ -56382,7 +58597,28 @@ img.ProseMirror-separator {
|
|
|
56382
58597
|
};
|
|
56383
58598
|
const marks = {
|
|
56384
58599
|
italic: defaultMarkdownSerializer.marks.em,
|
|
56385
|
-
bold: defaultMarkdownSerializer.marks.strong
|
|
58600
|
+
bold: defaultMarkdownSerializer.marks.strong,
|
|
58601
|
+
/**
|
|
58602
|
+
* When a user inserts an absolute link into the editor and then modifies it, the 'defaultMarkdownSerializer.marks.link' function
|
|
58603
|
+
* will detect whether it should be serialized as an autolink (<url>) or a hyperlink ([text](url)) in Markdown format by
|
|
58604
|
+
* comparing the link text with 'href'. Since our markdown-parser only supports the autolink format, we need to ensure that the
|
|
58605
|
+
* serializer also only supports autolink. Unfortunately, prosemirror-markdown does not offer a built-in way to update the
|
|
58606
|
+
* 'defaultMarkdownSerializer' for this purpose. Therefore, we had to create a modified implementation to enable support for
|
|
58607
|
+
* only autolink in serialization. This modified implementation will just load the link text content in between '<>' angular brackets
|
|
58608
|
+
* and ignores the 'href' part.
|
|
58609
|
+
*
|
|
58610
|
+
* Autolink markdown in CommonMark flavor: https://spec.commonmark.org/0.30/#autolinks
|
|
58611
|
+
* ProseMirror model reference: https://github.com/ProseMirror/prosemirror-markdown/blob/c7210d0e55c82bfb0b2f7cba5dffe804575fafb3/src/to_markdown.ts#L3C1-L26C2
|
|
58612
|
+
*
|
|
58613
|
+
* The defaultMarkdownSerializer can be used once hyperlink support is added:
|
|
58614
|
+
* See: https://github.com/ni/nimble/issues/1527
|
|
58615
|
+
*/
|
|
58616
|
+
link: {
|
|
58617
|
+
open: '<',
|
|
58618
|
+
close: '>',
|
|
58619
|
+
escape: false,
|
|
58620
|
+
expelEnclosingWhitespace: true
|
|
58621
|
+
}
|
|
56386
58622
|
};
|
|
56387
58623
|
return new MarkdownSerializer(nodes, marks);
|
|
56388
58624
|
}
|
|
@@ -56602,6 +58838,7 @@ img.ProseMirror-separator {
|
|
|
56602
58838
|
return editor;
|
|
56603
58839
|
}
|
|
56604
58840
|
createTiptapEditor() {
|
|
58841
|
+
const customLink = this.getCustomLinkExtension();
|
|
56605
58842
|
/**
|
|
56606
58843
|
* For more information on the extensions for the supported formatting options, refer to the links below.
|
|
56607
58844
|
* Tiptap marks: https://tiptap.dev/api/marks
|
|
@@ -56622,10 +58859,55 @@ img.ProseMirror-separator {
|
|
|
56622
58859
|
Placeholder.configure({
|
|
56623
58860
|
placeholder: '',
|
|
56624
58861
|
showOnlyWhenEditable: false
|
|
58862
|
+
}),
|
|
58863
|
+
customLink.configure({
|
|
58864
|
+
// HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap
|
|
58865
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
58866
|
+
HTMLAttributes: {
|
|
58867
|
+
rel: 'noopener noreferrer',
|
|
58868
|
+
target: null
|
|
58869
|
+
},
|
|
58870
|
+
autolink: true,
|
|
58871
|
+
openOnClick: false,
|
|
58872
|
+
// linkOnPaste can be enabled when hyperlink support added
|
|
58873
|
+
// See: https://github.com/ni/nimble/issues/1527
|
|
58874
|
+
linkOnPaste: false,
|
|
58875
|
+
validate: href => /^https?:\/\//i.test(href)
|
|
56625
58876
|
})
|
|
56626
58877
|
]
|
|
56627
58878
|
});
|
|
56628
58879
|
}
|
|
58880
|
+
/**
|
|
58881
|
+
* Extending the default link mark schema defined in the TipTap.
|
|
58882
|
+
*
|
|
58883
|
+
* "excludes": https://prosemirror.net/docs/ref/#model.MarkSpec.excludes
|
|
58884
|
+
* "inclusive": https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive
|
|
58885
|
+
* "parseHTML": https://tiptap.dev/guide/custom-extensions#parse-html
|
|
58886
|
+
* "renderHTML": https://tiptap.dev/guide/custom-extensions/#render-html
|
|
58887
|
+
*/
|
|
58888
|
+
getCustomLinkExtension() {
|
|
58889
|
+
return Link.extend({
|
|
58890
|
+
// Excludes can be removed/enabled when hyperlink support added
|
|
58891
|
+
// See: https://github.com/ni/nimble/issues/1527
|
|
58892
|
+
excludes: '_',
|
|
58893
|
+
// Inclusive can be updated when hyperlink support added
|
|
58894
|
+
// See: https://github.com/ni/nimble/issues/1527
|
|
58895
|
+
inclusive: false,
|
|
58896
|
+
parseHTML() {
|
|
58897
|
+
// To load the `nimble-anchor` from the HTML parsed content by markdown-parser as links in the
|
|
58898
|
+
// Tiptap editor, the `parseHTML` of Link extension should return `anchorTag`. This is because the
|
|
58899
|
+
// link mark schema in `markdown-parser.ts` file uses `<nimble-anchor>` as anchor tag and not `<a>`.
|
|
58900
|
+
return [{ tag: anchorTag }];
|
|
58901
|
+
},
|
|
58902
|
+
// HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap
|
|
58903
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
58904
|
+
renderHTML({ HTMLAttributes }) {
|
|
58905
|
+
// The below 'a' tag should be replaced with 'nimble-anchor' once the below issue is fixed.
|
|
58906
|
+
// https://github.com/ni/nimble/issues/1516
|
|
58907
|
+
return ['a', HTMLAttributes];
|
|
58908
|
+
}
|
|
58909
|
+
});
|
|
58910
|
+
}
|
|
56629
58911
|
/**
|
|
56630
58912
|
* This function takes the Fragment from parseMarkdownToDOM function and return the serialized string using XMLSerializer
|
|
56631
58913
|
*/
|
|
@@ -56809,15 +59091,6 @@ img.ProseMirror-separator {
|
|
|
56809
59091
|
li > p:empty {
|
|
56810
59092
|
display: none;
|
|
56811
59093
|
}
|
|
56812
|
-
|
|
56813
|
-
a {
|
|
56814
|
-
word-break: break-all;
|
|
56815
|
-
color: ${linkFontColor};
|
|
56816
|
-
}
|
|
56817
|
-
|
|
56818
|
-
a:active {
|
|
56819
|
-
color: ${linkActiveFontColor};
|
|
56820
|
-
}
|
|
56821
59094
|
`;
|
|
56822
59095
|
|
|
56823
59096
|
/**
|