| 1 |
(function (global, factory) { |
| 2 |
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
| 3 |
typeof define === 'function' && define.amd ? define(['exports'], factory) : |
| 4 |
(global = global || self, factory(global.remarkable = {})); |
| 5 |
}(this, function (exports) { 'use strict'; |
| 6 |
|
| 7 |
// List of valid entities |
| 8 |
// |
| 9 |
// Generate with ./support/entities.js script |
| 10 |
// |
| 11 |
|
| 12 |
/*eslint quotes:0*/ |
| 13 |
var entities = { |
| 14 |
"Aacute":"\u00C1", |
| 15 |
"aacute":"\u00E1", |
| 16 |
"Abreve":"\u0102", |
| 17 |
"abreve":"\u0103", |
| 18 |
"ac":"\u223E", |
| 19 |
"acd":"\u223F", |
| 20 |
"acE":"\u223E\u0333", |
| 21 |
"Acirc":"\u00C2", |
| 22 |
"acirc":"\u00E2", |
| 23 |
"acute":"\u00B4", |
| 24 |
"Acy":"\u0410", |
| 25 |
"acy":"\u0430", |
| 26 |
"AElig":"\u00C6", |
| 27 |
"aelig":"\u00E6", |
| 28 |
"af":"\u2061", |
| 29 |
"Afr":"\uD835\uDD04", |
| 30 |
"afr":"\uD835\uDD1E", |
| 31 |
"Agrave":"\u00C0", |
| 32 |
"agrave":"\u00E0", |
| 33 |
"alefsym":"\u2135", |
| 34 |
"aleph":"\u2135", |
| 35 |
"Alpha":"\u0391", |
| 36 |
"alpha":"\u03B1", |
| 37 |
"Amacr":"\u0100", |
| 38 |
"amacr":"\u0101", |
| 39 |
"amalg":"\u2A3F", |
| 40 |
"AMP":"\u0026", |
| 41 |
"amp":"\u0026", |
| 42 |
"And":"\u2A53", |
| 43 |
"and":"\u2227", |
| 44 |
"andand":"\u2A55", |
| 45 |
"andd":"\u2A5C", |
| 46 |
"andslope":"\u2A58", |
| 47 |
"andv":"\u2A5A", |
| 48 |
"ang":"\u2220", |
| 49 |
"ange":"\u29A4", |
| 50 |
"angle":"\u2220", |
| 51 |
"angmsd":"\u2221", |
| 52 |
"angmsdaa":"\u29A8", |
| 53 |
"angmsdab":"\u29A9", |
| 54 |
"angmsdac":"\u29AA", |
| 55 |
"angmsdad":"\u29AB", |
| 56 |
"angmsdae":"\u29AC", |
| 57 |
"angmsdaf":"\u29AD", |
| 58 |
"angmsdag":"\u29AE", |
| 59 |
"angmsdah":"\u29AF", |
| 60 |
"angrt":"\u221F", |
| 61 |
"angrtvb":"\u22BE", |
| 62 |
"angrtvbd":"\u299D", |
| 63 |
"angsph":"\u2222", |
| 64 |
"angst":"\u00C5", |
| 65 |
"angzarr":"\u237C", |
| 66 |
"Aogon":"\u0104", |
| 67 |
"aogon":"\u0105", |
| 68 |
"Aopf":"\uD835\uDD38", |
| 69 |
"aopf":"\uD835\uDD52", |
| 70 |
"ap":"\u2248", |
| 71 |
"apacir":"\u2A6F", |
| 72 |
"apE":"\u2A70", |
| 73 |
"ape":"\u224A", |
| 74 |
"apid":"\u224B", |
| 75 |
"apos":"\u0027", |
| 76 |
"ApplyFunction":"\u2061", |
| 77 |
"approx":"\u2248", |
| 78 |
"approxeq":"\u224A", |
| 79 |
"Aring":"\u00C5", |
| 80 |
"aring":"\u00E5", |
| 81 |
"Ascr":"\uD835\uDC9C", |
| 82 |
"ascr":"\uD835\uDCB6", |
| 83 |
"Assign":"\u2254", |
| 84 |
"ast":"\u002A", |
| 85 |
"asymp":"\u2248", |
| 86 |
"asympeq":"\u224D", |
| 87 |
"Atilde":"\u00C3", |
| 88 |
"atilde":"\u00E3", |
| 89 |
"Auml":"\u00C4", |
| 90 |
"auml":"\u00E4", |
| 91 |
"awconint":"\u2233", |
| 92 |
"awint":"\u2A11", |
| 93 |
"backcong":"\u224C", |
| 94 |
"backepsilon":"\u03F6", |
| 95 |
"backprime":"\u2035", |
| 96 |
"backsim":"\u223D", |
| 97 |
"backsimeq":"\u22CD", |
| 98 |
"Backslash":"\u2216", |
| 99 |
"Barv":"\u2AE7", |
| 100 |
"barvee":"\u22BD", |
| 101 |
"Barwed":"\u2306", |
| 102 |
"barwed":"\u2305", |
| 103 |
"barwedge":"\u2305", |
| 104 |
"bbrk":"\u23B5", |
| 105 |
"bbrktbrk":"\u23B6", |
| 106 |
"bcong":"\u224C", |
| 107 |
"Bcy":"\u0411", |
| 108 |
"bcy":"\u0431", |
| 109 |
"bdquo":"\u201E", |
| 110 |
"becaus":"\u2235", |
| 111 |
"Because":"\u2235", |
| 112 |
"because":"\u2235", |
| 113 |
"bemptyv":"\u29B0", |
| 114 |
"bepsi":"\u03F6", |
| 115 |
"bernou":"\u212C", |
| 116 |
"Bernoullis":"\u212C", |
| 117 |
"Beta":"\u0392", |
| 118 |
"beta":"\u03B2", |
| 119 |
"beth":"\u2136", |
| 120 |
"between":"\u226C", |
| 121 |
"Bfr":"\uD835\uDD05", |
| 122 |
"bfr":"\uD835\uDD1F", |
| 123 |
"bigcap":"\u22C2", |
| 124 |
"bigcirc":"\u25EF", |
| 125 |
"bigcup":"\u22C3", |
| 126 |
"bigodot":"\u2A00", |
| 127 |
"bigoplus":"\u2A01", |
| 128 |
"bigotimes":"\u2A02", |
| 129 |
"bigsqcup":"\u2A06", |
| 130 |
"bigstar":"\u2605", |
| 131 |
"bigtriangledown":"\u25BD", |
| 132 |
"bigtriangleup":"\u25B3", |
| 133 |
"biguplus":"\u2A04", |
| 134 |
"bigvee":"\u22C1", |
| 135 |
"bigwedge":"\u22C0", |
| 136 |
"bkarow":"\u290D", |
| 137 |
"blacklozenge":"\u29EB", |
| 138 |
"blacksquare":"\u25AA", |
| 139 |
"blacktriangle":"\u25B4", |
| 140 |
"blacktriangledown":"\u25BE", |
| 141 |
"blacktriangleleft":"\u25C2", |
| 142 |
"blacktriangleright":"\u25B8", |
| 143 |
"blank":"\u2423", |
| 144 |
"blk12":"\u2592", |
| 145 |
"blk14":"\u2591", |
| 146 |
"blk34":"\u2593", |
| 147 |
"block":"\u2588", |
| 148 |
"bne":"\u003D\u20E5", |
| 149 |
"bnequiv":"\u2261\u20E5", |
| 150 |
"bNot":"\u2AED", |
| 151 |
"bnot":"\u2310", |
| 152 |
"Bopf":"\uD835\uDD39", |
| 153 |
"bopf":"\uD835\uDD53", |
| 154 |
"bot":"\u22A5", |
| 155 |
"bottom":"\u22A5", |
| 156 |
"bowtie":"\u22C8", |
| 157 |
"boxbox":"\u29C9", |
| 158 |
"boxDL":"\u2557", |
| 159 |
"boxDl":"\u2556", |
| 160 |
"boxdL":"\u2555", |
| 161 |
"boxdl":"\u2510", |
| 162 |
"boxDR":"\u2554", |
| 163 |
"boxDr":"\u2553", |
| 164 |
"boxdR":"\u2552", |
| 165 |
"boxdr":"\u250C", |
| 166 |
"boxH":"\u2550", |
| 167 |
"boxh":"\u2500", |
| 168 |
"boxHD":"\u2566", |
| 169 |
"boxHd":"\u2564", |
| 170 |
"boxhD":"\u2565", |
| 171 |
"boxhd":"\u252C", |
| 172 |
"boxHU":"\u2569", |
| 173 |
"boxHu":"\u2567", |
| 174 |
"boxhU":"\u2568", |
| 175 |
"boxhu":"\u2534", |
| 176 |
"boxminus":"\u229F", |
| 177 |
"boxplus":"\u229E", |
| 178 |
"boxtimes":"\u22A0", |
| 179 |
"boxUL":"\u255D", |
| 180 |
"boxUl":"\u255C", |
| 181 |
"boxuL":"\u255B", |
| 182 |
"boxul":"\u2518", |
| 183 |
"boxUR":"\u255A", |
| 184 |
"boxUr":"\u2559", |
| 185 |
"boxuR":"\u2558", |
| 186 |
"boxur":"\u2514", |
| 187 |
"boxV":"\u2551", |
| 188 |
"boxv":"\u2502", |
| 189 |
"boxVH":"\u256C", |
| 190 |
"boxVh":"\u256B", |
| 191 |
"boxvH":"\u256A", |
| 192 |
"boxvh":"\u253C", |
| 193 |
"boxVL":"\u2563", |
| 194 |
"boxVl":"\u2562", |
| 195 |
"boxvL":"\u2561", |
| 196 |
"boxvl":"\u2524", |
| 197 |
"boxVR":"\u2560", |
| 198 |
"boxVr":"\u255F", |
| 199 |
"boxvR":"\u255E", |
| 200 |
"boxvr":"\u251C", |
| 201 |
"bprime":"\u2035", |
| 202 |
"Breve":"\u02D8", |
| 203 |
"breve":"\u02D8", |
| 204 |
"brvbar":"\u00A6", |
| 205 |
"Bscr":"\u212C", |
| 206 |
"bscr":"\uD835\uDCB7", |
| 207 |
"bsemi":"\u204F", |
| 208 |
"bsim":"\u223D", |
| 209 |
"bsime":"\u22CD", |
| 210 |
"bsol":"\u005C", |
| 211 |
"bsolb":"\u29C5", |
| 212 |
"bsolhsub":"\u27C8", |
| 213 |
"bull":"\u2022", |
| 214 |
"bullet":"\u2022", |
| 215 |
"bump":"\u224E", |
| 216 |
"bumpE":"\u2AAE", |
| 217 |
"bumpe":"\u224F", |
| 218 |
"Bumpeq":"\u224E", |
| 219 |
"bumpeq":"\u224F", |
| 220 |
"Cacute":"\u0106", |
| 221 |
"cacute":"\u0107", |
| 222 |
"Cap":"\u22D2", |
| 223 |
"cap":"\u2229", |
| 224 |
"capand":"\u2A44", |
| 225 |
"capbrcup":"\u2A49", |
| 226 |
"capcap":"\u2A4B", |
| 227 |
"capcup":"\u2A47", |
| 228 |
"capdot":"\u2A40", |
| 229 |
"CapitalDifferentialD":"\u2145", |
| 230 |
"caps":"\u2229\uFE00", |
| 231 |
"caret":"\u2041", |
| 232 |
"caron":"\u02C7", |
| 233 |
"Cayleys":"\u212D", |
| 234 |
"ccaps":"\u2A4D", |
| 235 |
"Ccaron":"\u010C", |
| 236 |
"ccaron":"\u010D", |
| 237 |
"Ccedil":"\u00C7", |
| 238 |
"ccedil":"\u00E7", |
| 239 |
"Ccirc":"\u0108", |
| 240 |
"ccirc":"\u0109", |
| 241 |
"Cconint":"\u2230", |
| 242 |
"ccups":"\u2A4C", |
| 243 |
"ccupssm":"\u2A50", |
| 244 |
"Cdot":"\u010A", |
| 245 |
"cdot":"\u010B", |
| 246 |
"cedil":"\u00B8", |
| 247 |
"Cedilla":"\u00B8", |
| 248 |
"cemptyv":"\u29B2", |
| 249 |
"cent":"\u00A2", |
| 250 |
"CenterDot":"\u00B7", |
| 251 |
"centerdot":"\u00B7", |
| 252 |
"Cfr":"\u212D", |
| 253 |
"cfr":"\uD835\uDD20", |
| 254 |
"CHcy":"\u0427", |
| 255 |
"chcy":"\u0447", |
| 256 |
"check":"\u2713", |
| 257 |
"checkmark":"\u2713", |
| 258 |
"Chi":"\u03A7", |
| 259 |
"chi":"\u03C7", |
| 260 |
"cir":"\u25CB", |
| 261 |
"circ":"\u02C6", |
| 262 |
"circeq":"\u2257", |
| 263 |
"circlearrowleft":"\u21BA", |
| 264 |
"circlearrowright":"\u21BB", |
| 265 |
"circledast":"\u229B", |
| 266 |
"circledcirc":"\u229A", |
| 267 |
"circleddash":"\u229D", |
| 268 |
"CircleDot":"\u2299", |
| 269 |
"circledR":"\u00AE", |
| 270 |
"circledS":"\u24C8", |
| 271 |
"CircleMinus":"\u2296", |
| 272 |
"CirclePlus":"\u2295", |
| 273 |
"CircleTimes":"\u2297", |
| 274 |
"cirE":"\u29C3", |
| 275 |
"cire":"\u2257", |
| 276 |
"cirfnint":"\u2A10", |
| 277 |
"cirmid":"\u2AEF", |
| 278 |
"cirscir":"\u29C2", |
| 279 |
"ClockwiseContourIntegral":"\u2232", |
| 280 |
"CloseCurlyDoubleQuote":"\u201D", |
| 281 |
"CloseCurlyQuote":"\u2019", |
| 282 |
"clubs":"\u2663", |
| 283 |
"clubsuit":"\u2663", |
| 284 |
"Colon":"\u2237", |
| 285 |
"colon":"\u003A", |
| 286 |
"Colone":"\u2A74", |
| 287 |
"colone":"\u2254", |
| 288 |
"coloneq":"\u2254", |
| 289 |
"comma":"\u002C", |
| 290 |
"commat":"\u0040", |
| 291 |
"comp":"\u2201", |
| 292 |
"compfn":"\u2218", |
| 293 |
"complement":"\u2201", |
| 294 |
"complexes":"\u2102", |
| 295 |
"cong":"\u2245", |
| 296 |
"congdot":"\u2A6D", |
| 297 |
"Congruent":"\u2261", |
| 298 |
"Conint":"\u222F", |
| 299 |
"conint":"\u222E", |
| 300 |
"ContourIntegral":"\u222E", |
| 301 |
"Copf":"\u2102", |
| 302 |
"copf":"\uD835\uDD54", |
| 303 |
"coprod":"\u2210", |
| 304 |
"Coproduct":"\u2210", |
| 305 |
"COPY":"\u00A9", |
| 306 |
"copy":"\u00A9", |
| 307 |
"copysr":"\u2117", |
| 308 |
"CounterClockwiseContourIntegral":"\u2233", |
| 309 |
"crarr":"\u21B5", |
| 310 |
"Cross":"\u2A2F", |
| 311 |
"cross":"\u2717", |
| 312 |
"Cscr":"\uD835\uDC9E", |
| 313 |
"cscr":"\uD835\uDCB8", |
| 314 |
"csub":"\u2ACF", |
| 315 |
"csube":"\u2AD1", |
| 316 |
"csup":"\u2AD0", |
| 317 |
"csupe":"\u2AD2", |
| 318 |
"ctdot":"\u22EF", |
| 319 |
"cudarrl":"\u2938", |
| 320 |
"cudarrr":"\u2935", |
| 321 |
"cuepr":"\u22DE", |
| 322 |
"cuesc":"\u22DF", |
| 323 |
"cularr":"\u21B6", |
| 324 |
"cularrp":"\u293D", |
| 325 |
"Cup":"\u22D3", |
| 326 |
"cup":"\u222A", |
| 327 |
"cupbrcap":"\u2A48", |
| 328 |
"CupCap":"\u224D", |
| 329 |
"cupcap":"\u2A46", |
| 330 |
"cupcup":"\u2A4A", |
| 331 |
"cupdot":"\u228D", |
| 332 |
"cupor":"\u2A45", |
| 333 |
"cups":"\u222A\uFE00", |
| 334 |
"curarr":"\u21B7", |
| 335 |
"curarrm":"\u293C", |
| 336 |
"curlyeqprec":"\u22DE", |
| 337 |
"curlyeqsucc":"\u22DF", |
| 338 |
"curlyvee":"\u22CE", |
| 339 |
"curlywedge":"\u22CF", |
| 340 |
"curren":"\u00A4", |
| 341 |
"curvearrowleft":"\u21B6", |
| 342 |
"curvearrowright":"\u21B7", |
| 343 |
"cuvee":"\u22CE", |
| 344 |
"cuwed":"\u22CF", |
| 345 |
"cwconint":"\u2232", |
| 346 |
"cwint":"\u2231", |
| 347 |
"cylcty":"\u232D", |
| 348 |
"Dagger":"\u2021", |
| 349 |
"dagger":"\u2020", |
| 350 |
"daleth":"\u2138", |
| 351 |
"Darr":"\u21A1", |
| 352 |
"dArr":"\u21D3", |
| 353 |
"darr":"\u2193", |
| 354 |
"dash":"\u2010", |
| 355 |
"Dashv":"\u2AE4", |
| 356 |
"dashv":"\u22A3", |
| 357 |
"dbkarow":"\u290F", |
| 358 |
"dblac":"\u02DD", |
| 359 |
"Dcaron":"\u010E", |
| 360 |
"dcaron":"\u010F", |
| 361 |
"Dcy":"\u0414", |
| 362 |
"dcy":"\u0434", |
| 363 |
"DD":"\u2145", |
| 364 |
"dd":"\u2146", |
| 365 |
"ddagger":"\u2021", |
| 366 |
"ddarr":"\u21CA", |
| 367 |
"DDotrahd":"\u2911", |
| 368 |
"ddotseq":"\u2A77", |
| 369 |
"deg":"\u00B0", |
| 370 |
"Del":"\u2207", |
| 371 |
"Delta":"\u0394", |
| 372 |
"delta":"\u03B4", |
| 373 |
"demptyv":"\u29B1", |
| 374 |
"dfisht":"\u297F", |
| 375 |
"Dfr":"\uD835\uDD07", |
| 376 |
"dfr":"\uD835\uDD21", |
| 377 |
"dHar":"\u2965", |
| 378 |
"dharl":"\u21C3", |
| 379 |
"dharr":"\u21C2", |
| 380 |
"DiacriticalAcute":"\u00B4", |
| 381 |
"DiacriticalDot":"\u02D9", |
| 382 |
"DiacriticalDoubleAcute":"\u02DD", |
| 383 |
"DiacriticalGrave":"\u0060", |
| 384 |
"DiacriticalTilde":"\u02DC", |
| 385 |
"diam":"\u22C4", |
| 386 |
"Diamond":"\u22C4", |
| 387 |
"diamond":"\u22C4", |
| 388 |
"diamondsuit":"\u2666", |
| 389 |
"diams":"\u2666", |
| 390 |
"die":"\u00A8", |
| 391 |
"DifferentialD":"\u2146", |
| 392 |
"digamma":"\u03DD", |
| 393 |
"disin":"\u22F2", |
| 394 |
"div":"\u00F7", |
| 395 |
"divide":"\u00F7", |
| 396 |
"divideontimes":"\u22C7", |
| 397 |
"divonx":"\u22C7", |
| 398 |
"DJcy":"\u0402", |
| 399 |
"djcy":"\u0452", |
| 400 |
"dlcorn":"\u231E", |
| 401 |
"dlcrop":"\u230D", |
| 402 |
"dollar":"\u0024", |
| 403 |
"Dopf":"\uD835\uDD3B", |
| 404 |
"dopf":"\uD835\uDD55", |
| 405 |
"Dot":"\u00A8", |
| 406 |
"dot":"\u02D9", |
| 407 |
"DotDot":"\u20DC", |
| 408 |
"doteq":"\u2250", |
| 409 |
"doteqdot":"\u2251", |
| 410 |
"DotEqual":"\u2250", |
| 411 |
"dotminus":"\u2238", |
| 412 |
"dotplus":"\u2214", |
| 413 |
"dotsquare":"\u22A1", |
| 414 |
"doublebarwedge":"\u2306", |
| 415 |
"DoubleContourIntegral":"\u222F", |
| 416 |
"DoubleDot":"\u00A8", |
| 417 |
"DoubleDownArrow":"\u21D3", |
| 418 |
"DoubleLeftArrow":"\u21D0", |
| 419 |
"DoubleLeftRightArrow":"\u21D4", |
| 420 |
"DoubleLeftTee":"\u2AE4", |
| 421 |
"DoubleLongLeftArrow":"\u27F8", |
| 422 |
"DoubleLongLeftRightArrow":"\u27FA", |
| 423 |
"DoubleLongRightArrow":"\u27F9", |
| 424 |
"DoubleRightArrow":"\u21D2", |
| 425 |
"DoubleRightTee":"\u22A8", |
| 426 |
"DoubleUpArrow":"\u21D1", |
| 427 |
"DoubleUpDownArrow":"\u21D5", |
| 428 |
"DoubleVerticalBar":"\u2225", |
| 429 |
"DownArrow":"\u2193", |
| 430 |
"Downarrow":"\u21D3", |
| 431 |
"downarrow":"\u2193", |
| 432 |
"DownArrowBar":"\u2913", |
| 433 |
"DownArrowUpArrow":"\u21F5", |
| 434 |
"DownBreve":"\u0311", |
| 435 |
"downdownarrows":"\u21CA", |
| 436 |
"downharpoonleft":"\u21C3", |
| 437 |
"downharpoonright":"\u21C2", |
| 438 |
"DownLeftRightVector":"\u2950", |
| 439 |
"DownLeftTeeVector":"\u295E", |
| 440 |
"DownLeftVector":"\u21BD", |
| 441 |
"DownLeftVectorBar":"\u2956", |
| 442 |
"DownRightTeeVector":"\u295F", |
| 443 |
"DownRightVector":"\u21C1", |
| 444 |
"DownRightVectorBar":"\u2957", |
| 445 |
"DownTee":"\u22A4", |
| 446 |
"DownTeeArrow":"\u21A7", |
| 447 |
"drbkarow":"\u2910", |
| 448 |
"drcorn":"\u231F", |
| 449 |
"drcrop":"\u230C", |
| 450 |
"Dscr":"\uD835\uDC9F", |
| 451 |
"dscr":"\uD835\uDCB9", |
| 452 |
"DScy":"\u0405", |
| 453 |
"dscy":"\u0455", |
| 454 |
"dsol":"\u29F6", |
| 455 |
"Dstrok":"\u0110", |
| 456 |
"dstrok":"\u0111", |
| 457 |
"dtdot":"\u22F1", |
| 458 |
"dtri":"\u25BF", |
| 459 |
"dtrif":"\u25BE", |
| 460 |
"duarr":"\u21F5", |
| 461 |
"duhar":"\u296F", |
| 462 |
"dwangle":"\u29A6", |
| 463 |
"DZcy":"\u040F", |
| 464 |
"dzcy":"\u045F", |
| 465 |
"dzigrarr":"\u27FF", |
| 466 |
"Eacute":"\u00C9", |
| 467 |
"eacute":"\u00E9", |
| 468 |
"easter":"\u2A6E", |
| 469 |
"Ecaron":"\u011A", |
| 470 |
"ecaron":"\u011B", |
| 471 |
"ecir":"\u2256", |
| 472 |
"Ecirc":"\u00CA", |
| 473 |
"ecirc":"\u00EA", |
| 474 |
"ecolon":"\u2255", |
| 475 |
"Ecy":"\u042D", |
| 476 |
"ecy":"\u044D", |
| 477 |
"eDDot":"\u2A77", |
| 478 |
"Edot":"\u0116", |
| 479 |
"eDot":"\u2251", |
| 480 |
"edot":"\u0117", |
| 481 |
"ee":"\u2147", |
| 482 |
"efDot":"\u2252", |
| 483 |
"Efr":"\uD835\uDD08", |
| 484 |
"efr":"\uD835\uDD22", |
| 485 |
"eg":"\u2A9A", |
| 486 |
"Egrave":"\u00C8", |
| 487 |
"egrave":"\u00E8", |
| 488 |
"egs":"\u2A96", |
| 489 |
"egsdot":"\u2A98", |
| 490 |
"el":"\u2A99", |
| 491 |
"Element":"\u2208", |
| 492 |
"elinters":"\u23E7", |
| 493 |
"ell":"\u2113", |
| 494 |
"els":"\u2A95", |
| 495 |
"elsdot":"\u2A97", |
| 496 |
"Emacr":"\u0112", |
| 497 |
"emacr":"\u0113", |
| 498 |
"empty":"\u2205", |
| 499 |
"emptyset":"\u2205", |
| 500 |
"EmptySmallSquare":"\u25FB", |
| 501 |
"emptyv":"\u2205", |
| 502 |
"EmptyVerySmallSquare":"\u25AB", |
| 503 |
"emsp":"\u2003", |
| 504 |
"emsp13":"\u2004", |
| 505 |
"emsp14":"\u2005", |
| 506 |
"ENG":"\u014A", |
| 507 |
"eng":"\u014B", |
| 508 |
"ensp":"\u2002", |
| 509 |
"Eogon":"\u0118", |
| 510 |
"eogon":"\u0119", |
| 511 |
"Eopf":"\uD835\uDD3C", |
| 512 |
"eopf":"\uD835\uDD56", |
| 513 |
"epar":"\u22D5", |
| 514 |
"eparsl":"\u29E3", |
| 515 |
"eplus":"\u2A71", |
| 516 |
"epsi":"\u03B5", |
| 517 |
"Epsilon":"\u0395", |
| 518 |
"epsilon":"\u03B5", |
| 519 |
"epsiv":"\u03F5", |
| 520 |
"eqcirc":"\u2256", |
| 521 |
"eqcolon":"\u2255", |
| 522 |
"eqsim":"\u2242", |
| 523 |
"eqslantgtr":"\u2A96", |
| 524 |
"eqslantless":"\u2A95", |
| 525 |
"Equal":"\u2A75", |
| 526 |
"equals":"\u003D", |
| 527 |
"EqualTilde":"\u2242", |
| 528 |
"equest":"\u225F", |
| 529 |
"Equilibrium":"\u21CC", |
| 530 |
"equiv":"\u2261", |
| 531 |
"equivDD":"\u2A78", |
| 532 |
"eqvparsl":"\u29E5", |
| 533 |
"erarr":"\u2971", |
| 534 |
"erDot":"\u2253", |
| 535 |
"Escr":"\u2130", |
| 536 |
"escr":"\u212F", |
| 537 |
"esdot":"\u2250", |
| 538 |
"Esim":"\u2A73", |
| 539 |
"esim":"\u2242", |
| 540 |
"Eta":"\u0397", |
| 541 |
"eta":"\u03B7", |
| 542 |
"ETH":"\u00D0", |
| 543 |
"eth":"\u00F0", |
| 544 |
"Euml":"\u00CB", |
| 545 |
"euml":"\u00EB", |
| 546 |
"euro":"\u20AC", |
| 547 |
"excl":"\u0021", |
| 548 |
"exist":"\u2203", |
| 549 |
"Exists":"\u2203", |
| 550 |
"expectation":"\u2130", |
| 551 |
"ExponentialE":"\u2147", |
| 552 |
"exponentiale":"\u2147", |
| 553 |
"fallingdotseq":"\u2252", |
| 554 |
"Fcy":"\u0424", |
| 555 |
"fcy":"\u0444", |
| 556 |
"female":"\u2640", |
| 557 |
"ffilig":"\uFB03", |
| 558 |
"fflig":"\uFB00", |
| 559 |
"ffllig":"\uFB04", |
| 560 |
"Ffr":"\uD835\uDD09", |
| 561 |
"ffr":"\uD835\uDD23", |
| 562 |
"filig":"\uFB01", |
| 563 |
"FilledSmallSquare":"\u25FC", |
| 564 |
"FilledVerySmallSquare":"\u25AA", |
| 565 |
"fjlig":"\u0066\u006A", |
| 566 |
"flat":"\u266D", |
| 567 |
"fllig":"\uFB02", |
| 568 |
"fltns":"\u25B1", |
| 569 |
"fnof":"\u0192", |
| 570 |
"Fopf":"\uD835\uDD3D", |
| 571 |
"fopf":"\uD835\uDD57", |
| 572 |
"ForAll":"\u2200", |
| 573 |
"forall":"\u2200", |
| 574 |
"fork":"\u22D4", |
| 575 |
"forkv":"\u2AD9", |
| 576 |
"Fouriertrf":"\u2131", |
| 577 |
"fpartint":"\u2A0D", |
| 578 |
"frac12":"\u00BD", |
| 579 |
"frac13":"\u2153", |
| 580 |
"frac14":"\u00BC", |
| 581 |
"frac15":"\u2155", |
| 582 |
"frac16":"\u2159", |
| 583 |
"frac18":"\u215B", |
| 584 |
"frac23":"\u2154", |
| 585 |
"frac25":"\u2156", |
| 586 |
"frac34":"\u00BE", |
| 587 |
"frac35":"\u2157", |
| 588 |
"frac38":"\u215C", |
| 589 |
"frac45":"\u2158", |
| 590 |
"frac56":"\u215A", |
| 591 |
"frac58":"\u215D", |
| 592 |
"frac78":"\u215E", |
| 593 |
"frasl":"\u2044", |
| 594 |
"frown":"\u2322", |
| 595 |
"Fscr":"\u2131", |
| 596 |
"fscr":"\uD835\uDCBB", |
| 597 |
"gacute":"\u01F5", |
| 598 |
"Gamma":"\u0393", |
| 599 |
"gamma":"\u03B3", |
| 600 |
"Gammad":"\u03DC", |
| 601 |
"gammad":"\u03DD", |
| 602 |
"gap":"\u2A86", |
| 603 |
"Gbreve":"\u011E", |
| 604 |
"gbreve":"\u011F", |
| 605 |
"Gcedil":"\u0122", |
| 606 |
"Gcirc":"\u011C", |
| 607 |
"gcirc":"\u011D", |
| 608 |
"Gcy":"\u0413", |
| 609 |
"gcy":"\u0433", |
| 610 |
"Gdot":"\u0120", |
| 611 |
"gdot":"\u0121", |
| 612 |
"gE":"\u2267", |
| 613 |
"ge":"\u2265", |
| 614 |
"gEl":"\u2A8C", |
| 615 |
"gel":"\u22DB", |
| 616 |
"geq":"\u2265", |
| 617 |
"geqq":"\u2267", |
| 618 |
"geqslant":"\u2A7E", |
| 619 |
"ges":"\u2A7E", |
| 620 |
"gescc":"\u2AA9", |
| 621 |
"gesdot":"\u2A80", |
| 622 |
"gesdoto":"\u2A82", |
| 623 |
"gesdotol":"\u2A84", |
| 624 |
"gesl":"\u22DB\uFE00", |
| 625 |
"gesles":"\u2A94", |
| 626 |
"Gfr":"\uD835\uDD0A", |
| 627 |
"gfr":"\uD835\uDD24", |
| 628 |
"Gg":"\u22D9", |
| 629 |
"gg":"\u226B", |
| 630 |
"ggg":"\u22D9", |
| 631 |
"gimel":"\u2137", |
| 632 |
"GJcy":"\u0403", |
| 633 |
"gjcy":"\u0453", |
| 634 |
"gl":"\u2277", |
| 635 |
"gla":"\u2AA5", |
| 636 |
"glE":"\u2A92", |
| 637 |
"glj":"\u2AA4", |
| 638 |
"gnap":"\u2A8A", |
| 639 |
"gnapprox":"\u2A8A", |
| 640 |
"gnE":"\u2269", |
| 641 |
"gne":"\u2A88", |
| 642 |
"gneq":"\u2A88", |
| 643 |
"gneqq":"\u2269", |
| 644 |
"gnsim":"\u22E7", |
| 645 |
"Gopf":"\uD835\uDD3E", |
| 646 |
"gopf":"\uD835\uDD58", |
| 647 |
"grave":"\u0060", |
| 648 |
"GreaterEqual":"\u2265", |
| 649 |
"GreaterEqualLess":"\u22DB", |
| 650 |
"GreaterFullEqual":"\u2267", |
| 651 |
"GreaterGreater":"\u2AA2", |
| 652 |
"GreaterLess":"\u2277", |
| 653 |
"GreaterSlantEqual":"\u2A7E", |
| 654 |
"GreaterTilde":"\u2273", |
| 655 |
"Gscr":"\uD835\uDCA2", |
| 656 |
"gscr":"\u210A", |
| 657 |
"gsim":"\u2273", |
| 658 |
"gsime":"\u2A8E", |
| 659 |
"gsiml":"\u2A90", |
| 660 |
"GT":"\u003E", |
| 661 |
"Gt":"\u226B", |
| 662 |
"gt":"\u003E", |
| 663 |
"gtcc":"\u2AA7", |
| 664 |
"gtcir":"\u2A7A", |
| 665 |
"gtdot":"\u22D7", |
| 666 |
"gtlPar":"\u2995", |
| 667 |
"gtquest":"\u2A7C", |
| 668 |
"gtrapprox":"\u2A86", |
| 669 |
"gtrarr":"\u2978", |
| 670 |
"gtrdot":"\u22D7", |
| 671 |
"gtreqless":"\u22DB", |
| 672 |
"gtreqqless":"\u2A8C", |
| 673 |
"gtrless":"\u2277", |
| 674 |
"gtrsim":"\u2273", |
| 675 |
"gvertneqq":"\u2269\uFE00", |
| 676 |
"gvnE":"\u2269\uFE00", |
| 677 |
"Hacek":"\u02C7", |
| 678 |
"hairsp":"\u200A", |
| 679 |
"half":"\u00BD", |
| 680 |
"hamilt":"\u210B", |
| 681 |
"HARDcy":"\u042A", |
| 682 |
"hardcy":"\u044A", |
| 683 |
"hArr":"\u21D4", |
| 684 |
"harr":"\u2194", |
| 685 |
"harrcir":"\u2948", |
| 686 |
"harrw":"\u21AD", |
| 687 |
"Hat":"\u005E", |
| 688 |
"hbar":"\u210F", |
| 689 |
"Hcirc":"\u0124", |
| 690 |
"hcirc":"\u0125", |
| 691 |
"hearts":"\u2665", |
| 692 |
"heartsuit":"\u2665", |
| 693 |
"hellip":"\u2026", |
| 694 |
"hercon":"\u22B9", |
| 695 |
"Hfr":"\u210C", |
| 696 |
"hfr":"\uD835\uDD25", |
| 697 |
"HilbertSpace":"\u210B", |
| 698 |
"hksearow":"\u2925", |
| 699 |
"hkswarow":"\u2926", |
| 700 |
"hoarr":"\u21FF", |
| 701 |
"homtht":"\u223B", |
| 702 |
"hookleftarrow":"\u21A9", |
| 703 |
"hookrightarrow":"\u21AA", |
| 704 |
"Hopf":"\u210D", |
| 705 |
"hopf":"\uD835\uDD59", |
| 706 |
"horbar":"\u2015", |
| 707 |
"HorizontalLine":"\u2500", |
| 708 |
"Hscr":"\u210B", |
| 709 |
"hscr":"\uD835\uDCBD", |
| 710 |
"hslash":"\u210F", |
| 711 |
"Hstrok":"\u0126", |
| 712 |
"hstrok":"\u0127", |
| 713 |
"HumpDownHump":"\u224E", |
| 714 |
"HumpEqual":"\u224F", |
| 715 |
"hybull":"\u2043", |
| 716 |
"hyphen":"\u2010", |
| 717 |
"Iacute":"\u00CD", |
| 718 |
"iacute":"\u00ED", |
| 719 |
"ic":"\u2063", |
| 720 |
"Icirc":"\u00CE", |
| 721 |
"icirc":"\u00EE", |
| 722 |
"Icy":"\u0418", |
| 723 |
"icy":"\u0438", |
| 724 |
"Idot":"\u0130", |
| 725 |
"IEcy":"\u0415", |
| 726 |
"iecy":"\u0435", |
| 727 |
"iexcl":"\u00A1", |
| 728 |
"iff":"\u21D4", |
| 729 |
"Ifr":"\u2111", |
| 730 |
"ifr":"\uD835\uDD26", |
| 731 |
"Igrave":"\u00CC", |
| 732 |
"igrave":"\u00EC", |
| 733 |
"ii":"\u2148", |
| 734 |
"iiiint":"\u2A0C", |
| 735 |
"iiint":"\u222D", |
| 736 |
"iinfin":"\u29DC", |
| 737 |
"iiota":"\u2129", |
| 738 |
"IJlig":"\u0132", |
| 739 |
"ijlig":"\u0133", |
| 740 |
"Im":"\u2111", |
| 741 |
"Imacr":"\u012A", |
| 742 |
"imacr":"\u012B", |
| 743 |
"image":"\u2111", |
| 744 |
"ImaginaryI":"\u2148", |
| 745 |
"imagline":"\u2110", |
| 746 |
"imagpart":"\u2111", |
| 747 |
"imath":"\u0131", |
| 748 |
"imof":"\u22B7", |
| 749 |
"imped":"\u01B5", |
| 750 |
"Implies":"\u21D2", |
| 751 |
"in":"\u2208", |
| 752 |
"incare":"\u2105", |
| 753 |
"infin":"\u221E", |
| 754 |
"infintie":"\u29DD", |
| 755 |
"inodot":"\u0131", |
| 756 |
"Int":"\u222C", |
| 757 |
"int":"\u222B", |
| 758 |
"intcal":"\u22BA", |
| 759 |
"integers":"\u2124", |
| 760 |
"Integral":"\u222B", |
| 761 |
"intercal":"\u22BA", |
| 762 |
"Intersection":"\u22C2", |
| 763 |
"intlarhk":"\u2A17", |
| 764 |
"intprod":"\u2A3C", |
| 765 |
"InvisibleComma":"\u2063", |
| 766 |
"InvisibleTimes":"\u2062", |
| 767 |
"IOcy":"\u0401", |
| 768 |
"iocy":"\u0451", |
| 769 |
"Iogon":"\u012E", |
| 770 |
"iogon":"\u012F", |
| 771 |
"Iopf":"\uD835\uDD40", |
| 772 |
"iopf":"\uD835\uDD5A", |
| 773 |
"Iota":"\u0399", |
| 774 |
"iota":"\u03B9", |
| 775 |
"iprod":"\u2A3C", |
| 776 |
"iquest":"\u00BF", |
| 777 |
"Iscr":"\u2110", |
| 778 |
"iscr":"\uD835\uDCBE", |
| 779 |
"isin":"\u2208", |
| 780 |
"isindot":"\u22F5", |
| 781 |
"isinE":"\u22F9", |
| 782 |
"isins":"\u22F4", |
| 783 |
"isinsv":"\u22F3", |
| 784 |
"isinv":"\u2208", |
| 785 |
"it":"\u2062", |
| 786 |
"Itilde":"\u0128", |
| 787 |
"itilde":"\u0129", |
| 788 |
"Iukcy":"\u0406", |
| 789 |
"iukcy":"\u0456", |
| 790 |
"Iuml":"\u00CF", |
| 791 |
"iuml":"\u00EF", |
| 792 |
"Jcirc":"\u0134", |
| 793 |
"jcirc":"\u0135", |
| 794 |
"Jcy":"\u0419", |
| 795 |
"jcy":"\u0439", |
| 796 |
"Jfr":"\uD835\uDD0D", |
| 797 |
"jfr":"\uD835\uDD27", |
| 798 |
"jmath":"\u0237", |
| 799 |
"Jopf":"\uD835\uDD41", |
| 800 |
"jopf":"\uD835\uDD5B", |
| 801 |
"Jscr":"\uD835\uDCA5", |
| 802 |
"jscr":"\uD835\uDCBF", |
| 803 |
"Jsercy":"\u0408", |
| 804 |
"jsercy":"\u0458", |
| 805 |
"Jukcy":"\u0404", |
| 806 |
"jukcy":"\u0454", |
| 807 |
"Kappa":"\u039A", |
| 808 |
"kappa":"\u03BA", |
| 809 |
"kappav":"\u03F0", |
| 810 |
"Kcedil":"\u0136", |
| 811 |
"kcedil":"\u0137", |
| 812 |
"Kcy":"\u041A", |
| 813 |
"kcy":"\u043A", |
| 814 |
"Kfr":"\uD835\uDD0E", |
| 815 |
"kfr":"\uD835\uDD28", |
| 816 |
"kgreen":"\u0138", |
| 817 |
"KHcy":"\u0425", |
| 818 |
"khcy":"\u0445", |
| 819 |
"KJcy":"\u040C", |
| 820 |
"kjcy":"\u045C", |
| 821 |
"Kopf":"\uD835\uDD42", |
| 822 |
"kopf":"\uD835\uDD5C", |
| 823 |
"Kscr":"\uD835\uDCA6", |
| 824 |
"kscr":"\uD835\uDCC0", |
| 825 |
"lAarr":"\u21DA", |
| 826 |
"Lacute":"\u0139", |
| 827 |
"lacute":"\u013A", |
| 828 |
"laemptyv":"\u29B4", |
| 829 |
"lagran":"\u2112", |
| 830 |
"Lambda":"\u039B", |
| 831 |
"lambda":"\u03BB", |
| 832 |
"Lang":"\u27EA", |
| 833 |
"lang":"\u27E8", |
| 834 |
"langd":"\u2991", |
| 835 |
"langle":"\u27E8", |
| 836 |
"lap":"\u2A85", |
| 837 |
"Laplacetrf":"\u2112", |
| 838 |
"laquo":"\u00AB", |
| 839 |
"Larr":"\u219E", |
| 840 |
"lArr":"\u21D0", |
| 841 |
"larr":"\u2190", |
| 842 |
"larrb":"\u21E4", |
| 843 |
"larrbfs":"\u291F", |
| 844 |
"larrfs":"\u291D", |
| 845 |
"larrhk":"\u21A9", |
| 846 |
"larrlp":"\u21AB", |
| 847 |
"larrpl":"\u2939", |
| 848 |
"larrsim":"\u2973", |
| 849 |
"larrtl":"\u21A2", |
| 850 |
"lat":"\u2AAB", |
| 851 |
"lAtail":"\u291B", |
| 852 |
"latail":"\u2919", |
| 853 |
"late":"\u2AAD", |
| 854 |
"lates":"\u2AAD\uFE00", |
| 855 |
"lBarr":"\u290E", |
| 856 |
"lbarr":"\u290C", |
| 857 |
"lbbrk":"\u2772", |
| 858 |
"lbrace":"\u007B", |
| 859 |
"lbrack":"\u005B", |
| 860 |
"lbrke":"\u298B", |
| 861 |
"lbrksld":"\u298F", |
| 862 |
"lbrkslu":"\u298D", |
| 863 |
"Lcaron":"\u013D", |
| 864 |
"lcaron":"\u013E", |
| 865 |
"Lcedil":"\u013B", |
| 866 |
"lcedil":"\u013C", |
| 867 |
"lceil":"\u2308", |
| 868 |
"lcub":"\u007B", |
| 869 |
"Lcy":"\u041B", |
| 870 |
"lcy":"\u043B", |
| 871 |
"ldca":"\u2936", |
| 872 |
"ldquo":"\u201C", |
| 873 |
"ldquor":"\u201E", |
| 874 |
"ldrdhar":"\u2967", |
| 875 |
"ldrushar":"\u294B", |
| 876 |
"ldsh":"\u21B2", |
| 877 |
"lE":"\u2266", |
| 878 |
"le":"\u2264", |
| 879 |
"LeftAngleBracket":"\u27E8", |
| 880 |
"LeftArrow":"\u2190", |
| 881 |
"Leftarrow":"\u21D0", |
| 882 |
"leftarrow":"\u2190", |
| 883 |
"LeftArrowBar":"\u21E4", |
| 884 |
"LeftArrowRightArrow":"\u21C6", |
| 885 |
"leftarrowtail":"\u21A2", |
| 886 |
"LeftCeiling":"\u2308", |
| 887 |
"LeftDoubleBracket":"\u27E6", |
| 888 |
"LeftDownTeeVector":"\u2961", |
| 889 |
"LeftDownVector":"\u21C3", |
| 890 |
"LeftDownVectorBar":"\u2959", |
| 891 |
"LeftFloor":"\u230A", |
| 892 |
"leftharpoondown":"\u21BD", |
| 893 |
"leftharpoonup":"\u21BC", |
| 894 |
"leftleftarrows":"\u21C7", |
| 895 |
"LeftRightArrow":"\u2194", |
| 896 |
"Leftrightarrow":"\u21D4", |
| 897 |
"leftrightarrow":"\u2194", |
| 898 |
"leftrightarrows":"\u21C6", |
| 899 |
"leftrightharpoons":"\u21CB", |
| 900 |
"leftrightsquigarrow":"\u21AD", |
| 901 |
"LeftRightVector":"\u294E", |
| 902 |
"LeftTee":"\u22A3", |
| 903 |
"LeftTeeArrow":"\u21A4", |
| 904 |
"LeftTeeVector":"\u295A", |
| 905 |
"leftthreetimes":"\u22CB", |
| 906 |
"LeftTriangle":"\u22B2", |
| 907 |
"LeftTriangleBar":"\u29CF", |
| 908 |
"LeftTriangleEqual":"\u22B4", |
| 909 |
"LeftUpDownVector":"\u2951", |
| 910 |
"LeftUpTeeVector":"\u2960", |
| 911 |
"LeftUpVector":"\u21BF", |
| 912 |
"LeftUpVectorBar":"\u2958", |
| 913 |
"LeftVector":"\u21BC", |
| 914 |
"LeftVectorBar":"\u2952", |
| 915 |
"lEg":"\u2A8B", |
| 916 |
"leg":"\u22DA", |
| 917 |
"leq":"\u2264", |
| 918 |
"leqq":"\u2266", |
| 919 |
"leqslant":"\u2A7D", |
| 920 |
"les":"\u2A7D", |
| 921 |
"lescc":"\u2AA8", |
| 922 |
"lesdot":"\u2A7F", |
| 923 |
"lesdoto":"\u2A81", |
| 924 |
"lesdotor":"\u2A83", |
| 925 |
"lesg":"\u22DA\uFE00", |
| 926 |
"lesges":"\u2A93", |
| 927 |
"lessapprox":"\u2A85", |
| 928 |
"lessdot":"\u22D6", |
| 929 |
"lesseqgtr":"\u22DA", |
| 930 |
"lesseqqgtr":"\u2A8B", |
| 931 |
"LessEqualGreater":"\u22DA", |
| 932 |
"LessFullEqual":"\u2266", |
| 933 |
"LessGreater":"\u2276", |
| 934 |
"lessgtr":"\u2276", |
| 935 |
"LessLess":"\u2AA1", |
| 936 |
"lesssim":"\u2272", |
| 937 |
"LessSlantEqual":"\u2A7D", |
| 938 |
"LessTilde":"\u2272", |
| 939 |
"lfisht":"\u297C", |
| 940 |
"lfloor":"\u230A", |
| 941 |
"Lfr":"\uD835\uDD0F", |
| 942 |
"lfr":"\uD835\uDD29", |
| 943 |
"lg":"\u2276", |
| 944 |
"lgE":"\u2A91", |
| 945 |
"lHar":"\u2962", |
| 946 |
"lhard":"\u21BD", |
| 947 |
"lharu":"\u21BC", |
| 948 |
"lharul":"\u296A", |
| 949 |
"lhblk":"\u2584", |
| 950 |
"LJcy":"\u0409", |
| 951 |
"ljcy":"\u0459", |
| 952 |
"Ll":"\u22D8", |
| 953 |
"ll":"\u226A", |
| 954 |
"llarr":"\u21C7", |
| 955 |
"llcorner":"\u231E", |
| 956 |
"Lleftarrow":"\u21DA", |
| 957 |
"llhard":"\u296B", |
| 958 |
"lltri":"\u25FA", |
| 959 |
"Lmidot":"\u013F", |
| 960 |
"lmidot":"\u0140", |
| 961 |
"lmoust":"\u23B0", |
| 962 |
"lmoustache":"\u23B0", |
| 963 |
"lnap":"\u2A89", |
| 964 |
"lnapprox":"\u2A89", |
| 965 |
"lnE":"\u2268", |
| 966 |
"lne":"\u2A87", |
| 967 |
"lneq":"\u2A87", |
| 968 |
"lneqq":"\u2268", |
| 969 |
"lnsim":"\u22E6", |
| 970 |
"loang":"\u27EC", |
| 971 |
"loarr":"\u21FD", |
| 972 |
"lobrk":"\u27E6", |
| 973 |
"LongLeftArrow":"\u27F5", |
| 974 |
"Longleftarrow":"\u27F8", |
| 975 |
"longleftarrow":"\u27F5", |
| 976 |
"LongLeftRightArrow":"\u27F7", |
| 977 |
"Longleftrightarrow":"\u27FA", |
| 978 |
"longleftrightarrow":"\u27F7", |
| 979 |
"longmapsto":"\u27FC", |
| 980 |
"LongRightArrow":"\u27F6", |
| 981 |
"Longrightarrow":"\u27F9", |
| 982 |
"longrightarrow":"\u27F6", |
| 983 |
"looparrowleft":"\u21AB", |
| 984 |
"looparrowright":"\u21AC", |
| 985 |
"lopar":"\u2985", |
| 986 |
"Lopf":"\uD835\uDD43", |
| 987 |
"lopf":"\uD835\uDD5D", |
| 988 |
"loplus":"\u2A2D", |
| 989 |
"lotimes":"\u2A34", |
| 990 |
"lowast":"\u2217", |
| 991 |
"lowbar":"\u005F", |
| 992 |
"LowerLeftArrow":"\u2199", |
| 993 |
"LowerRightArrow":"\u2198", |
| 994 |
"loz":"\u25CA", |
| 995 |
"lozenge":"\u25CA", |
| 996 |
"lozf":"\u29EB", |
| 997 |
"lpar":"\u0028", |
| 998 |
"lparlt":"\u2993", |
| 999 |
"lrarr":"\u21C6", |
| 1000 |
"lrcorner":"\u231F", |
| 1001 |
"lrhar":"\u21CB", |
| 1002 |
"lrhard":"\u296D", |
| 1003 |
"lrm":"\u200E", |
| 1004 |
"lrtri":"\u22BF", |
| 1005 |
"lsaquo":"\u2039", |
| 1006 |
"Lscr":"\u2112", |
| 1007 |
"lscr":"\uD835\uDCC1", |
| 1008 |
"Lsh":"\u21B0", |
| 1009 |
"lsh":"\u21B0", |
| 1010 |
"lsim":"\u2272", |
| 1011 |
"lsime":"\u2A8D", |
| 1012 |
"lsimg":"\u2A8F", |
| 1013 |
"lsqb":"\u005B", |
| 1014 |
"lsquo":"\u2018", |
| 1015 |
"lsquor":"\u201A", |
| 1016 |
"Lstrok":"\u0141", |
| 1017 |
"lstrok":"\u0142", |
| 1018 |
"LT":"\u003C", |
| 1019 |
"Lt":"\u226A", |
| 1020 |
"lt":"\u003C", |
| 1021 |
"ltcc":"\u2AA6", |
| 1022 |
"ltcir":"\u2A79", |
| 1023 |
"ltdot":"\u22D6", |
| 1024 |
"lthree":"\u22CB", |
| 1025 |
"ltimes":"\u22C9", |
| 1026 |
"ltlarr":"\u2976", |
| 1027 |
"ltquest":"\u2A7B", |
| 1028 |
"ltri":"\u25C3", |
| 1029 |
"ltrie":"\u22B4", |
| 1030 |
"ltrif":"\u25C2", |
| 1031 |
"ltrPar":"\u2996", |
| 1032 |
"lurdshar":"\u294A", |
| 1033 |
"luruhar":"\u2966", |
| 1034 |
"lvertneqq":"\u2268\uFE00", |
| 1035 |
"lvnE":"\u2268\uFE00", |
| 1036 |
"macr":"\u00AF", |
| 1037 |
"male":"\u2642", |
| 1038 |
"malt":"\u2720", |
| 1039 |
"maltese":"\u2720", |
| 1040 |
"Map":"\u2905", |
| 1041 |
"map":"\u21A6", |
| 1042 |
"mapsto":"\u21A6", |
| 1043 |
"mapstodown":"\u21A7", |
| 1044 |
"mapstoleft":"\u21A4", |
| 1045 |
"mapstoup":"\u21A5", |
| 1046 |
"marker":"\u25AE", |
| 1047 |
"mcomma":"\u2A29", |
| 1048 |
"Mcy":"\u041C", |
| 1049 |
"mcy":"\u043C", |
| 1050 |
"mdash":"\u2014", |
| 1051 |
"mDDot":"\u223A", |
| 1052 |
"measuredangle":"\u2221", |
| 1053 |
"MediumSpace":"\u205F", |
| 1054 |
"Mellintrf":"\u2133", |
| 1055 |
"Mfr":"\uD835\uDD10", |
| 1056 |
"mfr":"\uD835\uDD2A", |
| 1057 |
"mho":"\u2127", |
| 1058 |
"micro":"\u00B5", |
| 1059 |
"mid":"\u2223", |
| 1060 |
"midast":"\u002A", |
| 1061 |
"midcir":"\u2AF0", |
| 1062 |
"middot":"\u00B7", |
| 1063 |
"minus":"\u2212", |
| 1064 |
"minusb":"\u229F", |
| 1065 |
"minusd":"\u2238", |
| 1066 |
"minusdu":"\u2A2A", |
| 1067 |
"MinusPlus":"\u2213", |
| 1068 |
"mlcp":"\u2ADB", |
| 1069 |
"mldr":"\u2026", |
| 1070 |
"mnplus":"\u2213", |
| 1071 |
"models":"\u22A7", |
| 1072 |
"Mopf":"\uD835\uDD44", |
| 1073 |
"mopf":"\uD835\uDD5E", |
| 1074 |
"mp":"\u2213", |
| 1075 |
"Mscr":"\u2133", |
| 1076 |
"mscr":"\uD835\uDCC2", |
| 1077 |
"mstpos":"\u223E", |
| 1078 |
"Mu":"\u039C", |
| 1079 |
"mu":"\u03BC", |
| 1080 |
"multimap":"\u22B8", |
| 1081 |
"mumap":"\u22B8", |
| 1082 |
"nabla":"\u2207", |
| 1083 |
"Nacute":"\u0143", |
| 1084 |
"nacute":"\u0144", |
| 1085 |
"nang":"\u2220\u20D2", |
| 1086 |
"nap":"\u2249", |
| 1087 |
"napE":"\u2A70\u0338", |
| 1088 |
"napid":"\u224B\u0338", |
| 1089 |
"napos":"\u0149", |
| 1090 |
"napprox":"\u2249", |
| 1091 |
"natur":"\u266E", |
| 1092 |
"natural":"\u266E", |
| 1093 |
"naturals":"\u2115", |
| 1094 |
"nbsp":"\u00A0", |
| 1095 |
"nbump":"\u224E\u0338", |
| 1096 |
"nbumpe":"\u224F\u0338", |
| 1097 |
"ncap":"\u2A43", |
| 1098 |
"Ncaron":"\u0147", |
| 1099 |
"ncaron":"\u0148", |
| 1100 |
"Ncedil":"\u0145", |
| 1101 |
"ncedil":"\u0146", |
| 1102 |
"ncong":"\u2247", |
| 1103 |
"ncongdot":"\u2A6D\u0338", |
| 1104 |
"ncup":"\u2A42", |
| 1105 |
"Ncy":"\u041D", |
| 1106 |
"ncy":"\u043D", |
| 1107 |
"ndash":"\u2013", |
| 1108 |
"ne":"\u2260", |
| 1109 |
"nearhk":"\u2924", |
| 1110 |
"neArr":"\u21D7", |
| 1111 |
"nearr":"\u2197", |
| 1112 |
"nearrow":"\u2197", |
| 1113 |
"nedot":"\u2250\u0338", |
| 1114 |
"NegativeMediumSpace":"\u200B", |
| 1115 |
"NegativeThickSpace":"\u200B", |
| 1116 |
"NegativeThinSpace":"\u200B", |
| 1117 |
"NegativeVeryThinSpace":"\u200B", |
| 1118 |
"nequiv":"\u2262", |
| 1119 |
"nesear":"\u2928", |
| 1120 |
"nesim":"\u2242\u0338", |
| 1121 |
"NestedGreaterGreater":"\u226B", |
| 1122 |
"NestedLessLess":"\u226A", |
| 1123 |
"NewLine":"\u000A", |
| 1124 |
"nexist":"\u2204", |
| 1125 |
"nexists":"\u2204", |
| 1126 |
"Nfr":"\uD835\uDD11", |
| 1127 |
"nfr":"\uD835\uDD2B", |
| 1128 |
"ngE":"\u2267\u0338", |
| 1129 |
"nge":"\u2271", |
| 1130 |
"ngeq":"\u2271", |
| 1131 |
"ngeqq":"\u2267\u0338", |
| 1132 |
"ngeqslant":"\u2A7E\u0338", |
| 1133 |
"nges":"\u2A7E\u0338", |
| 1134 |
"nGg":"\u22D9\u0338", |
| 1135 |
"ngsim":"\u2275", |
| 1136 |
"nGt":"\u226B\u20D2", |
| 1137 |
"ngt":"\u226F", |
| 1138 |
"ngtr":"\u226F", |
| 1139 |
"nGtv":"\u226B\u0338", |
| 1140 |
"nhArr":"\u21CE", |
| 1141 |
"nharr":"\u21AE", |
| 1142 |
"nhpar":"\u2AF2", |
| 1143 |
"ni":"\u220B", |
| 1144 |
"nis":"\u22FC", |
| 1145 |
"nisd":"\u22FA", |
| 1146 |
"niv":"\u220B", |
| 1147 |
"NJcy":"\u040A", |
| 1148 |
"njcy":"\u045A", |
| 1149 |
"nlArr":"\u21CD", |
| 1150 |
"nlarr":"\u219A", |
| 1151 |
"nldr":"\u2025", |
| 1152 |
"nlE":"\u2266\u0338", |
| 1153 |
"nle":"\u2270", |
| 1154 |
"nLeftarrow":"\u21CD", |
| 1155 |
"nleftarrow":"\u219A", |
| 1156 |
"nLeftrightarrow":"\u21CE", |
| 1157 |
"nleftrightarrow":"\u21AE", |
| 1158 |
"nleq":"\u2270", |
| 1159 |
"nleqq":"\u2266\u0338", |
| 1160 |
"nleqslant":"\u2A7D\u0338", |
| 1161 |
"nles":"\u2A7D\u0338", |
| 1162 |
"nless":"\u226E", |
| 1163 |
"nLl":"\u22D8\u0338", |
| 1164 |
"nlsim":"\u2274", |
| 1165 |
"nLt":"\u226A\u20D2", |
| 1166 |
"nlt":"\u226E", |
| 1167 |
"nltri":"\u22EA", |
| 1168 |
"nltrie":"\u22EC", |
| 1169 |
"nLtv":"\u226A\u0338", |
| 1170 |
"nmid":"\u2224", |
| 1171 |
"NoBreak":"\u2060", |
| 1172 |
"NonBreakingSpace":"\u00A0", |
| 1173 |
"Nopf":"\u2115", |
| 1174 |
"nopf":"\uD835\uDD5F", |
| 1175 |
"Not":"\u2AEC", |
| 1176 |
"not":"\u00AC", |
| 1177 |
"NotCongruent":"\u2262", |
| 1178 |
"NotCupCap":"\u226D", |
| 1179 |
"NotDoubleVerticalBar":"\u2226", |
| 1180 |
"NotElement":"\u2209", |
| 1181 |
"NotEqual":"\u2260", |
| 1182 |
"NotEqualTilde":"\u2242\u0338", |
| 1183 |
"NotExists":"\u2204", |
| 1184 |
"NotGreater":"\u226F", |
| 1185 |
"NotGreaterEqual":"\u2271", |
| 1186 |
"NotGreaterFullEqual":"\u2267\u0338", |
| 1187 |
"NotGreaterGreater":"\u226B\u0338", |
| 1188 |
"NotGreaterLess":"\u2279", |
| 1189 |
"NotGreaterSlantEqual":"\u2A7E\u0338", |
| 1190 |
"NotGreaterTilde":"\u2275", |
| 1191 |
"NotHumpDownHump":"\u224E\u0338", |
| 1192 |
"NotHumpEqual":"\u224F\u0338", |
| 1193 |
"notin":"\u2209", |
| 1194 |
"notindot":"\u22F5\u0338", |
| 1195 |
"notinE":"\u22F9\u0338", |
| 1196 |
"notinva":"\u2209", |
| 1197 |
"notinvb":"\u22F7", |
| 1198 |
"notinvc":"\u22F6", |
| 1199 |
"NotLeftTriangle":"\u22EA", |
| 1200 |
"NotLeftTriangleBar":"\u29CF\u0338", |
| 1201 |
"NotLeftTriangleEqual":"\u22EC", |
| 1202 |
"NotLess":"\u226E", |
| 1203 |
"NotLessEqual":"\u2270", |
| 1204 |
"NotLessGreater":"\u2278", |
| 1205 |
"NotLessLess":"\u226A\u0338", |
| 1206 |
"NotLessSlantEqual":"\u2A7D\u0338", |
| 1207 |
"NotLessTilde":"\u2274", |
| 1208 |
"NotNestedGreaterGreater":"\u2AA2\u0338", |
| 1209 |
"NotNestedLessLess":"\u2AA1\u0338", |
| 1210 |
"notni":"\u220C", |
| 1211 |
"notniva":"\u220C", |
| 1212 |
"notnivb":"\u22FE", |
| 1213 |
"notnivc":"\u22FD", |
| 1214 |
"NotPrecedes":"\u2280", |
| 1215 |
"NotPrecedesEqual":"\u2AAF\u0338", |
| 1216 |
"NotPrecedesSlantEqual":"\u22E0", |
| 1217 |
"NotReverseElement":"\u220C", |
| 1218 |
"NotRightTriangle":"\u22EB", |
| 1219 |
"NotRightTriangleBar":"\u29D0\u0338", |
| 1220 |
"NotRightTriangleEqual":"\u22ED", |
| 1221 |
"NotSquareSubset":"\u228F\u0338", |
| 1222 |
"NotSquareSubsetEqual":"\u22E2", |
| 1223 |
"NotSquareSuperset":"\u2290\u0338", |
| 1224 |
"NotSquareSupersetEqual":"\u22E3", |
| 1225 |
"NotSubset":"\u2282\u20D2", |
| 1226 |
"NotSubsetEqual":"\u2288", |
| 1227 |
"NotSucceeds":"\u2281", |
| 1228 |
"NotSucceedsEqual":"\u2AB0\u0338", |
| 1229 |
"NotSucceedsSlantEqual":"\u22E1", |
| 1230 |
"NotSucceedsTilde":"\u227F\u0338", |
| 1231 |
"NotSuperset":"\u2283\u20D2", |
| 1232 |
"NotSupersetEqual":"\u2289", |
| 1233 |
"NotTilde":"\u2241", |
| 1234 |
"NotTildeEqual":"\u2244", |
| 1235 |
"NotTildeFullEqual":"\u2247", |
| 1236 |
"NotTildeTilde":"\u2249", |
| 1237 |
"NotVerticalBar":"\u2224", |
| 1238 |
"npar":"\u2226", |
| 1239 |
"nparallel":"\u2226", |
| 1240 |
"nparsl":"\u2AFD\u20E5", |
| 1241 |
"npart":"\u2202\u0338", |
| 1242 |
"npolint":"\u2A14", |
| 1243 |
"npr":"\u2280", |
| 1244 |
"nprcue":"\u22E0", |
| 1245 |
"npre":"\u2AAF\u0338", |
| 1246 |
"nprec":"\u2280", |
| 1247 |
"npreceq":"\u2AAF\u0338", |
| 1248 |
"nrArr":"\u21CF", |
| 1249 |
"nrarr":"\u219B", |
| 1250 |
"nrarrc":"\u2933\u0338", |
| 1251 |
"nrarrw":"\u219D\u0338", |
| 1252 |
"nRightarrow":"\u21CF", |
| 1253 |
"nrightarrow":"\u219B", |
| 1254 |
"nrtri":"\u22EB", |
| 1255 |
"nrtrie":"\u22ED", |
| 1256 |
"nsc":"\u2281", |
| 1257 |
"nsccue":"\u22E1", |
| 1258 |
"nsce":"\u2AB0\u0338", |
| 1259 |
"Nscr":"\uD835\uDCA9", |
| 1260 |
"nscr":"\uD835\uDCC3", |
| 1261 |
"nshortmid":"\u2224", |
| 1262 |
"nshortparallel":"\u2226", |
| 1263 |
"nsim":"\u2241", |
| 1264 |
"nsime":"\u2244", |
| 1265 |
"nsimeq":"\u2244", |
| 1266 |
"nsmid":"\u2224", |
| 1267 |
"nspar":"\u2226", |
| 1268 |
"nsqsube":"\u22E2", |
| 1269 |
"nsqsupe":"\u22E3", |
| 1270 |
"nsub":"\u2284", |
| 1271 |
"nsubE":"\u2AC5\u0338", |
| 1272 |
"nsube":"\u2288", |
| 1273 |
"nsubset":"\u2282\u20D2", |
| 1274 |
"nsubseteq":"\u2288", |
| 1275 |
"nsubseteqq":"\u2AC5\u0338", |
| 1276 |
"nsucc":"\u2281", |
| 1277 |
"nsucceq":"\u2AB0\u0338", |
| 1278 |
"nsup":"\u2285", |
| 1279 |
"nsupE":"\u2AC6\u0338", |
| 1280 |
"nsupe":"\u2289", |
| 1281 |
"nsupset":"\u2283\u20D2", |
| 1282 |
"nsupseteq":"\u2289", |
| 1283 |
"nsupseteqq":"\u2AC6\u0338", |
| 1284 |
"ntgl":"\u2279", |
| 1285 |
"Ntilde":"\u00D1", |
| 1286 |
"ntilde":"\u00F1", |
| 1287 |
"ntlg":"\u2278", |
| 1288 |
"ntriangleleft":"\u22EA", |
| 1289 |
"ntrianglelefteq":"\u22EC", |
| 1290 |
"ntriangleright":"\u22EB", |
| 1291 |
"ntrianglerighteq":"\u22ED", |
| 1292 |
"Nu":"\u039D", |
| 1293 |
"nu":"\u03BD", |
| 1294 |
"num":"\u0023", |
| 1295 |
"numero":"\u2116", |
| 1296 |
"numsp":"\u2007", |
| 1297 |
"nvap":"\u224D\u20D2", |
| 1298 |
"nVDash":"\u22AF", |
| 1299 |
"nVdash":"\u22AE", |
| 1300 |
"nvDash":"\u22AD", |
| 1301 |
"nvdash":"\u22AC", |
| 1302 |
"nvge":"\u2265\u20D2", |
| 1303 |
"nvgt":"\u003E\u20D2", |
| 1304 |
"nvHarr":"\u2904", |
| 1305 |
"nvinfin":"\u29DE", |
| 1306 |
"nvlArr":"\u2902", |
| 1307 |
"nvle":"\u2264\u20D2", |
| 1308 |
"nvlt":"\u003C\u20D2", |
| 1309 |
"nvltrie":"\u22B4\u20D2", |
| 1310 |
"nvrArr":"\u2903", |
| 1311 |
"nvrtrie":"\u22B5\u20D2", |
| 1312 |
"nvsim":"\u223C\u20D2", |
| 1313 |
"nwarhk":"\u2923", |
| 1314 |
"nwArr":"\u21D6", |
| 1315 |
"nwarr":"\u2196", |
| 1316 |
"nwarrow":"\u2196", |
| 1317 |
"nwnear":"\u2927", |
| 1318 |
"Oacute":"\u00D3", |
| 1319 |
"oacute":"\u00F3", |
| 1320 |
"oast":"\u229B", |
| 1321 |
"ocir":"\u229A", |
| 1322 |
"Ocirc":"\u00D4", |
| 1323 |
"ocirc":"\u00F4", |
| 1324 |
"Ocy":"\u041E", |
| 1325 |
"ocy":"\u043E", |
| 1326 |
"odash":"\u229D", |
| 1327 |
"Odblac":"\u0150", |
| 1328 |
"odblac":"\u0151", |
| 1329 |
"odiv":"\u2A38", |
| 1330 |
"odot":"\u2299", |
| 1331 |
"odsold":"\u29BC", |
| 1332 |
"OElig":"\u0152", |
| 1333 |
"oelig":"\u0153", |
| 1334 |
"ofcir":"\u29BF", |
| 1335 |
"Ofr":"\uD835\uDD12", |
| 1336 |
"ofr":"\uD835\uDD2C", |
| 1337 |
"ogon":"\u02DB", |
| 1338 |
"Ograve":"\u00D2", |
| 1339 |
"ograve":"\u00F2", |
| 1340 |
"ogt":"\u29C1", |
| 1341 |
"ohbar":"\u29B5", |
| 1342 |
"ohm":"\u03A9", |
| 1343 |
"oint":"\u222E", |
| 1344 |
"olarr":"\u21BA", |
| 1345 |
"olcir":"\u29BE", |
| 1346 |
"olcross":"\u29BB", |
| 1347 |
"oline":"\u203E", |
| 1348 |
"olt":"\u29C0", |
| 1349 |
"Omacr":"\u014C", |
| 1350 |
"omacr":"\u014D", |
| 1351 |
"Omega":"\u03A9", |
| 1352 |
"omega":"\u03C9", |
| 1353 |
"Omicron":"\u039F", |
| 1354 |
"omicron":"\u03BF", |
| 1355 |
"omid":"\u29B6", |
| 1356 |
"ominus":"\u2296", |
| 1357 |
"Oopf":"\uD835\uDD46", |
| 1358 |
"oopf":"\uD835\uDD60", |
| 1359 |
"opar":"\u29B7", |
| 1360 |
"OpenCurlyDoubleQuote":"\u201C", |
| 1361 |
"OpenCurlyQuote":"\u2018", |
| 1362 |
"operp":"\u29B9", |
| 1363 |
"oplus":"\u2295", |
| 1364 |
"Or":"\u2A54", |
| 1365 |
"or":"\u2228", |
| 1366 |
"orarr":"\u21BB", |
| 1367 |
"ord":"\u2A5D", |
| 1368 |
"order":"\u2134", |
| 1369 |
"orderof":"\u2134", |
| 1370 |
"ordf":"\u00AA", |
| 1371 |
"ordm":"\u00BA", |
| 1372 |
"origof":"\u22B6", |
| 1373 |
"oror":"\u2A56", |
| 1374 |
"orslope":"\u2A57", |
| 1375 |
"orv":"\u2A5B", |
| 1376 |
"oS":"\u24C8", |
| 1377 |
"Oscr":"\uD835\uDCAA", |
| 1378 |
"oscr":"\u2134", |
| 1379 |
"Oslash":"\u00D8", |
| 1380 |
"oslash":"\u00F8", |
| 1381 |
"osol":"\u2298", |
| 1382 |
"Otilde":"\u00D5", |
| 1383 |
"otilde":"\u00F5", |
| 1384 |
"Otimes":"\u2A37", |
| 1385 |
"otimes":"\u2297", |
| 1386 |
"otimesas":"\u2A36", |
| 1387 |
"Ouml":"\u00D6", |
| 1388 |
"ouml":"\u00F6", |
| 1389 |
"ovbar":"\u233D", |
| 1390 |
"OverBar":"\u203E", |
| 1391 |
"OverBrace":"\u23DE", |
| 1392 |
"OverBracket":"\u23B4", |
| 1393 |
"OverParenthesis":"\u23DC", |
| 1394 |
"par":"\u2225", |
| 1395 |
"para":"\u00B6", |
| 1396 |
"parallel":"\u2225", |
| 1397 |
"parsim":"\u2AF3", |
| 1398 |
"parsl":"\u2AFD", |
| 1399 |
"part":"\u2202", |
| 1400 |
"PartialD":"\u2202", |
| 1401 |
"Pcy":"\u041F", |
| 1402 |
"pcy":"\u043F", |
| 1403 |
"percnt":"\u0025", |
| 1404 |
"period":"\u002E", |
| 1405 |
"permil":"\u2030", |
| 1406 |
"perp":"\u22A5", |
| 1407 |
"pertenk":"\u2031", |
| 1408 |
"Pfr":"\uD835\uDD13", |
| 1409 |
"pfr":"\uD835\uDD2D", |
| 1410 |
"Phi":"\u03A6", |
| 1411 |
"phi":"\u03C6", |
| 1412 |
"phiv":"\u03D5", |
| 1413 |
"phmmat":"\u2133", |
| 1414 |
"phone":"\u260E", |
| 1415 |
"Pi":"\u03A0", |
| 1416 |
"pi":"\u03C0", |
| 1417 |
"pitchfork":"\u22D4", |
| 1418 |
"piv":"\u03D6", |
| 1419 |
"planck":"\u210F", |
| 1420 |
"planckh":"\u210E", |
| 1421 |
"plankv":"\u210F", |
| 1422 |
"plus":"\u002B", |
| 1423 |
"plusacir":"\u2A23", |
| 1424 |
"plusb":"\u229E", |
| 1425 |
"pluscir":"\u2A22", |
| 1426 |
"plusdo":"\u2214", |
| 1427 |
"plusdu":"\u2A25", |
| 1428 |
"pluse":"\u2A72", |
| 1429 |
"PlusMinus":"\u00B1", |
| 1430 |
"plusmn":"\u00B1", |
| 1431 |
"plussim":"\u2A26", |
| 1432 |
"plustwo":"\u2A27", |
| 1433 |
"pm":"\u00B1", |
| 1434 |
"Poincareplane":"\u210C", |
| 1435 |
"pointint":"\u2A15", |
| 1436 |
"Popf":"\u2119", |
| 1437 |
"popf":"\uD835\uDD61", |
| 1438 |
"pound":"\u00A3", |
| 1439 |
"Pr":"\u2ABB", |
| 1440 |
"pr":"\u227A", |
| 1441 |
"prap":"\u2AB7", |
| 1442 |
"prcue":"\u227C", |
| 1443 |
"prE":"\u2AB3", |
| 1444 |
"pre":"\u2AAF", |
| 1445 |
"prec":"\u227A", |
| 1446 |
"precapprox":"\u2AB7", |
| 1447 |
"preccurlyeq":"\u227C", |
| 1448 |
"Precedes":"\u227A", |
| 1449 |
"PrecedesEqual":"\u2AAF", |
| 1450 |
"PrecedesSlantEqual":"\u227C", |
| 1451 |
"PrecedesTilde":"\u227E", |
| 1452 |
"preceq":"\u2AAF", |
| 1453 |
"precnapprox":"\u2AB9", |
| 1454 |
"precneqq":"\u2AB5", |
| 1455 |
"precnsim":"\u22E8", |
| 1456 |
"precsim":"\u227E", |
| 1457 |
"Prime":"\u2033", |
| 1458 |
"prime":"\u2032", |
| 1459 |
"primes":"\u2119", |
| 1460 |
"prnap":"\u2AB9", |
| 1461 |
"prnE":"\u2AB5", |
| 1462 |
"prnsim":"\u22E8", |
| 1463 |
"prod":"\u220F", |
| 1464 |
"Product":"\u220F", |
| 1465 |
"profalar":"\u232E", |
| 1466 |
"profline":"\u2312", |
| 1467 |
"profsurf":"\u2313", |
| 1468 |
"prop":"\u221D", |
| 1469 |
"Proportion":"\u2237", |
| 1470 |
"Proportional":"\u221D", |
| 1471 |
"propto":"\u221D", |
| 1472 |
"prsim":"\u227E", |
| 1473 |
"prurel":"\u22B0", |
| 1474 |
"Pscr":"\uD835\uDCAB", |
| 1475 |
"pscr":"\uD835\uDCC5", |
| 1476 |
"Psi":"\u03A8", |
| 1477 |
"psi":"\u03C8", |
| 1478 |
"puncsp":"\u2008", |
| 1479 |
"Qfr":"\uD835\uDD14", |
| 1480 |
"qfr":"\uD835\uDD2E", |
| 1481 |
"qint":"\u2A0C", |
| 1482 |
"Qopf":"\u211A", |
| 1483 |
"qopf":"\uD835\uDD62", |
| 1484 |
"qprime":"\u2057", |
| 1485 |
"Qscr":"\uD835\uDCAC", |
| 1486 |
"qscr":"\uD835\uDCC6", |
| 1487 |
"quaternions":"\u210D", |
| 1488 |
"quatint":"\u2A16", |
| 1489 |
"quest":"\u003F", |
| 1490 |
"questeq":"\u225F", |
| 1491 |
"QUOT":"\u0022", |
| 1492 |
"quot":"\u0022", |
| 1493 |
"rAarr":"\u21DB", |
| 1494 |
"race":"\u223D\u0331", |
| 1495 |
"Racute":"\u0154", |
| 1496 |
"racute":"\u0155", |
| 1497 |
"radic":"\u221A", |
| 1498 |
"raemptyv":"\u29B3", |
| 1499 |
"Rang":"\u27EB", |
| 1500 |
"rang":"\u27E9", |
| 1501 |
"rangd":"\u2992", |
| 1502 |
"range":"\u29A5", |
| 1503 |
"rangle":"\u27E9", |
| 1504 |
"raquo":"\u00BB", |
| 1505 |
"Rarr":"\u21A0", |
| 1506 |
"rArr":"\u21D2", |
| 1507 |
"rarr":"\u2192", |
| 1508 |
"rarrap":"\u2975", |
| 1509 |
"rarrb":"\u21E5", |
| 1510 |
"rarrbfs":"\u2920", |
| 1511 |
"rarrc":"\u2933", |
| 1512 |
"rarrfs":"\u291E", |
| 1513 |
"rarrhk":"\u21AA", |
| 1514 |
"rarrlp":"\u21AC", |
| 1515 |
"rarrpl":"\u2945", |
| 1516 |
"rarrsim":"\u2974", |
| 1517 |
"Rarrtl":"\u2916", |
| 1518 |
"rarrtl":"\u21A3", |
| 1519 |
"rarrw":"\u219D", |
| 1520 |
"rAtail":"\u291C", |
| 1521 |
"ratail":"\u291A", |
| 1522 |
"ratio":"\u2236", |
| 1523 |
"rationals":"\u211A", |
| 1524 |
"RBarr":"\u2910", |
| 1525 |
"rBarr":"\u290F", |
| 1526 |
"rbarr":"\u290D", |
| 1527 |
"rbbrk":"\u2773", |
| 1528 |
"rbrace":"\u007D", |
| 1529 |
"rbrack":"\u005D", |
| 1530 |
"rbrke":"\u298C", |
| 1531 |
"rbrksld":"\u298E", |
| 1532 |
"rbrkslu":"\u2990", |
| 1533 |
"Rcaron":"\u0158", |
| 1534 |
"rcaron":"\u0159", |
| 1535 |
"Rcedil":"\u0156", |
| 1536 |
"rcedil":"\u0157", |
| 1537 |
"rceil":"\u2309", |
| 1538 |
"rcub":"\u007D", |
| 1539 |
"Rcy":"\u0420", |
| 1540 |
"rcy":"\u0440", |
| 1541 |
"rdca":"\u2937", |
| 1542 |
"rdldhar":"\u2969", |
| 1543 |
"rdquo":"\u201D", |
| 1544 |
"rdquor":"\u201D", |
| 1545 |
"rdsh":"\u21B3", |
| 1546 |
"Re":"\u211C", |
| 1547 |
"real":"\u211C", |
| 1548 |
"realine":"\u211B", |
| 1549 |
"realpart":"\u211C", |
| 1550 |
"reals":"\u211D", |
| 1551 |
"rect":"\u25AD", |
| 1552 |
"REG":"\u00AE", |
| 1553 |
"reg":"\u00AE", |
| 1554 |
"ReverseElement":"\u220B", |
| 1555 |
"ReverseEquilibrium":"\u21CB", |
| 1556 |
"ReverseUpEquilibrium":"\u296F", |
| 1557 |
"rfisht":"\u297D", |
| 1558 |
"rfloor":"\u230B", |
| 1559 |
"Rfr":"\u211C", |
| 1560 |
"rfr":"\uD835\uDD2F", |
| 1561 |
"rHar":"\u2964", |
| 1562 |
"rhard":"\u21C1", |
| 1563 |
"rharu":"\u21C0", |
| 1564 |
"rharul":"\u296C", |
| 1565 |
"Rho":"\u03A1", |
| 1566 |
"rho":"\u03C1", |
| 1567 |
"rhov":"\u03F1", |
| 1568 |
"RightAngleBracket":"\u27E9", |
| 1569 |
"RightArrow":"\u2192", |
| 1570 |
"Rightarrow":"\u21D2", |
| 1571 |
"rightarrow":"\u2192", |
| 1572 |
"RightArrowBar":"\u21E5", |
| 1573 |
"RightArrowLeftArrow":"\u21C4", |
| 1574 |
"rightarrowtail":"\u21A3", |
| 1575 |
"RightCeiling":"\u2309", |
| 1576 |
"RightDoubleBracket":"\u27E7", |
| 1577 |
"RightDownTeeVector":"\u295D", |
| 1578 |
"RightDownVector":"\u21C2", |
| 1579 |
"RightDownVectorBar":"\u2955", |
| 1580 |
"RightFloor":"\u230B", |
| 1581 |
"rightharpoondown":"\u21C1", |
| 1582 |
"rightharpoonup":"\u21C0", |
| 1583 |
"rightleftarrows":"\u21C4", |
| 1584 |
"rightleftharpoons":"\u21CC", |
| 1585 |
"rightrightarrows":"\u21C9", |
| 1586 |
"rightsquigarrow":"\u219D", |
| 1587 |
"RightTee":"\u22A2", |
| 1588 |
"RightTeeArrow":"\u21A6", |
| 1589 |
"RightTeeVector":"\u295B", |
| 1590 |
"rightthreetimes":"\u22CC", |
| 1591 |
"RightTriangle":"\u22B3", |
| 1592 |
"RightTriangleBar":"\u29D0", |
| 1593 |
"RightTriangleEqual":"\u22B5", |
| 1594 |
"RightUpDownVector":"\u294F", |
| 1595 |
"RightUpTeeVector":"\u295C", |
| 1596 |
"RightUpVector":"\u21BE", |
| 1597 |
"RightUpVectorBar":"\u2954", |
| 1598 |
"RightVector":"\u21C0", |
| 1599 |
"RightVectorBar":"\u2953", |
| 1600 |
"ring":"\u02DA", |
| 1601 |
"risingdotseq":"\u2253", |
| 1602 |
"rlarr":"\u21C4", |
| 1603 |
"rlhar":"\u21CC", |
| 1604 |
"rlm":"\u200F", |
| 1605 |
"rmoust":"\u23B1", |
| 1606 |
"rmoustache":"\u23B1", |
| 1607 |
"rnmid":"\u2AEE", |
| 1608 |
"roang":"\u27ED", |
| 1609 |
"roarr":"\u21FE", |
| 1610 |
"robrk":"\u27E7", |
| 1611 |
"ropar":"\u2986", |
| 1612 |
"Ropf":"\u211D", |
| 1613 |
"ropf":"\uD835\uDD63", |
| 1614 |
"roplus":"\u2A2E", |
| 1615 |
"rotimes":"\u2A35", |
| 1616 |
"RoundImplies":"\u2970", |
| 1617 |
"rpar":"\u0029", |
| 1618 |
"rpargt":"\u2994", |
| 1619 |
"rppolint":"\u2A12", |
| 1620 |
"rrarr":"\u21C9", |
| 1621 |
"Rrightarrow":"\u21DB", |
| 1622 |
"rsaquo":"\u203A", |
| 1623 |
"Rscr":"\u211B", |
| 1624 |
"rscr":"\uD835\uDCC7", |
| 1625 |
"Rsh":"\u21B1", |
| 1626 |
"rsh":"\u21B1", |
| 1627 |
"rsqb":"\u005D", |
| 1628 |
"rsquo":"\u2019", |
| 1629 |
"rsquor":"\u2019", |
| 1630 |
"rthree":"\u22CC", |
| 1631 |
"rtimes":"\u22CA", |
| 1632 |
"rtri":"\u25B9", |
| 1633 |
"rtrie":"\u22B5", |
| 1634 |
"rtrif":"\u25B8", |
| 1635 |
"rtriltri":"\u29CE", |
| 1636 |
"RuleDelayed":"\u29F4", |
| 1637 |
"ruluhar":"\u2968", |
| 1638 |
"rx":"\u211E", |
| 1639 |
"Sacute":"\u015A", |
| 1640 |
"sacute":"\u015B", |
| 1641 |
"sbquo":"\u201A", |
| 1642 |
"Sc":"\u2ABC", |
| 1643 |
"sc":"\u227B", |
| 1644 |
"scap":"\u2AB8", |
| 1645 |
"Scaron":"\u0160", |
| 1646 |
"scaron":"\u0161", |
| 1647 |
"sccue":"\u227D", |
| 1648 |
"scE":"\u2AB4", |
| 1649 |
"sce":"\u2AB0", |
| 1650 |
"Scedil":"\u015E", |
| 1651 |
"scedil":"\u015F", |
| 1652 |
"Scirc":"\u015C", |
| 1653 |
"scirc":"\u015D", |
| 1654 |
"scnap":"\u2ABA", |
| 1655 |
"scnE":"\u2AB6", |
| 1656 |
"scnsim":"\u22E9", |
| 1657 |
"scpolint":"\u2A13", |
| 1658 |
"scsim":"\u227F", |
| 1659 |
"Scy":"\u0421", |
| 1660 |
"scy":"\u0441", |
| 1661 |
"sdot":"\u22C5", |
| 1662 |
"sdotb":"\u22A1", |
| 1663 |
"sdote":"\u2A66", |
| 1664 |
"searhk":"\u2925", |
| 1665 |
"seArr":"\u21D8", |
| 1666 |
"searr":"\u2198", |
| 1667 |
"searrow":"\u2198", |
| 1668 |
"sect":"\u00A7", |
| 1669 |
"semi":"\u003B", |
| 1670 |
"seswar":"\u2929", |
| 1671 |
"setminus":"\u2216", |
| 1672 |
"setmn":"\u2216", |
| 1673 |
"sext":"\u2736", |
| 1674 |
"Sfr":"\uD835\uDD16", |
| 1675 |
"sfr":"\uD835\uDD30", |
| 1676 |
"sfrown":"\u2322", |
| 1677 |
"sharp":"\u266F", |
| 1678 |
"SHCHcy":"\u0429", |
| 1679 |
"shchcy":"\u0449", |
| 1680 |
"SHcy":"\u0428", |
| 1681 |
"shcy":"\u0448", |
| 1682 |
"ShortDownArrow":"\u2193", |
| 1683 |
"ShortLeftArrow":"\u2190", |
| 1684 |
"shortmid":"\u2223", |
| 1685 |
"shortparallel":"\u2225", |
| 1686 |
"ShortRightArrow":"\u2192", |
| 1687 |
"ShortUpArrow":"\u2191", |
| 1688 |
"shy":"\u00AD", |
| 1689 |
"Sigma":"\u03A3", |
| 1690 |
"sigma":"\u03C3", |
| 1691 |
"sigmaf":"\u03C2", |
| 1692 |
"sigmav":"\u03C2", |
| 1693 |
"sim":"\u223C", |
| 1694 |
"simdot":"\u2A6A", |
| 1695 |
"sime":"\u2243", |
| 1696 |
"simeq":"\u2243", |
| 1697 |
"simg":"\u2A9E", |
| 1698 |
"simgE":"\u2AA0", |
| 1699 |
"siml":"\u2A9D", |
| 1700 |
"simlE":"\u2A9F", |
| 1701 |
"simne":"\u2246", |
| 1702 |
"simplus":"\u2A24", |
| 1703 |
"simrarr":"\u2972", |
| 1704 |
"slarr":"\u2190", |
| 1705 |
"SmallCircle":"\u2218", |
| 1706 |
"smallsetminus":"\u2216", |
| 1707 |
"smashp":"\u2A33", |
| 1708 |
"smeparsl":"\u29E4", |
| 1709 |
"smid":"\u2223", |
| 1710 |
"smile":"\u2323", |
| 1711 |
"smt":"\u2AAA", |
| 1712 |
"smte":"\u2AAC", |
| 1713 |
"smtes":"\u2AAC\uFE00", |
| 1714 |
"SOFTcy":"\u042C", |
| 1715 |
"softcy":"\u044C", |
| 1716 |
"sol":"\u002F", |
| 1717 |
"solb":"\u29C4", |
| 1718 |
"solbar":"\u233F", |
| 1719 |
"Sopf":"\uD835\uDD4A", |
| 1720 |
"sopf":"\uD835\uDD64", |
| 1721 |
"spades":"\u2660", |
| 1722 |
"spadesuit":"\u2660", |
| 1723 |
"spar":"\u2225", |
| 1724 |
"sqcap":"\u2293", |
| 1725 |
"sqcaps":"\u2293\uFE00", |
| 1726 |
"sqcup":"\u2294", |
| 1727 |
"sqcups":"\u2294\uFE00", |
| 1728 |
"Sqrt":"\u221A", |
| 1729 |
"sqsub":"\u228F", |
| 1730 |
"sqsube":"\u2291", |
| 1731 |
"sqsubset":"\u228F", |
| 1732 |
"sqsubseteq":"\u2291", |
| 1733 |
"sqsup":"\u2290", |
| 1734 |
"sqsupe":"\u2292", |
| 1735 |
"sqsupset":"\u2290", |
| 1736 |
"sqsupseteq":"\u2292", |
| 1737 |
"squ":"\u25A1", |
| 1738 |
"Square":"\u25A1", |
| 1739 |
"square":"\u25A1", |
| 1740 |
"SquareIntersection":"\u2293", |
| 1741 |
"SquareSubset":"\u228F", |
| 1742 |
"SquareSubsetEqual":"\u2291", |
| 1743 |
"SquareSuperset":"\u2290", |
| 1744 |
"SquareSupersetEqual":"\u2292", |
| 1745 |
"SquareUnion":"\u2294", |
| 1746 |
"squarf":"\u25AA", |
| 1747 |
"squf":"\u25AA", |
| 1748 |
"srarr":"\u2192", |
| 1749 |
"Sscr":"\uD835\uDCAE", |
| 1750 |
"sscr":"\uD835\uDCC8", |
| 1751 |
"ssetmn":"\u2216", |
| 1752 |
"ssmile":"\u2323", |
| 1753 |
"sstarf":"\u22C6", |
| 1754 |
"Star":"\u22C6", |
| 1755 |
"star":"\u2606", |
| 1756 |
"starf":"\u2605", |
| 1757 |
"straightepsilon":"\u03F5", |
| 1758 |
"straightphi":"\u03D5", |
| 1759 |
"strns":"\u00AF", |
| 1760 |
"Sub":"\u22D0", |
| 1761 |
"sub":"\u2282", |
| 1762 |
"subdot":"\u2ABD", |
| 1763 |
"subE":"\u2AC5", |
| 1764 |
"sube":"\u2286", |
| 1765 |
"subedot":"\u2AC3", |
| 1766 |
"submult":"\u2AC1", |
| 1767 |
"subnE":"\u2ACB", |
| 1768 |
"subne":"\u228A", |
| 1769 |
"subplus":"\u2ABF", |
| 1770 |
"subrarr":"\u2979", |
| 1771 |
"Subset":"\u22D0", |
| 1772 |
"subset":"\u2282", |
| 1773 |
"subseteq":"\u2286", |
| 1774 |
"subseteqq":"\u2AC5", |
| 1775 |
"SubsetEqual":"\u2286", |
| 1776 |
"subsetneq":"\u228A", |
| 1777 |
"subsetneqq":"\u2ACB", |
| 1778 |
"subsim":"\u2AC7", |
| 1779 |
"subsub":"\u2AD5", |
| 1780 |
"subsup":"\u2AD3", |
| 1781 |
"succ":"\u227B", |
| 1782 |
"succapprox":"\u2AB8", |
| 1783 |
"succcurlyeq":"\u227D", |
| 1784 |
"Succeeds":"\u227B", |
| 1785 |
"SucceedsEqual":"\u2AB0", |
| 1786 |
"SucceedsSlantEqual":"\u227D", |
| 1787 |
"SucceedsTilde":"\u227F", |
| 1788 |
"succeq":"\u2AB0", |
| 1789 |
"succnapprox":"\u2ABA", |
| 1790 |
"succneqq":"\u2AB6", |
| 1791 |
"succnsim":"\u22E9", |
| 1792 |
"succsim":"\u227F", |
| 1793 |
"SuchThat":"\u220B", |
| 1794 |
"Sum":"\u2211", |
| 1795 |
"sum":"\u2211", |
| 1796 |
"sung":"\u266A", |
| 1797 |
"Sup":"\u22D1", |
| 1798 |
"sup":"\u2283", |
| 1799 |
"sup1":"\u00B9", |
| 1800 |
"sup2":"\u00B2", |
| 1801 |
"sup3":"\u00B3", |
| 1802 |
"supdot":"\u2ABE", |
| 1803 |
"supdsub":"\u2AD8", |
| 1804 |
"supE":"\u2AC6", |
| 1805 |
"supe":"\u2287", |
| 1806 |
"supedot":"\u2AC4", |
| 1807 |
"Superset":"\u2283", |
| 1808 |
"SupersetEqual":"\u2287", |
| 1809 |
"suphsol":"\u27C9", |
| 1810 |
"suphsub":"\u2AD7", |
| 1811 |
"suplarr":"\u297B", |
| 1812 |
"supmult":"\u2AC2", |
| 1813 |
"supnE":"\u2ACC", |
| 1814 |
"supne":"\u228B", |
| 1815 |
"supplus":"\u2AC0", |
| 1816 |
"Supset":"\u22D1", |
| 1817 |
"supset":"\u2283", |
| 1818 |
"supseteq":"\u2287", |
| 1819 |
"supseteqq":"\u2AC6", |
| 1820 |
"supsetneq":"\u228B", |
| 1821 |
"supsetneqq":"\u2ACC", |
| 1822 |
"supsim":"\u2AC8", |
| 1823 |
"supsub":"\u2AD4", |
| 1824 |
"supsup":"\u2AD6", |
| 1825 |
"swarhk":"\u2926", |
| 1826 |
"swArr":"\u21D9", |
| 1827 |
"swarr":"\u2199", |
| 1828 |
"swarrow":"\u2199", |
| 1829 |
"swnwar":"\u292A", |
| 1830 |
"szlig":"\u00DF", |
| 1831 |
"Tab":"\u0009", |
| 1832 |
"target":"\u2316", |
| 1833 |
"Tau":"\u03A4", |
| 1834 |
"tau":"\u03C4", |
| 1835 |
"tbrk":"\u23B4", |
| 1836 |
"Tcaron":"\u0164", |
| 1837 |
"tcaron":"\u0165", |
| 1838 |
"Tcedil":"\u0162", |
| 1839 |
"tcedil":"\u0163", |
| 1840 |
"Tcy":"\u0422", |
| 1841 |
"tcy":"\u0442", |
| 1842 |
"tdot":"\u20DB", |
| 1843 |
"telrec":"\u2315", |
| 1844 |
"Tfr":"\uD835\uDD17", |
| 1845 |
"tfr":"\uD835\uDD31", |
| 1846 |
"there4":"\u2234", |
| 1847 |
"Therefore":"\u2234", |
| 1848 |
"therefore":"\u2234", |
| 1849 |
"Theta":"\u0398", |
| 1850 |
"theta":"\u03B8", |
| 1851 |
"thetasym":"\u03D1", |
| 1852 |
"thetav":"\u03D1", |
| 1853 |
"thickapprox":"\u2248", |
| 1854 |
"thicksim":"\u223C", |
| 1855 |
"ThickSpace":"\u205F\u200A", |
| 1856 |
"thinsp":"\u2009", |
| 1857 |
"ThinSpace":"\u2009", |
| 1858 |
"thkap":"\u2248", |
| 1859 |
"thksim":"\u223C", |
| 1860 |
"THORN":"\u00DE", |
| 1861 |
"thorn":"\u00FE", |
| 1862 |
"Tilde":"\u223C", |
| 1863 |
"tilde":"\u02DC", |
| 1864 |
"TildeEqual":"\u2243", |
| 1865 |
"TildeFullEqual":"\u2245", |
| 1866 |
"TildeTilde":"\u2248", |
| 1867 |
"times":"\u00D7", |
| 1868 |
"timesb":"\u22A0", |
| 1869 |
"timesbar":"\u2A31", |
| 1870 |
"timesd":"\u2A30", |
| 1871 |
"tint":"\u222D", |
| 1872 |
"toea":"\u2928", |
| 1873 |
"top":"\u22A4", |
| 1874 |
"topbot":"\u2336", |
| 1875 |
"topcir":"\u2AF1", |
| 1876 |
"Topf":"\uD835\uDD4B", |
| 1877 |
"topf":"\uD835\uDD65", |
| 1878 |
"topfork":"\u2ADA", |
| 1879 |
"tosa":"\u2929", |
| 1880 |
"tprime":"\u2034", |
| 1881 |
"TRADE":"\u2122", |
| 1882 |
"trade":"\u2122", |
| 1883 |
"triangle":"\u25B5", |
| 1884 |
"triangledown":"\u25BF", |
| 1885 |
"triangleleft":"\u25C3", |
| 1886 |
"trianglelefteq":"\u22B4", |
| 1887 |
"triangleq":"\u225C", |
| 1888 |
"triangleright":"\u25B9", |
| 1889 |
"trianglerighteq":"\u22B5", |
| 1890 |
"tridot":"\u25EC", |
| 1891 |
"trie":"\u225C", |
| 1892 |
"triminus":"\u2A3A", |
| 1893 |
"TripleDot":"\u20DB", |
| 1894 |
"triplus":"\u2A39", |
| 1895 |
"trisb":"\u29CD", |
| 1896 |
"tritime":"\u2A3B", |
| 1897 |
"trpezium":"\u23E2", |
| 1898 |
"Tscr":"\uD835\uDCAF", |
| 1899 |
"tscr":"\uD835\uDCC9", |
| 1900 |
"TScy":"\u0426", |
| 1901 |
"tscy":"\u0446", |
| 1902 |
"TSHcy":"\u040B", |
| 1903 |
"tshcy":"\u045B", |
| 1904 |
"Tstrok":"\u0166", |
| 1905 |
"tstrok":"\u0167", |
| 1906 |
"twixt":"\u226C", |
| 1907 |
"twoheadleftarrow":"\u219E", |
| 1908 |
"twoheadrightarrow":"\u21A0", |
| 1909 |
"Uacute":"\u00DA", |
| 1910 |
"uacute":"\u00FA", |
| 1911 |
"Uarr":"\u219F", |
| 1912 |
"uArr":"\u21D1", |
| 1913 |
"uarr":"\u2191", |
| 1914 |
"Uarrocir":"\u2949", |
| 1915 |
"Ubrcy":"\u040E", |
| 1916 |
"ubrcy":"\u045E", |
| 1917 |
"Ubreve":"\u016C", |
| 1918 |
"ubreve":"\u016D", |
| 1919 |
"Ucirc":"\u00DB", |
| 1920 |
"ucirc":"\u00FB", |
| 1921 |
"Ucy":"\u0423", |
| 1922 |
"ucy":"\u0443", |
| 1923 |
"udarr":"\u21C5", |
| 1924 |
"Udblac":"\u0170", |
| 1925 |
"udblac":"\u0171", |
| 1926 |
"udhar":"\u296E", |
| 1927 |
"ufisht":"\u297E", |
| 1928 |
"Ufr":"\uD835\uDD18", |
| 1929 |
"ufr":"\uD835\uDD32", |
| 1930 |
"Ugrave":"\u00D9", |
| 1931 |
"ugrave":"\u00F9", |
| 1932 |
"uHar":"\u2963", |
| 1933 |
"uharl":"\u21BF", |
| 1934 |
"uharr":"\u21BE", |
| 1935 |
"uhblk":"\u2580", |
| 1936 |
"ulcorn":"\u231C", |
| 1937 |
"ulcorner":"\u231C", |
| 1938 |
"ulcrop":"\u230F", |
| 1939 |
"ultri":"\u25F8", |
| 1940 |
"Umacr":"\u016A", |
| 1941 |
"umacr":"\u016B", |
| 1942 |
"uml":"\u00A8", |
| 1943 |
"UnderBar":"\u005F", |
| 1944 |
"UnderBrace":"\u23DF", |
| 1945 |
"UnderBracket":"\u23B5", |
| 1946 |
"UnderParenthesis":"\u23DD", |
| 1947 |
"Union":"\u22C3", |
| 1948 |
"UnionPlus":"\u228E", |
| 1949 |
"Uogon":"\u0172", |
| 1950 |
"uogon":"\u0173", |
| 1951 |
"Uopf":"\uD835\uDD4C", |
| 1952 |
"uopf":"\uD835\uDD66", |
| 1953 |
"UpArrow":"\u2191", |
| 1954 |
"Uparrow":"\u21D1", |
| 1955 |
"uparrow":"\u2191", |
| 1956 |
"UpArrowBar":"\u2912", |
| 1957 |
"UpArrowDownArrow":"\u21C5", |
| 1958 |
"UpDownArrow":"\u2195", |
| 1959 |
"Updownarrow":"\u21D5", |
| 1960 |
"updownarrow":"\u2195", |
| 1961 |
"UpEquilibrium":"\u296E", |
| 1962 |
"upharpoonleft":"\u21BF", |
| 1963 |
"upharpoonright":"\u21BE", |
| 1964 |
"uplus":"\u228E", |
| 1965 |
"UpperLeftArrow":"\u2196", |
| 1966 |
"UpperRightArrow":"\u2197", |
| 1967 |
"Upsi":"\u03D2", |
| 1968 |
"upsi":"\u03C5", |
| 1969 |
"upsih":"\u03D2", |
| 1970 |
"Upsilon":"\u03A5", |
| 1971 |
"upsilon":"\u03C5", |
| 1972 |
"UpTee":"\u22A5", |
| 1973 |
"UpTeeArrow":"\u21A5", |
| 1974 |
"upuparrows":"\u21C8", |
| 1975 |
"urcorn":"\u231D", |
| 1976 |
"urcorner":"\u231D", |
| 1977 |
"urcrop":"\u230E", |
| 1978 |
"Uring":"\u016E", |
| 1979 |
"uring":"\u016F", |
| 1980 |
"urtri":"\u25F9", |
| 1981 |
"Uscr":"\uD835\uDCB0", |
| 1982 |
"uscr":"\uD835\uDCCA", |
| 1983 |
"utdot":"\u22F0", |
| 1984 |
"Utilde":"\u0168", |
| 1985 |
"utilde":"\u0169", |
| 1986 |
"utri":"\u25B5", |
| 1987 |
"utrif":"\u25B4", |
| 1988 |
"uuarr":"\u21C8", |
| 1989 |
"Uuml":"\u00DC", |
| 1990 |
"uuml":"\u00FC", |
| 1991 |
"uwangle":"\u29A7", |
| 1992 |
"vangrt":"\u299C", |
| 1993 |
"varepsilon":"\u03F5", |
| 1994 |
"varkappa":"\u03F0", |
| 1995 |
"varnothing":"\u2205", |
| 1996 |
"varphi":"\u03D5", |
| 1997 |
"varpi":"\u03D6", |
| 1998 |
"varpropto":"\u221D", |
| 1999 |
"vArr":"\u21D5", |
| 2000 |
"varr":"\u2195", |
| 2001 |
"varrho":"\u03F1", |
| 2002 |
"varsigma":"\u03C2", |
| 2003 |
"varsubsetneq":"\u228A\uFE00", |
| 2004 |
"varsubsetneqq":"\u2ACB\uFE00", |
| 2005 |
"varsupsetneq":"\u228B\uFE00", |
| 2006 |
"varsupsetneqq":"\u2ACC\uFE00", |
| 2007 |
"vartheta":"\u03D1", |
| 2008 |
"vartriangleleft":"\u22B2", |
| 2009 |
"vartriangleright":"\u22B3", |
| 2010 |
"Vbar":"\u2AEB", |
| 2011 |
"vBar":"\u2AE8", |
| 2012 |
"vBarv":"\u2AE9", |
| 2013 |
"Vcy":"\u0412", |
| 2014 |
"vcy":"\u0432", |
| 2015 |
"VDash":"\u22AB", |
| 2016 |
"Vdash":"\u22A9", |
| 2017 |
"vDash":"\u22A8", |
| 2018 |
"vdash":"\u22A2", |
| 2019 |
"Vdashl":"\u2AE6", |
| 2020 |
"Vee":"\u22C1", |
| 2021 |
"vee":"\u2228", |
| 2022 |
"veebar":"\u22BB", |
| 2023 |
"veeeq":"\u225A", |
| 2024 |
"vellip":"\u22EE", |
| 2025 |
"Verbar":"\u2016", |
| 2026 |
"verbar":"\u007C", |
| 2027 |
"Vert":"\u2016", |
| 2028 |
"vert":"\u007C", |
| 2029 |
"VerticalBar":"\u2223", |
| 2030 |
"VerticalLine":"\u007C", |
| 2031 |
"VerticalSeparator":"\u2758", |
| 2032 |
"VerticalTilde":"\u2240", |
| 2033 |
"VeryThinSpace":"\u200A", |
| 2034 |
"Vfr":"\uD835\uDD19", |
| 2035 |
"vfr":"\uD835\uDD33", |
| 2036 |
"vltri":"\u22B2", |
| 2037 |
"vnsub":"\u2282\u20D2", |
| 2038 |
"vnsup":"\u2283\u20D2", |
| 2039 |
"Vopf":"\uD835\uDD4D", |
| 2040 |
"vopf":"\uD835\uDD67", |
| 2041 |
"vprop":"\u221D", |
| 2042 |
"vrtri":"\u22B3", |
| 2043 |
"Vscr":"\uD835\uDCB1", |
| 2044 |
"vscr":"\uD835\uDCCB", |
| 2045 |
"vsubnE":"\u2ACB\uFE00", |
| 2046 |
"vsubne":"\u228A\uFE00", |
| 2047 |
"vsupnE":"\u2ACC\uFE00", |
| 2048 |
"vsupne":"\u228B\uFE00", |
| 2049 |
"Vvdash":"\u22AA", |
| 2050 |
"vzigzag":"\u299A", |
| 2051 |
"Wcirc":"\u0174", |
| 2052 |
"wcirc":"\u0175", |
| 2053 |
"wedbar":"\u2A5F", |
| 2054 |
"Wedge":"\u22C0", |
| 2055 |
"wedge":"\u2227", |
| 2056 |
"wedgeq":"\u2259", |
| 2057 |
"weierp":"\u2118", |
| 2058 |
"Wfr":"\uD835\uDD1A", |
| 2059 |
"wfr":"\uD835\uDD34", |
| 2060 |
"Wopf":"\uD835\uDD4E", |
| 2061 |
"wopf":"\uD835\uDD68", |
| 2062 |
"wp":"\u2118", |
| 2063 |
"wr":"\u2240", |
| 2064 |
"wreath":"\u2240", |
| 2065 |
"Wscr":"\uD835\uDCB2", |
| 2066 |
"wscr":"\uD835\uDCCC", |
| 2067 |
"xcap":"\u22C2", |
| 2068 |
"xcirc":"\u25EF", |
| 2069 |
"xcup":"\u22C3", |
| 2070 |
"xdtri":"\u25BD", |
| 2071 |
"Xfr":"\uD835\uDD1B", |
| 2072 |
"xfr":"\uD835\uDD35", |
| 2073 |
"xhArr":"\u27FA", |
| 2074 |
"xharr":"\u27F7", |
| 2075 |
"Xi":"\u039E", |
| 2076 |
"xi":"\u03BE", |
| 2077 |
"xlArr":"\u27F8", |
| 2078 |
"xlarr":"\u27F5", |
| 2079 |
"xmap":"\u27FC", |
| 2080 |
"xnis":"\u22FB", |
| 2081 |
"xodot":"\u2A00", |
| 2082 |
"Xopf":"\uD835\uDD4F", |
| 2083 |
"xopf":"\uD835\uDD69", |
| 2084 |
"xoplus":"\u2A01", |
| 2085 |
"xotime":"\u2A02", |
| 2086 |
"xrArr":"\u27F9", |
| 2087 |
"xrarr":"\u27F6", |
| 2088 |
"Xscr":"\uD835\uDCB3", |
| 2089 |
"xscr":"\uD835\uDCCD", |
| 2090 |
"xsqcup":"\u2A06", |
| 2091 |
"xuplus":"\u2A04", |
| 2092 |
"xutri":"\u25B3", |
| 2093 |
"xvee":"\u22C1", |
| 2094 |
"xwedge":"\u22C0", |
| 2095 |
"Yacute":"\u00DD", |
| 2096 |
"yacute":"\u00FD", |
| 2097 |
"YAcy":"\u042F", |
| 2098 |
"yacy":"\u044F", |
| 2099 |
"Ycirc":"\u0176", |
| 2100 |
"ycirc":"\u0177", |
| 2101 |
"Ycy":"\u042B", |
| 2102 |
"ycy":"\u044B", |
| 2103 |
"yen":"\u00A5", |
| 2104 |
"Yfr":"\uD835\uDD1C", |
| 2105 |
"yfr":"\uD835\uDD36", |
| 2106 |
"YIcy":"\u0407", |
| 2107 |
"yicy":"\u0457", |
| 2108 |
"Yopf":"\uD835\uDD50", |
| 2109 |
"yopf":"\uD835\uDD6A", |
| 2110 |
"Yscr":"\uD835\uDCB4", |
| 2111 |
"yscr":"\uD835\uDCCE", |
| 2112 |
"YUcy":"\u042E", |
| 2113 |
"yucy":"\u044E", |
| 2114 |
"Yuml":"\u0178", |
| 2115 |
"yuml":"\u00FF", |
| 2116 |
"Zacute":"\u0179", |
| 2117 |
"zacute":"\u017A", |
| 2118 |
"Zcaron":"\u017D", |
| 2119 |
"zcaron":"\u017E", |
| 2120 |
"Zcy":"\u0417", |
| 2121 |
"zcy":"\u0437", |
| 2122 |
"Zdot":"\u017B", |
| 2123 |
"zdot":"\u017C", |
| 2124 |
"zeetrf":"\u2128", |
| 2125 |
"ZeroWidthSpace":"\u200B", |
| 2126 |
"Zeta":"\u0396", |
| 2127 |
"zeta":"\u03B6", |
| 2128 |
"Zfr":"\u2128", |
| 2129 |
"zfr":"\uD835\uDD37", |
| 2130 |
"ZHcy":"\u0416", |
| 2131 |
"zhcy":"\u0436", |
| 2132 |
"zigrarr":"\u21DD", |
| 2133 |
"Zopf":"\u2124", |
| 2134 |
"zopf":"\uD835\uDD6B", |
| 2135 |
"Zscr":"\uD835\uDCB5", |
| 2136 |
"zscr":"\uD835\uDCCF", |
| 2137 |
"zwj":"\u200D", |
| 2138 |
"zwnj":"\u200C" |
| 2139 |
}; |
| 2140 |
|
| 2141 |
var hasOwn = Object.prototype.hasOwnProperty; |
| 2142 |
|
| 2143 |
function has(object, key) { |
| 2144 |
return object |
| 2145 |
? hasOwn.call(object, key) |
| 2146 |
: false; |
| 2147 |
} |
| 2148 |
|
| 2149 |
function decodeEntity(name) { |
| 2150 |
if (has(entities, name)) { |
| 2151 |
return entities[name] |
| 2152 |
} else { |
| 2153 |
return name; |
| 2154 |
} |
| 2155 |
} |
| 2156 |
|
| 2157 |
/** |
| 2158 |
* Utility functions |
| 2159 |
*/ |
| 2160 |
|
| 2161 |
function typeOf(obj) { |
| 2162 |
return Object.prototype.toString.call(obj); |
| 2163 |
} |
| 2164 |
|
| 2165 |
function isString(obj) { |
| 2166 |
return typeOf(obj) === '[object String]'; |
| 2167 |
} |
| 2168 |
|
| 2169 |
var hasOwn$1 = Object.prototype.hasOwnProperty; |
| 2170 |
|
| 2171 |
function has$1(object, key) { |
| 2172 |
return object |
| 2173 |
? hasOwn$1.call(object, key) |
| 2174 |
: false; |
| 2175 |
} |
| 2176 |
|
| 2177 |
// Extend objects |
| 2178 |
// |
| 2179 |
function assign(obj /*from1, from2, from3, ...*/) { |
| 2180 |
var sources = [].slice.call(arguments, 1); |
| 2181 |
|
| 2182 |
sources.forEach(function (source) { |
| 2183 |
if (!source) { return; } |
| 2184 |
|
| 2185 |
if (typeof source !== 'object') { |
| 2186 |
throw new TypeError(source + 'must be object'); |
| 2187 |
} |
| 2188 |
|
| 2189 |
Object.keys(source).forEach(function (key) { |
| 2190 |
obj[key] = source[key]; |
| 2191 |
}); |
| 2192 |
}); |
| 2193 |
|
| 2194 |
return obj; |
| 2195 |
} |
| 2196 |
|
| 2197 |
//////////////////////////////////////////////////////////////////////////////// |
| 2198 |
|
| 2199 |
var UNESCAPE_MD_RE = /\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; |
| 2200 |
|
| 2201 |
function unescapeMd(str) { |
| 2202 |
if (str.indexOf('\\') < 0) { return str; } |
| 2203 |
return str.replace(UNESCAPE_MD_RE, '$1'); |
| 2204 |
} |
| 2205 |
|
| 2206 |
//////////////////////////////////////////////////////////////////////////////// |
| 2207 |
|
| 2208 |
function isValidEntityCode(c) { |
| 2209 |
/*eslint no-bitwise:0*/ |
| 2210 |
// broken sequence |
| 2211 |
if (c >= 0xD800 && c <= 0xDFFF) { return false; } |
| 2212 |
// never used |
| 2213 |
if (c >= 0xFDD0 && c <= 0xFDEF) { return false; } |
| 2214 |
if ((c & 0xFFFF) === 0xFFFF || (c & 0xFFFF) === 0xFFFE) { return false; } |
| 2215 |
// control codes |
| 2216 |
if (c >= 0x00 && c <= 0x08) { return false; } |
| 2217 |
if (c === 0x0B) { return false; } |
| 2218 |
if (c >= 0x0E && c <= 0x1F) { return false; } |
| 2219 |
if (c >= 0x7F && c <= 0x9F) { return false; } |
| 2220 |
// out of range |
| 2221 |
if (c > 0x10FFFF) { return false; } |
| 2222 |
return true; |
| 2223 |
} |
| 2224 |
|
| 2225 |
function fromCodePoint(c) { |
| 2226 |
/*eslint no-bitwise:0*/ |
| 2227 |
if (c > 0xffff) { |
| 2228 |
c -= 0x10000; |
| 2229 |
var surrogate1 = 0xd800 + (c >> 10), |
| 2230 |
surrogate2 = 0xdc00 + (c & 0x3ff); |
| 2231 |
|
| 2232 |
return String.fromCharCode(surrogate1, surrogate2); |
| 2233 |
} |
| 2234 |
return String.fromCharCode(c); |
| 2235 |
} |
| 2236 |
|
| 2237 |
var NAMED_ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi; |
| 2238 |
var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i; |
| 2239 |
|
| 2240 |
function replaceEntityPattern(match, name) { |
| 2241 |
var code = 0; |
| 2242 |
var decoded = decodeEntity(name); |
| 2243 |
|
| 2244 |
if (name !== decoded) { |
| 2245 |
return decoded; |
| 2246 |
} else if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { |
| 2247 |
code = name[1].toLowerCase() === 'x' ? |
| 2248 |
parseInt(name.slice(2), 16) |
| 2249 |
: |
| 2250 |
parseInt(name.slice(1), 10); |
| 2251 |
if (isValidEntityCode(code)) { |
| 2252 |
return fromCodePoint(code); |
| 2253 |
} |
| 2254 |
} |
| 2255 |
return match; |
| 2256 |
} |
| 2257 |
|
| 2258 |
function replaceEntities(str) { |
| 2259 |
if (str.indexOf('&') < 0) { return str; } |
| 2260 |
|
| 2261 |
return str.replace(NAMED_ENTITY_RE, replaceEntityPattern); |
| 2262 |
} |
| 2263 |
|
| 2264 |
//////////////////////////////////////////////////////////////////////////////// |
| 2265 |
|
| 2266 |
var HTML_ESCAPE_TEST_RE = /[&<>"]/; |
| 2267 |
var HTML_ESCAPE_REPLACE_RE = /[&<>"]/g; |
| 2268 |
var HTML_REPLACEMENTS = { |
| 2269 |
'&': '&', |
| 2270 |
'<': '<', |
| 2271 |
'>': '>', |
| 2272 |
'"': '"' |
| 2273 |
}; |
| 2274 |
|
| 2275 |
function replaceUnsafeChar(ch) { |
| 2276 |
return HTML_REPLACEMENTS[ch]; |
| 2277 |
} |
| 2278 |
|
| 2279 |
function escapeHtml(str) { |
| 2280 |
if (HTML_ESCAPE_TEST_RE.test(str)) { |
| 2281 |
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar); |
| 2282 |
} |
| 2283 |
return str; |
| 2284 |
} |
| 2285 |
|
| 2286 |
var utils = /*#__PURE__*/Object.freeze({ |
| 2287 |
isString: isString, |
| 2288 |
has: has$1, |
| 2289 |
assign: assign, |
| 2290 |
unescapeMd: unescapeMd, |
| 2291 |
isValidEntityCode: isValidEntityCode, |
| 2292 |
fromCodePoint: fromCodePoint, |
| 2293 |
replaceEntities: replaceEntities, |
| 2294 |
escapeHtml: escapeHtml |
| 2295 |
}); |
| 2296 |
|
| 2297 |
/** |
| 2298 |
* Renderer rules cache |
| 2299 |
*/ |
| 2300 |
|
| 2301 |
var rules = {}; |
| 2302 |
|
| 2303 |
/** |
| 2304 |
* Blockquotes |
| 2305 |
*/ |
| 2306 |
|
| 2307 |
rules.blockquote_open = function(/* tokens, idx, options, env */) { |
| 2308 |
return '<blockquote>\n'; |
| 2309 |
}; |
| 2310 |
|
| 2311 |
rules.blockquote_close = function(tokens, idx /*, options, env */) { |
| 2312 |
return '</blockquote>' + getBreak(tokens, idx); |
| 2313 |
}; |
| 2314 |
|
| 2315 |
/** |
| 2316 |
* Code |
| 2317 |
*/ |
| 2318 |
|
| 2319 |
rules.code = function(tokens, idx /*, options, env */) { |
| 2320 |
if (tokens[idx].block) { |
| 2321 |
return '<pre><code>' + escapeHtml(tokens[idx].content) + '</code></pre>' + getBreak(tokens, idx); |
| 2322 |
} |
| 2323 |
return '<code>' + escapeHtml(tokens[idx].content) + '</code>'; |
| 2324 |
}; |
| 2325 |
|
| 2326 |
/** |
| 2327 |
* Fenced code blocks |
| 2328 |
*/ |
| 2329 |
|
| 2330 |
rules.fence = function(tokens, idx, options, env, instance) { |
| 2331 |
var token = tokens[idx]; |
| 2332 |
var langClass = ''; |
| 2333 |
var langPrefix = options.langPrefix; |
| 2334 |
var langName = '', fences, fenceName; |
| 2335 |
var highlighted; |
| 2336 |
|
| 2337 |
if (token.params) { |
| 2338 |
|
| 2339 |
// |
| 2340 |
// ```foo bar |
| 2341 |
// |
| 2342 |
// Try custom renderer "foo" first. That will simplify overwrite |
| 2343 |
// for diagrams, latex, and any other fenced block with custom look |
| 2344 |
// |
| 2345 |
|
| 2346 |
fences = token.params.split(/\s+/g); |
| 2347 |
fenceName = fences.join(' '); |
| 2348 |
|
| 2349 |
if (has$1(instance.rules.fence_custom, fences[0])) { |
| 2350 |
return instance.rules.fence_custom[fences[0]](tokens, idx, options, env, instance); |
| 2351 |
} |
| 2352 |
|
| 2353 |
langName = escapeHtml(replaceEntities(unescapeMd(fenceName))); |
| 2354 |
langClass = ' class="' + langPrefix + langName + '"'; |
| 2355 |
} |
| 2356 |
|
| 2357 |
if (options.highlight) { |
| 2358 |
highlighted = options.highlight.apply(options.highlight, [ token.content ].concat(fences)) |
| 2359 |
|| escapeHtml(token.content); |
| 2360 |
} else { |
| 2361 |
highlighted = escapeHtml(token.content); |
| 2362 |
} |
| 2363 |
|
| 2364 |
return '<pre><code' + langClass + '>' |
| 2365 |
+ highlighted |
| 2366 |
+ '</code></pre>' |
| 2367 |
+ getBreak(tokens, idx); |
| 2368 |
}; |
| 2369 |
|
| 2370 |
rules.fence_custom = {}; |
| 2371 |
|
| 2372 |
/** |
| 2373 |
* Headings |
| 2374 |
*/ |
| 2375 |
|
| 2376 |
rules.heading_open = function(tokens, idx /*, options, env */) { |
| 2377 |
return '<h' + tokens[idx].hLevel + '>'; |
| 2378 |
}; |
| 2379 |
rules.heading_close = function(tokens, idx /*, options, env */) { |
| 2380 |
return '</h' + tokens[idx].hLevel + '>\n'; |
| 2381 |
}; |
| 2382 |
|
| 2383 |
/** |
| 2384 |
* Horizontal rules |
| 2385 |
*/ |
| 2386 |
|
| 2387 |
rules.hr = function(tokens, idx, options /*, env */) { |
| 2388 |
return (options.xhtmlOut ? '<hr />' : '<hr>') + getBreak(tokens, idx); |
| 2389 |
}; |
| 2390 |
|
| 2391 |
/** |
| 2392 |
* Bullets |
| 2393 |
*/ |
| 2394 |
|
| 2395 |
rules.bullet_list_open = function(/* tokens, idx, options, env */) { |
| 2396 |
return '<ul>\n'; |
| 2397 |
}; |
| 2398 |
rules.bullet_list_close = function(tokens, idx /*, options, env */) { |
| 2399 |
return '</ul>' + getBreak(tokens, idx); |
| 2400 |
}; |
| 2401 |
|
| 2402 |
/** |
| 2403 |
* List items |
| 2404 |
*/ |
| 2405 |
|
| 2406 |
rules.list_item_open = function(/* tokens, idx, options, env */) { |
| 2407 |
return '<li>'; |
| 2408 |
}; |
| 2409 |
rules.list_item_close = function(/* tokens, idx, options, env */) { |
| 2410 |
return '</li>\n'; |
| 2411 |
}; |
| 2412 |
|
| 2413 |
/** |
| 2414 |
* Ordered list items |
| 2415 |
*/ |
| 2416 |
|
| 2417 |
rules.ordered_list_open = function(tokens, idx /*, options, env */) { |
| 2418 |
var token = tokens[idx]; |
| 2419 |
var order = token.order > 1 ? ' start="' + token.order + '"' : ''; |
| 2420 |
return '<ol' + order + '>\n'; |
| 2421 |
}; |
| 2422 |
rules.ordered_list_close = function(tokens, idx /*, options, env */) { |
| 2423 |
return '</ol>' + getBreak(tokens, idx); |
| 2424 |
}; |
| 2425 |
|
| 2426 |
/** |
| 2427 |
* Paragraphs |
| 2428 |
*/ |
| 2429 |
|
| 2430 |
rules.paragraph_open = function(tokens, idx /*, options, env */) { |
| 2431 |
return tokens[idx].tight ? '' : '<p>'; |
| 2432 |
}; |
| 2433 |
rules.paragraph_close = function(tokens, idx /*, options, env */) { |
| 2434 |
var addBreak = !(tokens[idx].tight && idx && tokens[idx - 1].type === 'inline' && !tokens[idx - 1].content); |
| 2435 |
return (tokens[idx].tight ? '' : '</p>') + (addBreak ? getBreak(tokens, idx) : ''); |
| 2436 |
}; |
| 2437 |
|
| 2438 |
/** |
| 2439 |
* Links |
| 2440 |
*/ |
| 2441 |
|
| 2442 |
rules.link_open = function(tokens, idx, options /* env */) { |
| 2443 |
var title = tokens[idx].title ? (' title="' + escapeHtml(replaceEntities(tokens[idx].title)) + '"') : ''; |
| 2444 |
var target = options.linkTarget ? (' target="' + options.linkTarget + '"') : ''; |
| 2445 |
return '<a href="' + escapeHtml(tokens[idx].href) + '"' + title + target + '>'; |
| 2446 |
}; |
| 2447 |
rules.link_close = function(/* tokens, idx, options, env */) { |
| 2448 |
return '</a>'; |
| 2449 |
}; |
| 2450 |
|
| 2451 |
/** |
| 2452 |
* Images |
| 2453 |
*/ |
| 2454 |
|
| 2455 |
rules.image = function(tokens, idx, options /*, env */) { |
| 2456 |
var src = ' src="' + escapeHtml(tokens[idx].src) + '"'; |
| 2457 |
var title = tokens[idx].title ? (' title="' + escapeHtml(replaceEntities(tokens[idx].title)) + '"') : ''; |
| 2458 |
var alt = ' alt="' + (tokens[idx].alt ? escapeHtml(replaceEntities(unescapeMd(tokens[idx].alt))) : '') + '"'; |
| 2459 |
var suffix = options.xhtmlOut ? ' /' : ''; |
| 2460 |
return '<img' + src + alt + title + suffix + '>'; |
| 2461 |
}; |
| 2462 |
|
| 2463 |
/** |
| 2464 |
* Tables |
| 2465 |
*/ |
| 2466 |
|
| 2467 |
rules.table_open = function(/* tokens, idx, options, env */) { |
| 2468 |
return '<table>\n'; |
| 2469 |
}; |
| 2470 |
rules.table_close = function(/* tokens, idx, options, env */) { |
| 2471 |
return '</table>\n'; |
| 2472 |
}; |
| 2473 |
rules.thead_open = function(/* tokens, idx, options, env */) { |
| 2474 |
return '<thead>\n'; |
| 2475 |
}; |
| 2476 |
rules.thead_close = function(/* tokens, idx, options, env */) { |
| 2477 |
return '</thead>\n'; |
| 2478 |
}; |
| 2479 |
rules.tbody_open = function(/* tokens, idx, options, env */) { |
| 2480 |
return '<tbody>\n'; |
| 2481 |
}; |
| 2482 |
rules.tbody_close = function(/* tokens, idx, options, env */) { |
| 2483 |
return '</tbody>\n'; |
| 2484 |
}; |
| 2485 |
rules.tr_open = function(/* tokens, idx, options, env */) { |
| 2486 |
return '<tr>'; |
| 2487 |
}; |
| 2488 |
rules.tr_close = function(/* tokens, idx, options, env */) { |
| 2489 |
return '</tr>\n'; |
| 2490 |
}; |
| 2491 |
rules.th_open = function(tokens, idx /*, options, env */) { |
| 2492 |
var token = tokens[idx]; |
| 2493 |
return '<th' |
| 2494 |
+ (token.align ? ' style="text-align:' + token.align + '"' : '') |
| 2495 |
+ '>'; |
| 2496 |
}; |
| 2497 |
rules.th_close = function(/* tokens, idx, options, env */) { |
| 2498 |
return '</th>'; |
| 2499 |
}; |
| 2500 |
rules.td_open = function(tokens, idx /*, options, env */) { |
| 2501 |
var token = tokens[idx]; |
| 2502 |
return '<td' |
| 2503 |
+ (token.align ? ' style="text-align:' + token.align + '"' : '') |
| 2504 |
+ '>'; |
| 2505 |
}; |
| 2506 |
rules.td_close = function(/* tokens, idx, options, env */) { |
| 2507 |
return '</td>'; |
| 2508 |
}; |
| 2509 |
|
| 2510 |
/** |
| 2511 |
* Bold |
| 2512 |
*/ |
| 2513 |
|
| 2514 |
rules.strong_open = function(/* tokens, idx, options, env */) { |
| 2515 |
return '<strong>'; |
| 2516 |
}; |
| 2517 |
rules.strong_close = function(/* tokens, idx, options, env */) { |
| 2518 |
return '</strong>'; |
| 2519 |
}; |
| 2520 |
|
| 2521 |
/** |
| 2522 |
* Italicize |
| 2523 |
*/ |
| 2524 |
|
| 2525 |
rules.em_open = function(/* tokens, idx, options, env */) { |
| 2526 |
return '<em>'; |
| 2527 |
}; |
| 2528 |
rules.em_close = function(/* tokens, idx, options, env */) { |
| 2529 |
return '</em>'; |
| 2530 |
}; |
| 2531 |
|
| 2532 |
/** |
| 2533 |
* Strikethrough |
| 2534 |
*/ |
| 2535 |
|
| 2536 |
rules.del_open = function(/* tokens, idx, options, env */) { |
| 2537 |
return '<del>'; |
| 2538 |
}; |
| 2539 |
rules.del_close = function(/* tokens, idx, options, env */) { |
| 2540 |
return '</del>'; |
| 2541 |
}; |
| 2542 |
|
| 2543 |
/** |
| 2544 |
* Insert |
| 2545 |
*/ |
| 2546 |
|
| 2547 |
rules.ins_open = function(/* tokens, idx, options, env */) { |
| 2548 |
return '<ins>'; |
| 2549 |
}; |
| 2550 |
rules.ins_close = function(/* tokens, idx, options, env */) { |
| 2551 |
return '</ins>'; |
| 2552 |
}; |
| 2553 |
|
| 2554 |
/** |
| 2555 |
* Highlight |
| 2556 |
*/ |
| 2557 |
|
| 2558 |
rules.mark_open = function(/* tokens, idx, options, env */) { |
| 2559 |
return '<mark>'; |
| 2560 |
}; |
| 2561 |
rules.mark_close = function(/* tokens, idx, options, env */) { |
| 2562 |
return '</mark>'; |
| 2563 |
}; |
| 2564 |
|
| 2565 |
/** |
| 2566 |
* Super- and sub-script |
| 2567 |
*/ |
| 2568 |
|
| 2569 |
rules.sub = function(tokens, idx /*, options, env */) { |
| 2570 |
return '<sub>' + escapeHtml(tokens[idx].content) + '</sub>'; |
| 2571 |
}; |
| 2572 |
rules.sup = function(tokens, idx /*, options, env */) { |
| 2573 |
return '<sup>' + escapeHtml(tokens[idx].content) + '</sup>'; |
| 2574 |
}; |
| 2575 |
|
| 2576 |
/** |
| 2577 |
* Breaks |
| 2578 |
*/ |
| 2579 |
|
| 2580 |
rules.hardbreak = function(tokens, idx, options /*, env */) { |
| 2581 |
return options.xhtmlOut ? '<br />\n' : '<br>\n'; |
| 2582 |
}; |
| 2583 |
rules.softbreak = function(tokens, idx, options /*, env */) { |
| 2584 |
return options.breaks ? (options.xhtmlOut ? '<br />\n' : '<br>\n') : '\n'; |
| 2585 |
}; |
| 2586 |
|
| 2587 |
/** |
| 2588 |
* Text |
| 2589 |
*/ |
| 2590 |
|
| 2591 |
rules.text = function(tokens, idx /*, options, env */) { |
| 2592 |
return escapeHtml(tokens[idx].content); |
| 2593 |
}; |
| 2594 |
|
| 2595 |
/** |
| 2596 |
* Content |
| 2597 |
*/ |
| 2598 |
|
| 2599 |
rules.htmlblock = function(tokens, idx /*, options, env */) { |
| 2600 |
return tokens[idx].content; |
| 2601 |
}; |
| 2602 |
rules.htmltag = function(tokens, idx /*, options, env */) { |
| 2603 |
return tokens[idx].content; |
| 2604 |
}; |
| 2605 |
|
| 2606 |
/** |
| 2607 |
* Abbreviations, initialism |
| 2608 |
*/ |
| 2609 |
|
| 2610 |
rules.abbr_open = function(tokens, idx /*, options, env */) { |
| 2611 |
return '<abbr title="' + escapeHtml(replaceEntities(tokens[idx].title)) + '">'; |
| 2612 |
}; |
| 2613 |
rules.abbr_close = function(/* tokens, idx, options, env */) { |
| 2614 |
return '</abbr>'; |
| 2615 |
}; |
| 2616 |
|
| 2617 |
/** |
| 2618 |
* Footnotes |
| 2619 |
*/ |
| 2620 |
|
| 2621 |
rules.footnote_ref = function(tokens, idx) { |
| 2622 |
var n = Number(tokens[idx].id + 1).toString(); |
| 2623 |
var id = 'fnref' + n; |
| 2624 |
if (tokens[idx].subId > 0) { |
| 2625 |
id += ':' + tokens[idx].subId; |
| 2626 |
} |
| 2627 |
return '<sup class="footnote-ref"><a href="#fn' + n + '" id="' + id + '">[' + n + ']</a></sup>'; |
| 2628 |
}; |
| 2629 |
rules.footnote_block_open = function(tokens, idx, options) { |
| 2630 |
var hr = options.xhtmlOut |
| 2631 |
? '<hr class="footnotes-sep" />\n' |
| 2632 |
: '<hr class="footnotes-sep">\n'; |
| 2633 |
return hr + '<section class="footnotes">\n<ol class="footnotes-list">\n'; |
| 2634 |
}; |
| 2635 |
rules.footnote_block_close = function() { |
| 2636 |
return '</ol>\n</section>\n'; |
| 2637 |
}; |
| 2638 |
rules.footnote_open = function(tokens, idx) { |
| 2639 |
var id = Number(tokens[idx].id + 1).toString(); |
| 2640 |
return '<li id="fn' + id + '" class="footnote-item">'; |
| 2641 |
}; |
| 2642 |
rules.footnote_close = function() { |
| 2643 |
return '</li>\n'; |
| 2644 |
}; |
| 2645 |
rules.footnote_anchor = function(tokens, idx) { |
| 2646 |
var n = Number(tokens[idx].id + 1).toString(); |
| 2647 |
var id = 'fnref' + n; |
| 2648 |
if (tokens[idx].subId > 0) { |
| 2649 |
id += ':' + tokens[idx].subId; |
| 2650 |
} |
| 2651 |
return ' <a href="#' + id + '" class="footnote-backref">↩</a>'; |
| 2652 |
}; |
| 2653 |
|
| 2654 |
/** |
| 2655 |
* Definition lists |
| 2656 |
*/ |
| 2657 |
|
| 2658 |
rules.dl_open = function() { |
| 2659 |
return '<dl>\n'; |
| 2660 |
}; |
| 2661 |
rules.dt_open = function() { |
| 2662 |
return '<dt>'; |
| 2663 |
}; |
| 2664 |
rules.dd_open = function() { |
| 2665 |
return '<dd>'; |
| 2666 |
}; |
| 2667 |
rules.dl_close = function() { |
| 2668 |
return '</dl>\n'; |
| 2669 |
}; |
| 2670 |
rules.dt_close = function() { |
| 2671 |
return '</dt>\n'; |
| 2672 |
}; |
| 2673 |
rules.dd_close = function() { |
| 2674 |
return '</dd>\n'; |
| 2675 |
}; |
| 2676 |
|
| 2677 |
/** |
| 2678 |
* Helper functions |
| 2679 |
*/ |
| 2680 |
|
| 2681 |
function nextToken(tokens, idx) { |
| 2682 |
if (++idx >= tokens.length - 2) { |
| 2683 |
return idx; |
| 2684 |
} |
| 2685 |
if ((tokens[idx].type === 'paragraph_open' && tokens[idx].tight) && |
| 2686 |
(tokens[idx + 1].type === 'inline' && tokens[idx + 1].content.length === 0) && |
| 2687 |
(tokens[idx + 2].type === 'paragraph_close' && tokens[idx + 2].tight)) { |
| 2688 |
return nextToken(tokens, idx + 2); |
| 2689 |
} |
| 2690 |
return idx; |
| 2691 |
} |
| 2692 |
|
| 2693 |
/** |
| 2694 |
* Check to see if `\n` is needed before the next token. |
| 2695 |
* |
| 2696 |
* @param {Array} `tokens` |
| 2697 |
* @param {Number} `idx` |
| 2698 |
* @return {String} Empty string or newline |
| 2699 |
* @api private |
| 2700 |
*/ |
| 2701 |
|
| 2702 |
var getBreak = rules.getBreak = function getBreak(tokens, idx) { |
| 2703 |
idx = nextToken(tokens, idx); |
| 2704 |
if (idx < tokens.length && tokens[idx].type === 'list_item_close') { |
| 2705 |
return ''; |
| 2706 |
} |
| 2707 |
return '\n'; |
| 2708 |
}; |
| 2709 |
|
| 2710 |
/** |
| 2711 |
* Renderer class. Renders HTML and exposes `rules` to allow |
| 2712 |
* local modifications. |
| 2713 |
*/ |
| 2714 |
|
| 2715 |
function Renderer() { |
| 2716 |
this.rules = assign({}, rules); |
| 2717 |
|
| 2718 |
// exported helper, for custom rules only |
| 2719 |
this.getBreak = rules.getBreak; |
| 2720 |
} |
| 2721 |
|
| 2722 |
/** |
| 2723 |
* Render a string of inline HTML with the given `tokens` and |
| 2724 |
* `options`. |
| 2725 |
* |
| 2726 |
* @param {Array} `tokens` |
| 2727 |
* @param {Object} `options` |
| 2728 |
* @param {Object} `env` |
| 2729 |
* @return {String} |
| 2730 |
* @api public |
| 2731 |
*/ |
| 2732 |
|
| 2733 |
Renderer.prototype.renderInline = function (tokens, options, env) { |
| 2734 |
var _rules = this.rules; |
| 2735 |
var len = tokens.length, i = 0; |
| 2736 |
var result = ''; |
| 2737 |
|
| 2738 |
while (len--) { |
| 2739 |
result += _rules[tokens[i].type](tokens, i++, options, env, this); |
| 2740 |
} |
| 2741 |
|
| 2742 |
return result; |
| 2743 |
}; |
| 2744 |
|
| 2745 |
/** |
| 2746 |
* Render a string of HTML with the given `tokens` and |
| 2747 |
* `options`. |
| 2748 |
* |
| 2749 |
* @param {Array} `tokens` |
| 2750 |
* @param {Object} `options` |
| 2751 |
* @param {Object} `env` |
| 2752 |
* @return {String} |
| 2753 |
* @api public |
| 2754 |
*/ |
| 2755 |
|
| 2756 |
Renderer.prototype.render = function (tokens, options, env) { |
| 2757 |
var _rules = this.rules; |
| 2758 |
var len = tokens.length, i = -1; |
| 2759 |
var result = ''; |
| 2760 |
|
| 2761 |
while (++i < len) { |
| 2762 |
if (tokens[i].type === 'inline') { |
| 2763 |
result += this.renderInline(tokens[i].children, options, env); |
| 2764 |
} else { |
| 2765 |
result += _rules[tokens[i].type](tokens, i, options, env, this); |
| 2766 |
} |
| 2767 |
} |
| 2768 |
return result; |
| 2769 |
}; |
| 2770 |
|
| 2771 |
/** |
| 2772 |
* Ruler is a helper class for building responsibility chains from |
| 2773 |
* parse rules. It allows: |
| 2774 |
* |
| 2775 |
* - easy stack rules chains |
| 2776 |
* - getting main chain and named chains content (as arrays of functions) |
| 2777 |
* |
| 2778 |
* Helper methods, should not be used directly. |
| 2779 |
* @api private |
| 2780 |
*/ |
| 2781 |
|
| 2782 |
function Ruler() { |
| 2783 |
// List of added rules. Each element is: |
| 2784 |
// |
| 2785 |
// { name: XXX, |
| 2786 |
// enabled: Boolean, |
| 2787 |
// fn: Function(), |
| 2788 |
// alt: [ name2, name3 ] } |
| 2789 |
// |
| 2790 |
this.__rules__ = []; |
| 2791 |
|
| 2792 |
// Cached rule chains. |
| 2793 |
// |
| 2794 |
// First level - chain name, '' for default. |
| 2795 |
// Second level - digital anchor for fast filtering by charcodes. |
| 2796 |
// |
| 2797 |
this.__cache__ = null; |
| 2798 |
} |
| 2799 |
|
| 2800 |
/** |
| 2801 |
* Find the index of a rule by `name`. |
| 2802 |
* |
| 2803 |
* @param {String} `name` |
| 2804 |
* @return {Number} Index of the given `name` |
| 2805 |
* @api private |
| 2806 |
*/ |
| 2807 |
|
| 2808 |
Ruler.prototype.__find__ = function (name) { |
| 2809 |
var len = this.__rules__.length; |
| 2810 |
var i = -1; |
| 2811 |
|
| 2812 |
while (len--) { |
| 2813 |
if (this.__rules__[++i].name === name) { |
| 2814 |
return i; |
| 2815 |
} |
| 2816 |
} |
| 2817 |
return -1; |
| 2818 |
}; |
| 2819 |
|
| 2820 |
/** |
| 2821 |
* Build the rules lookup cache |
| 2822 |
* |
| 2823 |
* @api private |
| 2824 |
*/ |
| 2825 |
|
| 2826 |
Ruler.prototype.__compile__ = function () { |
| 2827 |
var self = this; |
| 2828 |
var chains = [ '' ]; |
| 2829 |
|
| 2830 |
// collect unique names |
| 2831 |
self.__rules__.forEach(function (rule) { |
| 2832 |
if (!rule.enabled) { |
| 2833 |
return; |
| 2834 |
} |
| 2835 |
|
| 2836 |
rule.alt.forEach(function (altName) { |
| 2837 |
if (chains.indexOf(altName) < 0) { |
| 2838 |
chains.push(altName); |
| 2839 |
} |
| 2840 |
}); |
| 2841 |
}); |
| 2842 |
|
| 2843 |
self.__cache__ = {}; |
| 2844 |
|
| 2845 |
chains.forEach(function (chain) { |
| 2846 |
self.__cache__[chain] = []; |
| 2847 |
self.__rules__.forEach(function (rule) { |
| 2848 |
if (!rule.enabled) { |
| 2849 |
return; |
| 2850 |
} |
| 2851 |
|
| 2852 |
if (chain && rule.alt.indexOf(chain) < 0) { |
| 2853 |
return; |
| 2854 |
} |
| 2855 |
self.__cache__[chain].push(rule.fn); |
| 2856 |
}); |
| 2857 |
}); |
| 2858 |
}; |
| 2859 |
|
| 2860 |
/** |
| 2861 |
* Ruler public methods |
| 2862 |
* ------------------------------------------------ |
| 2863 |
*/ |
| 2864 |
|
| 2865 |
/** |
| 2866 |
* Replace rule function |
| 2867 |
* |
| 2868 |
* @param {String} `name` Rule name |
| 2869 |
* @param {Function `fn` |
| 2870 |
* @param {Object} `options` |
| 2871 |
* @api private |
| 2872 |
*/ |
| 2873 |
|
| 2874 |
Ruler.prototype.at = function (name, fn, options) { |
| 2875 |
var idx = this.__find__(name); |
| 2876 |
var opt = options || {}; |
| 2877 |
|
| 2878 |
if (idx === -1) { |
| 2879 |
throw new Error('Parser rule not found: ' + name); |
| 2880 |
} |
| 2881 |
|
| 2882 |
this.__rules__[idx].fn = fn; |
| 2883 |
this.__rules__[idx].alt = opt.alt || []; |
| 2884 |
this.__cache__ = null; |
| 2885 |
}; |
| 2886 |
|
| 2887 |
/** |
| 2888 |
* Add a rule to the chain before given the `ruleName`. |
| 2889 |
* |
| 2890 |
* @param {String} `beforeName` |
| 2891 |
* @param {String} `ruleName` |
| 2892 |
* @param {Function} `fn` |
| 2893 |
* @param {Object} `options` |
| 2894 |
* @api private |
| 2895 |
*/ |
| 2896 |
|
| 2897 |
Ruler.prototype.before = function (beforeName, ruleName, fn, options) { |
| 2898 |
var idx = this.__find__(beforeName); |
| 2899 |
var opt = options || {}; |
| 2900 |
|
| 2901 |
if (idx === -1) { |
| 2902 |
throw new Error('Parser rule not found: ' + beforeName); |
| 2903 |
} |
| 2904 |
|
| 2905 |
this.__rules__.splice(idx, 0, { |
| 2906 |
name: ruleName, |
| 2907 |
enabled: true, |
| 2908 |
fn: fn, |
| 2909 |
alt: opt.alt || [] |
| 2910 |
}); |
| 2911 |
|
| 2912 |
this.__cache__ = null; |
| 2913 |
}; |
| 2914 |
|
| 2915 |
/** |
| 2916 |
* Add a rule to the chain after the given `ruleName`. |
| 2917 |
* |
| 2918 |
* @param {String} `afterName` |
| 2919 |
* @param {String} `ruleName` |
| 2920 |
* @param {Function} `fn` |
| 2921 |
* @param {Object} `options` |
| 2922 |
* @api private |
| 2923 |
*/ |
| 2924 |
|
| 2925 |
Ruler.prototype.after = function (afterName, ruleName, fn, options) { |
| 2926 |
var idx = this.__find__(afterName); |
| 2927 |
var opt = options || {}; |
| 2928 |
|
| 2929 |
if (idx === -1) { |
| 2930 |
throw new Error('Parser rule not found: ' + afterName); |
| 2931 |
} |
| 2932 |
|
| 2933 |
this.__rules__.splice(idx + 1, 0, { |
| 2934 |
name: ruleName, |
| 2935 |
enabled: true, |
| 2936 |
fn: fn, |
| 2937 |
alt: opt.alt || [] |
| 2938 |
}); |
| 2939 |
|
| 2940 |
this.__cache__ = null; |
| 2941 |
}; |
| 2942 |
|
| 2943 |
/** |
| 2944 |
* Add a rule to the end of chain. |
| 2945 |
* |
| 2946 |
* @param {String} `ruleName` |
| 2947 |
* @param {Function} `fn` |
| 2948 |
* @param {Object} `options` |
| 2949 |
* @return {String} |
| 2950 |
*/ |
| 2951 |
|
| 2952 |
Ruler.prototype.push = function (ruleName, fn, options) { |
| 2953 |
var opt = options || {}; |
| 2954 |
|
| 2955 |
this.__rules__.push({ |
| 2956 |
name: ruleName, |
| 2957 |
enabled: true, |
| 2958 |
fn: fn, |
| 2959 |
alt: opt.alt || [] |
| 2960 |
}); |
| 2961 |
|
| 2962 |
this.__cache__ = null; |
| 2963 |
}; |
| 2964 |
|
| 2965 |
/** |
| 2966 |
* Enable a rule or list of rules. |
| 2967 |
* |
| 2968 |
* @param {String|Array} `list` Name or array of rule names to enable |
| 2969 |
* @param {Boolean} `strict` If `true`, all non listed rules will be disabled. |
| 2970 |
* @api private |
| 2971 |
*/ |
| 2972 |
|
| 2973 |
Ruler.prototype.enable = function (list, strict) { |
| 2974 |
list = !Array.isArray(list) |
| 2975 |
? [ list ] |
| 2976 |
: list; |
| 2977 |
|
| 2978 |
// In strict mode disable all existing rules first |
| 2979 |
if (strict) { |
| 2980 |
this.__rules__.forEach(function (rule) { |
| 2981 |
rule.enabled = false; |
| 2982 |
}); |
| 2983 |
} |
| 2984 |
|
| 2985 |
// Search by name and enable |
| 2986 |
list.forEach(function (name) { |
| 2987 |
var idx = this.__find__(name); |
| 2988 |
if (idx < 0) { |
| 2989 |
throw new Error('Rules manager: invalid rule name ' + name); |
| 2990 |
} |
| 2991 |
this.__rules__[idx].enabled = true; |
| 2992 |
}, this); |
| 2993 |
|
| 2994 |
this.__cache__ = null; |
| 2995 |
}; |
| 2996 |
|
| 2997 |
|
| 2998 |
/** |
| 2999 |
* Disable a rule or list of rules. |
| 3000 |
* |
| 3001 |
* @param {String|Array} `list` Name or array of rule names to disable |
| 3002 |
* @api private |
| 3003 |
*/ |
| 3004 |
|
| 3005 |
Ruler.prototype.disable = function (list) { |
| 3006 |
list = !Array.isArray(list) |
| 3007 |
? [ list ] |
| 3008 |
: list; |
| 3009 |
|
| 3010 |
// Search by name and disable |
| 3011 |
list.forEach(function (name) { |
| 3012 |
var idx = this.__find__(name); |
| 3013 |
if (idx < 0) { |
| 3014 |
throw new Error('Rules manager: invalid rule name ' + name); |
| 3015 |
} |
| 3016 |
this.__rules__[idx].enabled = false; |
| 3017 |
}, this); |
| 3018 |
|
| 3019 |
this.__cache__ = null; |
| 3020 |
}; |
| 3021 |
|
| 3022 |
/** |
| 3023 |
* Get a rules list as an array of functions. |
| 3024 |
* |
| 3025 |
* @param {String} `chainName` |
| 3026 |
* @return {Object} |
| 3027 |
* @api private |
| 3028 |
*/ |
| 3029 |
|
| 3030 |
Ruler.prototype.getRules = function (chainName) { |
| 3031 |
if (this.__cache__ === null) { |
| 3032 |
this.__compile__(); |
| 3033 |
} |
| 3034 |
return this.__cache__[chainName] || []; |
| 3035 |
}; |
| 3036 |
|
| 3037 |
function block(state) { |
| 3038 |
|
| 3039 |
if (state.inlineMode) { |
| 3040 |
state.tokens.push({ |
| 3041 |
type: 'inline', |
| 3042 |
content: state.src.replace(/\n/g, ' ').trim(), |
| 3043 |
level: 0, |
| 3044 |
lines: [ 0, 1 ], |
| 3045 |
children: [] |
| 3046 |
}); |
| 3047 |
|
| 3048 |
} else { |
| 3049 |
state.block.parse(state.src, state.options, state.env, state.tokens); |
| 3050 |
} |
| 3051 |
} |
| 3052 |
|
| 3053 |
// Inline parser state |
| 3054 |
|
| 3055 |
function StateInline(src, parserInline, options, env, outTokens) { |
| 3056 |
this.src = src; |
| 3057 |
this.env = env; |
| 3058 |
this.options = options; |
| 3059 |
this.parser = parserInline; |
| 3060 |
this.tokens = outTokens; |
| 3061 |
this.pos = 0; |
| 3062 |
this.posMax = this.src.length; |
| 3063 |
this.level = 0; |
| 3064 |
this.pending = ''; |
| 3065 |
this.pendingLevel = 0; |
| 3066 |
|
| 3067 |
this.cache = []; // Stores { start: end } pairs. Useful for backtrack |
| 3068 |
// optimization of pairs parse (emphasis, strikes). |
| 3069 |
|
| 3070 |
// Link parser state vars |
| 3071 |
|
| 3072 |
this.isInLabel = false; // Set true when seek link label - we should disable |
| 3073 |
// "paired" rules (emphasis, strikes) to not skip |
| 3074 |
// tailing `]` |
| 3075 |
|
| 3076 |
this.linkLevel = 0; // Increment for each nesting link. Used to prevent |
| 3077 |
// nesting in definitions |
| 3078 |
|
| 3079 |
this.linkContent = ''; // Temporary storage for link url |
| 3080 |
|
| 3081 |
this.labelUnmatchedScopes = 0; // Track unpaired `[` for link labels |
| 3082 |
// (backtrack optimization) |
| 3083 |
} |
| 3084 |
|
| 3085 |
// Flush pending text |
| 3086 |
// |
| 3087 |
StateInline.prototype.pushPending = function () { |
| 3088 |
this.tokens.push({ |
| 3089 |
type: 'text', |
| 3090 |
content: this.pending, |
| 3091 |
level: this.pendingLevel |
| 3092 |
}); |
| 3093 |
this.pending = ''; |
| 3094 |
}; |
| 3095 |
|
| 3096 |
// Push new token to "stream". |
| 3097 |
// If pending text exists - flush it as text token |
| 3098 |
// |
| 3099 |
StateInline.prototype.push = function (token) { |
| 3100 |
if (this.pending) { |
| 3101 |
this.pushPending(); |
| 3102 |
} |
| 3103 |
|
| 3104 |
this.tokens.push(token); |
| 3105 |
this.pendingLevel = this.level; |
| 3106 |
}; |
| 3107 |
|
| 3108 |
// Store value to cache. |
| 3109 |
// !!! Implementation has parser-specific optimizations |
| 3110 |
// !!! keys MUST be integer, >= 0; values MUST be integer, > 0 |
| 3111 |
// |
| 3112 |
StateInline.prototype.cacheSet = function (key, val) { |
| 3113 |
for (var i = this.cache.length; i <= key; i++) { |
| 3114 |
this.cache.push(0); |
| 3115 |
} |
| 3116 |
|
| 3117 |
this.cache[key] = val; |
| 3118 |
}; |
| 3119 |
|
| 3120 |
// Get cache value |
| 3121 |
// |
| 3122 |
StateInline.prototype.cacheGet = function (key) { |
| 3123 |
return key < this.cache.length ? this.cache[key] : 0; |
| 3124 |
}; |
| 3125 |
|
| 3126 |
/** |
| 3127 |
* Parse link labels |
| 3128 |
* |
| 3129 |
* This function assumes that first character (`[`) already matches; |
| 3130 |
* returns the end of the label. |
| 3131 |
* |
| 3132 |
* @param {Object} state |
| 3133 |
* @param {Number} start |
| 3134 |
* @api private |
| 3135 |
*/ |
| 3136 |
|
| 3137 |
function parseLinkLabel(state, start) { |
| 3138 |
var level, found, marker, |
| 3139 |
labelEnd = -1, |
| 3140 |
max = state.posMax, |
| 3141 |
oldPos = state.pos, |
| 3142 |
oldFlag = state.isInLabel; |
| 3143 |
|
| 3144 |
if (state.isInLabel) { return -1; } |
| 3145 |
|
| 3146 |
if (state.labelUnmatchedScopes) { |
| 3147 |
state.labelUnmatchedScopes--; |
| 3148 |
return -1; |
| 3149 |
} |
| 3150 |
|
| 3151 |
state.pos = start + 1; |
| 3152 |
state.isInLabel = true; |
| 3153 |
level = 1; |
| 3154 |
|
| 3155 |
while (state.pos < max) { |
| 3156 |
marker = state.src.charCodeAt(state.pos); |
| 3157 |
if (marker === 0x5B /* [ */) { |
| 3158 |
level++; |
| 3159 |
} else if (marker === 0x5D /* ] */) { |
| 3160 |
level--; |
| 3161 |
if (level === 0) { |
| 3162 |
found = true; |
| 3163 |
break; |
| 3164 |
} |
| 3165 |
} |
| 3166 |
|
| 3167 |
state.parser.skipToken(state); |
| 3168 |
} |
| 3169 |
|
| 3170 |
if (found) { |
| 3171 |
labelEnd = state.pos; |
| 3172 |
state.labelUnmatchedScopes = 0; |
| 3173 |
} else { |
| 3174 |
state.labelUnmatchedScopes = level - 1; |
| 3175 |
} |
| 3176 |
|
| 3177 |
// restore old state |
| 3178 |
state.pos = oldPos; |
| 3179 |
state.isInLabel = oldFlag; |
| 3180 |
|
| 3181 |
return labelEnd; |
| 3182 |
} |
| 3183 |
|
| 3184 |
// Parse abbreviation definitions, i.e. `*[abbr]: description` |
| 3185 |
|
| 3186 |
|
| 3187 |
function parseAbbr(str, parserInline, options, env) { |
| 3188 |
var state, labelEnd, pos, max, label, title; |
| 3189 |
|
| 3190 |
if (str.charCodeAt(0) !== 0x2A/* * */) { return -1; } |
| 3191 |
if (str.charCodeAt(1) !== 0x5B/* [ */) { return -1; } |
| 3192 |
|
| 3193 |
if (str.indexOf(']:') === -1) { return -1; } |
| 3194 |
|
| 3195 |
state = new StateInline(str, parserInline, options, env, []); |
| 3196 |
labelEnd = parseLinkLabel(state, 1); |
| 3197 |
|
| 3198 |
if (labelEnd < 0 || str.charCodeAt(labelEnd + 1) !== 0x3A/* : */) { return -1; } |
| 3199 |
|
| 3200 |
max = state.posMax; |
| 3201 |
|
| 3202 |
// abbr title is always one line, so looking for ending "\n" here |
| 3203 |
for (pos = labelEnd + 2; pos < max; pos++) { |
| 3204 |
if (state.src.charCodeAt(pos) === 0x0A) { break; } |
| 3205 |
} |
| 3206 |
|
| 3207 |
label = str.slice(2, labelEnd); |
| 3208 |
title = str.slice(labelEnd + 2, pos).trim(); |
| 3209 |
if (title.length === 0) { return -1; } |
| 3210 |
if (!env.abbreviations) { env.abbreviations = {}; } |
| 3211 |
// prepend ':' to avoid conflict with Object.prototype members |
| 3212 |
if (typeof env.abbreviations[':' + label] === 'undefined') { |
| 3213 |
env.abbreviations[':' + label] = title; |
| 3214 |
} |
| 3215 |
|
| 3216 |
return pos; |
| 3217 |
} |
| 3218 |
|
| 3219 |
function abbr(state) { |
| 3220 |
var tokens = state.tokens, i, l, content, pos; |
| 3221 |
|
| 3222 |
if (state.inlineMode) { |
| 3223 |
return; |
| 3224 |
} |
| 3225 |
|
| 3226 |
// Parse inlines |
| 3227 |
for (i = 1, l = tokens.length - 1; i < l; i++) { |
| 3228 |
if (tokens[i - 1].type === 'paragraph_open' && |
| 3229 |
tokens[i].type === 'inline' && |
| 3230 |
tokens[i + 1].type === 'paragraph_close') { |
| 3231 |
|
| 3232 |
content = tokens[i].content; |
| 3233 |
while (content.length) { |
| 3234 |
pos = parseAbbr(content, state.inline, state.options, state.env); |
| 3235 |
if (pos < 0) { break; } |
| 3236 |
content = content.slice(pos).trim(); |
| 3237 |
} |
| 3238 |
|
| 3239 |
tokens[i].content = content; |
| 3240 |
if (!content.length) { |
| 3241 |
tokens[i - 1].tight = true; |
| 3242 |
tokens[i + 1].tight = true; |
| 3243 |
} |
| 3244 |
} |
| 3245 |
} |
| 3246 |
} |
| 3247 |
|
| 3248 |
function normalizeLink(url) { |
| 3249 |
var normalized = replaceEntities(url); |
| 3250 |
// We shouldn't care about the result of malformed URIs, |
| 3251 |
// and should not throw an exception. |
| 3252 |
try { |
| 3253 |
normalized = decodeURI(normalized); |
| 3254 |
} catch (err) {} |
| 3255 |
return encodeURI(normalized); |
| 3256 |
} |
| 3257 |
|
| 3258 |
/** |
| 3259 |
* Parse link destination |
| 3260 |
* |
| 3261 |
* - on success it returns a string and updates state.pos; |
| 3262 |
* - on failure it returns null |
| 3263 |
* |
| 3264 |
* @param {Object} state |
| 3265 |
* @param {Number} pos |
| 3266 |
* @api private |
| 3267 |
*/ |
| 3268 |
|
| 3269 |
function parseLinkDestination(state, pos) { |
| 3270 |
var code, level, link, |
| 3271 |
start = pos, |
| 3272 |
max = state.posMax; |
| 3273 |
|
| 3274 |
if (state.src.charCodeAt(pos) === 0x3C /* < */) { |
| 3275 |
pos++; |
| 3276 |
while (pos < max) { |
| 3277 |
code = state.src.charCodeAt(pos); |
| 3278 |
if (code === 0x0A /* \n */) { return false; } |
| 3279 |
if (code === 0x3E /* > */) { |
| 3280 |
link = normalizeLink(unescapeMd(state.src.slice(start + 1, pos))); |
| 3281 |
if (!state.parser.validateLink(link)) { return false; } |
| 3282 |
state.pos = pos + 1; |
| 3283 |
state.linkContent = link; |
| 3284 |
return true; |
| 3285 |
} |
| 3286 |
if (code === 0x5C /* \ */ && pos + 1 < max) { |
| 3287 |
pos += 2; |
| 3288 |
continue; |
| 3289 |
} |
| 3290 |
|
| 3291 |
pos++; |
| 3292 |
} |
| 3293 |
|
| 3294 |
// no closing '>' |
| 3295 |
return false; |
| 3296 |
} |
| 3297 |
|
| 3298 |
// this should be ... } else { ... branch |
| 3299 |
|
| 3300 |
level = 0; |
| 3301 |
while (pos < max) { |
| 3302 |
code = state.src.charCodeAt(pos); |
| 3303 |
|
| 3304 |
if (code === 0x20) { break; } |
| 3305 |
|
| 3306 |
// ascii control chars |
| 3307 |
if (code < 0x20 || code === 0x7F) { break; } |
| 3308 |
|
| 3309 |
if (code === 0x5C /* \ */ && pos + 1 < max) { |
| 3310 |
pos += 2; |
| 3311 |
continue; |
| 3312 |
} |
| 3313 |
|
| 3314 |
if (code === 0x28 /* ( */) { |
| 3315 |
level++; |
| 3316 |
if (level > 1) { break; } |
| 3317 |
} |
| 3318 |
|
| 3319 |
if (code === 0x29 /* ) */) { |
| 3320 |
level--; |
| 3321 |
if (level < 0) { break; } |
| 3322 |
} |
| 3323 |
|
| 3324 |
pos++; |
| 3325 |
} |
| 3326 |
|
| 3327 |
if (start === pos) { return false; } |
| 3328 |
|
| 3329 |
link = unescapeMd(state.src.slice(start, pos)); |
| 3330 |
if (!state.parser.validateLink(link)) { return false; } |
| 3331 |
|
| 3332 |
state.linkContent = link; |
| 3333 |
state.pos = pos; |
| 3334 |
return true; |
| 3335 |
} |
| 3336 |
|
| 3337 |
/** |
| 3338 |
* Parse link title |
| 3339 |
* |
| 3340 |
* - on success it returns a string and updates state.pos; |
| 3341 |
* - on failure it returns null |
| 3342 |
* |
| 3343 |
* @param {Object} state |
| 3344 |
* @param {Number} pos |
| 3345 |
* @api private |
| 3346 |
*/ |
| 3347 |
|
| 3348 |
function parseLinkTitle(state, pos) { |
| 3349 |
var code, |
| 3350 |
start = pos, |
| 3351 |
max = state.posMax, |
| 3352 |
marker = state.src.charCodeAt(pos); |
| 3353 |
|
| 3354 |
if (marker !== 0x22 /* " */ && marker !== 0x27 /* ' */ && marker !== 0x28 /* ( */) { return false; } |
| 3355 |
|
| 3356 |
pos++; |
| 3357 |
|
| 3358 |
// if opening marker is "(", switch it to closing marker ")" |
| 3359 |
if (marker === 0x28) { marker = 0x29; } |
| 3360 |
|
| 3361 |
while (pos < max) { |
| 3362 |
code = state.src.charCodeAt(pos); |
| 3363 |
if (code === marker) { |
| 3364 |
state.pos = pos + 1; |
| 3365 |
state.linkContent = unescapeMd(state.src.slice(start + 1, pos)); |
| 3366 |
return true; |
| 3367 |
} |
| 3368 |
if (code === 0x5C /* \ */ && pos + 1 < max) { |
| 3369 |
pos += 2; |
| 3370 |
continue; |
| 3371 |
} |
| 3372 |
|
| 3373 |
pos++; |
| 3374 |
} |
| 3375 |
|
| 3376 |
return false; |
| 3377 |
} |
| 3378 |
|
| 3379 |
function normalizeReference(str) { |
| 3380 |
// use .toUpperCase() instead of .toLowerCase() |
| 3381 |
// here to avoid a conflict with Object.prototype |
| 3382 |
// members (most notably, `__proto__`) |
| 3383 |
return str.trim().replace(/\s+/g, ' ').toUpperCase(); |
| 3384 |
} |
| 3385 |
|
| 3386 |
function parseReference(str, parser, options, env) { |
| 3387 |
var state, labelEnd, pos, max, code, start, href, title, label; |
| 3388 |
|
| 3389 |
if (str.charCodeAt(0) !== 0x5B/* [ */) { return -1; } |
| 3390 |
|
| 3391 |
if (str.indexOf(']:') === -1) { return -1; } |
| 3392 |
|
| 3393 |
state = new StateInline(str, parser, options, env, []); |
| 3394 |
labelEnd = parseLinkLabel(state, 0); |
| 3395 |
|
| 3396 |
if (labelEnd < 0 || str.charCodeAt(labelEnd + 1) !== 0x3A/* : */) { return -1; } |
| 3397 |
|
| 3398 |
max = state.posMax; |
| 3399 |
|
| 3400 |
// [label]: destination 'title' |
| 3401 |
// ^^^ skip optional whitespace here |
| 3402 |
for (pos = labelEnd + 2; pos < max; pos++) { |
| 3403 |
code = state.src.charCodeAt(pos); |
| 3404 |
if (code !== 0x20 && code !== 0x0A) { break; } |
| 3405 |
} |
| 3406 |
|
| 3407 |
// [label]: destination 'title' |
| 3408 |
// ^^^^^^^^^^^ parse this |
| 3409 |
if (!parseLinkDestination(state, pos)) { return -1; } |
| 3410 |
href = state.linkContent; |
| 3411 |
pos = state.pos; |
| 3412 |
|
| 3413 |
// [label]: destination 'title' |
| 3414 |
// ^^^ skipping those spaces |
| 3415 |
start = pos; |
| 3416 |
for (pos = pos + 1; pos < max; pos++) { |
| 3417 |
code = state.src.charCodeAt(pos); |
| 3418 |
if (code !== 0x20 && code !== 0x0A) { break; } |
| 3419 |
} |
| 3420 |
|
| 3421 |
// [label]: destination 'title' |
| 3422 |
// ^^^^^^^ parse this |
| 3423 |
if (pos < max && start !== pos && parseLinkTitle(state, pos)) { |
| 3424 |
title = state.linkContent; |
| 3425 |
pos = state.pos; |
| 3426 |
} else { |
| 3427 |
title = ''; |
| 3428 |
pos = start; |
| 3429 |
} |
| 3430 |
|
| 3431 |
// ensure that the end of the line is empty |
| 3432 |
while (pos < max && state.src.charCodeAt(pos) === 0x20/* space */) { pos++; } |
| 3433 |
if (pos < max && state.src.charCodeAt(pos) !== 0x0A) { return -1; } |
| 3434 |
|
| 3435 |
label = normalizeReference(str.slice(1, labelEnd)); |
| 3436 |
if (typeof env.references[label] === 'undefined') { |
| 3437 |
env.references[label] = { title: title, href: href }; |
| 3438 |
} |
| 3439 |
|
| 3440 |
return pos; |
| 3441 |
} |
| 3442 |
|
| 3443 |
|
| 3444 |
function references(state) { |
| 3445 |
var tokens = state.tokens, i, l, content, pos; |
| 3446 |
|
| 3447 |
state.env.references = state.env.references || {}; |
| 3448 |
|
| 3449 |
if (state.inlineMode) { |
| 3450 |
return; |
| 3451 |
} |
| 3452 |
|
| 3453 |
// Scan definitions in paragraph inlines |
| 3454 |
for (i = 1, l = tokens.length - 1; i < l; i++) { |
| 3455 |
if (tokens[i].type === 'inline' && |
| 3456 |
tokens[i - 1].type === 'paragraph_open' && |
| 3457 |
tokens[i + 1].type === 'paragraph_close') { |
| 3458 |
|
| 3459 |
content = tokens[i].content; |
| 3460 |
while (content.length) { |
| 3461 |
pos = parseReference(content, state.inline, state.options, state.env); |
| 3462 |
if (pos < 0) { break; } |
| 3463 |
content = content.slice(pos).trim(); |
| 3464 |
} |
| 3465 |
|
| 3466 |
tokens[i].content = content; |
| 3467 |
if (!content.length) { |
| 3468 |
tokens[i - 1].tight = true; |
| 3469 |
tokens[i + 1].tight = true; |
| 3470 |
} |
| 3471 |
} |
| 3472 |
} |
| 3473 |
} |
| 3474 |
|
| 3475 |
function inline(state) { |
| 3476 |
var tokens = state.tokens, tok, i, l; |
| 3477 |
|
| 3478 |
// Parse inlines |
| 3479 |
for (i = 0, l = tokens.length; i < l; i++) { |
| 3480 |
tok = tokens[i]; |
| 3481 |
if (tok.type === 'inline') { |
| 3482 |
state.inline.parse(tok.content, state.options, state.env, tok.children); |
| 3483 |
} |
| 3484 |
} |
| 3485 |
} |
| 3486 |
|
| 3487 |
function footnote_block(state) { |
| 3488 |
var i, l, j, t, lastParagraph, list, tokens, current, currentLabel, |
| 3489 |
level = 0, |
| 3490 |
insideRef = false, |
| 3491 |
refTokens = {}; |
| 3492 |
|
| 3493 |
if (!state.env.footnotes) { return; } |
| 3494 |
|
| 3495 |
state.tokens = state.tokens.filter(function(tok) { |
| 3496 |
if (tok.type === 'footnote_reference_open') { |
| 3497 |
insideRef = true; |
| 3498 |
current = []; |
| 3499 |
currentLabel = tok.label; |
| 3500 |
return false; |
| 3501 |
} |
| 3502 |
if (tok.type === 'footnote_reference_close') { |
| 3503 |
insideRef = false; |
| 3504 |
// prepend ':' to avoid conflict with Object.prototype members |
| 3505 |
refTokens[':' + currentLabel] = current; |
| 3506 |
return false; |
| 3507 |
} |
| 3508 |
if (insideRef) { current.push(tok); } |
| 3509 |
return !insideRef; |
| 3510 |
}); |
| 3511 |
|
| 3512 |
if (!state.env.footnotes.list) { return; } |
| 3513 |
list = state.env.footnotes.list; |
| 3514 |
|
| 3515 |
state.tokens.push({ |
| 3516 |
type: 'footnote_block_open', |
| 3517 |
level: level++ |
| 3518 |
}); |
| 3519 |
for (i = 0, l = list.length; i < l; i++) { |
| 3520 |
state.tokens.push({ |
| 3521 |
type: 'footnote_open', |
| 3522 |
id: i, |
| 3523 |
level: level++ |
| 3524 |
}); |
| 3525 |
|
| 3526 |
if (list[i].tokens) { |
| 3527 |
tokens = []; |
| 3528 |
tokens.push({ |
| 3529 |
type: 'paragraph_open', |
| 3530 |
tight: false, |
| 3531 |
level: level++ |
| 3532 |
}); |
| 3533 |
tokens.push({ |
| 3534 |
type: 'inline', |
| 3535 |
content: '', |
| 3536 |
level: level, |
| 3537 |
children: list[i].tokens |
| 3538 |
}); |
| 3539 |
tokens.push({ |
| 3540 |
type: 'paragraph_close', |
| 3541 |
tight: false, |
| 3542 |
level: --level |
| 3543 |
}); |
| 3544 |
} else if (list[i].label) { |
| 3545 |
tokens = refTokens[':' + list[i].label]; |
| 3546 |
} |
| 3547 |
|
| 3548 |
state.tokens = state.tokens.concat(tokens); |
| 3549 |
if (state.tokens[state.tokens.length - 1].type === 'paragraph_close') { |
| 3550 |
lastParagraph = state.tokens.pop(); |
| 3551 |
} else { |
| 3552 |
lastParagraph = null; |
| 3553 |
} |
| 3554 |
|
| 3555 |
t = list[i].count > 0 ? list[i].count : 1; |
| 3556 |
for (j = 0; j < t; j++) { |
| 3557 |
state.tokens.push({ |
| 3558 |
type: 'footnote_anchor', |
| 3559 |
id: i, |
| 3560 |
subId: j, |
| 3561 |
level: level |
| 3562 |
}); |
| 3563 |
} |
| 3564 |
|
| 3565 |
if (lastParagraph) { |
| 3566 |
state.tokens.push(lastParagraph); |
| 3567 |
} |
| 3568 |
|
| 3569 |
state.tokens.push({ |
| 3570 |
type: 'footnote_close', |
| 3571 |
level: --level |
| 3572 |
}); |
| 3573 |
} |
| 3574 |
state.tokens.push({ |
| 3575 |
type: 'footnote_block_close', |
| 3576 |
level: --level |
| 3577 |
}); |
| 3578 |
} |
| 3579 |
|
| 3580 |
// Enclose abbreviations in <abbr> tags |
| 3581 |
// |
| 3582 |
|
| 3583 |
var PUNCT_CHARS = ' \n()[]\'".,!?-'; |
| 3584 |
|
| 3585 |
|
| 3586 |
// from Google closure library |
| 3587 |
// http://closure-library.googlecode.com/git-history/docs/local_closure_goog_string_string.js.source.html#line1021 |
| 3588 |
function regEscape(s) { |
| 3589 |
return s.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1'); |
| 3590 |
} |
| 3591 |
|
| 3592 |
|
| 3593 |
function abbr2(state) { |
| 3594 |
var i, j, l, tokens, token, text, nodes, pos, level, reg, m, regText, |
| 3595 |
blockTokens = state.tokens; |
| 3596 |
|
| 3597 |
if (!state.env.abbreviations) { return; } |
| 3598 |
if (!state.env.abbrRegExp) { |
| 3599 |
regText = '(^|[' + PUNCT_CHARS.split('').map(regEscape).join('') + '])' |
| 3600 |
+ '(' + Object.keys(state.env.abbreviations).map(function (x) { |
| 3601 |
return x.substr(1); |
| 3602 |
}).sort(function (a, b) { |
| 3603 |
return b.length - a.length; |
| 3604 |
}).map(regEscape).join('|') + ')' |
| 3605 |
+ '($|[' + PUNCT_CHARS.split('').map(regEscape).join('') + '])'; |
| 3606 |
state.env.abbrRegExp = new RegExp(regText, 'g'); |
| 3607 |
} |
| 3608 |
reg = state.env.abbrRegExp; |
| 3609 |
|
| 3610 |
for (j = 0, l = blockTokens.length; j < l; j++) { |
| 3611 |
if (blockTokens[j].type !== 'inline') { continue; } |
| 3612 |
tokens = blockTokens[j].children; |
| 3613 |
|
| 3614 |
// We scan from the end, to keep position when new tags added. |
| 3615 |
for (i = tokens.length - 1; i >= 0; i--) { |
| 3616 |
token = tokens[i]; |
| 3617 |
if (token.type !== 'text') { continue; } |
| 3618 |
|
| 3619 |
pos = 0; |
| 3620 |
text = token.content; |
| 3621 |
reg.lastIndex = 0; |
| 3622 |
level = token.level; |
| 3623 |
nodes = []; |
| 3624 |
|
| 3625 |
while ((m = reg.exec(text))) { |
| 3626 |
if (reg.lastIndex > pos) { |
| 3627 |
nodes.push({ |
| 3628 |
type: 'text', |
| 3629 |
content: text.slice(pos, m.index + m[1].length), |
| 3630 |
level: level |
| 3631 |
}); |
| 3632 |
} |
| 3633 |
|
| 3634 |
nodes.push({ |
| 3635 |
type: 'abbr_open', |
| 3636 |
title: state.env.abbreviations[':' + m[2]], |
| 3637 |
level: level++ |
| 3638 |
}); |
| 3639 |
nodes.push({ |
| 3640 |
type: 'text', |
| 3641 |
content: m[2], |
| 3642 |
level: level |
| 3643 |
}); |
| 3644 |
nodes.push({ |
| 3645 |
type: 'abbr_close', |
| 3646 |
level: --level |
| 3647 |
}); |
| 3648 |
pos = reg.lastIndex - m[3].length; |
| 3649 |
} |
| 3650 |
|
| 3651 |
if (!nodes.length) { continue; } |
| 3652 |
|
| 3653 |
if (pos < text.length) { |
| 3654 |
nodes.push({ |
| 3655 |
type: 'text', |
| 3656 |
content: text.slice(pos), |
| 3657 |
level: level |
| 3658 |
}); |
| 3659 |
} |
| 3660 |
|
| 3661 |
// replace current node |
| 3662 |
blockTokens[j].children = tokens = [].concat(tokens.slice(0, i), nodes, tokens.slice(i + 1)); |
| 3663 |
} |
| 3664 |
} |
| 3665 |
} |
| 3666 |
|
| 3667 |
// Simple typographical replacements |
| 3668 |
// |
| 3669 |
// TODO: |
| 3670 |
// - fractionals 1/2, 1/4, 3/4 -> ½, ¼, ¾ |
| 3671 |
// - miltiplication 2 x 4 -> 2 × 4 |
| 3672 |
|
| 3673 |
var RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/; |
| 3674 |
|
| 3675 |
var SCOPED_ABBR_RE = /\((c|tm|r|p)\)/ig; |
| 3676 |
var SCOPED_ABBR = { |
| 3677 |
'c': '©', |
| 3678 |
'r': '®', |
| 3679 |
'p': '§', |
| 3680 |
'tm': '™' |
| 3681 |
}; |
| 3682 |
|
| 3683 |
function replaceScopedAbbr(str) { |
| 3684 |
if (str.indexOf('(') < 0) { return str; } |
| 3685 |
|
| 3686 |
return str.replace(SCOPED_ABBR_RE, function(match, name) { |
| 3687 |
return SCOPED_ABBR[name.toLowerCase()]; |
| 3688 |
}); |
| 3689 |
} |
| 3690 |
|
| 3691 |
|
| 3692 |
function replace(state) { |
| 3693 |
var i, token, text, inlineTokens, blkIdx; |
| 3694 |
|
| 3695 |
if (!state.options.typographer) { return; } |
| 3696 |
|
| 3697 |
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { |
| 3698 |
|
| 3699 |
if (state.tokens[blkIdx].type !== 'inline') { continue; } |
| 3700 |
|
| 3701 |
inlineTokens = state.tokens[blkIdx].children; |
| 3702 |
|
| 3703 |
for (i = inlineTokens.length - 1; i >= 0; i--) { |
| 3704 |
token = inlineTokens[i]; |
| 3705 |
if (token.type === 'text') { |
| 3706 |
text = token.content; |
| 3707 |
|
| 3708 |
text = replaceScopedAbbr(text); |
| 3709 |
|
| 3710 |
if (RARE_RE.test(text)) { |
| 3711 |
text = text |
| 3712 |
.replace(/\+-/g, '±') |
| 3713 |
// .., ..., ....... -> … |
| 3714 |
// but ?..... & !..... -> ?.. & !.. |
| 3715 |
.replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..') |
| 3716 |
.replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',') |
| 3717 |
// em-dash |
| 3718 |
.replace(/(^|[^-])---([^-]|$)/mg, '$1\u2014$2') |
| 3719 |
// en-dash |
| 3720 |
.replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2') |
| 3721 |
.replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2'); |
| 3722 |
} |
| 3723 |
|
| 3724 |
token.content = text; |
| 3725 |
} |
| 3726 |
} |
| 3727 |
} |
| 3728 |
} |
| 3729 |
|
| 3730 |
// Convert straight quotation marks to typographic ones |
| 3731 |
// |
| 3732 |
|
| 3733 |
var QUOTE_TEST_RE = /['"]/; |
| 3734 |
var QUOTE_RE = /['"]/g; |
| 3735 |
var PUNCT_RE = /[-\s()\[\]]/; |
| 3736 |
var APOSTROPHE = '’'; |
| 3737 |
|
| 3738 |
// This function returns true if the character at `pos` |
| 3739 |
// could be inside a word. |
| 3740 |
function isLetter(str, pos) { |
| 3741 |
if (pos < 0 || pos >= str.length) { return false; } |
| 3742 |
return !PUNCT_RE.test(str[pos]); |
| 3743 |
} |
| 3744 |
|
| 3745 |
|
| 3746 |
function replaceAt(str, index, ch) { |
| 3747 |
return str.substr(0, index) + ch + str.substr(index + 1); |
| 3748 |
} |
| 3749 |
|
| 3750 |
|
| 3751 |
function smartquotes(state) { |
| 3752 |
/*eslint max-depth:0*/ |
| 3753 |
var i, token, text, t, pos, max, thisLevel, lastSpace, nextSpace, item, |
| 3754 |
canOpen, canClose, j, isSingle, blkIdx, tokens, |
| 3755 |
stack; |
| 3756 |
|
| 3757 |
if (!state.options.typographer) { return; } |
| 3758 |
|
| 3759 |
stack = []; |
| 3760 |
|
| 3761 |
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { |
| 3762 |
|
| 3763 |
if (state.tokens[blkIdx].type !== 'inline') { continue; } |
| 3764 |
|
| 3765 |
tokens = state.tokens[blkIdx].children; |
| 3766 |
stack.length = 0; |
| 3767 |
|
| 3768 |
for (i = 0; i < tokens.length; i++) { |
| 3769 |
token = tokens[i]; |
| 3770 |
|
| 3771 |
if (token.type !== 'text' || QUOTE_TEST_RE.test(token.text)) { continue; } |
| 3772 |
|
| 3773 |
thisLevel = tokens[i].level; |
| 3774 |
|
| 3775 |
for (j = stack.length - 1; j >= 0; j--) { |
| 3776 |
if (stack[j].level <= thisLevel) { break; } |
| 3777 |
} |
| 3778 |
stack.length = j + 1; |
| 3779 |
|
| 3780 |
text = token.content; |
| 3781 |
pos = 0; |
| 3782 |
max = text.length; |
| 3783 |
|
| 3784 |
/*eslint no-labels:0,block-scoped-var:0*/ |
| 3785 |
OUTER: |
| 3786 |
while (pos < max) { |
| 3787 |
QUOTE_RE.lastIndex = pos; |
| 3788 |
t = QUOTE_RE.exec(text); |
| 3789 |
if (!t) { break; } |
| 3790 |
|
| 3791 |
lastSpace = !isLetter(text, t.index - 1); |
| 3792 |
pos = t.index + 1; |
| 3793 |
isSingle = (t[0] === "'"); |
| 3794 |
nextSpace = !isLetter(text, pos); |
| 3795 |
|
| 3796 |
if (!nextSpace && !lastSpace) { |
| 3797 |
// middle of word |
| 3798 |
if (isSingle) { |
| 3799 |
token.content = replaceAt(token.content, t.index, APOSTROPHE); |
| 3800 |
} |
| 3801 |
continue; |
| 3802 |
} |
| 3803 |
|
| 3804 |
canOpen = !nextSpace; |
| 3805 |
canClose = !lastSpace; |
| 3806 |
|
| 3807 |
if (canClose) { |
| 3808 |
// this could be a closing quote, rewind the stack to get a match |
| 3809 |
for (j = stack.length - 1; j >= 0; j--) { |
| 3810 |
item = stack[j]; |
| 3811 |
if (stack[j].level < thisLevel) { break; } |
| 3812 |
if (item.single === isSingle && stack[j].level === thisLevel) { |
| 3813 |
item = stack[j]; |
| 3814 |
if (isSingle) { |
| 3815 |
tokens[item.token].content = replaceAt(tokens[item.token].content, item.pos, state.options.quotes[2]); |
| 3816 |
token.content = replaceAt(token.content, t.index, state.options.quotes[3]); |
| 3817 |
} else { |
| 3818 |
tokens[item.token].content = replaceAt(tokens[item.token].content, item.pos, state.options.quotes[0]); |
| 3819 |
token.content = replaceAt(token.content, t.index, state.options.quotes[1]); |
| 3820 |
} |
| 3821 |
stack.length = j; |
| 3822 |
continue OUTER; |
| 3823 |
} |
| 3824 |
} |
| 3825 |
} |
| 3826 |
|
| 3827 |
if (canOpen) { |
| 3828 |
stack.push({ |
| 3829 |
token: i, |
| 3830 |
pos: t.index, |
| 3831 |
single: isSingle, |
| 3832 |
level: thisLevel |
| 3833 |
}); |
| 3834 |
} else if (canClose && isSingle) { |
| 3835 |
token.content = replaceAt(token.content, t.index, APOSTROPHE); |
| 3836 |
} |
| 3837 |
} |
| 3838 |
} |
| 3839 |
} |
| 3840 |
} |
| 3841 |
|
| 3842 |
/** |
| 3843 |
* Core parser `rules` |
| 3844 |
*/ |
| 3845 |
|
| 3846 |
var _rules = [ |
| 3847 |
[ 'block', block ], |
| 3848 |
[ 'abbr', abbr ], |
| 3849 |
[ 'references', references ], |
| 3850 |
[ 'inline', inline ], |
| 3851 |
[ 'footnote_tail', footnote_block ], |
| 3852 |
[ 'abbr2', abbr2 ], |
| 3853 |
[ 'replacements', replace ], |
| 3854 |
[ 'smartquotes', smartquotes ], |
| 3855 |
]; |
| 3856 |
|
| 3857 |
/** |
| 3858 |
* Class for top level (`core`) parser rules |
| 3859 |
* |
| 3860 |
* @api private |
| 3861 |
*/ |
| 3862 |
|
| 3863 |
function Core() { |
| 3864 |
this.options = {}; |
| 3865 |
this.ruler = new Ruler(); |
| 3866 |
for (var i = 0; i < _rules.length; i++) { |
| 3867 |
this.ruler.push(_rules[i][0], _rules[i][1]); |
| 3868 |
} |
| 3869 |
} |
| 3870 |
|
| 3871 |
/** |
| 3872 |
* Process rules with the given `state` |
| 3873 |
* |
| 3874 |
* @param {Object} `state` |
| 3875 |
* @api private |
| 3876 |
*/ |
| 3877 |
|
| 3878 |
Core.prototype.process = function (state) { |
| 3879 |
var i, l, rules; |
| 3880 |
rules = this.ruler.getRules(''); |
| 3881 |
for (i = 0, l = rules.length; i < l; i++) { |
| 3882 |
rules[i](state); |
| 3883 |
} |
| 3884 |
}; |
| 3885 |
|
| 3886 |
// Parser state class |
| 3887 |
|
| 3888 |
function StateBlock(src, parser, options, env, tokens) { |
| 3889 |
var ch, s, start, pos, len, indent, indent_found; |
| 3890 |
|
| 3891 |
this.src = src; |
| 3892 |
|
| 3893 |
// Shortcuts to simplify nested calls |
| 3894 |
this.parser = parser; |
| 3895 |
|
| 3896 |
this.options = options; |
| 3897 |
|
| 3898 |
this.env = env; |
| 3899 |
|
| 3900 |
// |
| 3901 |
// Internal state vartiables |
| 3902 |
// |
| 3903 |
|
| 3904 |
this.tokens = tokens; |
| 3905 |
|
| 3906 |
this.bMarks = []; // line begin offsets for fast jumps |
| 3907 |
this.eMarks = []; // line end offsets for fast jumps |
| 3908 |
this.tShift = []; // indent for each line |
| 3909 |
|
| 3910 |
// block parser variables |
| 3911 |
this.blkIndent = 0; // required block content indent |
| 3912 |
// (for example, if we are in list) |
| 3913 |
this.line = 0; // line index in src |
| 3914 |
this.lineMax = 0; // lines count |
| 3915 |
this.tight = false; // loose/tight mode for lists |
| 3916 |
this.parentType = 'root'; // if `list`, block parser stops on two newlines |
| 3917 |
this.ddIndent = -1; // indent of the current dd block (-1 if there isn't any) |
| 3918 |
|
| 3919 |
this.level = 0; |
| 3920 |
|
| 3921 |
// renderer |
| 3922 |
this.result = ''; |
| 3923 |
|
| 3924 |
// Create caches |
| 3925 |
// Generate markers. |
| 3926 |
s = this.src; |
| 3927 |
indent = 0; |
| 3928 |
indent_found = false; |
| 3929 |
|
| 3930 |
for (start = pos = indent = 0, len = s.length; pos < len; pos++) { |
| 3931 |
ch = s.charCodeAt(pos); |
| 3932 |
|
| 3933 |
if (!indent_found) { |
| 3934 |
if (ch === 0x20/* space */) { |
| 3935 |
indent++; |
| 3936 |
continue; |
| 3937 |
} else { |
| 3938 |
indent_found = true; |
| 3939 |
} |
| 3940 |
} |
| 3941 |
|
| 3942 |
if (ch === 0x0A || pos === len - 1) { |
| 3943 |
if (ch !== 0x0A) { pos++; } |
| 3944 |
this.bMarks.push(start); |
| 3945 |
this.eMarks.push(pos); |
| 3946 |
this.tShift.push(indent); |
| 3947 |
|
| 3948 |
indent_found = false; |
| 3949 |
indent = 0; |
| 3950 |
start = pos + 1; |
| 3951 |
} |
| 3952 |
} |
| 3953 |
|
| 3954 |
// Push fake entry to simplify cache bounds checks |
| 3955 |
this.bMarks.push(s.length); |
| 3956 |
this.eMarks.push(s.length); |
| 3957 |
this.tShift.push(0); |
| 3958 |
|
| 3959 |
this.lineMax = this.bMarks.length - 1; // don't count last fake line |
| 3960 |
} |
| 3961 |
|
| 3962 |
StateBlock.prototype.isEmpty = function isEmpty(line) { |
| 3963 |
return this.bMarks[line] + this.tShift[line] >= this.eMarks[line]; |
| 3964 |
}; |
| 3965 |
|
| 3966 |
StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) { |
| 3967 |
for (var max = this.lineMax; from < max; from++) { |
| 3968 |
if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) { |
| 3969 |
break; |
| 3970 |
} |
| 3971 |
} |
| 3972 |
return from; |
| 3973 |
}; |
| 3974 |
|
| 3975 |
// Skip spaces from given position. |
| 3976 |
StateBlock.prototype.skipSpaces = function skipSpaces(pos) { |
| 3977 |
for (var max = this.src.length; pos < max; pos++) { |
| 3978 |
if (this.src.charCodeAt(pos) !== 0x20/* space */) { break; } |
| 3979 |
} |
| 3980 |
return pos; |
| 3981 |
}; |
| 3982 |
|
| 3983 |
// Skip char codes from given position |
| 3984 |
StateBlock.prototype.skipChars = function skipChars(pos, code) { |
| 3985 |
for (var max = this.src.length; pos < max; pos++) { |
| 3986 |
if (this.src.charCodeAt(pos) !== code) { break; } |
| 3987 |
} |
| 3988 |
return pos; |
| 3989 |
}; |
| 3990 |
|
| 3991 |
// Skip char codes reverse from given position - 1 |
| 3992 |
StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code, min) { |
| 3993 |
if (pos <= min) { return pos; } |
| 3994 |
|
| 3995 |
while (pos > min) { |
| 3996 |
if (code !== this.src.charCodeAt(--pos)) { return pos + 1; } |
| 3997 |
} |
| 3998 |
return pos; |
| 3999 |
}; |
| 4000 |
|
| 4001 |
// cut lines range from source. |
| 4002 |
StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF) { |
| 4003 |
var i, first, last, queue, shift, |
| 4004 |
line = begin; |
| 4005 |
|
| 4006 |
if (begin >= end) { |
| 4007 |
return ''; |
| 4008 |
} |
| 4009 |
|
| 4010 |
// Opt: don't use push queue for single line; |
| 4011 |
if (line + 1 === end) { |
| 4012 |
first = this.bMarks[line] + Math.min(this.tShift[line], indent); |
| 4013 |
last = keepLastLF ? this.eMarks[line] + 1 : this.eMarks[line]; |
| 4014 |
return this.src.slice(first, last); |
| 4015 |
} |
| 4016 |
|
| 4017 |
queue = new Array(end - begin); |
| 4018 |
|
| 4019 |
for (i = 0; line < end; line++, i++) { |
| 4020 |
shift = this.tShift[line]; |
| 4021 |
if (shift > indent) { shift = indent; } |
| 4022 |
if (shift < 0) { shift = 0; } |
| 4023 |
|
| 4024 |
first = this.bMarks[line] + shift; |
| 4025 |
|
| 4026 |
if (line + 1 < end || keepLastLF) { |
| 4027 |
// No need for bounds check because we have fake entry on tail. |
| 4028 |
last = this.eMarks[line] + 1; |
| 4029 |
} else { |
| 4030 |
last = this.eMarks[line]; |
| 4031 |
} |
| 4032 |
|
| 4033 |
queue[i] = this.src.slice(first, last); |
| 4034 |
} |
| 4035 |
|
| 4036 |
return queue.join(''); |
| 4037 |
}; |
| 4038 |
|
| 4039 |
// Code block (4 spaces padded) |
| 4040 |
|
| 4041 |
function code(state, startLine, endLine/*, silent*/) { |
| 4042 |
var nextLine, last; |
| 4043 |
|
| 4044 |
if (state.tShift[startLine] - state.blkIndent < 4) { return false; } |
| 4045 |
|
| 4046 |
last = nextLine = startLine + 1; |
| 4047 |
|
| 4048 |
while (nextLine < endLine) { |
| 4049 |
if (state.isEmpty(nextLine)) { |
| 4050 |
nextLine++; |
| 4051 |
continue; |
| 4052 |
} |
| 4053 |
if (state.tShift[nextLine] - state.blkIndent >= 4) { |
| 4054 |
nextLine++; |
| 4055 |
last = nextLine; |
| 4056 |
continue; |
| 4057 |
} |
| 4058 |
break; |
| 4059 |
} |
| 4060 |
|
| 4061 |
state.line = nextLine; |
| 4062 |
state.tokens.push({ |
| 4063 |
type: 'code', |
| 4064 |
content: state.getLines(startLine, last, 4 + state.blkIndent, true), |
| 4065 |
block: true, |
| 4066 |
lines: [ startLine, state.line ], |
| 4067 |
level: state.level |
| 4068 |
}); |
| 4069 |
|
| 4070 |
return true; |
| 4071 |
} |
| 4072 |
|
| 4073 |
// fences (``` lang, ~~~ lang) |
| 4074 |
|
| 4075 |
function fences(state, startLine, endLine, silent) { |
| 4076 |
var marker, len, params, nextLine, mem, |
| 4077 |
haveEndMarker = false, |
| 4078 |
pos = state.bMarks[startLine] + state.tShift[startLine], |
| 4079 |
max = state.eMarks[startLine]; |
| 4080 |
|
| 4081 |
if (pos + 3 > max) { return false; } |
| 4082 |
|
| 4083 |
marker = state.src.charCodeAt(pos); |
| 4084 |
|
| 4085 |
if (marker !== 0x7E/* ~ */ && marker !== 0x60 /* ` */) { |
| 4086 |
return false; |
| 4087 |
} |
| 4088 |
|
| 4089 |
// scan marker length |
| 4090 |
mem = pos; |
| 4091 |
pos = state.skipChars(pos, marker); |
| 4092 |
|
| 4093 |
len = pos - mem; |
| 4094 |
|
| 4095 |
if (len < 3) { return false; } |
| 4096 |
|
| 4097 |
params = state.src.slice(pos, max).trim(); |
| 4098 |
|
| 4099 |
if (params.indexOf('`') >= 0) { return false; } |
| 4100 |
|
| 4101 |
// Since start is found, we can report success here in validation mode |
| 4102 |
if (silent) { return true; } |
| 4103 |
|
| 4104 |
// search end of block |
| 4105 |
nextLine = startLine; |
| 4106 |
|
| 4107 |
for (;;) { |
| 4108 |
nextLine++; |
| 4109 |
if (nextLine >= endLine) { |
| 4110 |
// unclosed block should be autoclosed by end of document. |
| 4111 |
// also block seems to be autoclosed by end of parent |
| 4112 |
break; |
| 4113 |
} |
| 4114 |
|
| 4115 |
pos = mem = state.bMarks[nextLine] + state.tShift[nextLine]; |
| 4116 |
max = state.eMarks[nextLine]; |
| 4117 |
|
| 4118 |
if (pos < max && state.tShift[nextLine] < state.blkIndent) { |
| 4119 |
// non-empty line with negative indent should stop the list: |
| 4120 |
// - ``` |
| 4121 |
// test |
| 4122 |
break; |
| 4123 |
} |
| 4124 |
|
| 4125 |
if (state.src.charCodeAt(pos) !== marker) { continue; } |
| 4126 |
|
| 4127 |
if (state.tShift[nextLine] - state.blkIndent >= 4) { |
| 4128 |
// closing fence should be indented less than 4 spaces |
| 4129 |
continue; |
| 4130 |
} |
| 4131 |
|
| 4132 |
pos = state.skipChars(pos, marker); |
| 4133 |
|
| 4134 |
// closing code fence must be at least as long as the opening one |
| 4135 |
if (pos - mem < len) { continue; } |
| 4136 |
|
| 4137 |
// make sure tail has spaces only |
| 4138 |
pos = state.skipSpaces(pos); |
| 4139 |
|
| 4140 |
if (pos < max) { continue; } |
| 4141 |
|
| 4142 |
haveEndMarker = true; |
| 4143 |
// found! |
| 4144 |
break; |
| 4145 |
} |
| 4146 |
|
| 4147 |
// If a fence has heading spaces, they should be removed from its inner block |
| 4148 |
len = state.tShift[startLine]; |
| 4149 |
|
| 4150 |
state.line = nextLine + (haveEndMarker ? 1 : 0); |
| 4151 |
state.tokens.push({ |
| 4152 |
type: 'fence', |
| 4153 |
params: params, |
| 4154 |
content: state.getLines(startLine + 1, nextLine, len, true), |
| 4155 |
lines: [ startLine, state.line ], |
| 4156 |
level: state.level |
| 4157 |
}); |
| 4158 |
|
| 4159 |
return true; |
| 4160 |
} |
| 4161 |
|
| 4162 |
// Block quotes |
| 4163 |
|
| 4164 |
function blockquote(state, startLine, endLine, silent) { |
| 4165 |
var nextLine, lastLineEmpty, oldTShift, oldBMarks, oldIndent, oldParentType, lines, |
| 4166 |
terminatorRules, |
| 4167 |
i, l, terminate, |
| 4168 |
pos = state.bMarks[startLine] + state.tShift[startLine], |
| 4169 |
max = state.eMarks[startLine]; |
| 4170 |
|
| 4171 |
if (pos > max) { return false; } |
| 4172 |
|
| 4173 |
// check the block quote marker |
| 4174 |
if (state.src.charCodeAt(pos++) !== 0x3E/* > */) { return false; } |
| 4175 |
|
| 4176 |
if (state.level >= state.options.maxNesting) { return false; } |
| 4177 |
|
| 4178 |
// we know that it's going to be a valid blockquote, |
| 4179 |
// so no point trying to find the end of it in silent mode |
| 4180 |
if (silent) { return true; } |
| 4181 |
|
| 4182 |
// skip one optional space after '>' |
| 4183 |
if (state.src.charCodeAt(pos) === 0x20) { pos++; } |
| 4184 |
|
| 4185 |
oldIndent = state.blkIndent; |
| 4186 |
state.blkIndent = 0; |
| 4187 |
|
| 4188 |
oldBMarks = [ state.bMarks[startLine] ]; |
| 4189 |
state.bMarks[startLine] = pos; |
| 4190 |
|
| 4191 |
// check if we have an empty blockquote |
| 4192 |
pos = pos < max ? state.skipSpaces(pos) : pos; |
| 4193 |
lastLineEmpty = pos >= max; |
| 4194 |
|
| 4195 |
oldTShift = [ state.tShift[startLine] ]; |
| 4196 |
state.tShift[startLine] = pos - state.bMarks[startLine]; |
| 4197 |
|
| 4198 |
terminatorRules = state.parser.ruler.getRules('blockquote'); |
| 4199 |
|
| 4200 |
// Search the end of the block |
| 4201 |
// |
| 4202 |
// Block ends with either: |
| 4203 |
// 1. an empty line outside: |
| 4204 |
// ``` |
| 4205 |
// > test |
| 4206 |
// |
| 4207 |
// ``` |
| 4208 |
// 2. an empty line inside: |
| 4209 |
// ``` |
| 4210 |
// > |
| 4211 |
// test |
| 4212 |
// ``` |
| 4213 |
// 3. another tag |
| 4214 |
// ``` |
| 4215 |
// > test |
| 4216 |
// - - - |
| 4217 |
// ``` |
| 4218 |
for (nextLine = startLine + 1; nextLine < endLine; nextLine++) { |
| 4219 |
pos = state.bMarks[nextLine] + state.tShift[nextLine]; |
| 4220 |
max = state.eMarks[nextLine]; |
| 4221 |
|
| 4222 |
if (pos >= max) { |
| 4223 |
// Case 1: line is not inside the blockquote, and this line is empty. |
| 4224 |
break; |
| 4225 |
} |
| 4226 |
|
| 4227 |
if (state.src.charCodeAt(pos++) === 0x3E/* > */) { |
| 4228 |
// This line is inside the blockquote. |
| 4229 |
|
| 4230 |
// skip one optional space after '>' |
| 4231 |
if (state.src.charCodeAt(pos) === 0x20) { pos++; } |
| 4232 |
|
| 4233 |
oldBMarks.push(state.bMarks[nextLine]); |
| 4234 |
state.bMarks[nextLine] = pos; |
| 4235 |
|
| 4236 |
pos = pos < max ? state.skipSpaces(pos) : pos; |
| 4237 |
lastLineEmpty = pos >= max; |
| 4238 |
|
| 4239 |
oldTShift.push(state.tShift[nextLine]); |
| 4240 |
state.tShift[nextLine] = pos - state.bMarks[nextLine]; |
| 4241 |
continue; |
| 4242 |
} |
| 4243 |
|
| 4244 |
// Case 2: line is not inside the blockquote, and the last line was empty. |
| 4245 |
if (lastLineEmpty) { break; } |
| 4246 |
|
| 4247 |
// Case 3: another tag found. |
| 4248 |
terminate = false; |
| 4249 |
for (i = 0, l = terminatorRules.length; i < l; i++) { |
| 4250 |
if (terminatorRules[i](state, nextLine, endLine, true)) { |
| 4251 |
terminate = true; |
| 4252 |
break; |
| 4253 |
} |
| 4254 |
} |
| 4255 |
if (terminate) { break; } |
| 4256 |
|
| 4257 |
oldBMarks.push(state.bMarks[nextLine]); |
| 4258 |
oldTShift.push(state.tShift[nextLine]); |
| 4259 |
|
| 4260 |
// A negative number means that this is a paragraph continuation; |
| 4261 |
// |
| 4262 |
// Any negative number will do the job here, but it's better for it |
| 4263 |
// to be large enough to make any bugs obvious. |
| 4264 |
state.tShift[nextLine] = -1337; |
| 4265 |
} |
| 4266 |
|
| 4267 |
oldParentType = state.parentType; |
| 4268 |
state.parentType = 'blockquote'; |
| 4269 |
state.tokens.push({ |
| 4270 |
type: 'blockquote_open', |
| 4271 |
lines: lines = [ startLine, 0 ], |
| 4272 |
level: state.level++ |
| 4273 |
}); |
| 4274 |
state.parser.tokenize(state, startLine, nextLine); |
| 4275 |
state.tokens.push({ |
| 4276 |
type: 'blockquote_close', |
| 4277 |
level: --state.level |
| 4278 |
}); |
| 4279 |
state.parentType = oldParentType; |
| 4280 |
lines[1] = state.line; |
| 4281 |
|
| 4282 |
// Restore original tShift; this might not be necessary since the parser |
| 4283 |
// has already been here, but just to make sure we can do that. |
| 4284 |
for (i = 0; i < oldTShift.length; i++) { |
| 4285 |
state.bMarks[i + startLine] = oldBMarks[i]; |
| 4286 |
state.tShift[i + startLine] = oldTShift[i]; |
| 4287 |
} |
| 4288 |
state.blkIndent = oldIndent; |
| 4289 |
|
| 4290 |
return true; |
| 4291 |
} |
| 4292 |
|
| 4293 |
// Horizontal rule |
| 4294 |
|
| 4295 |
function hr(state, startLine, endLine, silent) { |
| 4296 |
var marker, cnt, ch, |
| 4297 |
pos = state.bMarks[startLine], |
| 4298 |
max = state.eMarks[startLine]; |
| 4299 |
|
| 4300 |
pos += state.tShift[startLine]; |
| 4301 |
|
| 4302 |
if (pos > max) { return false; } |
| 4303 |
|
| 4304 |
marker = state.src.charCodeAt(pos++); |
| 4305 |
|
| 4306 |
// Check hr marker |
| 4307 |
if (marker !== 0x2A/* * */ && |
| 4308 |
marker !== 0x2D/* - */ && |
| 4309 |
marker !== 0x5F/* _ */) { |
| 4310 |
return false; |
| 4311 |
} |
| 4312 |
|
| 4313 |
// markers can be mixed with spaces, but there should be at least 3 one |
| 4314 |
|
| 4315 |
cnt = 1; |
| 4316 |
while (pos < max) { |
| 4317 |
ch = state.src.charCodeAt(pos++); |
| 4318 |
if (ch !== marker && ch !== 0x20/* space */) { return false; } |
| 4319 |
if (ch === marker) { cnt++; } |
| 4320 |
} |
| 4321 |
|
| 4322 |
if (cnt < 3) { return false; } |
| 4323 |
|
| 4324 |
if (silent) { return true; } |
| 4325 |
|
| 4326 |
state.line = startLine + 1; |
| 4327 |
state.tokens.push({ |
| 4328 |
type: 'hr', |
| 4329 |
lines: [ startLine, state.line ], |
| 4330 |
level: state.level |
| 4331 |
}); |
| 4332 |
|
| 4333 |
return true; |
| 4334 |
} |
| 4335 |
|
| 4336 |
// Lists |
| 4337 |
|
| 4338 |
// Search `[-+*][\n ]`, returns next pos arter marker on success |
| 4339 |
// or -1 on fail. |
| 4340 |
function skipBulletListMarker(state, startLine) { |
| 4341 |
var marker, pos, max; |
| 4342 |
|
| 4343 |
pos = state.bMarks[startLine] + state.tShift[startLine]; |
| 4344 |
max = state.eMarks[startLine]; |
| 4345 |
|
| 4346 |
if (pos >= max) { return -1; } |
| 4347 |
|
| 4348 |
marker = state.src.charCodeAt(pos++); |
| 4349 |
// Check bullet |
| 4350 |
if (marker !== 0x2A/* * */ && |
| 4351 |
marker !== 0x2D/* - */ && |
| 4352 |
marker !== 0x2B/* + */) { |
| 4353 |
return -1; |
| 4354 |
} |
| 4355 |
|
| 4356 |
if (pos < max && state.src.charCodeAt(pos) !== 0x20) { |
| 4357 |
// " 1.test " - is not a list item |
| 4358 |
return -1; |
| 4359 |
} |
| 4360 |
|
| 4361 |
return pos; |
| 4362 |
} |
| 4363 |
|
| 4364 |
// Search `\d+[.)][\n ]`, returns next pos arter marker on success |
| 4365 |
// or -1 on fail. |
| 4366 |
function skipOrderedListMarker(state, startLine) { |
| 4367 |
var ch, |
| 4368 |
pos = state.bMarks[startLine] + state.tShift[startLine], |
| 4369 |
max = state.eMarks[startLine]; |
| 4370 |
|
| 4371 |
if (pos + 1 >= max) { return -1; } |
| 4372 |
|
| 4373 |
ch = state.src.charCodeAt(pos++); |
| 4374 |
|
| 4375 |
if (ch < 0x30/* 0 */ || ch > 0x39/* 9 */) { return -1; } |
| 4376 |
|
| 4377 |
for (;;) { |
| 4378 |
// EOL -> fail |
| 4379 |
if (pos >= max) { return -1; } |
| 4380 |
|
| 4381 |
ch = state.src.charCodeAt(pos++); |
| 4382 |
|
| 4383 |
if (ch >= 0x30/* 0 */ && ch <= 0x39/* 9 */) { |
| 4384 |
continue; |
| 4385 |
} |
| 4386 |
|
| 4387 |
// found valid marker |
| 4388 |
if (ch === 0x29/* ) */ || ch === 0x2e/* . */) { |
| 4389 |
break; |
| 4390 |
} |
| 4391 |
|
| 4392 |
return -1; |
| 4393 |
} |
| 4394 |
|
| 4395 |
|
| 4396 |
if (pos < max && state.src.charCodeAt(pos) !== 0x20/* space */) { |
| 4397 |
// " 1.test " - is not a list item |
| 4398 |
return -1; |
| 4399 |
} |
| 4400 |
return pos; |
| 4401 |
} |
| 4402 |
|
| 4403 |
function markTightParagraphs(state, idx) { |
| 4404 |
var i, l, |
| 4405 |
level = state.level + 2; |
| 4406 |
|
| 4407 |
for (i = idx + 2, l = state.tokens.length - 2; i < l; i++) { |
| 4408 |
if (state.tokens[i].level === level && state.tokens[i].type === 'paragraph_open') { |
| 4409 |
state.tokens[i + 2].tight = true; |
| 4410 |
state.tokens[i].tight = true; |
| 4411 |
i += 2; |
| 4412 |
} |
| 4413 |
} |
| 4414 |
} |
| 4415 |
|
| 4416 |
|
| 4417 |
function list(state, startLine, endLine, silent) { |
| 4418 |
var nextLine, |
| 4419 |
indent, |
| 4420 |
oldTShift, |
| 4421 |
oldIndent, |
| 4422 |
oldTight, |
| 4423 |
oldParentType, |
| 4424 |
start, |
| 4425 |
posAfterMarker, |
| 4426 |
max, |
| 4427 |
indentAfterMarker, |
| 4428 |
markerValue, |
| 4429 |
markerCharCode, |
| 4430 |
isOrdered, |
| 4431 |
contentStart, |
| 4432 |
listTokIdx, |
| 4433 |
prevEmptyEnd, |
| 4434 |
listLines, |
| 4435 |
itemLines, |
| 4436 |
tight = true, |
| 4437 |
terminatorRules, |
| 4438 |
i, l, terminate; |
| 4439 |
|
| 4440 |
// Detect list type and position after marker |
| 4441 |
if ((posAfterMarker = skipOrderedListMarker(state, startLine)) >= 0) { |
| 4442 |
isOrdered = true; |
| 4443 |
} else if ((posAfterMarker = skipBulletListMarker(state, startLine)) >= 0) { |
| 4444 |
isOrdered = false; |
| 4445 |
} else { |
| 4446 |
return false; |
| 4447 |
} |
| 4448 |
|
| 4449 |
if (state.level >= state.options.maxNesting) { return false; } |
| 4450 |
|
| 4451 |
// We should terminate list on style change. Remember first one to compare. |
| 4452 |
markerCharCode = state.src.charCodeAt(posAfterMarker - 1); |
| 4453 |
|
| 4454 |
// For validation mode we can terminate immediately |
| 4455 |
if (silent) { return true; } |
| 4456 |
|
| 4457 |
// Start list |
| 4458 |
listTokIdx = state.tokens.length; |
| 4459 |
|
| 4460 |
if (isOrdered) { |
| 4461 |
start = state.bMarks[startLine] + state.tShift[startLine]; |
| 4462 |
markerValue = Number(state.src.substr(start, posAfterMarker - start - 1)); |
| 4463 |
|
| 4464 |
state.tokens.push({ |
| 4465 |
type: 'ordered_list_open', |
| 4466 |
order: markerValue, |
| 4467 |
lines: listLines = [ startLine, 0 ], |
| 4468 |
level: state.level++ |
| 4469 |
}); |
| 4470 |
|
| 4471 |
} else { |
| 4472 |
state.tokens.push({ |
| 4473 |
type: 'bullet_list_open', |
| 4474 |
lines: listLines = [ startLine, 0 ], |
| 4475 |
level: state.level++ |
| 4476 |
}); |
| 4477 |
} |
| 4478 |
|
| 4479 |
// |
| 4480 |
// Iterate list items |
| 4481 |
// |
| 4482 |
|
| 4483 |
nextLine = startLine; |
| 4484 |
prevEmptyEnd = false; |
| 4485 |
terminatorRules = state.parser.ruler.getRules('list'); |
| 4486 |
|
| 4487 |
while (nextLine < endLine) { |
| 4488 |
contentStart = state.skipSpaces(posAfterMarker); |
| 4489 |
max = state.eMarks[nextLine]; |
| 4490 |
|
| 4491 |
if (contentStart >= max) { |
| 4492 |
// trimming space in "- \n 3" case, indent is 1 here |
| 4493 |
indentAfterMarker = 1; |
| 4494 |
} else { |
| 4495 |
indentAfterMarker = contentStart - posAfterMarker; |
| 4496 |
} |
| 4497 |
|
| 4498 |
// If we have more than 4 spaces, the indent is 1 |
| 4499 |
// (the rest is just indented code block) |
| 4500 |
if (indentAfterMarker > 4) { indentAfterMarker = 1; } |
| 4501 |
|
| 4502 |
// If indent is less than 1, assume that it's one, example: |
| 4503 |
// "-\n test" |
| 4504 |
if (indentAfterMarker < 1) { indentAfterMarker = 1; } |
| 4505 |
|
| 4506 |
// " - test" |
| 4507 |
// ^^^^^ - calculating total length of this thing |
| 4508 |
indent = (posAfterMarker - state.bMarks[nextLine]) + indentAfterMarker; |
| 4509 |
|
| 4510 |
// Run subparser & write tokens |
| 4511 |
state.tokens.push({ |
| 4512 |
type: 'list_item_open', |
| 4513 |
lines: itemLines = [ startLine, 0 ], |
| 4514 |
level: state.level++ |
| 4515 |
}); |
| 4516 |
|
| 4517 |
oldIndent = state.blkIndent; |
| 4518 |
oldTight = state.tight; |
| 4519 |
oldTShift = state.tShift[startLine]; |
| 4520 |
oldParentType = state.parentType; |
| 4521 |
state.tShift[startLine] = contentStart - state.bMarks[startLine]; |
| 4522 |
state.blkIndent = indent; |
| 4523 |
state.tight = true; |
| 4524 |
state.parentType = 'list'; |
| 4525 |
|
| 4526 |
state.parser.tokenize(state, startLine, endLine, true); |
| 4527 |
|
| 4528 |
// If any of list item is tight, mark list as tight |
| 4529 |
if (!state.tight || prevEmptyEnd) { |
| 4530 |
tight = false; |
| 4531 |
} |
| 4532 |
// Item become loose if finish with empty line, |
| 4533 |
// but we should filter last element, because it means list finish |
| 4534 |
prevEmptyEnd = (state.line - startLine) > 1 && state.isEmpty(state.line - 1); |
| 4535 |
|
| 4536 |
state.blkIndent = oldIndent; |
| 4537 |
state.tShift[startLine] = oldTShift; |
| 4538 |
state.tight = oldTight; |
| 4539 |
state.parentType = oldParentType; |
| 4540 |
|
| 4541 |
state.tokens.push({ |
| 4542 |
type: 'list_item_close', |
| 4543 |
level: --state.level |
| 4544 |
}); |
| 4545 |
|
| 4546 |
nextLine = startLine = state.line; |
| 4547 |
itemLines[1] = nextLine; |
| 4548 |
contentStart = state.bMarks[startLine]; |
| 4549 |
|
| 4550 |
if (nextLine >= endLine) { break; } |
| 4551 |
|
| 4552 |
if (state.isEmpty(nextLine)) { |
| 4553 |
break; |
| 4554 |
} |
| 4555 |
|
| 4556 |
// |
| 4557 |
// Try to check if list is terminated or continued. |
| 4558 |
// |
| 4559 |
if (state.tShift[nextLine] < state.blkIndent) { break; } |
| 4560 |
|
| 4561 |
// fail if terminating block found |
| 4562 |
terminate = false; |
| 4563 |
for (i = 0, l = terminatorRules.length; i < l; i++) { |
| 4564 |
if (terminatorRules[i](state, nextLine, endLine, true)) { |
| 4565 |
terminate = true; |
| 4566 |
break; |
| 4567 |
} |
| 4568 |
} |
| 4569 |
if (terminate) { break; } |
| 4570 |
|
| 4571 |
// fail if list has another type |
| 4572 |
if (isOrdered) { |
| 4573 |
posAfterMarker = skipOrderedListMarker(state, nextLine); |
| 4574 |
if (posAfterMarker < 0) { break; } |
| 4575 |
} else { |
| 4576 |
posAfterMarker = skipBulletListMarker(state, nextLine); |
| 4577 |
if (posAfterMarker < 0) { break; } |
| 4578 |
} |
| 4579 |
|
| 4580 |
if (markerCharCode !== state.src.charCodeAt(posAfterMarker - 1)) { break; } |
| 4581 |
} |
| 4582 |
|
| 4583 |
// Finilize list |
| 4584 |
state.tokens.push({ |
| 4585 |
type: isOrdered ? 'ordered_list_close' : 'bullet_list_close', |
| 4586 |
level: --state.level |
| 4587 |
}); |
| 4588 |
listLines[1] = nextLine; |
| 4589 |
|
| 4590 |
state.line = nextLine; |
| 4591 |
|
| 4592 |
// mark paragraphs tight if needed |
| 4593 |
if (tight) { |
| 4594 |
markTightParagraphs(state, listTokIdx); |
| 4595 |
} |
| 4596 |
|
| 4597 |
return true; |
| 4598 |
} |
| 4599 |
|
| 4600 |
// Process footnote reference list |
| 4601 |
|
| 4602 |
function footnote(state, startLine, endLine, silent) { |
| 4603 |
var oldBMark, oldTShift, oldParentType, pos, label, |
| 4604 |
start = state.bMarks[startLine] + state.tShift[startLine], |
| 4605 |
max = state.eMarks[startLine]; |
| 4606 |
|
| 4607 |
// line should be at least 5 chars - "[^x]:" |
| 4608 |
if (start + 4 > max) { return false; } |
| 4609 |
|
| 4610 |
if (state.src.charCodeAt(start) !== 0x5B/* [ */) { return false; } |
| 4611 |
if (state.src.charCodeAt(start + 1) !== 0x5E/* ^ */) { return false; } |
| 4612 |
if (state.level >= state.options.maxNesting) { return false; } |
| 4613 |
|
| 4614 |
for (pos = start + 2; pos < max; pos++) { |
| 4615 |
if (state.src.charCodeAt(pos) === 0x20) { return false; } |
| 4616 |
if (state.src.charCodeAt(pos) === 0x5D /* ] */) { |
| 4617 |
break; |
| 4618 |
} |
| 4619 |
} |
| 4620 |
|
| 4621 |
if (pos === start + 2) { return false; } // no empty footnote labels |
| 4622 |
if (pos + 1 >= max || state.src.charCodeAt(++pos) !== 0x3A /* : */) { return false; } |
| 4623 |
if (silent) { return true; } |
| 4624 |
pos++; |
| 4625 |
|
| 4626 |
if (!state.env.footnotes) { state.env.footnotes = {}; } |
| 4627 |
if (!state.env.footnotes.refs) { state.env.footnotes.refs = {}; } |
| 4628 |
label = state.src.slice(start + 2, pos - 2); |
| 4629 |
state.env.footnotes.refs[':' + label] = -1; |
| 4630 |
|
| 4631 |
state.tokens.push({ |
| 4632 |
type: 'footnote_reference_open', |
| 4633 |
label: label, |
| 4634 |
level: state.level++ |
| 4635 |
}); |
| 4636 |
|
| 4637 |
oldBMark = state.bMarks[startLine]; |
| 4638 |
oldTShift = state.tShift[startLine]; |
| 4639 |
oldParentType = state.parentType; |
| 4640 |
state.tShift[startLine] = state.skipSpaces(pos) - pos; |
| 4641 |
state.bMarks[startLine] = pos; |
| 4642 |
state.blkIndent += 4; |
| 4643 |
state.parentType = 'footnote'; |
| 4644 |
|
| 4645 |
if (state.tShift[startLine] < state.blkIndent) { |
| 4646 |
state.tShift[startLine] += state.blkIndent; |
| 4647 |
state.bMarks[startLine] -= state.blkIndent; |
| 4648 |
} |
| 4649 |
|
| 4650 |
state.parser.tokenize(state, startLine, endLine, true); |
| 4651 |
|
| 4652 |
state.parentType = oldParentType; |
| 4653 |
state.blkIndent -= 4; |
| 4654 |
state.tShift[startLine] = oldTShift; |
| 4655 |
state.bMarks[startLine] = oldBMark; |
| 4656 |
|
| 4657 |
state.tokens.push({ |
| 4658 |
type: 'footnote_reference_close', |
| 4659 |
level: --state.level |
| 4660 |
}); |
| 4661 |
|
| 4662 |
return true; |
| 4663 |
} |
| 4664 |
|
| 4665 |
// heading (#, ##, ...) |
| 4666 |
|
| 4667 |
function heading(state, startLine, endLine, silent) { |
| 4668 |
var ch, level, tmp, |
| 4669 |
pos = state.bMarks[startLine] + state.tShift[startLine], |
| 4670 |
max = state.eMarks[startLine]; |
| 4671 |
|
| 4672 |
if (pos >= max) { return false; } |
| 4673 |
|
| 4674 |
ch = state.src.charCodeAt(pos); |
| 4675 |
|
| 4676 |
if (ch !== 0x23/* # */ || pos >= max) { return false; } |
| 4677 |
|
| 4678 |
// count heading level |
| 4679 |
level = 1; |
| 4680 |
ch = state.src.charCodeAt(++pos); |
| 4681 |
while (ch === 0x23/* # */ && pos < max && level <= 6) { |
| 4682 |
level++; |
| 4683 |
ch = state.src.charCodeAt(++pos); |
| 4684 |
} |
| 4685 |
|
| 4686 |
if (level > 6 || (pos < max && ch !== 0x20/* space */)) { return false; } |
| 4687 |
|
| 4688 |
if (silent) { return true; } |
| 4689 |
|
| 4690 |
// Let's cut tails like ' ### ' from the end of string |
| 4691 |
|
| 4692 |
max = state.skipCharsBack(max, 0x20, pos); // space |
| 4693 |
tmp = state.skipCharsBack(max, 0x23, pos); // # |
| 4694 |
if (tmp > pos && state.src.charCodeAt(tmp - 1) === 0x20/* space */) { |
| 4695 |
max = tmp; |
| 4696 |
} |
| 4697 |
|
| 4698 |
state.line = startLine + 1; |
| 4699 |
|
| 4700 |
state.tokens.push({ type: 'heading_open', |
| 4701 |
hLevel: level, |
| 4702 |
lines: [ startLine, state.line ], |
| 4703 |
level: state.level |
| 4704 |
}); |
| 4705 |
|
| 4706 |
// only if header is not empty |
| 4707 |
if (pos < max) { |
| 4708 |
state.tokens.push({ |
| 4709 |
type: 'inline', |
| 4710 |
content: state.src.slice(pos, max).trim(), |
| 4711 |
level: state.level + 1, |
| 4712 |
lines: [ startLine, state.line ], |
| 4713 |
children: [] |
| 4714 |
}); |
| 4715 |
} |
| 4716 |
state.tokens.push({ type: 'heading_close', hLevel: level, level: state.level }); |
| 4717 |
|
| 4718 |
return true; |
| 4719 |
} |
| 4720 |
|
| 4721 |
// lheading (---, ===) |
| 4722 |
|
| 4723 |
function lheading(state, startLine, endLine/*, silent*/) { |
| 4724 |
var marker, pos, max, |
| 4725 |
next = startLine + 1; |
| 4726 |
|
| 4727 |
if (next >= endLine) { return false; } |
| 4728 |
if (state.tShift[next] < state.blkIndent) { return false; } |
| 4729 |
|
| 4730 |
// Scan next line |
| 4731 |
|
| 4732 |
if (state.tShift[next] - state.blkIndent > 3) { return false; } |
| 4733 |
|
| 4734 |
pos = state.bMarks[next] + state.tShift[next]; |
| 4735 |
max = state.eMarks[next]; |
| 4736 |
|
| 4737 |
if (pos >= max) { return false; } |
| 4738 |
|
| 4739 |
marker = state.src.charCodeAt(pos); |
| 4740 |
|
| 4741 |
if (marker !== 0x2D/* - */ && marker !== 0x3D/* = */) { return false; } |
| 4742 |
|
| 4743 |
pos = state.skipChars(pos, marker); |
| 4744 |
|
| 4745 |
pos = state.skipSpaces(pos); |
| 4746 |
|
| 4747 |
if (pos < max) { return false; } |
| 4748 |
|
| 4749 |
pos = state.bMarks[startLine] + state.tShift[startLine]; |
| 4750 |
|
| 4751 |
state.line = next + 1; |
| 4752 |
state.tokens.push({ |
| 4753 |
type: 'heading_open', |
| 4754 |
hLevel: marker === 0x3D/* = */ ? 1 : 2, |
| 4755 |
lines: [ startLine, state.line ], |
| 4756 |
level: state.level |
| 4757 |
}); |
| 4758 |
state.tokens.push({ |
| 4759 |
type: 'inline', |
| 4760 |
content: state.src.slice(pos, state.eMarks[startLine]).trim(), |
| 4761 |
level: state.level + 1, |
| 4762 |
lines: [ startLine, state.line - 1 ], |
| 4763 |
children: [] |
| 4764 |
}); |
| 4765 |
state.tokens.push({ |
| 4766 |
type: 'heading_close', |
| 4767 |
hLevel: marker === 0x3D/* = */ ? 1 : 2, |
| 4768 |
level: state.level |
| 4769 |
}); |
| 4770 |
|
| 4771 |
return true; |
| 4772 |
} |
| 4773 |
|
| 4774 |
// List of valid html blocks names, accorting to commonmark spec |
| 4775 |
// http://jgm.github.io/CommonMark/spec.html#html-blocks |
| 4776 |
|
| 4777 |
var html_blocks = {}; |
| 4778 |
|
| 4779 |
[ |
| 4780 |
'article', |
| 4781 |
'aside', |
| 4782 |
'button', |
| 4783 |
'blockquote', |
| 4784 |
'body', |
| 4785 |
'canvas', |
| 4786 |
'caption', |
| 4787 |
'col', |
| 4788 |
'colgroup', |
| 4789 |
'dd', |
| 4790 |
'div', |
| 4791 |
'dl', |
| 4792 |
'dt', |
| 4793 |
'embed', |
| 4794 |
'fieldset', |
| 4795 |
'figcaption', |
| 4796 |
'figure', |
| 4797 |
'footer', |
| 4798 |
'form', |
| 4799 |
'h1', |
| 4800 |
'h2', |
| 4801 |
'h3', |
| 4802 |
'h4', |
| 4803 |
'h5', |
| 4804 |
'h6', |
| 4805 |
'header', |
| 4806 |
'hgroup', |
| 4807 |
'hr', |
| 4808 |
'iframe', |
| 4809 |
'li', |
| 4810 |
'map', |
| 4811 |
'object', |
| 4812 |
'ol', |
| 4813 |
'output', |
| 4814 |
'p', |
| 4815 |
'pre', |
| 4816 |
'progress', |
| 4817 |
'script', |
| 4818 |
'section', |
| 4819 |
'style', |
| 4820 |
'table', |
| 4821 |
'tbody', |
| 4822 |
'td', |
| 4823 |
'textarea', |
| 4824 |
'tfoot', |
| 4825 |
'th', |
| 4826 |
'tr', |
| 4827 |
'thead', |
| 4828 |
'ul', |
| 4829 |
'video' |
| 4830 |
].forEach(function (name) { html_blocks[name] = true; }); |
| 4831 |
|
| 4832 |
// HTML block |
| 4833 |
|
| 4834 |
|
| 4835 |
var HTML_TAG_OPEN_RE = /^<([a-zA-Z]{1,15})[\s\/>]/; |
| 4836 |
var HTML_TAG_CLOSE_RE = /^<\/([a-zA-Z]{1,15})[\s>]/; |
| 4837 |
|
| 4838 |
function isLetter$1(ch) { |
| 4839 |
/*eslint no-bitwise:0*/ |
| 4840 |
var lc = ch | 0x20; // to lower case |
| 4841 |
return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */); |
| 4842 |
} |
| 4843 |
|
| 4844 |
function htmlblock(state, startLine, endLine, silent) { |
| 4845 |
var ch, match, nextLine, |
| 4846 |
pos = state.bMarks[startLine], |
| 4847 |
max = state.eMarks[startLine], |
| 4848 |
shift = state.tShift[startLine]; |
| 4849 |
|
| 4850 |
pos += shift; |
| 4851 |
|
| 4852 |
if (!state.options.html) { return false; } |
| 4853 |
|
| 4854 |
if (shift > 3 || pos + 2 >= max) { return false; } |
| 4855 |
|
| 4856 |
if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false; } |
| 4857 |
|
| 4858 |
ch = state.src.charCodeAt(pos + 1); |
| 4859 |
|
| 4860 |
if (ch === 0x21/* ! */ || ch === 0x3F/* ? */) { |
| 4861 |
// Directive start / comment start / processing instruction start |
| 4862 |
if (silent) { return true; } |
| 4863 |
|
| 4864 |
} else if (ch === 0x2F/* / */ || isLetter$1(ch)) { |
| 4865 |
|
| 4866 |
// Probably start or end of tag |
| 4867 |
if (ch === 0x2F/* \ */) { |
| 4868 |
// closing tag |
| 4869 |
match = state.src.slice(pos, max).match(HTML_TAG_CLOSE_RE); |
| 4870 |
if (!match) { return false; } |
| 4871 |
} else { |
| 4872 |
// opening tag |
| 4873 |
match = state.src.slice(pos, max).match(HTML_TAG_OPEN_RE); |
| 4874 |
if (!match) { return false; } |
| 4875 |
} |
| 4876 |
// Make sure tag name is valid |
| 4877 |
if (html_blocks[match[1].toLowerCase()] !== true) { return false; } |
| 4878 |
if (silent) { return true; } |
| 4879 |
|
| 4880 |
} else { |
| 4881 |
return false; |
| 4882 |
} |
| 4883 |
|
| 4884 |
// If we are here - we detected HTML block. |
| 4885 |
// Let's roll down till empty line (block end). |
| 4886 |
nextLine = startLine + 1; |
| 4887 |
while (nextLine < state.lineMax && !state.isEmpty(nextLine)) { |
| 4888 |
nextLine++; |
| 4889 |
} |
| 4890 |
|
| 4891 |
state.line = nextLine; |
| 4892 |
state.tokens.push({ |
| 4893 |
type: 'htmlblock', |
| 4894 |
level: state.level, |
| 4895 |
lines: [ startLine, state.line ], |
| 4896 |
content: state.getLines(startLine, nextLine, 0, true) |
| 4897 |
}); |
| 4898 |
|
| 4899 |
return true; |
| 4900 |
} |
| 4901 |
|
| 4902 |
// GFM table, non-standard |
| 4903 |
|
| 4904 |
function getLine(state, line) { |
| 4905 |
var pos = state.bMarks[line] + state.blkIndent, |
| 4906 |
max = state.eMarks[line]; |
| 4907 |
|
| 4908 |
return state.src.substr(pos, max - pos); |
| 4909 |
} |
| 4910 |
|
| 4911 |
function table(state, startLine, endLine, silent) { |
| 4912 |
var ch, lineText, pos, i, nextLine, rows, cell, |
| 4913 |
aligns, t, tableLines, tbodyLines; |
| 4914 |
|
| 4915 |
// should have at least three lines |
| 4916 |
if (startLine + 2 > endLine) { return false; } |
| 4917 |
|
| 4918 |
nextLine = startLine + 1; |
| 4919 |
|
| 4920 |
if (state.tShift[nextLine] < state.blkIndent) { return false; } |
| 4921 |
|
| 4922 |
// first character of the second line should be '|' or '-' |
| 4923 |
|
| 4924 |
pos = state.bMarks[nextLine] + state.tShift[nextLine]; |
| 4925 |
if (pos >= state.eMarks[nextLine]) { return false; } |
| 4926 |
|
| 4927 |
ch = state.src.charCodeAt(pos); |
| 4928 |
if (ch !== 0x7C/* | */ && ch !== 0x2D/* - */ && ch !== 0x3A/* : */) { return false; } |
| 4929 |
|
| 4930 |
lineText = getLine(state, startLine + 1); |
| 4931 |
if (!/^[-:| ]+$/.test(lineText)) { return false; } |
| 4932 |
|
| 4933 |
rows = lineText.split('|'); |
| 4934 |
if (rows <= 2) { return false; } |
| 4935 |
aligns = []; |
| 4936 |
for (i = 0; i < rows.length; i++) { |
| 4937 |
t = rows[i].trim(); |
| 4938 |
if (!t) { |
| 4939 |
// allow empty columns before and after table, but not in between columns; |
| 4940 |
// e.g. allow ` |---| `, disallow ` ---||--- ` |
| 4941 |
if (i === 0 || i === rows.length - 1) { |
| 4942 |
continue; |
| 4943 |
} else { |
| 4944 |
return false; |
| 4945 |
} |
| 4946 |
} |
| 4947 |
|
| 4948 |
if (!/^:?-+:?$/.test(t)) { return false; } |
| 4949 |
if (t.charCodeAt(t.length - 1) === 0x3A/* : */) { |
| 4950 |
aligns.push(t.charCodeAt(0) === 0x3A/* : */ ? 'center' : 'right'); |
| 4951 |
} else if (t.charCodeAt(0) === 0x3A/* : */) { |
| 4952 |
aligns.push('left'); |
| 4953 |
} else { |
| 4954 |
aligns.push(''); |
| 4955 |
} |
| 4956 |
} |
| 4957 |
|
| 4958 |
lineText = getLine(state, startLine).trim(); |
| 4959 |
if (lineText.indexOf('|') === -1) { return false; } |
| 4960 |
rows = lineText.replace(/^\||\|$/g, '').split('|'); |
| 4961 |
if (aligns.length !== rows.length) { return false; } |
| 4962 |
if (silent) { return true; } |
| 4963 |
|
| 4964 |
state.tokens.push({ |
| 4965 |
type: 'table_open', |
| 4966 |
lines: tableLines = [ startLine, 0 ], |
| 4967 |
level: state.level++ |
| 4968 |
}); |
| 4969 |
state.tokens.push({ |
| 4970 |
type: 'thead_open', |
| 4971 |
lines: [ startLine, startLine + 1 ], |
| 4972 |
level: state.level++ |
| 4973 |
}); |
| 4974 |
|
| 4975 |
state.tokens.push({ |
| 4976 |
type: 'tr_open', |
| 4977 |
lines: [ startLine, startLine + 1 ], |
| 4978 |
level: state.level++ |
| 4979 |
}); |
| 4980 |
for (i = 0; i < rows.length; i++) { |
| 4981 |
state.tokens.push({ |
| 4982 |
type: 'th_open', |
| 4983 |
align: aligns[i], |
| 4984 |
lines: [ startLine, startLine + 1 ], |
| 4985 |
level: state.level++ |
| 4986 |
}); |
| 4987 |
state.tokens.push({ |
| 4988 |
type: 'inline', |
| 4989 |
content: rows[i].trim(), |
| 4990 |
lines: [ startLine, startLine + 1 ], |
| 4991 |
level: state.level, |
| 4992 |
children: [] |
| 4993 |
}); |
| 4994 |
state.tokens.push({ type: 'th_close', level: --state.level }); |
| 4995 |
} |
| 4996 |
state.tokens.push({ type: 'tr_close', level: --state.level }); |
| 4997 |
state.tokens.push({ type: 'thead_close', level: --state.level }); |
| 4998 |
|
| 4999 |
state.tokens.push({ |
| 5000 |
type: 'tbody_open', |
| 5001 |
lines: tbodyLines = [ startLine + 2, 0 ], |
| 5002 |
level: state.level++ |
| 5003 |
}); |
| 5004 |
|
| 5005 |
for (nextLine = startLine + 2; nextLine < endLine; nextLine++) { |
| 5006 |
if (state.tShift[nextLine] < state.blkIndent) { break; } |
| 5007 |
|
| 5008 |
lineText = getLine(state, nextLine).trim(); |
| 5009 |
if (lineText.indexOf('|') === -1) { break; } |
| 5010 |
rows = lineText.replace(/^\||\|$/g, '').split('|'); |
| 5011 |
|
| 5012 |
state.tokens.push({ type: 'tr_open', level: state.level++ }); |
| 5013 |
for (i = 0; i < rows.length; i++) { |
| 5014 |
state.tokens.push({ type: 'td_open', align: aligns[i], level: state.level++ }); |
| 5015 |
// 0x7c === '|' |
| 5016 |
cell = rows[i].substring( |
| 5017 |
rows[i].charCodeAt(0) === 0x7c ? 1 : 0, |
| 5018 |
rows[i].charCodeAt(rows[i].length - 1) === 0x7c ? rows[i].length - 1 : rows[i].length |
| 5019 |
).trim(); |
| 5020 |
state.tokens.push({ |
| 5021 |
type: 'inline', |
| 5022 |
content: cell, |
| 5023 |
level: state.level, |
| 5024 |
children: [] |
| 5025 |
}); |
| 5026 |
state.tokens.push({ type: 'td_close', level: --state.level }); |
| 5027 |
} |
| 5028 |
state.tokens.push({ type: 'tr_close', level: --state.level }); |
| 5029 |
} |
| 5030 |
state.tokens.push({ type: 'tbody_close', level: --state.level }); |
| 5031 |
state.tokens.push({ type: 'table_close', level: --state.level }); |
| 5032 |
|
| 5033 |
tableLines[1] = tbodyLines[1] = nextLine; |
| 5034 |
state.line = nextLine; |
| 5035 |
return true; |
| 5036 |
} |
| 5037 |
|
| 5038 |
// Definition lists |
| 5039 |
|
| 5040 |
// Search `[:~][\n ]`, returns next pos after marker on success |
| 5041 |
// or -1 on fail. |
| 5042 |
function skipMarker(state, line) { |
| 5043 |
var pos, marker, |
| 5044 |
start = state.bMarks[line] + state.tShift[line], |
| 5045 |
max = state.eMarks[line]; |
| 5046 |
|
| 5047 |
if (start >= max) { return -1; } |
| 5048 |
|
| 5049 |
// Check bullet |
| 5050 |
marker = state.src.charCodeAt(start++); |
| 5051 |
if (marker !== 0x7E/* ~ */ && marker !== 0x3A/* : */) { return -1; } |
| 5052 |
|
| 5053 |
pos = state.skipSpaces(start); |
| 5054 |
|
| 5055 |
// require space after ":" |
| 5056 |
if (start === pos) { return -1; } |
| 5057 |
|
| 5058 |
// no empty definitions, e.g. " : " |
| 5059 |
if (pos >= max) { return -1; } |
| 5060 |
|
| 5061 |
return pos; |
| 5062 |
} |
| 5063 |
|
| 5064 |
function markTightParagraphs$1(state, idx) { |
| 5065 |
var i, l, |
| 5066 |
level = state.level + 2; |
| 5067 |
|
| 5068 |
for (i = idx + 2, l = state.tokens.length - 2; i < l; i++) { |
| 5069 |
if (state.tokens[i].level === level && state.tokens[i].type === 'paragraph_open') { |
| 5070 |
state.tokens[i + 2].tight = true; |
| 5071 |
state.tokens[i].tight = true; |
| 5072 |
i += 2; |
| 5073 |
} |
| 5074 |
} |
| 5075 |
} |
| 5076 |
|
| 5077 |
function deflist(state, startLine, endLine, silent) { |
| 5078 |
var contentStart, |
| 5079 |
ddLine, |
| 5080 |
dtLine, |
| 5081 |
itemLines, |
| 5082 |
listLines, |
| 5083 |
listTokIdx, |
| 5084 |
nextLine, |
| 5085 |
oldIndent, |
| 5086 |
oldDDIndent, |
| 5087 |
oldParentType, |
| 5088 |
oldTShift, |
| 5089 |
oldTight, |
| 5090 |
prevEmptyEnd, |
| 5091 |
tight; |
| 5092 |
|
| 5093 |
if (silent) { |
| 5094 |
// quirk: validation mode validates a dd block only, not a whole deflist |
| 5095 |
if (state.ddIndent < 0) { return false; } |
| 5096 |
return skipMarker(state, startLine) >= 0; |
| 5097 |
} |
| 5098 |
|
| 5099 |
nextLine = startLine + 1; |
| 5100 |
if (state.isEmpty(nextLine)) { |
| 5101 |
if (++nextLine > endLine) { return false; } |
| 5102 |
} |
| 5103 |
|
| 5104 |
if (state.tShift[nextLine] < state.blkIndent) { return false; } |
| 5105 |
contentStart = skipMarker(state, nextLine); |
| 5106 |
if (contentStart < 0) { return false; } |
| 5107 |
|
| 5108 |
if (state.level >= state.options.maxNesting) { return false; } |
| 5109 |
|
| 5110 |
// Start list |
| 5111 |
listTokIdx = state.tokens.length; |
| 5112 |
|
| 5113 |
state.tokens.push({ |
| 5114 |
type: 'dl_open', |
| 5115 |
lines: listLines = [ startLine, 0 ], |
| 5116 |
level: state.level++ |
| 5117 |
}); |
| 5118 |
|
| 5119 |
// |
| 5120 |
// Iterate list items |
| 5121 |
// |
| 5122 |
|
| 5123 |
dtLine = startLine; |
| 5124 |
ddLine = nextLine; |
| 5125 |
|
| 5126 |
// One definition list can contain multiple DTs, |
| 5127 |
// and one DT can be followed by multiple DDs. |
| 5128 |
// |
| 5129 |
// Thus, there is two loops here, and label is |
| 5130 |
// needed to break out of the second one |
| 5131 |
// |
| 5132 |
/*eslint no-labels:0,block-scoped-var:0*/ |
| 5133 |
OUTER: |
| 5134 |
for (;;) { |
| 5135 |
tight = true; |
| 5136 |
prevEmptyEnd = false; |
| 5137 |
|
| 5138 |
state.tokens.push({ |
| 5139 |
type: 'dt_open', |
| 5140 |
lines: [ dtLine, dtLine ], |
| 5141 |
level: state.level++ |
| 5142 |
}); |
| 5143 |
state.tokens.push({ |
| 5144 |
type: 'inline', |
| 5145 |
content: state.getLines(dtLine, dtLine + 1, state.blkIndent, false).trim(), |
| 5146 |
level: state.level + 1, |
| 5147 |
lines: [ dtLine, dtLine ], |
| 5148 |
children: [] |
| 5149 |
}); |
| 5150 |
state.tokens.push({ |
| 5151 |
type: 'dt_close', |
| 5152 |
level: --state.level |
| 5153 |
}); |
| 5154 |
|
| 5155 |
for (;;) { |
| 5156 |
state.tokens.push({ |
| 5157 |
type: 'dd_open', |
| 5158 |
lines: itemLines = [ nextLine, 0 ], |
| 5159 |
level: state.level++ |
| 5160 |
}); |
| 5161 |
|
| 5162 |
oldTight = state.tight; |
| 5163 |
oldDDIndent = state.ddIndent; |
| 5164 |
oldIndent = state.blkIndent; |
| 5165 |
oldTShift = state.tShift[ddLine]; |
| 5166 |
oldParentType = state.parentType; |
| 5167 |
state.blkIndent = state.ddIndent = state.tShift[ddLine] + 2; |
| 5168 |
state.tShift[ddLine] = contentStart - state.bMarks[ddLine]; |
| 5169 |
state.tight = true; |
| 5170 |
state.parentType = 'deflist'; |
| 5171 |
|
| 5172 |
state.parser.tokenize(state, ddLine, endLine, true); |
| 5173 |
|
| 5174 |
// If any of list item is tight, mark list as tight |
| 5175 |
if (!state.tight || prevEmptyEnd) { |
| 5176 |
tight = false; |
| 5177 |
} |
| 5178 |
// Item become loose if finish with empty line, |
| 5179 |
// but we should filter last element, because it means list finish |
| 5180 |
prevEmptyEnd = (state.line - ddLine) > 1 && state.isEmpty(state.line - 1); |
| 5181 |
|
| 5182 |
state.tShift[ddLine] = oldTShift; |
| 5183 |
state.tight = oldTight; |
| 5184 |
state.parentType = oldParentType; |
| 5185 |
state.blkIndent = oldIndent; |
| 5186 |
state.ddIndent = oldDDIndent; |
| 5187 |
|
| 5188 |
state.tokens.push({ |
| 5189 |
type: 'dd_close', |
| 5190 |
level: --state.level |
| 5191 |
}); |
| 5192 |
|
| 5193 |
itemLines[1] = nextLine = state.line; |
| 5194 |
|
| 5195 |
if (nextLine >= endLine) { break OUTER; } |
| 5196 |
|
| 5197 |
if (state.tShift[nextLine] < state.blkIndent) { break OUTER; } |
| 5198 |
contentStart = skipMarker(state, nextLine); |
| 5199 |
if (contentStart < 0) { break; } |
| 5200 |
|
| 5201 |
ddLine = nextLine; |
| 5202 |
|
| 5203 |
// go to the next loop iteration: |
| 5204 |
// insert DD tag and repeat checking |
| 5205 |
} |
| 5206 |
|
| 5207 |
if (nextLine >= endLine) { break; } |
| 5208 |
dtLine = nextLine; |
| 5209 |
|
| 5210 |
if (state.isEmpty(dtLine)) { break; } |
| 5211 |
if (state.tShift[dtLine] < state.blkIndent) { break; } |
| 5212 |
|
| 5213 |
ddLine = dtLine + 1; |
| 5214 |
if (ddLine >= endLine) { break; } |
| 5215 |
if (state.isEmpty(ddLine)) { ddLine++; } |
| 5216 |
if (ddLine >= endLine) { break; } |
| 5217 |
|
| 5218 |
if (state.tShift[ddLine] < state.blkIndent) { break; } |
| 5219 |
contentStart = skipMarker(state, ddLine); |
| 5220 |
if (contentStart < 0) { break; } |
| 5221 |
|
| 5222 |
// go to the next loop iteration: |
| 5223 |
// insert DT and DD tags and repeat checking |
| 5224 |
} |
| 5225 |
|
| 5226 |
// Finilize list |
| 5227 |
state.tokens.push({ |
| 5228 |
type: 'dl_close', |
| 5229 |
level: --state.level |
| 5230 |
}); |
| 5231 |
listLines[1] = nextLine; |
| 5232 |
|
| 5233 |
state.line = nextLine; |
| 5234 |
|
| 5235 |
// mark paragraphs tight if needed |
| 5236 |
if (tight) { |
| 5237 |
markTightParagraphs$1(state, listTokIdx); |
| 5238 |
} |
| 5239 |
|
| 5240 |
return true; |
| 5241 |
} |
| 5242 |
|
| 5243 |
// Paragraph |
| 5244 |
|
| 5245 |
function paragraph(state, startLine/*, endLine*/) { |
| 5246 |
var endLine, content, terminate, i, l, |
| 5247 |
nextLine = startLine + 1, |
| 5248 |
terminatorRules; |
| 5249 |
|
| 5250 |
endLine = state.lineMax; |
| 5251 |
|
| 5252 |
// jump line-by-line until empty one or EOF |
| 5253 |
if (nextLine < endLine && !state.isEmpty(nextLine)) { |
| 5254 |
terminatorRules = state.parser.ruler.getRules('paragraph'); |
| 5255 |
|
| 5256 |
for (; nextLine < endLine && !state.isEmpty(nextLine); nextLine++) { |
| 5257 |
// this would be a code block normally, but after paragraph |
| 5258 |
// it's considered a lazy continuation regardless of what's there |
| 5259 |
if (state.tShift[nextLine] - state.blkIndent > 3) { continue; } |
| 5260 |
|
| 5261 |
// Some tags can terminate paragraph without empty line. |
| 5262 |
terminate = false; |
| 5263 |
for (i = 0, l = terminatorRules.length; i < l; i++) { |
| 5264 |
if (terminatorRules[i](state, nextLine, endLine, true)) { |
| 5265 |
terminate = true; |
| 5266 |
break; |
| 5267 |
} |
| 5268 |
} |
| 5269 |
if (terminate) { break; } |
| 5270 |
} |
| 5271 |
} |
| 5272 |
|
| 5273 |
content = state.getLines(startLine, nextLine, state.blkIndent, false).trim(); |
| 5274 |
|
| 5275 |
state.line = nextLine; |
| 5276 |
if (content.length) { |
| 5277 |
state.tokens.push({ |
| 5278 |
type: 'paragraph_open', |
| 5279 |
tight: false, |
| 5280 |
lines: [ startLine, state.line ], |
| 5281 |
level: state.level |
| 5282 |
}); |
| 5283 |
state.tokens.push({ |
| 5284 |
type: 'inline', |
| 5285 |
content: content, |
| 5286 |
level: state.level + 1, |
| 5287 |
lines: [ startLine, state.line ], |
| 5288 |
children: [] |
| 5289 |
}); |
| 5290 |
state.tokens.push({ |
| 5291 |
type: 'paragraph_close', |
| 5292 |
tight: false, |
| 5293 |
level: state.level |
| 5294 |
}); |
| 5295 |
} |
| 5296 |
|
| 5297 |
return true; |
| 5298 |
} |
| 5299 |
|
| 5300 |
/** |
| 5301 |
* Parser rules |
| 5302 |
*/ |
| 5303 |
|
| 5304 |
var _rules$1 = [ |
| 5305 |
[ 'code', code ], |
| 5306 |
[ 'fences', fences, [ 'paragraph', 'blockquote', 'list' ] ], |
| 5307 |
[ 'blockquote', blockquote, [ 'paragraph', 'blockquote', 'list' ] ], |
| 5308 |
[ 'hr', hr, [ 'paragraph', 'blockquote', 'list' ] ], |
| 5309 |
[ 'list', list, [ 'paragraph', 'blockquote' ] ], |
| 5310 |
[ 'footnote', footnote, [ 'paragraph' ] ], |
| 5311 |
[ 'heading', heading, [ 'paragraph', 'blockquote' ] ], |
| 5312 |
[ 'lheading', lheading ], |
| 5313 |
[ 'htmlblock', htmlblock, [ 'paragraph', 'blockquote' ] ], |
| 5314 |
[ 'table', table, [ 'paragraph' ] ], |
| 5315 |
[ 'deflist', deflist, [ 'paragraph' ] ], |
| 5316 |
[ 'paragraph', paragraph ] |
| 5317 |
]; |
| 5318 |
|
| 5319 |
/** |
| 5320 |
* Block Parser class |
| 5321 |
* |
| 5322 |
* @api private |
| 5323 |
*/ |
| 5324 |
|
| 5325 |
function ParserBlock() { |
| 5326 |
this.ruler = new Ruler(); |
| 5327 |
for (var i = 0; i < _rules$1.length; i++) { |
| 5328 |
this.ruler.push(_rules$1[i][0], _rules$1[i][1], { |
| 5329 |
alt: (_rules$1[i][2] || []).slice() |
| 5330 |
}); |
| 5331 |
} |
| 5332 |
} |
| 5333 |
|
| 5334 |
/** |
| 5335 |
* Generate tokens for the given input range. |
| 5336 |
* |
| 5337 |
* @param {Object} `state` Has properties like `src`, `parser`, `options` etc |
| 5338 |
* @param {Number} `startLine` |
| 5339 |
* @param {Number} `endLine` |
| 5340 |
* @api private |
| 5341 |
*/ |
| 5342 |
|
| 5343 |
ParserBlock.prototype.tokenize = function (state, startLine, endLine) { |
| 5344 |
var rules = this.ruler.getRules(''); |
| 5345 |
var len = rules.length; |
| 5346 |
var line = startLine; |
| 5347 |
var hasEmptyLines = false; |
| 5348 |
var ok, i; |
| 5349 |
|
| 5350 |
while (line < endLine) { |
| 5351 |
state.line = line = state.skipEmptyLines(line); |
| 5352 |
if (line >= endLine) { |
| 5353 |
break; |
| 5354 |
} |
| 5355 |
|
| 5356 |
// Termination condition for nested calls. |
| 5357 |
// Nested calls currently used for blockquotes & lists |
| 5358 |
if (state.tShift[line] < state.blkIndent) { |
| 5359 |
break; |
| 5360 |
} |
| 5361 |
|
| 5362 |
// Try all possible rules. |
| 5363 |
// On success, rule should: |
| 5364 |
// |
| 5365 |
// - update `state.line` |
| 5366 |
// - update `state.tokens` |
| 5367 |
// - return true |
| 5368 |
|
| 5369 |
for (i = 0; i < len; i++) { |
| 5370 |
ok = rules[i](state, line, endLine, false); |
| 5371 |
if (ok) { |
| 5372 |
break; |
| 5373 |
} |
| 5374 |
} |
| 5375 |
|
| 5376 |
// set state.tight iff we had an empty line before current tag |
| 5377 |
// i.e. latest empty line should not count |
| 5378 |
state.tight = !hasEmptyLines; |
| 5379 |
|
| 5380 |
// paragraph might "eat" one newline after it in nested lists |
| 5381 |
if (state.isEmpty(state.line - 1)) { |
| 5382 |
hasEmptyLines = true; |
| 5383 |
} |
| 5384 |
|
| 5385 |
line = state.line; |
| 5386 |
|
| 5387 |
if (line < endLine && state.isEmpty(line)) { |
| 5388 |
hasEmptyLines = true; |
| 5389 |
line++; |
| 5390 |
|
| 5391 |
// two empty lines should stop the parser in list mode |
| 5392 |
if (line < endLine && state.parentType === 'list' && state.isEmpty(line)) { break; } |
| 5393 |
state.line = line; |
| 5394 |
} |
| 5395 |
} |
| 5396 |
}; |
| 5397 |
|
| 5398 |
var TABS_SCAN_RE = /[\n\t]/g; |
| 5399 |
var NEWLINES_RE = /\r[\n\u0085]|[\u2424\u2028\u0085]/g; |
| 5400 |
var SPACES_RE = /\u00a0/g; |
| 5401 |
|
| 5402 |
/** |
| 5403 |
* Tokenize the given `str`. |
| 5404 |
* |
| 5405 |
* @param {String} `str` Source string |
| 5406 |
* @param {Object} `options` |
| 5407 |
* @param {Object} `env` |
| 5408 |
* @param {Array} `outTokens` |
| 5409 |
* @api private |
| 5410 |
*/ |
| 5411 |
|
| 5412 |
ParserBlock.prototype.parse = function (str, options, env, outTokens) { |
| 5413 |
var state, lineStart = 0, lastTabPos = 0; |
| 5414 |
if (!str) { return []; } |
| 5415 |
|
| 5416 |
// Normalize spaces |
| 5417 |
str = str.replace(SPACES_RE, ' '); |
| 5418 |
|
| 5419 |
// Normalize newlines |
| 5420 |
str = str.replace(NEWLINES_RE, '\n'); |
| 5421 |
|
| 5422 |
// Replace tabs with proper number of spaces (1..4) |
| 5423 |
if (str.indexOf('\t') >= 0) { |
| 5424 |
str = str.replace(TABS_SCAN_RE, function (match, offset) { |
| 5425 |
var result; |
| 5426 |
if (str.charCodeAt(offset) === 0x0A) { |
| 5427 |
lineStart = offset + 1; |
| 5428 |
lastTabPos = 0; |
| 5429 |
return match; |
| 5430 |
} |
| 5431 |
result = ' '.slice((offset - lineStart - lastTabPos) % 4); |
| 5432 |
lastTabPos = offset - lineStart + 1; |
| 5433 |
return result; |
| 5434 |
}); |
| 5435 |
} |
| 5436 |
|
| 5437 |
state = new StateBlock(str, this, options, env, outTokens); |
| 5438 |
this.tokenize(state, state.line, state.lineMax); |
| 5439 |
}; |
| 5440 |
|
| 5441 |
// Skip text characters for text token, place those to pending buffer |
| 5442 |
// and increment current pos |
| 5443 |
|
| 5444 |
// Rule to skip pure text |
| 5445 |
// '{}$%@~+=:' reserved for extentions |
| 5446 |
|
| 5447 |
function isTerminatorChar(ch) { |
| 5448 |
switch (ch) { |
| 5449 |
case 0x0A/* \n */: |
| 5450 |
case 0x5C/* \ */: |
| 5451 |
case 0x60/* ` */: |
| 5452 |
case 0x2A/* * */: |
| 5453 |
case 0x5F/* _ */: |
| 5454 |
case 0x5E/* ^ */: |
| 5455 |
case 0x5B/* [ */: |
| 5456 |
case 0x5D/* ] */: |
| 5457 |
case 0x21/* ! */: |
| 5458 |
case 0x26/* & */: |
| 5459 |
case 0x3C/* < */: |
| 5460 |
case 0x3E/* > */: |
| 5461 |
case 0x7B/* { */: |
| 5462 |
case 0x7D/* } */: |
| 5463 |
case 0x24/* $ */: |
| 5464 |
case 0x25/* % */: |
| 5465 |
case 0x40/* @ */: |
| 5466 |
case 0x7E/* ~ */: |
| 5467 |
case 0x2B/* + */: |
| 5468 |
case 0x3D/* = */: |
| 5469 |
case 0x3A/* : */: |
| 5470 |
return true; |
| 5471 |
default: |
| 5472 |
return false; |
| 5473 |
} |
| 5474 |
} |
| 5475 |
|
| 5476 |
function text(state, silent) { |
| 5477 |
var pos = state.pos; |
| 5478 |
|
| 5479 |
while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) { |
| 5480 |
pos++; |
| 5481 |
} |
| 5482 |
|
| 5483 |
if (pos === state.pos) { return false; } |
| 5484 |
|
| 5485 |
if (!silent) { state.pending += state.src.slice(state.pos, pos); } |
| 5486 |
|
| 5487 |
state.pos = pos; |
| 5488 |
|
| 5489 |
return true; |
| 5490 |
} |
| 5491 |
|
| 5492 |
// Proceess '\n' |
| 5493 |
|
| 5494 |
function newline(state, silent) { |
| 5495 |
var pmax, max, pos = state.pos; |
| 5496 |
|
| 5497 |
if (state.src.charCodeAt(pos) !== 0x0A/* \n */) { return false; } |
| 5498 |
|
| 5499 |
pmax = state.pending.length - 1; |
| 5500 |
max = state.posMax; |
| 5501 |
|
| 5502 |
// ' \n' -> hardbreak |
| 5503 |
// Lookup in pending chars is bad practice! Don't copy to other rules! |
| 5504 |
// Pending string is stored in concat mode, indexed lookups will cause |
| 5505 |
// convertion to flat mode. |
| 5506 |
if (!silent) { |
| 5507 |
if (pmax >= 0 && state.pending.charCodeAt(pmax) === 0x20) { |
| 5508 |
if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 0x20) { |
| 5509 |
// Strip out all trailing spaces on this line. |
| 5510 |
for (var i = pmax - 2; i >= 0; i--) { |
| 5511 |
if (state.pending.charCodeAt(i) !== 0x20) { |
| 5512 |
state.pending = state.pending.substring(0, i + 1); |
| 5513 |
break; |
| 5514 |
} |
| 5515 |
} |
| 5516 |
state.push({ |
| 5517 |
type: 'hardbreak', |
| 5518 |
level: state.level |
| 5519 |
}); |
| 5520 |
} else { |
| 5521 |
state.pending = state.pending.slice(0, -1); |
| 5522 |
state.push({ |
| 5523 |
type: 'softbreak', |
| 5524 |
level: state.level |
| 5525 |
}); |
| 5526 |
} |
| 5527 |
|
| 5528 |
} else { |
| 5529 |
state.push({ |
| 5530 |
type: 'softbreak', |
| 5531 |
level: state.level |
| 5532 |
}); |
| 5533 |
} |
| 5534 |
} |
| 5535 |
|
| 5536 |
pos++; |
| 5537 |
|
| 5538 |
// skip heading spaces for next line |
| 5539 |
while (pos < max && state.src.charCodeAt(pos) === 0x20) { pos++; } |
| 5540 |
|
| 5541 |
state.pos = pos; |
| 5542 |
return true; |
| 5543 |
} |
| 5544 |
|
| 5545 |
// Proceess escaped chars and hardbreaks |
| 5546 |
|
| 5547 |
var ESCAPED = []; |
| 5548 |
|
| 5549 |
for (var i = 0; i < 256; i++) { ESCAPED.push(0); } |
| 5550 |
|
| 5551 |
'\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-' |
| 5552 |
.split('').forEach(function(ch) { ESCAPED[ch.charCodeAt(0)] = 1; }); |
| 5553 |
|
| 5554 |
|
| 5555 |
function escape(state, silent) { |
| 5556 |
var ch, pos = state.pos, max = state.posMax; |
| 5557 |
|
| 5558 |
if (state.src.charCodeAt(pos) !== 0x5C/* \ */) { return false; } |
| 5559 |
|
| 5560 |
pos++; |
| 5561 |
|
| 5562 |
if (pos < max) { |
| 5563 |
ch = state.src.charCodeAt(pos); |
| 5564 |
|
| 5565 |
if (ch < 256 && ESCAPED[ch] !== 0) { |
| 5566 |
if (!silent) { state.pending += state.src[pos]; } |
| 5567 |
state.pos += 2; |
| 5568 |
return true; |
| 5569 |
} |
| 5570 |
|
| 5571 |
if (ch === 0x0A) { |
| 5572 |
if (!silent) { |
| 5573 |
state.push({ |
| 5574 |
type: 'hardbreak', |
| 5575 |
level: state.level |
| 5576 |
}); |
| 5577 |
} |
| 5578 |
|
| 5579 |
pos++; |
| 5580 |
// skip leading whitespaces from next line |
| 5581 |
while (pos < max && state.src.charCodeAt(pos) === 0x20) { pos++; } |
| 5582 |
|
| 5583 |
state.pos = pos; |
| 5584 |
return true; |
| 5585 |
} |
| 5586 |
} |
| 5587 |
|
| 5588 |
if (!silent) { state.pending += '\\'; } |
| 5589 |
state.pos++; |
| 5590 |
return true; |
| 5591 |
} |
| 5592 |
|
| 5593 |
// Parse backticks |
| 5594 |
|
| 5595 |
function backticks(state, silent) { |
| 5596 |
var start, max, marker, matchStart, matchEnd, |
| 5597 |
pos = state.pos, |
| 5598 |
ch = state.src.charCodeAt(pos); |
| 5599 |
|
| 5600 |
if (ch !== 0x60/* ` */) { return false; } |
| 5601 |
|
| 5602 |
start = pos; |
| 5603 |
pos++; |
| 5604 |
max = state.posMax; |
| 5605 |
|
| 5606 |
while (pos < max && state.src.charCodeAt(pos) === 0x60/* ` */) { pos++; } |
| 5607 |
|
| 5608 |
marker = state.src.slice(start, pos); |
| 5609 |
|
| 5610 |
matchStart = matchEnd = pos; |
| 5611 |
|
| 5612 |
while ((matchStart = state.src.indexOf('`', matchEnd)) !== -1) { |
| 5613 |
matchEnd = matchStart + 1; |
| 5614 |
|
| 5615 |
while (matchEnd < max && state.src.charCodeAt(matchEnd) === 0x60/* ` */) { matchEnd++; } |
| 5616 |
|
| 5617 |
if (matchEnd - matchStart === marker.length) { |
| 5618 |
if (!silent) { |
| 5619 |
state.push({ |
| 5620 |
type: 'code', |
| 5621 |
content: state.src.slice(pos, matchStart) |
| 5622 |
.replace(/[ \n]+/g, ' ') |
| 5623 |
.trim(), |
| 5624 |
block: false, |
| 5625 |
level: state.level |
| 5626 |
}); |
| 5627 |
} |
| 5628 |
state.pos = matchEnd; |
| 5629 |
return true; |
| 5630 |
} |
| 5631 |
} |
| 5632 |
|
| 5633 |
if (!silent) { state.pending += marker; } |
| 5634 |
state.pos += marker.length; |
| 5635 |
return true; |
| 5636 |
} |
| 5637 |
|
| 5638 |
// Process ~~deleted text~~ |
| 5639 |
|
| 5640 |
function del(state, silent) { |
| 5641 |
var found, |
| 5642 |
pos, |
| 5643 |
stack, |
| 5644 |
max = state.posMax, |
| 5645 |
start = state.pos, |
| 5646 |
lastChar, |
| 5647 |
nextChar; |
| 5648 |
|
| 5649 |
if (state.src.charCodeAt(start) !== 0x7E/* ~ */) { return false; } |
| 5650 |
if (silent) { return false; } // don't run any pairs in validation mode |
| 5651 |
if (start + 4 >= max) { return false; } |
| 5652 |
if (state.src.charCodeAt(start + 1) !== 0x7E/* ~ */) { return false; } |
| 5653 |
if (state.level >= state.options.maxNesting) { return false; } |
| 5654 |
|
| 5655 |
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1; |
| 5656 |
nextChar = state.src.charCodeAt(start + 2); |
| 5657 |
|
| 5658 |
if (lastChar === 0x7E/* ~ */) { return false; } |
| 5659 |
if (nextChar === 0x7E/* ~ */) { return false; } |
| 5660 |
if (nextChar === 0x20 || nextChar === 0x0A) { return false; } |
| 5661 |
|
| 5662 |
pos = start + 2; |
| 5663 |
while (pos < max && state.src.charCodeAt(pos) === 0x7E/* ~ */) { pos++; } |
| 5664 |
if (pos > start + 3) { |
| 5665 |
// sequence of 4+ markers taking as literal, same as in a emphasis |
| 5666 |
state.pos += pos - start; |
| 5667 |
if (!silent) { state.pending += state.src.slice(start, pos); } |
| 5668 |
return true; |
| 5669 |
} |
| 5670 |
|
| 5671 |
state.pos = start + 2; |
| 5672 |
stack = 1; |
| 5673 |
|
| 5674 |
while (state.pos + 1 < max) { |
| 5675 |
if (state.src.charCodeAt(state.pos) === 0x7E/* ~ */) { |
| 5676 |
if (state.src.charCodeAt(state.pos + 1) === 0x7E/* ~ */) { |
| 5677 |
lastChar = state.src.charCodeAt(state.pos - 1); |
| 5678 |
nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1; |
| 5679 |
if (nextChar !== 0x7E/* ~ */ && lastChar !== 0x7E/* ~ */) { |
| 5680 |
if (lastChar !== 0x20 && lastChar !== 0x0A) { |
| 5681 |
// closing '~~' |
| 5682 |
stack--; |
| 5683 |
} else if (nextChar !== 0x20 && nextChar !== 0x0A) { |
| 5684 |
// opening '~~' |
| 5685 |
stack++; |
| 5686 |
} // else { |
| 5687 |
// // standalone ' ~~ ' indented with spaces |
| 5688 |
// } |
| 5689 |
if (stack <= 0) { |
| 5690 |
found = true; |
| 5691 |
break; |
| 5692 |
} |
| 5693 |
} |
| 5694 |
} |
| 5695 |
} |
| 5696 |
|
| 5697 |
state.parser.skipToken(state); |
| 5698 |
} |
| 5699 |
|
| 5700 |
if (!found) { |
| 5701 |
// parser failed to find ending tag, so it's not valid emphasis |
| 5702 |
state.pos = start; |
| 5703 |
return false; |
| 5704 |
} |
| 5705 |
|
| 5706 |
// found! |
| 5707 |
state.posMax = state.pos; |
| 5708 |
state.pos = start + 2; |
| 5709 |
|
| 5710 |
if (!silent) { |
| 5711 |
state.push({ type: 'del_open', level: state.level++ }); |
| 5712 |
state.parser.tokenize(state); |
| 5713 |
state.push({ type: 'del_close', level: --state.level }); |
| 5714 |
} |
| 5715 |
|
| 5716 |
state.pos = state.posMax + 2; |
| 5717 |
state.posMax = max; |
| 5718 |
return true; |
| 5719 |
} |
| 5720 |
|
| 5721 |
// Process ++inserted text++ |
| 5722 |
|
| 5723 |
function ins(state, silent) { |
| 5724 |
var found, |
| 5725 |
pos, |
| 5726 |
stack, |
| 5727 |
max = state.posMax, |
| 5728 |
start = state.pos, |
| 5729 |
lastChar, |
| 5730 |
nextChar; |
| 5731 |
|
| 5732 |
if (state.src.charCodeAt(start) !== 0x2B/* + */) { return false; } |
| 5733 |
if (silent) { return false; } // don't run any pairs in validation mode |
| 5734 |
if (start + 4 >= max) { return false; } |
| 5735 |
if (state.src.charCodeAt(start + 1) !== 0x2B/* + */) { return false; } |
| 5736 |
if (state.level >= state.options.maxNesting) { return false; } |
| 5737 |
|
| 5738 |
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1; |
| 5739 |
nextChar = state.src.charCodeAt(start + 2); |
| 5740 |
|
| 5741 |
if (lastChar === 0x2B/* + */) { return false; } |
| 5742 |
if (nextChar === 0x2B/* + */) { return false; } |
| 5743 |
if (nextChar === 0x20 || nextChar === 0x0A) { return false; } |
| 5744 |
|
| 5745 |
pos = start + 2; |
| 5746 |
while (pos < max && state.src.charCodeAt(pos) === 0x2B/* + */) { pos++; } |
| 5747 |
if (pos !== start + 2) { |
| 5748 |
// sequence of 3+ markers taking as literal, same as in a emphasis |
| 5749 |
state.pos += pos - start; |
| 5750 |
if (!silent) { state.pending += state.src.slice(start, pos); } |
| 5751 |
return true; |
| 5752 |
} |
| 5753 |
|
| 5754 |
state.pos = start + 2; |
| 5755 |
stack = 1; |
| 5756 |
|
| 5757 |
while (state.pos + 1 < max) { |
| 5758 |
if (state.src.charCodeAt(state.pos) === 0x2B/* + */) { |
| 5759 |
if (state.src.charCodeAt(state.pos + 1) === 0x2B/* + */) { |
| 5760 |
lastChar = state.src.charCodeAt(state.pos - 1); |
| 5761 |
nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1; |
| 5762 |
if (nextChar !== 0x2B/* + */ && lastChar !== 0x2B/* + */) { |
| 5763 |
if (lastChar !== 0x20 && lastChar !== 0x0A) { |
| 5764 |
// closing '++' |
| 5765 |
stack--; |
| 5766 |
} else if (nextChar !== 0x20 && nextChar !== 0x0A) { |
| 5767 |
// opening '++' |
| 5768 |
stack++; |
| 5769 |
} // else { |
| 5770 |
// // standalone ' ++ ' indented with spaces |
| 5771 |
// } |
| 5772 |
if (stack <= 0) { |
| 5773 |
found = true; |
| 5774 |
break; |
| 5775 |
} |
| 5776 |
} |
| 5777 |
} |
| 5778 |
} |
| 5779 |
|
| 5780 |
state.parser.skipToken(state); |
| 5781 |
} |
| 5782 |
|
| 5783 |
if (!found) { |
| 5784 |
// parser failed to find ending tag, so it's not valid emphasis |
| 5785 |
state.pos = start; |
| 5786 |
return false; |
| 5787 |
} |
| 5788 |
|
| 5789 |
// found! |
| 5790 |
state.posMax = state.pos; |
| 5791 |
state.pos = start + 2; |
| 5792 |
|
| 5793 |
if (!silent) { |
| 5794 |
state.push({ type: 'ins_open', level: state.level++ }); |
| 5795 |
state.parser.tokenize(state); |
| 5796 |
state.push({ type: 'ins_close', level: --state.level }); |
| 5797 |
} |
| 5798 |
|
| 5799 |
state.pos = state.posMax + 2; |
| 5800 |
state.posMax = max; |
| 5801 |
return true; |
| 5802 |
} |
| 5803 |
|
| 5804 |
// Process ==highlighted text== |
| 5805 |
|
| 5806 |
function mark(state, silent) { |
| 5807 |
var found, |
| 5808 |
pos, |
| 5809 |
stack, |
| 5810 |
max = state.posMax, |
| 5811 |
start = state.pos, |
| 5812 |
lastChar, |
| 5813 |
nextChar; |
| 5814 |
|
| 5815 |
if (state.src.charCodeAt(start) !== 0x3D/* = */) { return false; } |
| 5816 |
if (silent) { return false; } // don't run any pairs in validation mode |
| 5817 |
if (start + 4 >= max) { return false; } |
| 5818 |
if (state.src.charCodeAt(start + 1) !== 0x3D/* = */) { return false; } |
| 5819 |
if (state.level >= state.options.maxNesting) { return false; } |
| 5820 |
|
| 5821 |
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1; |
| 5822 |
nextChar = state.src.charCodeAt(start + 2); |
| 5823 |
|
| 5824 |
if (lastChar === 0x3D/* = */) { return false; } |
| 5825 |
if (nextChar === 0x3D/* = */) { return false; } |
| 5826 |
if (nextChar === 0x20 || nextChar === 0x0A) { return false; } |
| 5827 |
|
| 5828 |
pos = start + 2; |
| 5829 |
while (pos < max && state.src.charCodeAt(pos) === 0x3D/* = */) { pos++; } |
| 5830 |
if (pos !== start + 2) { |
| 5831 |
// sequence of 3+ markers taking as literal, same as in a emphasis |
| 5832 |
state.pos += pos - start; |
| 5833 |
if (!silent) { state.pending += state.src.slice(start, pos); } |
| 5834 |
return true; |
| 5835 |
} |
| 5836 |
|
| 5837 |
state.pos = start + 2; |
| 5838 |
stack = 1; |
| 5839 |
|
| 5840 |
while (state.pos + 1 < max) { |
| 5841 |
if (state.src.charCodeAt(state.pos) === 0x3D/* = */) { |
| 5842 |
if (state.src.charCodeAt(state.pos + 1) === 0x3D/* = */) { |
| 5843 |
lastChar = state.src.charCodeAt(state.pos - 1); |
| 5844 |
nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1; |
| 5845 |
if (nextChar !== 0x3D/* = */ && lastChar !== 0x3D/* = */) { |
| 5846 |
if (lastChar !== 0x20 && lastChar !== 0x0A) { |
| 5847 |
// closing '==' |
| 5848 |
stack--; |
| 5849 |
} else if (nextChar !== 0x20 && nextChar !== 0x0A) { |
| 5850 |
// opening '==' |
| 5851 |
stack++; |
| 5852 |
} // else { |
| 5853 |
// // standalone ' == ' indented with spaces |
| 5854 |
// } |
| 5855 |
if (stack <= 0) { |
| 5856 |
found = true; |
| 5857 |
break; |
| 5858 |
} |
| 5859 |
} |
| 5860 |
} |
| 5861 |
} |
| 5862 |
|
| 5863 |
state.parser.skipToken(state); |
| 5864 |
} |
| 5865 |
|
| 5866 |
if (!found) { |
| 5867 |
// parser failed to find ending tag, so it's not valid emphasis |
| 5868 |
state.pos = start; |
| 5869 |
return false; |
| 5870 |
} |
| 5871 |
|
| 5872 |
// found! |
| 5873 |
state.posMax = state.pos; |
| 5874 |
state.pos = start + 2; |
| 5875 |
|
| 5876 |
if (!silent) { |
| 5877 |
state.push({ type: 'mark_open', level: state.level++ }); |
| 5878 |
state.parser.tokenize(state); |
| 5879 |
state.push({ type: 'mark_close', level: --state.level }); |
| 5880 |
} |
| 5881 |
|
| 5882 |
state.pos = state.posMax + 2; |
| 5883 |
state.posMax = max; |
| 5884 |
return true; |
| 5885 |
} |
| 5886 |
|
| 5887 |
// Process *this* and _that_ |
| 5888 |
|
| 5889 |
function isAlphaNum(code) { |
| 5890 |
return (code >= 0x30 /* 0 */ && code <= 0x39 /* 9 */) || |
| 5891 |
(code >= 0x41 /* A */ && code <= 0x5A /* Z */) || |
| 5892 |
(code >= 0x61 /* a */ && code <= 0x7A /* z */); |
| 5893 |
} |
| 5894 |
|
| 5895 |
// parse sequence of emphasis markers, |
| 5896 |
// "start" should point at a valid marker |
| 5897 |
function scanDelims(state, start) { |
| 5898 |
var pos = start, lastChar, nextChar, count, |
| 5899 |
can_open = true, |
| 5900 |
can_close = true, |
| 5901 |
max = state.posMax, |
| 5902 |
marker = state.src.charCodeAt(start); |
| 5903 |
|
| 5904 |
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1; |
| 5905 |
|
| 5906 |
while (pos < max && state.src.charCodeAt(pos) === marker) { pos++; } |
| 5907 |
if (pos >= max) { can_open = false; } |
| 5908 |
count = pos - start; |
| 5909 |
|
| 5910 |
if (count >= 4) { |
| 5911 |
// sequence of four or more unescaped markers can't start/end an emphasis |
| 5912 |
can_open = can_close = false; |
| 5913 |
} else { |
| 5914 |
nextChar = pos < max ? state.src.charCodeAt(pos) : -1; |
| 5915 |
|
| 5916 |
// check whitespace conditions |
| 5917 |
if (nextChar === 0x20 || nextChar === 0x0A) { can_open = false; } |
| 5918 |
if (lastChar === 0x20 || lastChar === 0x0A) { can_close = false; } |
| 5919 |
|
| 5920 |
if (marker === 0x5F /* _ */) { |
| 5921 |
// check if we aren't inside the word |
| 5922 |
if (isAlphaNum(lastChar)) { can_open = false; } |
| 5923 |
if (isAlphaNum(nextChar)) { can_close = false; } |
| 5924 |
} |
| 5925 |
} |
| 5926 |
|
| 5927 |
return { |
| 5928 |
can_open: can_open, |
| 5929 |
can_close: can_close, |
| 5930 |
delims: count |
| 5931 |
}; |
| 5932 |
} |
| 5933 |
|
| 5934 |
function emphasis(state, silent) { |
| 5935 |
var startCount, |
| 5936 |
count, |
| 5937 |
found, |
| 5938 |
oldCount, |
| 5939 |
newCount, |
| 5940 |
stack, |
| 5941 |
res, |
| 5942 |
max = state.posMax, |
| 5943 |
start = state.pos, |
| 5944 |
marker = state.src.charCodeAt(start); |
| 5945 |
|
| 5946 |
if (marker !== 0x5F/* _ */ && marker !== 0x2A /* * */) { return false; } |
| 5947 |
if (silent) { return false; } // don't run any pairs in validation mode |
| 5948 |
|
| 5949 |
res = scanDelims(state, start); |
| 5950 |
startCount = res.delims; |
| 5951 |
if (!res.can_open) { |
| 5952 |
state.pos += startCount; |
| 5953 |
if (!silent) { state.pending += state.src.slice(start, state.pos); } |
| 5954 |
return true; |
| 5955 |
} |
| 5956 |
|
| 5957 |
if (state.level >= state.options.maxNesting) { return false; } |
| 5958 |
|
| 5959 |
state.pos = start + startCount; |
| 5960 |
stack = [ startCount ]; |
| 5961 |
|
| 5962 |
while (state.pos < max) { |
| 5963 |
if (state.src.charCodeAt(state.pos) === marker) { |
| 5964 |
res = scanDelims(state, state.pos); |
| 5965 |
count = res.delims; |
| 5966 |
if (res.can_close) { |
| 5967 |
oldCount = stack.pop(); |
| 5968 |
newCount = count; |
| 5969 |
|
| 5970 |
while (oldCount !== newCount) { |
| 5971 |
if (newCount < oldCount) { |
| 5972 |
stack.push(oldCount - newCount); |
| 5973 |
break; |
| 5974 |
} |
| 5975 |
|
| 5976 |
// assert(newCount > oldCount) |
| 5977 |
newCount -= oldCount; |
| 5978 |
|
| 5979 |
if (stack.length === 0) { break; } |
| 5980 |
state.pos += oldCount; |
| 5981 |
oldCount = stack.pop(); |
| 5982 |
} |
| 5983 |
|
| 5984 |
if (stack.length === 0) { |
| 5985 |
startCount = oldCount; |
| 5986 |
found = true; |
| 5987 |
break; |
| 5988 |
} |
| 5989 |
state.pos += count; |
| 5990 |
continue; |
| 5991 |
} |
| 5992 |
|
| 5993 |
if (res.can_open) { stack.push(count); } |
| 5994 |
state.pos += count; |
| 5995 |
continue; |
| 5996 |
} |
| 5997 |
|
| 5998 |
state.parser.skipToken(state); |
| 5999 |
} |
| 6000 |
|
| 6001 |
if (!found) { |
| 6002 |
// parser failed to find ending tag, so it's not valid emphasis |
| 6003 |
state.pos = start; |
| 6004 |
return false; |
| 6005 |
} |
| 6006 |
|
| 6007 |
// found! |
| 6008 |
state.posMax = state.pos; |
| 6009 |
state.pos = start + startCount; |
| 6010 |
|
| 6011 |
if (!silent) { |
| 6012 |
if (startCount === 2 || startCount === 3) { |
| 6013 |
state.push({ type: 'strong_open', level: state.level++ }); |
| 6014 |
} |
| 6015 |
if (startCount === 1 || startCount === 3) { |
| 6016 |
state.push({ type: 'em_open', level: state.level++ }); |
| 6017 |
} |
| 6018 |
|
| 6019 |
state.parser.tokenize(state); |
| 6020 |
|
| 6021 |
if (startCount === 1 || startCount === 3) { |
| 6022 |
state.push({ type: 'em_close', level: --state.level }); |
| 6023 |
} |
| 6024 |
if (startCount === 2 || startCount === 3) { |
| 6025 |
state.push({ type: 'strong_close', level: --state.level }); |
| 6026 |
} |
| 6027 |
} |
| 6028 |
|
| 6029 |
state.pos = state.posMax + startCount; |
| 6030 |
state.posMax = max; |
| 6031 |
return true; |
| 6032 |
} |
| 6033 |
|
| 6034 |
// Process ~subscript~ |
| 6035 |
|
| 6036 |
// same as UNESCAPE_MD_RE plus a space |
| 6037 |
var UNESCAPE_RE = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; |
| 6038 |
|
| 6039 |
function sub(state, silent) { |
| 6040 |
var found, |
| 6041 |
content, |
| 6042 |
max = state.posMax, |
| 6043 |
start = state.pos; |
| 6044 |
|
| 6045 |
if (state.src.charCodeAt(start) !== 0x7E/* ~ */) { return false; } |
| 6046 |
if (silent) { return false; } // don't run any pairs in validation mode |
| 6047 |
if (start + 2 >= max) { return false; } |
| 6048 |
if (state.level >= state.options.maxNesting) { return false; } |
| 6049 |
|
| 6050 |
state.pos = start + 1; |
| 6051 |
|
| 6052 |
while (state.pos < max) { |
| 6053 |
if (state.src.charCodeAt(state.pos) === 0x7E/* ~ */) { |
| 6054 |
found = true; |
| 6055 |
break; |
| 6056 |
} |
| 6057 |
|
| 6058 |
state.parser.skipToken(state); |
| 6059 |
} |
| 6060 |
|
| 6061 |
if (!found || start + 1 === state.pos) { |
| 6062 |
state.pos = start; |
| 6063 |
return false; |
| 6064 |
} |
| 6065 |
|
| 6066 |
content = state.src.slice(start + 1, state.pos); |
| 6067 |
|
| 6068 |
// don't allow unescaped spaces/newlines inside |
| 6069 |
if (content.match(/(^|[^\\])(\\\\)*\s/)) { |
| 6070 |
state.pos = start; |
| 6071 |
return false; |
| 6072 |
} |
| 6073 |
|
| 6074 |
// found! |
| 6075 |
state.posMax = state.pos; |
| 6076 |
state.pos = start + 1; |
| 6077 |
|
| 6078 |
if (!silent) { |
| 6079 |
state.push({ |
| 6080 |
type: 'sub', |
| 6081 |
level: state.level, |
| 6082 |
content: content.replace(UNESCAPE_RE, '$1') |
| 6083 |
}); |
| 6084 |
} |
| 6085 |
|
| 6086 |
state.pos = state.posMax + 1; |
| 6087 |
state.posMax = max; |
| 6088 |
return true; |
| 6089 |
} |
| 6090 |
|
| 6091 |
// Process ^superscript^ |
| 6092 |
|
| 6093 |
// same as UNESCAPE_MD_RE plus a space |
| 6094 |
var UNESCAPE_RE$1 = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; |
| 6095 |
|
| 6096 |
function sup(state, silent) { |
| 6097 |
var found, |
| 6098 |
content, |
| 6099 |
max = state.posMax, |
| 6100 |
start = state.pos; |
| 6101 |
|
| 6102 |
if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; } |
| 6103 |
if (silent) { return false; } // don't run any pairs in validation mode |
| 6104 |
if (start + 2 >= max) { return false; } |
| 6105 |
if (state.level >= state.options.maxNesting) { return false; } |
| 6106 |
|
| 6107 |
state.pos = start + 1; |
| 6108 |
|
| 6109 |
while (state.pos < max) { |
| 6110 |
if (state.src.charCodeAt(state.pos) === 0x5E/* ^ */) { |
| 6111 |
found = true; |
| 6112 |
break; |
| 6113 |
} |
| 6114 |
|
| 6115 |
state.parser.skipToken(state); |
| 6116 |
} |
| 6117 |
|
| 6118 |
if (!found || start + 1 === state.pos) { |
| 6119 |
state.pos = start; |
| 6120 |
return false; |
| 6121 |
} |
| 6122 |
|
| 6123 |
content = state.src.slice(start + 1, state.pos); |
| 6124 |
|
| 6125 |
// don't allow unescaped spaces/newlines inside |
| 6126 |
if (content.match(/(^|[^\\])(\\\\)*\s/)) { |
| 6127 |
state.pos = start; |
| 6128 |
return false; |
| 6129 |
} |
| 6130 |
|
| 6131 |
// found! |
| 6132 |
state.posMax = state.pos; |
| 6133 |
state.pos = start + 1; |
| 6134 |
|
| 6135 |
if (!silent) { |
| 6136 |
state.push({ |
| 6137 |
type: 'sup', |
| 6138 |
level: state.level, |
| 6139 |
content: content.replace(UNESCAPE_RE$1, '$1') |
| 6140 |
}); |
| 6141 |
} |
| 6142 |
|
| 6143 |
state.pos = state.posMax + 1; |
| 6144 |
state.posMax = max; |
| 6145 |
return true; |
| 6146 |
} |
| 6147 |
|
| 6148 |
// Process [links](<to> "stuff") |
| 6149 |
|
| 6150 |
|
| 6151 |
function links(state, silent) { |
| 6152 |
var labelStart, |
| 6153 |
labelEnd, |
| 6154 |
label, |
| 6155 |
href, |
| 6156 |
title, |
| 6157 |
pos, |
| 6158 |
ref, |
| 6159 |
code, |
| 6160 |
isImage = false, |
| 6161 |
oldPos = state.pos, |
| 6162 |
max = state.posMax, |
| 6163 |
start = state.pos, |
| 6164 |
marker = state.src.charCodeAt(start); |
| 6165 |
|
| 6166 |
if (marker === 0x21/* ! */) { |
| 6167 |
isImage = true; |
| 6168 |
marker = state.src.charCodeAt(++start); |
| 6169 |
} |
| 6170 |
|
| 6171 |
if (marker !== 0x5B/* [ */) { return false; } |
| 6172 |
if (state.level >= state.options.maxNesting) { return false; } |
| 6173 |
|
| 6174 |
labelStart = start + 1; |
| 6175 |
labelEnd = parseLinkLabel(state, start); |
| 6176 |
|
| 6177 |
// parser failed to find ']', so it's not a valid link |
| 6178 |
if (labelEnd < 0) { return false; } |
| 6179 |
|
| 6180 |
pos = labelEnd + 1; |
| 6181 |
if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) { |
| 6182 |
// |
| 6183 |
// Inline link |
| 6184 |
// |
| 6185 |
|
| 6186 |
// [link]( <href> "title" ) |
| 6187 |
// ^^ skipping these spaces |
| 6188 |
pos++; |
| 6189 |
for (; pos < max; pos++) { |
| 6190 |
code = state.src.charCodeAt(pos); |
| 6191 |
if (code !== 0x20 && code !== 0x0A) { break; } |
| 6192 |
} |
| 6193 |
if (pos >= max) { return false; } |
| 6194 |
|
| 6195 |
// [link]( <href> "title" ) |
| 6196 |
// ^^^^^^ parsing link destination |
| 6197 |
start = pos; |
| 6198 |
if (parseLinkDestination(state, pos)) { |
| 6199 |
href = state.linkContent; |
| 6200 |
pos = state.pos; |
| 6201 |
} else { |
| 6202 |
href = ''; |
| 6203 |
} |
| 6204 |
|
| 6205 |
// [link]( <href> "title" ) |
| 6206 |
// ^^ skipping these spaces |
| 6207 |
start = pos; |
| 6208 |
for (; pos < max; pos++) { |
| 6209 |
code = state.src.charCodeAt(pos); |
| 6210 |
if (code !== 0x20 && code !== 0x0A) { break; } |
| 6211 |
} |
| 6212 |
|
| 6213 |
// [link]( <href> "title" ) |
| 6214 |
// ^^^^^^^ parsing link title |
| 6215 |
if (pos < max && start !== pos && parseLinkTitle(state, pos)) { |
| 6216 |
title = state.linkContent; |
| 6217 |
pos = state.pos; |
| 6218 |
|
| 6219 |
// [link]( <href> "title" ) |
| 6220 |
// ^^ skipping these spaces |
| 6221 |
for (; pos < max; pos++) { |
| 6222 |
code = state.src.charCodeAt(pos); |
| 6223 |
if (code !== 0x20 && code !== 0x0A) { break; } |
| 6224 |
} |
| 6225 |
} else { |
| 6226 |
title = ''; |
| 6227 |
} |
| 6228 |
|
| 6229 |
if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) { |
| 6230 |
state.pos = oldPos; |
| 6231 |
return false; |
| 6232 |
} |
| 6233 |
pos++; |
| 6234 |
} else { |
| 6235 |
// |
| 6236 |
// Link reference |
| 6237 |
// |
| 6238 |
|
| 6239 |
// do not allow nested reference links |
| 6240 |
if (state.linkLevel > 0) { return false; } |
| 6241 |
|
| 6242 |
// [foo] [bar] |
| 6243 |
// ^^ optional whitespace (can include newlines) |
| 6244 |
for (; pos < max; pos++) { |
| 6245 |
code = state.src.charCodeAt(pos); |
| 6246 |
if (code !== 0x20 && code !== 0x0A) { break; } |
| 6247 |
} |
| 6248 |
|
| 6249 |
if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { |
| 6250 |
start = pos + 1; |
| 6251 |
pos = parseLinkLabel(state, pos); |
| 6252 |
if (pos >= 0) { |
| 6253 |
label = state.src.slice(start, pos++); |
| 6254 |
} else { |
| 6255 |
pos = start - 1; |
| 6256 |
} |
| 6257 |
} |
| 6258 |
|
| 6259 |
// covers label === '' and label === undefined |
| 6260 |
// (collapsed reference link and shortcut reference link respectively) |
| 6261 |
if (!label) { |
| 6262 |
if (typeof label === 'undefined') { |
| 6263 |
pos = labelEnd + 1; |
| 6264 |
} |
| 6265 |
label = state.src.slice(labelStart, labelEnd); |
| 6266 |
} |
| 6267 |
|
| 6268 |
ref = state.env.references[normalizeReference(label)]; |
| 6269 |
if (!ref) { |
| 6270 |
state.pos = oldPos; |
| 6271 |
return false; |
| 6272 |
} |
| 6273 |
href = ref.href; |
| 6274 |
title = ref.title; |
| 6275 |
} |
| 6276 |
|
| 6277 |
// |
| 6278 |
// We found the end of the link, and know for a fact it's a valid link; |
| 6279 |
// so all that's left to do is to call tokenizer. |
| 6280 |
// |
| 6281 |
if (!silent) { |
| 6282 |
state.pos = labelStart; |
| 6283 |
state.posMax = labelEnd; |
| 6284 |
|
| 6285 |
if (isImage) { |
| 6286 |
state.push({ |
| 6287 |
type: 'image', |
| 6288 |
src: href, |
| 6289 |
title: title, |
| 6290 |
alt: state.src.substr(labelStart, labelEnd - labelStart), |
| 6291 |
level: state.level |
| 6292 |
}); |
| 6293 |
} else { |
| 6294 |
state.push({ |
| 6295 |
type: 'link_open', |
| 6296 |
href: href, |
| 6297 |
title: title, |
| 6298 |
level: state.level++ |
| 6299 |
}); |
| 6300 |
state.linkLevel++; |
| 6301 |
state.parser.tokenize(state); |
| 6302 |
state.linkLevel--; |
| 6303 |
state.push({ type: 'link_close', level: --state.level }); |
| 6304 |
} |
| 6305 |
} |
| 6306 |
|
| 6307 |
state.pos = pos; |
| 6308 |
state.posMax = max; |
| 6309 |
return true; |
| 6310 |
} |
| 6311 |
|
| 6312 |
// Process inline footnotes (^[...]) |
| 6313 |
|
| 6314 |
|
| 6315 |
function footnote_inline(state, silent) { |
| 6316 |
var labelStart, |
| 6317 |
labelEnd, |
| 6318 |
footnoteId, |
| 6319 |
oldLength, |
| 6320 |
max = state.posMax, |
| 6321 |
start = state.pos; |
| 6322 |
|
| 6323 |
if (start + 2 >= max) { return false; } |
| 6324 |
if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; } |
| 6325 |
if (state.src.charCodeAt(start + 1) !== 0x5B/* [ */) { return false; } |
| 6326 |
if (state.level >= state.options.maxNesting) { return false; } |
| 6327 |
|
| 6328 |
labelStart = start + 2; |
| 6329 |
labelEnd = parseLinkLabel(state, start + 1); |
| 6330 |
|
| 6331 |
// parser failed to find ']', so it's not a valid note |
| 6332 |
if (labelEnd < 0) { return false; } |
| 6333 |
|
| 6334 |
// We found the end of the link, and know for a fact it's a valid link; |
| 6335 |
// so all that's left to do is to call tokenizer. |
| 6336 |
// |
| 6337 |
if (!silent) { |
| 6338 |
if (!state.env.footnotes) { state.env.footnotes = {}; } |
| 6339 |
if (!state.env.footnotes.list) { state.env.footnotes.list = []; } |
| 6340 |
footnoteId = state.env.footnotes.list.length; |
| 6341 |
|
| 6342 |
state.pos = labelStart; |
| 6343 |
state.posMax = labelEnd; |
| 6344 |
|
| 6345 |
state.push({ |
| 6346 |
type: 'footnote_ref', |
| 6347 |
id: footnoteId, |
| 6348 |
level: state.level |
| 6349 |
}); |
| 6350 |
state.linkLevel++; |
| 6351 |
oldLength = state.tokens.length; |
| 6352 |
state.parser.tokenize(state); |
| 6353 |
state.env.footnotes.list[footnoteId] = { tokens: state.tokens.splice(oldLength) }; |
| 6354 |
state.linkLevel--; |
| 6355 |
} |
| 6356 |
|
| 6357 |
state.pos = labelEnd + 1; |
| 6358 |
state.posMax = max; |
| 6359 |
return true; |
| 6360 |
} |
| 6361 |
|
| 6362 |
// Process footnote references ([^...]) |
| 6363 |
|
| 6364 |
function footnote_ref(state, silent) { |
| 6365 |
var label, |
| 6366 |
pos, |
| 6367 |
footnoteId, |
| 6368 |
footnoteSubId, |
| 6369 |
max = state.posMax, |
| 6370 |
start = state.pos; |
| 6371 |
|
| 6372 |
// should be at least 4 chars - "[^x]" |
| 6373 |
if (start + 3 > max) { return false; } |
| 6374 |
|
| 6375 |
if (!state.env.footnotes || !state.env.footnotes.refs) { return false; } |
| 6376 |
if (state.src.charCodeAt(start) !== 0x5B/* [ */) { return false; } |
| 6377 |
if (state.src.charCodeAt(start + 1) !== 0x5E/* ^ */) { return false; } |
| 6378 |
if (state.level >= state.options.maxNesting) { return false; } |
| 6379 |
|
| 6380 |
for (pos = start + 2; pos < max; pos++) { |
| 6381 |
if (state.src.charCodeAt(pos) === 0x20) { return false; } |
| 6382 |
if (state.src.charCodeAt(pos) === 0x0A) { return false; } |
| 6383 |
if (state.src.charCodeAt(pos) === 0x5D /* ] */) { |
| 6384 |
break; |
| 6385 |
} |
| 6386 |
} |
| 6387 |
|
| 6388 |
if (pos === start + 2) { return false; } // no empty footnote labels |
| 6389 |
if (pos >= max) { return false; } |
| 6390 |
pos++; |
| 6391 |
|
| 6392 |
label = state.src.slice(start + 2, pos - 1); |
| 6393 |
if (typeof state.env.footnotes.refs[':' + label] === 'undefined') { return false; } |
| 6394 |
|
| 6395 |
if (!silent) { |
| 6396 |
if (!state.env.footnotes.list) { state.env.footnotes.list = []; } |
| 6397 |
|
| 6398 |
if (state.env.footnotes.refs[':' + label] < 0) { |
| 6399 |
footnoteId = state.env.footnotes.list.length; |
| 6400 |
state.env.footnotes.list[footnoteId] = { label: label, count: 0 }; |
| 6401 |
state.env.footnotes.refs[':' + label] = footnoteId; |
| 6402 |
} else { |
| 6403 |
footnoteId = state.env.footnotes.refs[':' + label]; |
| 6404 |
} |
| 6405 |
|
| 6406 |
footnoteSubId = state.env.footnotes.list[footnoteId].count; |
| 6407 |
state.env.footnotes.list[footnoteId].count++; |
| 6408 |
|
| 6409 |
state.push({ |
| 6410 |
type: 'footnote_ref', |
| 6411 |
id: footnoteId, |
| 6412 |
subId: footnoteSubId, |
| 6413 |
level: state.level |
| 6414 |
}); |
| 6415 |
} |
| 6416 |
|
| 6417 |
state.pos = pos; |
| 6418 |
state.posMax = max; |
| 6419 |
return true; |
| 6420 |
} |
| 6421 |
|
| 6422 |
// List of valid url schemas, accorting to commonmark spec |
| 6423 |
// http://jgm.github.io/CommonMark/spec.html#autolinks |
| 6424 |
|
| 6425 |
var url_schemas = [ |
| 6426 |
'coap', |
| 6427 |
'doi', |
| 6428 |
'javascript', |
| 6429 |
'aaa', |
| 6430 |
'aaas', |
| 6431 |
'about', |
| 6432 |
'acap', |
| 6433 |
'cap', |
| 6434 |
'cid', |
| 6435 |
'crid', |
| 6436 |
'data', |
| 6437 |
'dav', |
| 6438 |
'dict', |
| 6439 |
'dns', |
| 6440 |
'file', |
| 6441 |
'ftp', |
| 6442 |
'geo', |
| 6443 |
'go', |
| 6444 |
'gopher', |
| 6445 |
'h323', |
| 6446 |
'http', |
| 6447 |
'https', |
| 6448 |
'iax', |
| 6449 |
'icap', |
| 6450 |
'im', |
| 6451 |
'imap', |
| 6452 |
'info', |
| 6453 |
'ipp', |
| 6454 |
'iris', |
| 6455 |
'iris.beep', |
| 6456 |
'iris.xpc', |
| 6457 |
'iris.xpcs', |
| 6458 |
'iris.lwz', |
| 6459 |
'ldap', |
| 6460 |
'mailto', |
| 6461 |
'mid', |
| 6462 |
'msrp', |
| 6463 |
'msrps', |
| 6464 |
'mtqp', |
| 6465 |
'mupdate', |
| 6466 |
'news', |
| 6467 |
'nfs', |
| 6468 |
'ni', |
| 6469 |
'nih', |
| 6470 |
'nntp', |
| 6471 |
'opaquelocktoken', |
| 6472 |
'pop', |
| 6473 |
'pres', |
| 6474 |
'rtsp', |
| 6475 |
'service', |
| 6476 |
'session', |
| 6477 |
'shttp', |
| 6478 |
'sieve', |
| 6479 |
'sip', |
| 6480 |
'sips', |
| 6481 |
'sms', |
| 6482 |
'snmp', |
| 6483 |
'soap.beep', |
| 6484 |
'soap.beeps', |
| 6485 |
'tag', |
| 6486 |
'tel', |
| 6487 |
'telnet', |
| 6488 |
'tftp', |
| 6489 |
'thismessage', |
| 6490 |
'tn3270', |
| 6491 |
'tip', |
| 6492 |
'tv', |
| 6493 |
'urn', |
| 6494 |
'vemmi', |
| 6495 |
'ws', |
| 6496 |
'wss', |
| 6497 |
'xcon', |
| 6498 |
'xcon-userid', |
| 6499 |
'xmlrpc.beep', |
| 6500 |
'xmlrpc.beeps', |
| 6501 |
'xmpp', |
| 6502 |
'z39.50r', |
| 6503 |
'z39.50s', |
| 6504 |
'adiumxtra', |
| 6505 |
'afp', |
| 6506 |
'afs', |
| 6507 |
'aim', |
| 6508 |
'apt', |
| 6509 |
'attachment', |
| 6510 |
'aw', |
| 6511 |
'beshare', |
| 6512 |
'bitcoin', |
| 6513 |
'bolo', |
| 6514 |
'callto', |
| 6515 |
'chrome', |
| 6516 |
'chrome-extension', |
| 6517 |
'com-eventbrite-attendee', |
| 6518 |
'content', |
| 6519 |
'cvs', |
| 6520 |
'dlna-playsingle', |
| 6521 |
'dlna-playcontainer', |
| 6522 |
'dtn', |
| 6523 |
'dvb', |
| 6524 |
'ed2k', |
| 6525 |
'facetime', |
| 6526 |
'feed', |
| 6527 |
'finger', |
| 6528 |
'fish', |
| 6529 |
'gg', |
| 6530 |
'git', |
| 6531 |
'gizmoproject', |
| 6532 |
'gtalk', |
| 6533 |
'hcp', |
| 6534 |
'icon', |
| 6535 |
'ipn', |
| 6536 |
'irc', |
| 6537 |
'irc6', |
| 6538 |
'ircs', |
| 6539 |
'itms', |
| 6540 |
'jar', |
| 6541 |
'jms', |
| 6542 |
'keyparc', |
| 6543 |
'lastfm', |
| 6544 |
'ldaps', |
| 6545 |
'magnet', |
| 6546 |
'maps', |
| 6547 |
'market', |
| 6548 |
'message', |
| 6549 |
'mms', |
| 6550 |
'ms-help', |
| 6551 |
'msnim', |
| 6552 |
'mumble', |
| 6553 |
'mvn', |
| 6554 |
'notes', |
| 6555 |
'oid', |
| 6556 |
'palm', |
| 6557 |
'paparazzi', |
| 6558 |
'platform', |
| 6559 |
'proxy', |
| 6560 |
'psyc', |
| 6561 |
'query', |
| 6562 |
'res', |
| 6563 |
'resource', |
| 6564 |
'rmi', |
| 6565 |
'rsync', |
| 6566 |
'rtmp', |
| 6567 |
'secondlife', |
| 6568 |
'sftp', |
| 6569 |
'sgn', |
| 6570 |
'skype', |
| 6571 |
'smb', |
| 6572 |
'soldat', |
| 6573 |
'spotify', |
| 6574 |
'ssh', |
| 6575 |
'steam', |
| 6576 |
'svn', |
| 6577 |
'teamspeak', |
| 6578 |
'things', |
| 6579 |
'udp', |
| 6580 |
'unreal', |
| 6581 |
'ut2004', |
| 6582 |
'ventrilo', |
| 6583 |
'view-source', |
| 6584 |
'webcal', |
| 6585 |
'wtai', |
| 6586 |
'wyciwyg', |
| 6587 |
'xfire', |
| 6588 |
'xri', |
| 6589 |
'ymsgr' |
| 6590 |
]; |
| 6591 |
|
| 6592 |
// Process autolinks '<protocol:...>' |
| 6593 |
|
| 6594 |
|
| 6595 |
/*eslint max-len:0*/ |
| 6596 |
var EMAIL_RE = /^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/; |
| 6597 |
var AUTOLINK_RE = /^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/; |
| 6598 |
|
| 6599 |
|
| 6600 |
function autolink(state, silent) { |
| 6601 |
var tail, linkMatch, emailMatch, url, fullUrl, pos = state.pos; |
| 6602 |
|
| 6603 |
if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false; } |
| 6604 |
|
| 6605 |
tail = state.src.slice(pos); |
| 6606 |
|
| 6607 |
if (tail.indexOf('>') < 0) { return false; } |
| 6608 |
|
| 6609 |
linkMatch = tail.match(AUTOLINK_RE); |
| 6610 |
|
| 6611 |
if (linkMatch) { |
| 6612 |
if (url_schemas.indexOf(linkMatch[1].toLowerCase()) < 0) { return false; } |
| 6613 |
|
| 6614 |
url = linkMatch[0].slice(1, -1); |
| 6615 |
fullUrl = normalizeLink(url); |
| 6616 |
if (!state.parser.validateLink(url)) { return false; } |
| 6617 |
|
| 6618 |
if (!silent) { |
| 6619 |
state.push({ |
| 6620 |
type: 'link_open', |
| 6621 |
href: fullUrl, |
| 6622 |
level: state.level |
| 6623 |
}); |
| 6624 |
state.push({ |
| 6625 |
type: 'text', |
| 6626 |
content: url, |
| 6627 |
level: state.level + 1 |
| 6628 |
}); |
| 6629 |
state.push({ type: 'link_close', level: state.level }); |
| 6630 |
} |
| 6631 |
|
| 6632 |
state.pos += linkMatch[0].length; |
| 6633 |
return true; |
| 6634 |
} |
| 6635 |
|
| 6636 |
emailMatch = tail.match(EMAIL_RE); |
| 6637 |
|
| 6638 |
if (emailMatch) { |
| 6639 |
|
| 6640 |
url = emailMatch[0].slice(1, -1); |
| 6641 |
|
| 6642 |
fullUrl = normalizeLink('mailto:' + url); |
| 6643 |
if (!state.parser.validateLink(fullUrl)) { return false; } |
| 6644 |
|
| 6645 |
if (!silent) { |
| 6646 |
state.push({ |
| 6647 |
type: 'link_open', |
| 6648 |
href: fullUrl, |
| 6649 |
level: state.level |
| 6650 |
}); |
| 6651 |
state.push({ |
| 6652 |
type: 'text', |
| 6653 |
content: url, |
| 6654 |
level: state.level + 1 |
| 6655 |
}); |
| 6656 |
state.push({ type: 'link_close', level: state.level }); |
| 6657 |
} |
| 6658 |
|
| 6659 |
state.pos += emailMatch[0].length; |
| 6660 |
return true; |
| 6661 |
} |
| 6662 |
|
| 6663 |
return false; |
| 6664 |
} |
| 6665 |
|
| 6666 |
// Regexps to match html elements |
| 6667 |
|
| 6668 |
function replace$1(regex, options) { |
| 6669 |
regex = regex.source; |
| 6670 |
options = options || ''; |
| 6671 |
|
| 6672 |
return function self(name, val) { |
| 6673 |
if (!name) { |
| 6674 |
return new RegExp(regex, options); |
| 6675 |
} |
| 6676 |
val = val.source || val; |
| 6677 |
regex = regex.replace(name, val); |
| 6678 |
return self; |
| 6679 |
}; |
| 6680 |
} |
| 6681 |
|
| 6682 |
|
| 6683 |
var attr_name = /[a-zA-Z_:][a-zA-Z0-9:._-]*/; |
| 6684 |
|
| 6685 |
var unquoted = /[^"'=<>`\x00-\x20]+/; |
| 6686 |
var single_quoted = /'[^']*'/; |
| 6687 |
var double_quoted = /"[^"]*"/; |
| 6688 |
|
| 6689 |
/*eslint no-spaced-func:0*/ |
| 6690 |
var attr_value = replace$1(/(?:unquoted|single_quoted|double_quoted)/) |
| 6691 |
('unquoted', unquoted) |
| 6692 |
('single_quoted', single_quoted) |
| 6693 |
('double_quoted', double_quoted) |
| 6694 |
(); |
| 6695 |
|
| 6696 |
var attribute = replace$1(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/) |
| 6697 |
('attr_name', attr_name) |
| 6698 |
('attr_value', attr_value) |
| 6699 |
(); |
| 6700 |
|
| 6701 |
var open_tag = replace$1(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/) |
| 6702 |
('attribute', attribute) |
| 6703 |
(); |
| 6704 |
|
| 6705 |
var close_tag = /<\/[A-Za-z][A-Za-z0-9]*\s*>/; |
| 6706 |
var comment = /<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/; |
| 6707 |
var processing = /<[?].*?[?]>/; |
| 6708 |
var declaration = /<![A-Z]+\s+[^>]*>/; |
| 6709 |
var cdata = /<!\[CDATA\[[\s\S]*?\]\]>/; |
| 6710 |
|
| 6711 |
var HTML_TAG_RE = replace$1(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/) |
| 6712 |
('open_tag', open_tag) |
| 6713 |
('close_tag', close_tag) |
| 6714 |
('comment', comment) |
| 6715 |
('processing', processing) |
| 6716 |
('declaration', declaration) |
| 6717 |
('cdata', cdata) |
| 6718 |
(); |
| 6719 |
|
| 6720 |
// Process html tags |
| 6721 |
|
| 6722 |
|
| 6723 |
function isLetter$2(ch) { |
| 6724 |
/*eslint no-bitwise:0*/ |
| 6725 |
var lc = ch | 0x20; // to lower case |
| 6726 |
return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */); |
| 6727 |
} |
| 6728 |
|
| 6729 |
|
| 6730 |
function htmltag(state, silent) { |
| 6731 |
var ch, match, max, pos = state.pos; |
| 6732 |
|
| 6733 |
if (!state.options.html) { return false; } |
| 6734 |
|
| 6735 |
// Check start |
| 6736 |
max = state.posMax; |
| 6737 |
if (state.src.charCodeAt(pos) !== 0x3C/* < */ || |
| 6738 |
pos + 2 >= max) { |
| 6739 |
return false; |
| 6740 |
} |
| 6741 |
|
| 6742 |
// Quick fail on second char |
| 6743 |
ch = state.src.charCodeAt(pos + 1); |
| 6744 |
if (ch !== 0x21/* ! */ && |
| 6745 |
ch !== 0x3F/* ? */ && |
| 6746 |
ch !== 0x2F/* / */ && |
| 6747 |
!isLetter$2(ch)) { |
| 6748 |
return false; |
| 6749 |
} |
| 6750 |
|
| 6751 |
match = state.src.slice(pos).match(HTML_TAG_RE); |
| 6752 |
if (!match) { return false; } |
| 6753 |
|
| 6754 |
if (!silent) { |
| 6755 |
state.push({ |
| 6756 |
type: 'htmltag', |
| 6757 |
content: state.src.slice(pos, pos + match[0].length), |
| 6758 |
level: state.level |
| 6759 |
}); |
| 6760 |
} |
| 6761 |
state.pos += match[0].length; |
| 6762 |
return true; |
| 6763 |
} |
| 6764 |
|
| 6765 |
// Process html entity - {, ¯, ", ... |
| 6766 |
|
| 6767 |
|
| 6768 |
var DIGITAL_RE = /^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i; |
| 6769 |
var NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i; |
| 6770 |
|
| 6771 |
|
| 6772 |
function entity(state, silent) { |
| 6773 |
var ch, code, match, pos = state.pos, max = state.posMax; |
| 6774 |
|
| 6775 |
if (state.src.charCodeAt(pos) !== 0x26/* & */) { return false; } |
| 6776 |
|
| 6777 |
if (pos + 1 < max) { |
| 6778 |
ch = state.src.charCodeAt(pos + 1); |
| 6779 |
|
| 6780 |
if (ch === 0x23 /* # */) { |
| 6781 |
match = state.src.slice(pos).match(DIGITAL_RE); |
| 6782 |
if (match) { |
| 6783 |
if (!silent) { |
| 6784 |
code = match[1][0].toLowerCase() === 'x' ? parseInt(match[1].slice(1), 16) : parseInt(match[1], 10); |
| 6785 |
state.pending += isValidEntityCode(code) ? fromCodePoint(code) : fromCodePoint(0xFFFD); |
| 6786 |
} |
| 6787 |
state.pos += match[0].length; |
| 6788 |
return true; |
| 6789 |
} |
| 6790 |
} else { |
| 6791 |
match = state.src.slice(pos).match(NAMED_RE); |
| 6792 |
if (match) { |
| 6793 |
var decoded = decodeEntity(match[1]); |
| 6794 |
if (match[1] !== decoded) { |
| 6795 |
if (!silent) { state.pending += decoded; } |
| 6796 |
state.pos += match[0].length; |
| 6797 |
return true; |
| 6798 |
} |
| 6799 |
} |
| 6800 |
} |
| 6801 |
} |
| 6802 |
|
| 6803 |
if (!silent) { state.pending += '&'; } |
| 6804 |
state.pos++; |
| 6805 |
return true; |
| 6806 |
} |
| 6807 |
|
| 6808 |
/** |
| 6809 |
* Inline Parser `rules` |
| 6810 |
*/ |
| 6811 |
|
| 6812 |
var _rules$2 = [ |
| 6813 |
[ 'text', text ], |
| 6814 |
[ 'newline', newline ], |
| 6815 |
[ 'escape', escape ], |
| 6816 |
[ 'backticks', backticks ], |
| 6817 |
[ 'del', del ], |
| 6818 |
[ 'ins', ins ], |
| 6819 |
[ 'mark', mark ], |
| 6820 |
[ 'emphasis', emphasis ], |
| 6821 |
[ 'sub', sub ], |
| 6822 |
[ 'sup', sup ], |
| 6823 |
[ 'links', links ], |
| 6824 |
[ 'footnote_inline', footnote_inline ], |
| 6825 |
[ 'footnote_ref', footnote_ref ], |
| 6826 |
[ 'autolink', autolink ], |
| 6827 |
[ 'htmltag', htmltag ], |
| 6828 |
[ 'entity', entity ] |
| 6829 |
]; |
| 6830 |
|
| 6831 |
/** |
| 6832 |
* Inline Parser class. Note that link validation is stricter |
| 6833 |
* in Remarkable than what is specified by CommonMark. If you |
| 6834 |
* want to change this you can use a custom validator. |
| 6835 |
* |
| 6836 |
* @api private |
| 6837 |
*/ |
| 6838 |
|
| 6839 |
function ParserInline() { |
| 6840 |
this.ruler = new Ruler(); |
| 6841 |
for (var i = 0; i < _rules$2.length; i++) { |
| 6842 |
this.ruler.push(_rules$2[i][0], _rules$2[i][1]); |
| 6843 |
} |
| 6844 |
|
| 6845 |
// Can be overridden with a custom validator |
| 6846 |
this.validateLink = validateLink; |
| 6847 |
} |
| 6848 |
|
| 6849 |
/** |
| 6850 |
* Skip a single token by running all rules in validation mode. |
| 6851 |
* Returns `true` if any rule reports success. |
| 6852 |
* |
| 6853 |
* @param {Object} `state` |
| 6854 |
* @api privage |
| 6855 |
*/ |
| 6856 |
|
| 6857 |
ParserInline.prototype.skipToken = function (state) { |
| 6858 |
var rules = this.ruler.getRules(''); |
| 6859 |
var len = rules.length; |
| 6860 |
var pos = state.pos; |
| 6861 |
var i, cached_pos; |
| 6862 |
|
| 6863 |
if ((cached_pos = state.cacheGet(pos)) > 0) { |
| 6864 |
state.pos = cached_pos; |
| 6865 |
return; |
| 6866 |
} |
| 6867 |
|
| 6868 |
for (i = 0; i < len; i++) { |
| 6869 |
if (rules[i](state, true)) { |
| 6870 |
state.cacheSet(pos, state.pos); |
| 6871 |
return; |
| 6872 |
} |
| 6873 |
} |
| 6874 |
|
| 6875 |
state.pos++; |
| 6876 |
state.cacheSet(pos, state.pos); |
| 6877 |
}; |
| 6878 |
|
| 6879 |
/** |
| 6880 |
* Generate tokens for the given input range. |
| 6881 |
* |
| 6882 |
* @param {Object} `state` |
| 6883 |
* @api private |
| 6884 |
*/ |
| 6885 |
|
| 6886 |
ParserInline.prototype.tokenize = function (state) { |
| 6887 |
var rules = this.ruler.getRules(''); |
| 6888 |
var len = rules.length; |
| 6889 |
var end = state.posMax; |
| 6890 |
var ok, i; |
| 6891 |
|
| 6892 |
while (state.pos < end) { |
| 6893 |
|
| 6894 |
// Try all possible rules. |
| 6895 |
// On success, the rule should: |
| 6896 |
// |
| 6897 |
// - update `state.pos` |
| 6898 |
// - update `state.tokens` |
| 6899 |
// - return true |
| 6900 |
for (i = 0; i < len; i++) { |
| 6901 |
ok = rules[i](state, false); |
| 6902 |
|
| 6903 |
if (ok) { |
| 6904 |
break; |
| 6905 |
} |
| 6906 |
} |
| 6907 |
|
| 6908 |
if (ok) { |
| 6909 |
if (state.pos >= end) { break; } |
| 6910 |
continue; |
| 6911 |
} |
| 6912 |
|
| 6913 |
state.pending += state.src[state.pos++]; |
| 6914 |
} |
| 6915 |
|
| 6916 |
if (state.pending) { |
| 6917 |
state.pushPending(); |
| 6918 |
} |
| 6919 |
}; |
| 6920 |
|
| 6921 |
/** |
| 6922 |
* Parse the given input string. |
| 6923 |
* |
| 6924 |
* @param {String} `str` |
| 6925 |
* @param {Object} `options` |
| 6926 |
* @param {Object} `env` |
| 6927 |
* @param {Array} `outTokens` |
| 6928 |
* @api private |
| 6929 |
*/ |
| 6930 |
|
| 6931 |
ParserInline.prototype.parse = function (str, options, env, outTokens) { |
| 6932 |
var state = new StateInline(str, this, options, env, outTokens); |
| 6933 |
this.tokenize(state); |
| 6934 |
}; |
| 6935 |
|
| 6936 |
/** |
| 6937 |
* Validate the given `url` by checking for bad protocols. |
| 6938 |
* |
| 6939 |
* @param {String} `url` |
| 6940 |
* @return {Boolean} |
| 6941 |
*/ |
| 6942 |
|
| 6943 |
function validateLink(url) { |
| 6944 |
var BAD_PROTOCOLS = [ 'vbscript', 'javascript', 'file', 'data' ]; |
| 6945 |
var str = url.trim().toLowerCase(); |
| 6946 |
// Care about digital entities "javascript:alert(1)" |
| 6947 |
str = replaceEntities(str); |
| 6948 |
if (str.indexOf(':') !== -1 && BAD_PROTOCOLS.indexOf(str.split(':')[0]) !== -1) { |
| 6949 |
return false; |
| 6950 |
} |
| 6951 |
return true; |
| 6952 |
} |
| 6953 |
|
| 6954 |
// Remarkable default options |
| 6955 |
|
| 6956 |
var defaultConfig = { |
| 6957 |
options: { |
| 6958 |
html: false, // Enable HTML tags in source |
| 6959 |
xhtmlOut: false, // Use '/' to close single tags (<br />) |
| 6960 |
breaks: false, // Convert '\n' in paragraphs into <br> |
| 6961 |
langPrefix: 'language-', // CSS language prefix for fenced blocks |
| 6962 |
linkTarget: '', // set target to open link in |
| 6963 |
|
| 6964 |
// Enable some language-neutral replacements + quotes beautification |
| 6965 |
typographer: false, |
| 6966 |
|
| 6967 |
// Double + single quotes replacement pairs, when typographer enabled, |
| 6968 |
// and smartquotes on. Set doubles to '«»' for Russian, '„“' for German. |
| 6969 |
quotes: '“”‘’', |
| 6970 |
|
| 6971 |
// Highlighter function. Should return escaped HTML, |
| 6972 |
// or '' if input not changed |
| 6973 |
// |
| 6974 |
// function (/*str, lang*/) { return ''; } |
| 6975 |
// |
| 6976 |
highlight: null, |
| 6977 |
|
| 6978 |
maxNesting: 20 // Internal protection, recursion limit |
| 6979 |
}, |
| 6980 |
|
| 6981 |
components: { |
| 6982 |
|
| 6983 |
core: { |
| 6984 |
rules: [ |
| 6985 |
'block', |
| 6986 |
'inline', |
| 6987 |
'references', |
| 6988 |
'replacements', |
| 6989 |
'smartquotes', |
| 6990 |
'references', |
| 6991 |
'abbr2', |
| 6992 |
'footnote_tail' |
| 6993 |
] |
| 6994 |
}, |
| 6995 |
|
| 6996 |
block: { |
| 6997 |
rules: [ |
| 6998 |
'blockquote', |
| 6999 |
'code', |
| 7000 |
'fences', |
| 7001 |
'footnote', |
| 7002 |
'heading', |
| 7003 |
'hr', |
| 7004 |
'htmlblock', |
| 7005 |
'lheading', |
| 7006 |
'list', |
| 7007 |
'paragraph', |
| 7008 |
'table' |
| 7009 |
] |
| 7010 |
}, |
| 7011 |
|
| 7012 |
inline: { |
| 7013 |
rules: [ |
| 7014 |
'autolink', |
| 7015 |
'backticks', |
| 7016 |
'del', |
| 7017 |
'emphasis', |
| 7018 |
'entity', |
| 7019 |
'escape', |
| 7020 |
'footnote_ref', |
| 7021 |
'htmltag', |
| 7022 |
'links', |
| 7023 |
'newline', |
| 7024 |
'text' |
| 7025 |
] |
| 7026 |
} |
| 7027 |
} |
| 7028 |
}; |
| 7029 |
|
| 7030 |
// Remarkable default options |
| 7031 |
|
| 7032 |
var fullConfig = { |
| 7033 |
options: { |
| 7034 |
html: false, // Enable HTML tags in source |
| 7035 |
xhtmlOut: false, // Use '/' to close single tags (<br />) |
| 7036 |
breaks: false, // Convert '\n' in paragraphs into <br> |
| 7037 |
langPrefix: 'language-', // CSS language prefix for fenced blocks |
| 7038 |
linkTarget: '', // set target to open link in |
| 7039 |
|
| 7040 |
// Enable some language-neutral replacements + quotes beautification |
| 7041 |
typographer: false, |
| 7042 |
|
| 7043 |
// Double + single quotes replacement pairs, when typographer enabled, |
| 7044 |
// and smartquotes on. Set doubles to '«»' for Russian, '„“' for German. |
| 7045 |
quotes: '“”‘’', |
| 7046 |
|
| 7047 |
// Highlighter function. Should return escaped HTML, |
| 7048 |
// or '' if input not changed |
| 7049 |
// |
| 7050 |
// function (/*str, lang*/) { return ''; } |
| 7051 |
// |
| 7052 |
highlight: null, |
| 7053 |
|
| 7054 |
maxNesting: 20 // Internal protection, recursion limit |
| 7055 |
}, |
| 7056 |
|
| 7057 |
components: { |
| 7058 |
// Don't restrict core/block/inline rules |
| 7059 |
core: {}, |
| 7060 |
block: {}, |
| 7061 |
inline: {} |
| 7062 |
} |
| 7063 |
}; |
| 7064 |
|
| 7065 |
// Commonmark default options |
| 7066 |
|
| 7067 |
var commonmarkConfig = { |
| 7068 |
options: { |
| 7069 |
html: true, // Enable HTML tags in source |
| 7070 |
xhtmlOut: true, // Use '/' to close single tags (<br />) |
| 7071 |
breaks: false, // Convert '\n' in paragraphs into <br> |
| 7072 |
langPrefix: 'language-', // CSS language prefix for fenced blocks |
| 7073 |
linkTarget: '', // set target to open link in |
| 7074 |
|
| 7075 |
// Enable some language-neutral replacements + quotes beautification |
| 7076 |
typographer: false, |
| 7077 |
|
| 7078 |
// Double + single quotes replacement pairs, when typographer enabled, |
| 7079 |
// and smartquotes on. Set doubles to '«»' for Russian, '„“' for German. |
| 7080 |
quotes: '“”‘’', |
| 7081 |
|
| 7082 |
// Highlighter function. Should return escaped HTML, |
| 7083 |
// or '' if input not changed |
| 7084 |
// |
| 7085 |
// function (/*str, lang*/) { return ''; } |
| 7086 |
// |
| 7087 |
highlight: null, |
| 7088 |
|
| 7089 |
maxNesting: 20 // Internal protection, recursion limit |
| 7090 |
}, |
| 7091 |
|
| 7092 |
components: { |
| 7093 |
|
| 7094 |
core: { |
| 7095 |
rules: [ |
| 7096 |
'block', |
| 7097 |
'inline', |
| 7098 |
'references', |
| 7099 |
'abbr2' |
| 7100 |
] |
| 7101 |
}, |
| 7102 |
|
| 7103 |
block: { |
| 7104 |
rules: [ |
| 7105 |
'blockquote', |
| 7106 |
'code', |
| 7107 |
'fences', |
| 7108 |
'heading', |
| 7109 |
'hr', |
| 7110 |
'htmlblock', |
| 7111 |
'lheading', |
| 7112 |
'list', |
| 7113 |
'paragraph' |
| 7114 |
] |
| 7115 |
}, |
| 7116 |
|
| 7117 |
inline: { |
| 7118 |
rules: [ |
| 7119 |
'autolink', |
| 7120 |
'backticks', |
| 7121 |
'emphasis', |
| 7122 |
'entity', |
| 7123 |
'escape', |
| 7124 |
'htmltag', |
| 7125 |
'links', |
| 7126 |
'newline', |
| 7127 |
'text' |
| 7128 |
] |
| 7129 |
} |
| 7130 |
} |
| 7131 |
}; |
| 7132 |
|
| 7133 |
/** |
| 7134 |
* Preset configs |
| 7135 |
*/ |
| 7136 |
|
| 7137 |
var config = { |
| 7138 |
'default': defaultConfig, |
| 7139 |
'full': fullConfig, |
| 7140 |
'commonmark': commonmarkConfig |
| 7141 |
}; |
| 7142 |
|
| 7143 |
/** |
| 7144 |
* The `StateCore` class manages state. |
| 7145 |
* |
| 7146 |
* @param {Object} `instance` Remarkable instance |
| 7147 |
* @param {String} `str` Markdown string |
| 7148 |
* @param {Object} `env` |
| 7149 |
*/ |
| 7150 |
|
| 7151 |
function StateCore(instance, str, env) { |
| 7152 |
this.src = str; |
| 7153 |
this.env = env; |
| 7154 |
this.options = instance.options; |
| 7155 |
this.tokens = []; |
| 7156 |
this.inlineMode = false; |
| 7157 |
|
| 7158 |
this.inline = instance.inline; |
| 7159 |
this.block = instance.block; |
| 7160 |
this.renderer = instance.renderer; |
| 7161 |
this.typographer = instance.typographer; |
| 7162 |
} |
| 7163 |
|
| 7164 |
/** |
| 7165 |
* The main `Remarkable` class. Create an instance of |
| 7166 |
* `Remarkable` with a `preset` and/or `options`. |
| 7167 |
* |
| 7168 |
* @param {String} `preset` If no preset is given, `default` is used. |
| 7169 |
* @param {Object} `options` |
| 7170 |
*/ |
| 7171 |
|
| 7172 |
function Remarkable(preset, options) { |
| 7173 |
if (typeof preset !== 'string') { |
| 7174 |
options = preset; |
| 7175 |
preset = 'default'; |
| 7176 |
} |
| 7177 |
|
| 7178 |
if (options && options.linkify != null) { |
| 7179 |
console.warn( |
| 7180 |
'linkify option is removed. Use linkify plugin instead:\n\n' + |
| 7181 |
'import Remarkable from \'remarkable\';\n' + |
| 7182 |
'import linkify from \'remarkable/linkify\';\n' + |
| 7183 |
'new Remarkable().use(linkify)\n' |
| 7184 |
); |
| 7185 |
} |
| 7186 |
|
| 7187 |
this.inline = new ParserInline(); |
| 7188 |
this.block = new ParserBlock(); |
| 7189 |
this.core = new Core(); |
| 7190 |
this.renderer = new Renderer(); |
| 7191 |
this.ruler = new Ruler(); |
| 7192 |
|
| 7193 |
this.options = {}; |
| 7194 |
this.configure(config[preset]); |
| 7195 |
this.set(options || {}); |
| 7196 |
} |
| 7197 |
|
| 7198 |
/** |
| 7199 |
* Set options as an alternative to passing them |
| 7200 |
* to the constructor. |
| 7201 |
* |
| 7202 |
* ```js |
| 7203 |
* md.set({typographer: true}); |
| 7204 |
* ``` |
| 7205 |
* @param {Object} `options` |
| 7206 |
* @api public |
| 7207 |
*/ |
| 7208 |
|
| 7209 |
Remarkable.prototype.set = function (options) { |
| 7210 |
assign(this.options, options); |
| 7211 |
}; |
| 7212 |
|
| 7213 |
/** |
| 7214 |
* Batch loader for components rules states, and options |
| 7215 |
* |
| 7216 |
* @param {Object} `presets` |
| 7217 |
*/ |
| 7218 |
|
| 7219 |
Remarkable.prototype.configure = function (presets) { |
| 7220 |
var self = this; |
| 7221 |
|
| 7222 |
if (!presets) { throw new Error('Wrong `remarkable` preset, check name/content'); } |
| 7223 |
if (presets.options) { self.set(presets.options); } |
| 7224 |
if (presets.components) { |
| 7225 |
Object.keys(presets.components).forEach(function (name) { |
| 7226 |
if (presets.components[name].rules) { |
| 7227 |
self[name].ruler.enable(presets.components[name].rules, true); |
| 7228 |
} |
| 7229 |
}); |
| 7230 |
} |
| 7231 |
}; |
| 7232 |
|
| 7233 |
/** |
| 7234 |
* Use a plugin. |
| 7235 |
* |
| 7236 |
* ```js |
| 7237 |
* var md = new Remarkable(); |
| 7238 |
* |
| 7239 |
* md.use(plugin1) |
| 7240 |
* .use(plugin2, opts) |
| 7241 |
* .use(plugin3); |
| 7242 |
* ``` |
| 7243 |
* |
| 7244 |
* @param {Function} `plugin` |
| 7245 |
* @param {Object} `options` |
| 7246 |
* @return {Object} `Remarkable` for chaining |
| 7247 |
*/ |
| 7248 |
|
| 7249 |
Remarkable.prototype.use = function (plugin, options) { |
| 7250 |
plugin(this, options); |
| 7251 |
return this; |
| 7252 |
}; |
| 7253 |
|
| 7254 |
|
| 7255 |
/** |
| 7256 |
* Parse the input `string` and return a tokens array. |
| 7257 |
* Modifies `env` with definitions data. |
| 7258 |
* |
| 7259 |
* @param {String} `string` |
| 7260 |
* @param {Object} `env` |
| 7261 |
* @return {Array} Array of tokens |
| 7262 |
*/ |
| 7263 |
|
| 7264 |
Remarkable.prototype.parse = function (str, env) { |
| 7265 |
var state = new StateCore(this, str, env); |
| 7266 |
this.core.process(state); |
| 7267 |
return state.tokens; |
| 7268 |
}; |
| 7269 |
|
| 7270 |
/** |
| 7271 |
* The main `.render()` method that does all the magic :) |
| 7272 |
* |
| 7273 |
* @param {String} `string` |
| 7274 |
* @param {Object} `env` |
| 7275 |
* @return {String} Rendered HTML. |
| 7276 |
*/ |
| 7277 |
|
| 7278 |
Remarkable.prototype.render = function (str, env) { |
| 7279 |
env = env || {}; |
| 7280 |
return this.renderer.render(this.parse(str, env), this.options, env); |
| 7281 |
}; |
| 7282 |
|
| 7283 |
/** |
| 7284 |
* Parse the given content `string` as a single string. |
| 7285 |
* |
| 7286 |
* @param {String} `string` |
| 7287 |
* @param {Object} `env` |
| 7288 |
* @return {Array} Array of tokens |
| 7289 |
*/ |
| 7290 |
|
| 7291 |
Remarkable.prototype.parseInline = function (str, env) { |
| 7292 |
var state = new StateCore(this, str, env); |
| 7293 |
state.inlineMode = true; |
| 7294 |
this.core.process(state); |
| 7295 |
return state.tokens; |
| 7296 |
}; |
| 7297 |
|
| 7298 |
/** |
| 7299 |
* Render a single content `string`, without wrapping it |
| 7300 |
* to paragraphs |
| 7301 |
* |
| 7302 |
* @param {String} `str` |
| 7303 |
* @param {Object} `env` |
| 7304 |
* @return {String} |
| 7305 |
*/ |
| 7306 |
|
| 7307 |
Remarkable.prototype.renderInline = function (str, env) { |
| 7308 |
env = env || {}; |
| 7309 |
return this.renderer.render(this.parseInline(str, env), this.options, env); |
| 7310 |
}; |
| 7311 |
|
| 7312 |
/** |
| 7313 |
* Assigns (shallow copies) the properties of `src` onto `dest`, if the |
| 7314 |
* corresponding property on `dest` === `undefined`. |
| 7315 |
* |
| 7316 |
* @param {Object} dest The destination object. |
| 7317 |
* @param {Object} src The source object. |
| 7318 |
* @return {Object} The destination object (`dest`) |
| 7319 |
*/ |
| 7320 |
function defaults(dest, src) { |
| 7321 |
for (var prop in src) { |
| 7322 |
if (src.hasOwnProperty(prop) && dest[prop] === undefined) { |
| 7323 |
dest[prop] = src[prop]; |
| 7324 |
} |
| 7325 |
} |
| 7326 |
return dest; |
| 7327 |
} |
| 7328 |
/** |
| 7329 |
* Truncates the `str` at `len - ellipsisChars.length`, and adds the `ellipsisChars` to the |
| 7330 |
* end of the string (by default, two periods: '..'). If the `str` length does not exceed |
| 7331 |
* `len`, the string will be returned unchanged. |
| 7332 |
* |
| 7333 |
* @param {String} str The string to truncate and add an ellipsis to. |
| 7334 |
* @param {Number} truncateLen The length to truncate the string at. |
| 7335 |
* @param {String} [ellipsisChars=...] The ellipsis character(s) to add to the end of `str` |
| 7336 |
* when truncated. Defaults to '...' |
| 7337 |
*/ |
| 7338 |
function ellipsis(str, truncateLen, ellipsisChars) { |
| 7339 |
var ellipsisLength; |
| 7340 |
if (str.length > truncateLen) { |
| 7341 |
if (ellipsisChars == null) { |
| 7342 |
ellipsisChars = '…'; |
| 7343 |
ellipsisLength = 3; |
| 7344 |
} |
| 7345 |
else { |
| 7346 |
ellipsisLength = ellipsisChars.length; |
| 7347 |
} |
| 7348 |
str = str.substring(0, truncateLen - ellipsisLength) + ellipsisChars; |
| 7349 |
} |
| 7350 |
return str; |
| 7351 |
} |
| 7352 |
/** |
| 7353 |
* Supports `Array.prototype.indexOf()` functionality for old IE (IE8 and below). |
| 7354 |
* |
| 7355 |
* @param {Array} arr The array to find an element of. |
| 7356 |
* @param {*} element The element to find in the array, and return the index of. |
| 7357 |
* @return {Number} The index of the `element`, or -1 if it was not found. |
| 7358 |
*/ |
| 7359 |
function indexOf(arr, element) { |
| 7360 |
if (Array.prototype.indexOf) { |
| 7361 |
return arr.indexOf(element); |
| 7362 |
} |
| 7363 |
else { |
| 7364 |
for (var i = 0, len = arr.length; i < len; i++) { |
| 7365 |
if (arr[i] === element) |
| 7366 |
return i; |
| 7367 |
} |
| 7368 |
return -1; |
| 7369 |
} |
| 7370 |
} |
| 7371 |
/** |
| 7372 |
* Removes array elements based on a filtering function. Mutates the input |
| 7373 |
* array. |
| 7374 |
* |
| 7375 |
* Using this instead of the ES5 Array.prototype.filter() function, to allow |
| 7376 |
* Autolinker compatibility with IE8, and also to prevent creating many new |
| 7377 |
* arrays in memory for filtering. |
| 7378 |
* |
| 7379 |
* @param {Array} arr The array to remove elements from. This array is |
| 7380 |
* mutated. |
| 7381 |
* @param {Function} fn A function which should return `true` to |
| 7382 |
* remove an element. |
| 7383 |
* @return {Array} The mutated input `arr`. |
| 7384 |
*/ |
| 7385 |
function remove(arr, fn) { |
| 7386 |
for (var i = arr.length - 1; i >= 0; i--) { |
| 7387 |
if (fn(arr[i]) === true) { |
| 7388 |
arr.splice(i, 1); |
| 7389 |
} |
| 7390 |
} |
| 7391 |
} |
| 7392 |
/** |
| 7393 |
* Performs the functionality of what modern browsers do when `String.prototype.split()` is called |
| 7394 |
* with a regular expression that contains capturing parenthesis. |
| 7395 |
* |
| 7396 |
* For example: |
| 7397 |
* |
| 7398 |
* // Modern browsers: |
| 7399 |
* "a,b,c".split( /(,)/ ); // --> [ 'a', ',', 'b', ',', 'c' ] |
| 7400 |
* |
| 7401 |
* // Old IE (including IE8): |
| 7402 |
* "a,b,c".split( /(,)/ ); // --> [ 'a', 'b', 'c' ] |
| 7403 |
* |
| 7404 |
* This method emulates the functionality of modern browsers for the old IE case. |
| 7405 |
* |
| 7406 |
* @param {String} str The string to split. |
| 7407 |
* @param {RegExp} splitRegex The regular expression to split the input `str` on. The splitting |
| 7408 |
* character(s) will be spliced into the array, as in the "modern browsers" example in the |
| 7409 |
* description of this method. |
| 7410 |
* Note #1: the supplied regular expression **must** have the 'g' flag specified. |
| 7411 |
* Note #2: for simplicity's sake, the regular expression does not need |
| 7412 |
* to contain capturing parenthesis - it will be assumed that any match has them. |
| 7413 |
* @return {String[]} The split array of strings, with the splitting character(s) included. |
| 7414 |
*/ |
| 7415 |
function splitAndCapture(str, splitRegex) { |
| 7416 |
if (!splitRegex.global) |
| 7417 |
throw new Error("`splitRegex` must have the 'g' flag set"); |
| 7418 |
var result = [], lastIdx = 0, match; |
| 7419 |
while (match = splitRegex.exec(str)) { |
| 7420 |
result.push(str.substring(lastIdx, match.index)); |
| 7421 |
result.push(match[0]); // push the splitting char(s) |
| 7422 |
lastIdx = match.index + match[0].length; |
| 7423 |
} |
| 7424 |
result.push(str.substring(lastIdx)); |
| 7425 |
return result; |
| 7426 |
} |
| 7427 |
/** |
| 7428 |
* Function that should never be called but is used to check that every |
| 7429 |
* enum value is handled using TypeScript's 'never' type. |
| 7430 |
*/ |
| 7431 |
function throwUnhandledCaseError(theValue) { |
| 7432 |
throw new Error("Unhandled case for value: '" + theValue + "'"); |
| 7433 |
} |
| 7434 |
|
| 7435 |
/** |
| 7436 |
* @class Autolinker.HtmlTag |
| 7437 |
* @extends Object |
| 7438 |
* |
| 7439 |
* Represents an HTML tag, which can be used to easily build/modify HTML tags programmatically. |
| 7440 |
* |
| 7441 |
* Autolinker uses this abstraction to create HTML tags, and then write them out as strings. You may also use |
| 7442 |
* this class in your code, especially within a {@link Autolinker#replaceFn replaceFn}. |
| 7443 |
* |
| 7444 |
* ## Examples |
| 7445 |
* |
| 7446 |
* Example instantiation: |
| 7447 |
* |
| 7448 |
* var tag = new Autolinker.HtmlTag( { |
| 7449 |
* tagName : 'a', |
| 7450 |
* attrs : { 'href': 'http://google.com', 'class': 'external-link' }, |
| 7451 |
* innerHtml : 'Google' |
| 7452 |
* } ); |
| 7453 |
* |
| 7454 |
* tag.toAnchorString(); // <a href="http://google.com" class="external-link">Google</a> |
| 7455 |
* |
| 7456 |
* // Individual accessor methods |
| 7457 |
* tag.getTagName(); // 'a' |
| 7458 |
* tag.getAttr( 'href' ); // 'http://google.com' |
| 7459 |
* tag.hasClass( 'external-link' ); // true |
| 7460 |
* |
| 7461 |
* |
| 7462 |
* Using mutator methods (which may be used in combination with instantiation config properties): |
| 7463 |
* |
| 7464 |
* var tag = new Autolinker.HtmlTag(); |
| 7465 |
* tag.setTagName( 'a' ); |
| 7466 |
* tag.setAttr( 'href', 'http://google.com' ); |
| 7467 |
* tag.addClass( 'external-link' ); |
| 7468 |
* tag.setInnerHtml( 'Google' ); |
| 7469 |
* |
| 7470 |
* tag.getTagName(); // 'a' |
| 7471 |
* tag.getAttr( 'href' ); // 'http://google.com' |
| 7472 |
* tag.hasClass( 'external-link' ); // true |
| 7473 |
* |
| 7474 |
* tag.toAnchorString(); // <a href="http://google.com" class="external-link">Google</a> |
| 7475 |
* |
| 7476 |
* |
| 7477 |
* ## Example use within a {@link Autolinker#replaceFn replaceFn} |
| 7478 |
* |
| 7479 |
* var html = Autolinker.link( "Test google.com", { |
| 7480 |
* replaceFn : function( match ) { |
| 7481 |
* var tag = match.buildTag(); // returns an {@link Autolinker.HtmlTag} instance, configured with the Match's href and anchor text |
| 7482 |
* tag.setAttr( 'rel', 'nofollow' ); |
| 7483 |
* |
| 7484 |
* return tag; |
| 7485 |
* } |
| 7486 |
* } ); |
| 7487 |
* |
| 7488 |
* // generated html: |
| 7489 |
* // Test <a href="http://google.com" target="_blank" rel="nofollow">google.com</a> |
| 7490 |
* |
| 7491 |
* |
| 7492 |
* ## Example use with a new tag for the replacement |
| 7493 |
* |
| 7494 |
* var html = Autolinker.link( "Test google.com", { |
| 7495 |
* replaceFn : function( match ) { |
| 7496 |
* var tag = new Autolinker.HtmlTag( { |
| 7497 |
* tagName : 'button', |
| 7498 |
* attrs : { 'title': 'Load URL: ' + match.getAnchorHref() }, |
| 7499 |
* innerHtml : 'Load URL: ' + match.getAnchorText() |
| 7500 |
* } ); |
| 7501 |
* |
| 7502 |
* return tag; |
| 7503 |
* } |
| 7504 |
* } ); |
| 7505 |
* |
| 7506 |
* // generated html: |
| 7507 |
* // Test <button title="Load URL: http://google.com">Load URL: google.com</button> |
| 7508 |
*/ |
| 7509 |
var HtmlTag = /** @class */ (function () { |
| 7510 |
/** |
| 7511 |
* @method constructor |
| 7512 |
* @param {Object} [cfg] The configuration properties for this class, in an Object (map) |
| 7513 |
*/ |
| 7514 |
function HtmlTag(cfg) { |
| 7515 |
if (cfg === void 0) { cfg = {}; } |
| 7516 |
/** |
| 7517 |
* @cfg {String} tagName |
| 7518 |
* |
| 7519 |
* The tag name. Ex: 'a', 'button', etc. |
| 7520 |
* |
| 7521 |
* Not required at instantiation time, but should be set using {@link #setTagName} before {@link #toAnchorString} |
| 7522 |
* is executed. |
| 7523 |
*/ |
| 7524 |
this.tagName = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 7525 |
/** |
| 7526 |
* @cfg {Object.<String, String>} attrs |
| 7527 |
* |
| 7528 |
* An key/value Object (map) of attributes to create the tag with. The keys are the attribute names, and the |
| 7529 |
* values are the attribute values. |
| 7530 |
*/ |
| 7531 |
this.attrs = {}; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 7532 |
/** |
| 7533 |
* @cfg {String} innerHTML |
| 7534 |
* |
| 7535 |
* The inner HTML for the tag. |
| 7536 |
*/ |
| 7537 |
this.innerHTML = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 7538 |
/** |
| 7539 |
* @protected |
| 7540 |
* @property {RegExp} whitespaceRegex |
| 7541 |
* |
| 7542 |
* Regular expression used to match whitespace in a string of CSS classes. |
| 7543 |
*/ |
| 7544 |
this.whitespaceRegex = /\s+/; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 7545 |
this.tagName = cfg.tagName || ''; |
| 7546 |
this.attrs = cfg.attrs || {}; |
| 7547 |
this.innerHTML = cfg.innerHtml || cfg.innerHTML || ''; // accept either the camelCased form or the fully capitalized acronym as in the DOM |
| 7548 |
} |
| 7549 |
/** |
| 7550 |
* Sets the tag name that will be used to generate the tag with. |
| 7551 |
* |
| 7552 |
* @param {String} tagName |
| 7553 |
* @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. |
| 7554 |
*/ |
| 7555 |
HtmlTag.prototype.setTagName = function (tagName) { |
| 7556 |
this.tagName = tagName; |
| 7557 |
return this; |
| 7558 |
}; |
| 7559 |
/** |
| 7560 |
* Retrieves the tag name. |
| 7561 |
* |
| 7562 |
* @return {String} |
| 7563 |
*/ |
| 7564 |
HtmlTag.prototype.getTagName = function () { |
| 7565 |
return this.tagName || ''; |
| 7566 |
}; |
| 7567 |
/** |
| 7568 |
* Sets an attribute on the HtmlTag. |
| 7569 |
* |
| 7570 |
* @param {String} attrName The attribute name to set. |
| 7571 |
* @param {String} attrValue The attribute value to set. |
| 7572 |
* @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. |
| 7573 |
*/ |
| 7574 |
HtmlTag.prototype.setAttr = function (attrName, attrValue) { |
| 7575 |
var tagAttrs = this.getAttrs(); |
| 7576 |
tagAttrs[attrName] = attrValue; |
| 7577 |
return this; |
| 7578 |
}; |
| 7579 |
/** |
| 7580 |
* Retrieves an attribute from the HtmlTag. If the attribute does not exist, returns `undefined`. |
| 7581 |
* |
| 7582 |
* @param {String} attrName The attribute name to retrieve. |
| 7583 |
* @return {String} The attribute's value, or `undefined` if it does not exist on the HtmlTag. |
| 7584 |
*/ |
| 7585 |
HtmlTag.prototype.getAttr = function (attrName) { |
| 7586 |
return this.getAttrs()[attrName]; |
| 7587 |
}; |
| 7588 |
/** |
| 7589 |
* Sets one or more attributes on the HtmlTag. |
| 7590 |
* |
| 7591 |
* @param {Object.<String, String>} attrs A key/value Object (map) of the attributes to set. |
| 7592 |
* @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. |
| 7593 |
*/ |
| 7594 |
HtmlTag.prototype.setAttrs = function (attrs) { |
| 7595 |
Object.assign(this.getAttrs(), attrs); |
| 7596 |
return this; |
| 7597 |
}; |
| 7598 |
/** |
| 7599 |
* Retrieves the attributes Object (map) for the HtmlTag. |
| 7600 |
* |
| 7601 |
* @return {Object.<String, String>} A key/value object of the attributes for the HtmlTag. |
| 7602 |
*/ |
| 7603 |
HtmlTag.prototype.getAttrs = function () { |
| 7604 |
return this.attrs || (this.attrs = {}); |
| 7605 |
}; |
| 7606 |
/** |
| 7607 |
* Sets the provided `cssClass`, overwriting any current CSS classes on the HtmlTag. |
| 7608 |
* |
| 7609 |
* @param {String} cssClass One or more space-separated CSS classes to set (overwrite). |
| 7610 |
* @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. |
| 7611 |
*/ |
| 7612 |
HtmlTag.prototype.setClass = function (cssClass) { |
| 7613 |
return this.setAttr('class', cssClass); |
| 7614 |
}; |
| 7615 |
/** |
| 7616 |
* Convenience method to add one or more CSS classes to the HtmlTag. Will not add duplicate CSS classes. |
| 7617 |
* |
| 7618 |
* @param {String} cssClass One or more space-separated CSS classes to add. |
| 7619 |
* @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. |
| 7620 |
*/ |
| 7621 |
HtmlTag.prototype.addClass = function (cssClass) { |
| 7622 |
var classAttr = this.getClass(), whitespaceRegex = this.whitespaceRegex, classes = (!classAttr) ? [] : classAttr.split(whitespaceRegex), newClasses = cssClass.split(whitespaceRegex), newClass; |
| 7623 |
while (newClass = newClasses.shift()) { |
| 7624 |
if (indexOf(classes, newClass) === -1) { |
| 7625 |
classes.push(newClass); |
| 7626 |
} |
| 7627 |
} |
| 7628 |
this.getAttrs()['class'] = classes.join(" "); |
| 7629 |
return this; |
| 7630 |
}; |
| 7631 |
/** |
| 7632 |
* Convenience method to remove one or more CSS classes from the HtmlTag. |
| 7633 |
* |
| 7634 |
* @param {String} cssClass One or more space-separated CSS classes to remove. |
| 7635 |
* @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. |
| 7636 |
*/ |
| 7637 |
HtmlTag.prototype.removeClass = function (cssClass) { |
| 7638 |
var classAttr = this.getClass(), whitespaceRegex = this.whitespaceRegex, classes = (!classAttr) ? [] : classAttr.split(whitespaceRegex), removeClasses = cssClass.split(whitespaceRegex), removeClass; |
| 7639 |
while (classes.length && (removeClass = removeClasses.shift())) { |
| 7640 |
var idx = indexOf(classes, removeClass); |
| 7641 |
if (idx !== -1) { |
| 7642 |
classes.splice(idx, 1); |
| 7643 |
} |
| 7644 |
} |
| 7645 |
this.getAttrs()['class'] = classes.join(" "); |
| 7646 |
return this; |
| 7647 |
}; |
| 7648 |
/** |
| 7649 |
* Convenience method to retrieve the CSS class(es) for the HtmlTag, which will each be separated by spaces when |
| 7650 |
* there are multiple. |
| 7651 |
* |
| 7652 |
* @return {String} |
| 7653 |
*/ |
| 7654 |
HtmlTag.prototype.getClass = function () { |
| 7655 |
return this.getAttrs()['class'] || ""; |
| 7656 |
}; |
| 7657 |
/** |
| 7658 |
* Convenience method to check if the tag has a CSS class or not. |
| 7659 |
* |
| 7660 |
* @param {String} cssClass The CSS class to check for. |
| 7661 |
* @return {Boolean} `true` if the HtmlTag has the CSS class, `false` otherwise. |
| 7662 |
*/ |
| 7663 |
HtmlTag.prototype.hasClass = function (cssClass) { |
| 7664 |
return (' ' + this.getClass() + ' ').indexOf(' ' + cssClass + ' ') !== -1; |
| 7665 |
}; |
| 7666 |
/** |
| 7667 |
* Sets the inner HTML for the tag. |
| 7668 |
* |
| 7669 |
* @param {String} html The inner HTML to set. |
| 7670 |
* @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. |
| 7671 |
*/ |
| 7672 |
HtmlTag.prototype.setInnerHTML = function (html) { |
| 7673 |
this.innerHTML = html; |
| 7674 |
return this; |
| 7675 |
}; |
| 7676 |
/** |
| 7677 |
* Backwards compatibility method name. |
| 7678 |
* |
| 7679 |
* @param {String} html The inner HTML to set. |
| 7680 |
* @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. |
| 7681 |
*/ |
| 7682 |
HtmlTag.prototype.setInnerHtml = function (html) { |
| 7683 |
return this.setInnerHTML(html); |
| 7684 |
}; |
| 7685 |
/** |
| 7686 |
* Retrieves the inner HTML for the tag. |
| 7687 |
* |
| 7688 |
* @return {String} |
| 7689 |
*/ |
| 7690 |
HtmlTag.prototype.getInnerHTML = function () { |
| 7691 |
return this.innerHTML || ""; |
| 7692 |
}; |
| 7693 |
/** |
| 7694 |
* Backward compatibility method name. |
| 7695 |
* |
| 7696 |
* @return {String} |
| 7697 |
*/ |
| 7698 |
HtmlTag.prototype.getInnerHtml = function () { |
| 7699 |
return this.getInnerHTML(); |
| 7700 |
}; |
| 7701 |
/** |
| 7702 |
* Override of superclass method used to generate the HTML string for the tag. |
| 7703 |
* |
| 7704 |
* @return {String} |
| 7705 |
*/ |
| 7706 |
HtmlTag.prototype.toAnchorString = function () { |
| 7707 |
var tagName = this.getTagName(), attrsStr = this.buildAttrsStr(); |
| 7708 |
attrsStr = (attrsStr) ? ' ' + attrsStr : ''; // prepend a space if there are actually attributes |
| 7709 |
return ['<', tagName, attrsStr, '>', this.getInnerHtml(), '</', tagName, '>'].join(""); |
| 7710 |
}; |
| 7711 |
/** |
| 7712 |
* Support method for {@link #toAnchorString}, returns the string space-separated key="value" pairs, used to populate |
| 7713 |
* the stringified HtmlTag. |
| 7714 |
* |
| 7715 |
* @protected |
| 7716 |
* @return {String} Example return: `attr1="value1" attr2="value2"` |
| 7717 |
*/ |
| 7718 |
HtmlTag.prototype.buildAttrsStr = function () { |
| 7719 |
if (!this.attrs) |
| 7720 |
return ""; // no `attrs` Object (map) has been set, return empty string |
| 7721 |
var attrs = this.getAttrs(), attrsArr = []; |
| 7722 |
for (var prop in attrs) { |
| 7723 |
if (attrs.hasOwnProperty(prop)) { |
| 7724 |
attrsArr.push(prop + '="' + attrs[prop] + '"'); |
| 7725 |
} |
| 7726 |
} |
| 7727 |
return attrsArr.join(" "); |
| 7728 |
}; |
| 7729 |
return HtmlTag; |
| 7730 |
}()); |
| 7731 |
|
| 7732 |
/** |
| 7733 |
* Date: 2015-10-05 |
| 7734 |
* Author: Kasper Søfren <[email protected]> (https://github.com/kafoso) |
| 7735 |
* |
| 7736 |
* A truncation feature, where the ellipsis will be placed at a section within |
| 7737 |
* the URL making it still somewhat human readable. |
| 7738 |
* |
| 7739 |
* @param {String} url A URL. |
| 7740 |
* @param {Number} truncateLen The maximum length of the truncated output URL string. |
| 7741 |
* @param {String} ellipsisChars The characters to place within the url, e.g. "...". |
| 7742 |
* @return {String} The truncated URL. |
| 7743 |
*/ |
| 7744 |
function truncateSmart(url, truncateLen, ellipsisChars) { |
| 7745 |
var ellipsisLengthBeforeParsing; |
| 7746 |
var ellipsisLength; |
| 7747 |
if (ellipsisChars == null) { |
| 7748 |
ellipsisChars = '…'; |
| 7749 |
ellipsisLength = 3; |
| 7750 |
ellipsisLengthBeforeParsing = 8; |
| 7751 |
} |
| 7752 |
else { |
| 7753 |
ellipsisLength = ellipsisChars.length; |
| 7754 |
ellipsisLengthBeforeParsing = ellipsisChars.length; |
| 7755 |
} |
| 7756 |
var parse_url = function (url) { |
| 7757 |
var urlObj = {}; |
| 7758 |
var urlSub = url; |
| 7759 |
var match = urlSub.match(/^([a-z]+):\/\//i); |
| 7760 |
if (match) { |
| 7761 |
urlObj.scheme = match[1]; |
| 7762 |
urlSub = urlSub.substr(match[0].length); |
| 7763 |
} |
| 7764 |
match = urlSub.match(/^(.*?)(?=(\?|#|\/|$))/i); |
| 7765 |
if (match) { |
| 7766 |
urlObj.host = match[1]; |
| 7767 |
urlSub = urlSub.substr(match[0].length); |
| 7768 |
} |
| 7769 |
match = urlSub.match(/^\/(.*?)(?=(\?|#|$))/i); |
| 7770 |
if (match) { |
| 7771 |
urlObj.path = match[1]; |
| 7772 |
urlSub = urlSub.substr(match[0].length); |
| 7773 |
} |
| 7774 |
match = urlSub.match(/^\?(.*?)(?=(#|$))/i); |
| 7775 |
if (match) { |
| 7776 |
urlObj.query = match[1]; |
| 7777 |
urlSub = urlSub.substr(match[0].length); |
| 7778 |
} |
| 7779 |
match = urlSub.match(/^#(.*?)$/i); |
| 7780 |
if (match) { |
| 7781 |
urlObj.fragment = match[1]; |
| 7782 |
//urlSub = urlSub.substr(match[0].length); -- not used. Uncomment if adding another block. |
| 7783 |
} |
| 7784 |
return urlObj; |
| 7785 |
}; |
| 7786 |
var buildUrl = function (urlObj) { |
| 7787 |
var url = ""; |
| 7788 |
if (urlObj.scheme && urlObj.host) { |
| 7789 |
url += urlObj.scheme + "://"; |
| 7790 |
} |
| 7791 |
if (urlObj.host) { |
| 7792 |
url += urlObj.host; |
| 7793 |
} |
| 7794 |
if (urlObj.path) { |
| 7795 |
url += "/" + urlObj.path; |
| 7796 |
} |
| 7797 |
if (urlObj.query) { |
| 7798 |
url += "?" + urlObj.query; |
| 7799 |
} |
| 7800 |
if (urlObj.fragment) { |
| 7801 |
url += "#" + urlObj.fragment; |
| 7802 |
} |
| 7803 |
return url; |
| 7804 |
}; |
| 7805 |
var buildSegment = function (segment, remainingAvailableLength) { |
| 7806 |
var remainingAvailableLengthHalf = remainingAvailableLength / 2, startOffset = Math.ceil(remainingAvailableLengthHalf), endOffset = (-1) * Math.floor(remainingAvailableLengthHalf), end = ""; |
| 7807 |
if (endOffset < 0) { |
| 7808 |
end = segment.substr(endOffset); |
| 7809 |
} |
| 7810 |
return segment.substr(0, startOffset) + ellipsisChars + end; |
| 7811 |
}; |
| 7812 |
if (url.length <= truncateLen) { |
| 7813 |
return url; |
| 7814 |
} |
| 7815 |
var availableLength = truncateLen - ellipsisLength; |
| 7816 |
var urlObj = parse_url(url); |
| 7817 |
// Clean up the URL |
| 7818 |
if (urlObj.query) { |
| 7819 |
var matchQuery = urlObj.query.match(/^(.*?)(?=(\?|\#))(.*?)$/i); |
| 7820 |
if (matchQuery) { |
| 7821 |
// Malformed URL; two or more "?". Removed any content behind the 2nd. |
| 7822 |
urlObj.query = urlObj.query.substr(0, matchQuery[1].length); |
| 7823 |
url = buildUrl(urlObj); |
| 7824 |
} |
| 7825 |
} |
| 7826 |
if (url.length <= truncateLen) { |
| 7827 |
return url; |
| 7828 |
} |
| 7829 |
if (urlObj.host) { |
| 7830 |
urlObj.host = urlObj.host.replace(/^www\./, ""); |
| 7831 |
url = buildUrl(urlObj); |
| 7832 |
} |
| 7833 |
if (url.length <= truncateLen) { |
| 7834 |
return url; |
| 7835 |
} |
| 7836 |
// Process and build the URL |
| 7837 |
var str = ""; |
| 7838 |
if (urlObj.host) { |
| 7839 |
str += urlObj.host; |
| 7840 |
} |
| 7841 |
if (str.length >= availableLength) { |
| 7842 |
if (urlObj.host.length == truncateLen) { |
| 7843 |
return (urlObj.host.substr(0, (truncateLen - ellipsisLength)) + ellipsisChars).substr(0, availableLength + ellipsisLengthBeforeParsing); |
| 7844 |
} |
| 7845 |
return buildSegment(str, availableLength).substr(0, availableLength + ellipsisLengthBeforeParsing); |
| 7846 |
} |
| 7847 |
var pathAndQuery = ""; |
| 7848 |
if (urlObj.path) { |
| 7849 |
pathAndQuery += "/" + urlObj.path; |
| 7850 |
} |
| 7851 |
if (urlObj.query) { |
| 7852 |
pathAndQuery += "?" + urlObj.query; |
| 7853 |
} |
| 7854 |
if (pathAndQuery) { |
| 7855 |
if ((str + pathAndQuery).length >= availableLength) { |
| 7856 |
if ((str + pathAndQuery).length == truncateLen) { |
| 7857 |
return (str + pathAndQuery).substr(0, truncateLen); |
| 7858 |
} |
| 7859 |
var remainingAvailableLength = availableLength - str.length; |
| 7860 |
return (str + buildSegment(pathAndQuery, remainingAvailableLength)).substr(0, availableLength + ellipsisLengthBeforeParsing); |
| 7861 |
} |
| 7862 |
else { |
| 7863 |
str += pathAndQuery; |
| 7864 |
} |
| 7865 |
} |
| 7866 |
if (urlObj.fragment) { |
| 7867 |
var fragment = "#" + urlObj.fragment; |
| 7868 |
if ((str + fragment).length >= availableLength) { |
| 7869 |
if ((str + fragment).length == truncateLen) { |
| 7870 |
return (str + fragment).substr(0, truncateLen); |
| 7871 |
} |
| 7872 |
var remainingAvailableLength2 = availableLength - str.length; |
| 7873 |
return (str + buildSegment(fragment, remainingAvailableLength2)).substr(0, availableLength + ellipsisLengthBeforeParsing); |
| 7874 |
} |
| 7875 |
else { |
| 7876 |
str += fragment; |
| 7877 |
} |
| 7878 |
} |
| 7879 |
if (urlObj.scheme && urlObj.host) { |
| 7880 |
var scheme = urlObj.scheme + "://"; |
| 7881 |
if ((str + scheme).length < availableLength) { |
| 7882 |
return (scheme + str).substr(0, truncateLen); |
| 7883 |
} |
| 7884 |
} |
| 7885 |
if (str.length <= truncateLen) { |
| 7886 |
return str; |
| 7887 |
} |
| 7888 |
var end = ""; |
| 7889 |
if (availableLength > 0) { |
| 7890 |
end = str.substr((-1) * Math.floor(availableLength / 2)); |
| 7891 |
} |
| 7892 |
return (str.substr(0, Math.ceil(availableLength / 2)) + ellipsisChars + end).substr(0, availableLength + ellipsisLengthBeforeParsing); |
| 7893 |
} |
| 7894 |
|
| 7895 |
/** |
| 7896 |
* Date: 2015-10-05 |
| 7897 |
* Author: Kasper Søfren <[email protected]> (https://github.com/kafoso) |
| 7898 |
* |
| 7899 |
* A truncation feature, where the ellipsis will be placed in the dead-center of the URL. |
| 7900 |
* |
| 7901 |
* @param {String} url A URL. |
| 7902 |
* @param {Number} truncateLen The maximum length of the truncated output URL string. |
| 7903 |
* @param {String} ellipsisChars The characters to place within the url, e.g. "..". |
| 7904 |
* @return {String} The truncated URL. |
| 7905 |
*/ |
| 7906 |
function truncateMiddle(url, truncateLen, ellipsisChars) { |
| 7907 |
if (url.length <= truncateLen) { |
| 7908 |
return url; |
| 7909 |
} |
| 7910 |
var ellipsisLengthBeforeParsing; |
| 7911 |
var ellipsisLength; |
| 7912 |
if (ellipsisChars == null) { |
| 7913 |
ellipsisChars = '…'; |
| 7914 |
ellipsisLengthBeforeParsing = 8; |
| 7915 |
ellipsisLength = 3; |
| 7916 |
} |
| 7917 |
else { |
| 7918 |
ellipsisLengthBeforeParsing = ellipsisChars.length; |
| 7919 |
ellipsisLength = ellipsisChars.length; |
| 7920 |
} |
| 7921 |
var availableLength = truncateLen - ellipsisLength; |
| 7922 |
var end = ""; |
| 7923 |
if (availableLength > 0) { |
| 7924 |
end = url.substr((-1) * Math.floor(availableLength / 2)); |
| 7925 |
} |
| 7926 |
return (url.substr(0, Math.ceil(availableLength / 2)) + ellipsisChars + end).substr(0, availableLength + ellipsisLengthBeforeParsing); |
| 7927 |
} |
| 7928 |
|
| 7929 |
/** |
| 7930 |
* A truncation feature where the ellipsis will be placed at the end of the URL. |
| 7931 |
* |
| 7932 |
* @param {String} anchorText |
| 7933 |
* @param {Number} truncateLen The maximum length of the truncated output URL string. |
| 7934 |
* @param {String} ellipsisChars The characters to place within the url, e.g. "..". |
| 7935 |
* @return {String} The truncated URL. |
| 7936 |
*/ |
| 7937 |
function truncateEnd(anchorText, truncateLen, ellipsisChars) { |
| 7938 |
return ellipsis(anchorText, truncateLen, ellipsisChars); |
| 7939 |
} |
| 7940 |
|
| 7941 |
/** |
| 7942 |
* @protected |
| 7943 |
* @class Autolinker.AnchorTagBuilder |
| 7944 |
* @extends Object |
| 7945 |
* |
| 7946 |
* Builds anchor (<a>) tags for the Autolinker utility when a match is |
| 7947 |
* found. |
| 7948 |
* |
| 7949 |
* Normally this class is instantiated, configured, and used internally by an |
| 7950 |
* {@link Autolinker} instance, but may actually be used indirectly in a |
| 7951 |
* {@link Autolinker#replaceFn replaceFn} to create {@link Autolinker.HtmlTag HtmlTag} |
| 7952 |
* instances which may be modified before returning from the |
| 7953 |
* {@link Autolinker#replaceFn replaceFn}. For example: |
| 7954 |
* |
| 7955 |
* var html = Autolinker.link( "Test google.com", { |
| 7956 |
* replaceFn : function( match ) { |
| 7957 |
* var tag = match.buildTag(); // returns an {@link Autolinker.HtmlTag} instance |
| 7958 |
* tag.setAttr( 'rel', 'nofollow' ); |
| 7959 |
* |
| 7960 |
* return tag; |
| 7961 |
* } |
| 7962 |
* } ); |
| 7963 |
* |
| 7964 |
* // generated html: |
| 7965 |
* // Test <a href="http://google.com" target="_blank" rel="nofollow">google.com</a> |
| 7966 |
*/ |
| 7967 |
var AnchorTagBuilder = /** @class */ (function () { |
| 7968 |
/** |
| 7969 |
* @method constructor |
| 7970 |
* @param {Object} [cfg] The configuration options for the AnchorTagBuilder instance, specified in an Object (map). |
| 7971 |
*/ |
| 7972 |
function AnchorTagBuilder(cfg) { |
| 7973 |
if (cfg === void 0) { cfg = {}; } |
| 7974 |
/** |
| 7975 |
* @cfg {Boolean} newWindow |
| 7976 |
* @inheritdoc Autolinker#newWindow |
| 7977 |
*/ |
| 7978 |
this.newWindow = false; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 7979 |
/** |
| 7980 |
* @cfg {Object} truncate |
| 7981 |
* @inheritdoc Autolinker#truncate |
| 7982 |
*/ |
| 7983 |
this.truncate = {}; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 7984 |
/** |
| 7985 |
* @cfg {String} className |
| 7986 |
* @inheritdoc Autolinker#className |
| 7987 |
*/ |
| 7988 |
this.className = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 7989 |
this.newWindow = cfg.newWindow || false; |
| 7990 |
this.truncate = cfg.truncate || {}; |
| 7991 |
this.className = cfg.className || ''; |
| 7992 |
} |
| 7993 |
/** |
| 7994 |
* Generates the actual anchor (<a>) tag to use in place of the |
| 7995 |
* matched text, via its `match` object. |
| 7996 |
* |
| 7997 |
* @param {Autolinker.match.Match} match The Match instance to generate an |
| 7998 |
* anchor tag from. |
| 7999 |
* @return {Autolinker.HtmlTag} The HtmlTag instance for the anchor tag. |
| 8000 |
*/ |
| 8001 |
AnchorTagBuilder.prototype.build = function (match) { |
| 8002 |
return new HtmlTag({ |
| 8003 |
tagName: 'a', |
| 8004 |
attrs: this.createAttrs(match), |
| 8005 |
innerHtml: this.processAnchorText(match.getAnchorText()) |
| 8006 |
}); |
| 8007 |
}; |
| 8008 |
/** |
| 8009 |
* Creates the Object (map) of the HTML attributes for the anchor (<a>) |
| 8010 |
* tag being generated. |
| 8011 |
* |
| 8012 |
* @protected |
| 8013 |
* @param {Autolinker.match.Match} match The Match instance to generate an |
| 8014 |
* anchor tag from. |
| 8015 |
* @return {Object} A key/value Object (map) of the anchor tag's attributes. |
| 8016 |
*/ |
| 8017 |
AnchorTagBuilder.prototype.createAttrs = function (match) { |
| 8018 |
var attrs = { |
| 8019 |
'href': match.getAnchorHref() // we'll always have the `href` attribute |
| 8020 |
}; |
| 8021 |
var cssClass = this.createCssClass(match); |
| 8022 |
if (cssClass) { |
| 8023 |
attrs['class'] = cssClass; |
| 8024 |
} |
| 8025 |
if (this.newWindow) { |
| 8026 |
attrs['target'] = "_blank"; |
| 8027 |
attrs['rel'] = "noopener noreferrer"; // Issue #149. See https://mathiasbynens.github.io/rel-noopener/ |
| 8028 |
} |
| 8029 |
if (this.truncate) { |
| 8030 |
if (this.truncate.length && this.truncate.length < match.getAnchorText().length) { |
| 8031 |
attrs['title'] = match.getAnchorHref(); |
| 8032 |
} |
| 8033 |
} |
| 8034 |
return attrs; |
| 8035 |
}; |
| 8036 |
/** |
| 8037 |
* Creates the CSS class that will be used for a given anchor tag, based on |
| 8038 |
* the `matchType` and the {@link #className} config. |
| 8039 |
* |
| 8040 |
* Example returns: |
| 8041 |
* |
| 8042 |
* - "" // no {@link #className} |
| 8043 |
* - "myLink myLink-url" // url match |
| 8044 |
* - "myLink myLink-email" // email match |
| 8045 |
* - "myLink myLink-phone" // phone match |
| 8046 |
* - "myLink myLink-hashtag" // hashtag match |
| 8047 |
* - "myLink myLink-mention myLink-twitter" // mention match with Twitter service |
| 8048 |
* |
| 8049 |
* @protected |
| 8050 |
* @param {Autolinker.match.Match} match The Match instance to generate an |
| 8051 |
* anchor tag from. |
| 8052 |
* @return {String} The CSS class string for the link. Example return: |
| 8053 |
* "myLink myLink-url". If no {@link #className} was configured, returns |
| 8054 |
* an empty string. |
| 8055 |
*/ |
| 8056 |
AnchorTagBuilder.prototype.createCssClass = function (match) { |
| 8057 |
var className = this.className; |
| 8058 |
if (!className) { |
| 8059 |
return ""; |
| 8060 |
} |
| 8061 |
else { |
| 8062 |
var returnClasses = [className], cssClassSuffixes = match.getCssClassSuffixes(); |
| 8063 |
for (var i = 0, len = cssClassSuffixes.length; i < len; i++) { |
| 8064 |
returnClasses.push(className + '-' + cssClassSuffixes[i]); |
| 8065 |
} |
| 8066 |
return returnClasses.join(' '); |
| 8067 |
} |
| 8068 |
}; |
| 8069 |
/** |
| 8070 |
* Processes the `anchorText` by truncating the text according to the |
| 8071 |
* {@link #truncate} config. |
| 8072 |
* |
| 8073 |
* @private |
| 8074 |
* @param {String} anchorText The anchor tag's text (i.e. what will be |
| 8075 |
* displayed). |
| 8076 |
* @return {String} The processed `anchorText`. |
| 8077 |
*/ |
| 8078 |
AnchorTagBuilder.prototype.processAnchorText = function (anchorText) { |
| 8079 |
anchorText = this.doTruncate(anchorText); |
| 8080 |
return anchorText; |
| 8081 |
}; |
| 8082 |
/** |
| 8083 |
* Performs the truncation of the `anchorText` based on the {@link #truncate} |
| 8084 |
* option. If the `anchorText` is longer than the length specified by the |
| 8085 |
* {@link #truncate} option, the truncation is performed based on the |
| 8086 |
* `location` property. See {@link #truncate} for details. |
| 8087 |
* |
| 8088 |
* @private |
| 8089 |
* @param {String} anchorText The anchor tag's text (i.e. what will be |
| 8090 |
* displayed). |
| 8091 |
* @return {String} The truncated anchor text. |
| 8092 |
*/ |
| 8093 |
AnchorTagBuilder.prototype.doTruncate = function (anchorText) { |
| 8094 |
var truncate = this.truncate; |
| 8095 |
if (!truncate || !truncate.length) |
| 8096 |
return anchorText; |
| 8097 |
var truncateLength = truncate.length, truncateLocation = truncate.location; |
| 8098 |
if (truncateLocation === 'smart') { |
| 8099 |
return truncateSmart(anchorText, truncateLength); |
| 8100 |
} |
| 8101 |
else if (truncateLocation === 'middle') { |
| 8102 |
return truncateMiddle(anchorText, truncateLength); |
| 8103 |
} |
| 8104 |
else { |
| 8105 |
return truncateEnd(anchorText, truncateLength); |
| 8106 |
} |
| 8107 |
}; |
| 8108 |
return AnchorTagBuilder; |
| 8109 |
}()); |
| 8110 |
|
| 8111 |
/** |
| 8112 |
* @abstract |
| 8113 |
* @class Autolinker.match.Match |
| 8114 |
* |
| 8115 |
* Represents a match found in an input string which should be Autolinked. A Match object is what is provided in a |
| 8116 |
* {@link Autolinker#replaceFn replaceFn}, and may be used to query for details about the match. |
| 8117 |
* |
| 8118 |
* For example: |
| 8119 |
* |
| 8120 |
* var input = "..."; // string with URLs, Email Addresses, and Mentions (Twitter, Instagram, Soundcloud) |
| 8121 |
* |
| 8122 |
* var linkedText = Autolinker.link( input, { |
| 8123 |
* replaceFn : function( match ) { |
| 8124 |
* console.log( "href = ", match.getAnchorHref() ); |
| 8125 |
* console.log( "text = ", match.getAnchorText() ); |
| 8126 |
* |
| 8127 |
* switch( match.getType() ) { |
| 8128 |
* case 'url' : |
| 8129 |
* console.log( "url: ", match.getUrl() ); |
| 8130 |
* |
| 8131 |
* case 'email' : |
| 8132 |
* console.log( "email: ", match.getEmail() ); |
| 8133 |
* |
| 8134 |
* case 'mention' : |
| 8135 |
* console.log( "mention: ", match.getMention() ); |
| 8136 |
* } |
| 8137 |
* } |
| 8138 |
* } ); |
| 8139 |
* |
| 8140 |
* See the {@link Autolinker} class for more details on using the {@link Autolinker#replaceFn replaceFn}. |
| 8141 |
*/ |
| 8142 |
var Match = /** @class */ (function () { |
| 8143 |
/** |
| 8144 |
* @member Autolinker.match.Match |
| 8145 |
* @method constructor |
| 8146 |
* @param {Object} cfg The configuration properties for the Match |
| 8147 |
* instance, specified in an Object (map). |
| 8148 |
*/ |
| 8149 |
function Match(cfg) { |
| 8150 |
/** |
| 8151 |
* @cfg {Autolinker.AnchorTagBuilder} tagBuilder (required) |
| 8152 |
* |
| 8153 |
* Reference to the AnchorTagBuilder instance to use to generate an anchor |
| 8154 |
* tag for the Match. |
| 8155 |
*/ |
| 8156 |
this.__jsduckDummyDocProp = null; // property used just to get the above doc comment into the ES5 output and documentation generator |
| 8157 |
/** |
| 8158 |
* @cfg {String} matchedText (required) |
| 8159 |
* |
| 8160 |
* The original text that was matched by the {@link Autolinker.matcher.Matcher}. |
| 8161 |
*/ |
| 8162 |
this.matchedText = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8163 |
/** |
| 8164 |
* @cfg {Number} offset (required) |
| 8165 |
* |
| 8166 |
* The offset of where the match was made in the input string. |
| 8167 |
*/ |
| 8168 |
this.offset = 0; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8169 |
this.tagBuilder = cfg.tagBuilder; |
| 8170 |
this.matchedText = cfg.matchedText; |
| 8171 |
this.offset = cfg.offset; |
| 8172 |
} |
| 8173 |
/** |
| 8174 |
* Returns the original text that was matched. |
| 8175 |
* |
| 8176 |
* @return {String} |
| 8177 |
*/ |
| 8178 |
Match.prototype.getMatchedText = function () { |
| 8179 |
return this.matchedText; |
| 8180 |
}; |
| 8181 |
/** |
| 8182 |
* Sets the {@link #offset} of where the match was made in the input string. |
| 8183 |
* |
| 8184 |
* A {@link Autolinker.matcher.Matcher} will be fed only HTML text nodes, |
| 8185 |
* and will therefore set an original offset that is relative to the HTML |
| 8186 |
* text node itself. However, we want this offset to be relative to the full |
| 8187 |
* HTML input string, and thus if using {@link Autolinker#parse} (rather |
| 8188 |
* than calling a {@link Autolinker.matcher.Matcher} directly), then this |
| 8189 |
* offset is corrected after the Matcher itself has done its job. |
| 8190 |
* |
| 8191 |
* @param {Number} offset |
| 8192 |
*/ |
| 8193 |
Match.prototype.setOffset = function (offset) { |
| 8194 |
this.offset = offset; |
| 8195 |
}; |
| 8196 |
/** |
| 8197 |
* Returns the offset of where the match was made in the input string. This |
| 8198 |
* is the 0-based index of the match. |
| 8199 |
* |
| 8200 |
* @return {Number} |
| 8201 |
*/ |
| 8202 |
Match.prototype.getOffset = function () { |
| 8203 |
return this.offset; |
| 8204 |
}; |
| 8205 |
/** |
| 8206 |
* Returns the CSS class suffix(es) for this match. |
| 8207 |
* |
| 8208 |
* A CSS class suffix is appended to the {@link Autolinker#className} in |
| 8209 |
* the {@link Autolinker.AnchorTagBuilder} when a match is translated into |
| 8210 |
* an anchor tag. |
| 8211 |
* |
| 8212 |
* For example, if {@link Autolinker#className} was configured as 'myLink', |
| 8213 |
* and this method returns `[ 'url' ]`, the final class name of the element |
| 8214 |
* will become: 'myLink myLink-url'. |
| 8215 |
* |
| 8216 |
* The match may provide multiple CSS class suffixes to be appended to the |
| 8217 |
* {@link Autolinker#className} in order to facilitate better styling |
| 8218 |
* options for different match criteria. See {@link Autolinker.match.Mention} |
| 8219 |
* for an example. |
| 8220 |
* |
| 8221 |
* By default, this method returns a single array with the match's |
| 8222 |
* {@link #getType type} name, but may be overridden by subclasses. |
| 8223 |
* |
| 8224 |
* @return {String[]} |
| 8225 |
*/ |
| 8226 |
Match.prototype.getCssClassSuffixes = function () { |
| 8227 |
return [this.getType()]; |
| 8228 |
}; |
| 8229 |
/** |
| 8230 |
* Builds and returns an {@link Autolinker.HtmlTag} instance based on the |
| 8231 |
* Match. |
| 8232 |
* |
| 8233 |
* This can be used to easily generate anchor tags from matches, and either |
| 8234 |
* return their HTML string, or modify them before doing so. |
| 8235 |
* |
| 8236 |
* Example Usage: |
| 8237 |
* |
| 8238 |
* var tag = match.buildTag(); |
| 8239 |
* tag.addClass( 'cordova-link' ); |
| 8240 |
* tag.setAttr( 'target', '_system' ); |
| 8241 |
* |
| 8242 |
* tag.toAnchorString(); // <a href="http://google.com" class="cordova-link" target="_system">Google</a> |
| 8243 |
* |
| 8244 |
* Example Usage in {@link Autolinker#replaceFn}: |
| 8245 |
* |
| 8246 |
* var html = Autolinker.link( "Test google.com", { |
| 8247 |
* replaceFn : function( match ) { |
| 8248 |
* var tag = match.buildTag(); // returns an {@link Autolinker.HtmlTag} instance |
| 8249 |
* tag.setAttr( 'rel', 'nofollow' ); |
| 8250 |
* |
| 8251 |
* return tag; |
| 8252 |
* } |
| 8253 |
* } ); |
| 8254 |
* |
| 8255 |
* // generated html: |
| 8256 |
* // Test <a href="http://google.com" target="_blank" rel="nofollow">google.com</a> |
| 8257 |
*/ |
| 8258 |
Match.prototype.buildTag = function () { |
| 8259 |
return this.tagBuilder.build(this); |
| 8260 |
}; |
| 8261 |
return Match; |
| 8262 |
}()); |
| 8263 |
|
| 8264 |
/*! ***************************************************************************** |
| 8265 |
Copyright (c) Microsoft Corporation. All rights reserved. |
| 8266 |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use |
| 8267 |
this file except in compliance with the License. You may obtain a copy of the |
| 8268 |
License at http://www.apache.org/licenses/LICENSE-2.0 |
| 8269 |
|
| 8270 |
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 8271 |
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED |
| 8272 |
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, |
| 8273 |
MERCHANTABLITY OR NON-INFRINGEMENT. |
| 8274 |
|
| 8275 |
See the Apache Version 2.0 License for specific language governing permissions |
| 8276 |
and limitations under the License. |
| 8277 |
***************************************************************************** */ |
| 8278 |
/* global Reflect, Promise */ |
| 8279 |
|
| 8280 |
var extendStatics = function(d, b) { |
| 8281 |
extendStatics = Object.setPrototypeOf || |
| 8282 |
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 8283 |
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
| 8284 |
return extendStatics(d, b); |
| 8285 |
}; |
| 8286 |
|
| 8287 |
function __extends(d, b) { |
| 8288 |
extendStatics(d, b); |
| 8289 |
function __() { this.constructor = d; } |
| 8290 |
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 8291 |
} |
| 8292 |
|
| 8293 |
var __assign = function() { |
| 8294 |
__assign = Object.assign || function __assign(t) { |
| 8295 |
for (var s, i = 1, n = arguments.length; i < n; i++) { |
| 8296 |
s = arguments[i]; |
| 8297 |
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; |
| 8298 |
} |
| 8299 |
return t; |
| 8300 |
}; |
| 8301 |
return __assign.apply(this, arguments); |
| 8302 |
}; |
| 8303 |
|
| 8304 |
/** |
| 8305 |
* @class Autolinker.match.Email |
| 8306 |
* @extends Autolinker.match.Match |
| 8307 |
* |
| 8308 |
* Represents a Email match found in an input string which should be Autolinked. |
| 8309 |
* |
| 8310 |
* See this class's superclass ({@link Autolinker.match.Match}) for more details. |
| 8311 |
*/ |
| 8312 |
var EmailMatch = /** @class */ (function (_super) { |
| 8313 |
__extends(EmailMatch, _super); |
| 8314 |
/** |
| 8315 |
* @method constructor |
| 8316 |
* @param {Object} cfg The configuration properties for the Match |
| 8317 |
* instance, specified in an Object (map). |
| 8318 |
*/ |
| 8319 |
function EmailMatch(cfg) { |
| 8320 |
var _this = _super.call(this, cfg) || this; |
| 8321 |
/** |
| 8322 |
* @cfg {String} email (required) |
| 8323 |
* |
| 8324 |
* The email address that was matched. |
| 8325 |
*/ |
| 8326 |
_this.email = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8327 |
_this.email = cfg.email; |
| 8328 |
return _this; |
| 8329 |
} |
| 8330 |
/** |
| 8331 |
* Returns a string name for the type of match that this class represents. |
| 8332 |
* For the case of EmailMatch, returns 'email'. |
| 8333 |
* |
| 8334 |
* @return {String} |
| 8335 |
*/ |
| 8336 |
EmailMatch.prototype.getType = function () { |
| 8337 |
return 'email'; |
| 8338 |
}; |
| 8339 |
/** |
| 8340 |
* Returns the email address that was matched. |
| 8341 |
* |
| 8342 |
* @return {String} |
| 8343 |
*/ |
| 8344 |
EmailMatch.prototype.getEmail = function () { |
| 8345 |
return this.email; |
| 8346 |
}; |
| 8347 |
/** |
| 8348 |
* Returns the anchor href that should be generated for the match. |
| 8349 |
* |
| 8350 |
* @return {String} |
| 8351 |
*/ |
| 8352 |
EmailMatch.prototype.getAnchorHref = function () { |
| 8353 |
return 'mailto:' + this.email; |
| 8354 |
}; |
| 8355 |
/** |
| 8356 |
* Returns the anchor text that should be generated for the match. |
| 8357 |
* |
| 8358 |
* @return {String} |
| 8359 |
*/ |
| 8360 |
EmailMatch.prototype.getAnchorText = function () { |
| 8361 |
return this.email; |
| 8362 |
}; |
| 8363 |
return EmailMatch; |
| 8364 |
}(Match)); |
| 8365 |
|
| 8366 |
/** |
| 8367 |
* @class Autolinker.match.Hashtag |
| 8368 |
* @extends Autolinker.match.Match |
| 8369 |
* |
| 8370 |
* Represents a Hashtag match found in an input string which should be |
| 8371 |
* Autolinked. |
| 8372 |
* |
| 8373 |
* See this class's superclass ({@link Autolinker.match.Match}) for more |
| 8374 |
* details. |
| 8375 |
*/ |
| 8376 |
var HashtagMatch = /** @class */ (function (_super) { |
| 8377 |
__extends(HashtagMatch, _super); |
| 8378 |
/** |
| 8379 |
* @method constructor |
| 8380 |
* @param {Object} cfg The configuration properties for the Match |
| 8381 |
* instance, specified in an Object (map). |
| 8382 |
*/ |
| 8383 |
function HashtagMatch(cfg) { |
| 8384 |
var _this = _super.call(this, cfg) || this; |
| 8385 |
/** |
| 8386 |
* @cfg {String} serviceName |
| 8387 |
* |
| 8388 |
* The service to point hashtag matches to. See {@link Autolinker#hashtag} |
| 8389 |
* for available values. |
| 8390 |
*/ |
| 8391 |
_this.serviceName = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8392 |
/** |
| 8393 |
* @cfg {String} hashtag (required) |
| 8394 |
* |
| 8395 |
* The HashtagMatch that was matched, without the '#'. |
| 8396 |
*/ |
| 8397 |
_this.hashtag = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8398 |
_this.serviceName = cfg.serviceName; |
| 8399 |
_this.hashtag = cfg.hashtag; |
| 8400 |
return _this; |
| 8401 |
} |
| 8402 |
/** |
| 8403 |
* Returns a string name for the type of match that this class represents. |
| 8404 |
* For the case of HashtagMatch, returns 'hashtag'. |
| 8405 |
* |
| 8406 |
* @return {String} |
| 8407 |
*/ |
| 8408 |
HashtagMatch.prototype.getType = function () { |
| 8409 |
return 'hashtag'; |
| 8410 |
}; |
| 8411 |
/** |
| 8412 |
* Returns the configured {@link #serviceName} to point the HashtagMatch to. |
| 8413 |
* Ex: 'facebook', 'twitter'. |
| 8414 |
* |
| 8415 |
* @return {String} |
| 8416 |
*/ |
| 8417 |
HashtagMatch.prototype.getServiceName = function () { |
| 8418 |
return this.serviceName; |
| 8419 |
}; |
| 8420 |
/** |
| 8421 |
* Returns the matched hashtag, without the '#' character. |
| 8422 |
* |
| 8423 |
* @return {String} |
| 8424 |
*/ |
| 8425 |
HashtagMatch.prototype.getHashtag = function () { |
| 8426 |
return this.hashtag; |
| 8427 |
}; |
| 8428 |
/** |
| 8429 |
* Returns the anchor href that should be generated for the match. |
| 8430 |
* |
| 8431 |
* @return {String} |
| 8432 |
*/ |
| 8433 |
HashtagMatch.prototype.getAnchorHref = function () { |
| 8434 |
var serviceName = this.serviceName, hashtag = this.hashtag; |
| 8435 |
switch (serviceName) { |
| 8436 |
case 'twitter': |
| 8437 |
return 'https://twitter.com/hashtag/' + hashtag; |
| 8438 |
case 'facebook': |
| 8439 |
return 'https://www.facebook.com/hashtag/' + hashtag; |
| 8440 |
case 'instagram': |
| 8441 |
return 'https://instagram.com/explore/tags/' + hashtag; |
| 8442 |
default: // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case. |
| 8443 |
throw new Error('Unknown service name to point hashtag to: ' + serviceName); |
| 8444 |
} |
| 8445 |
}; |
| 8446 |
/** |
| 8447 |
* Returns the anchor text that should be generated for the match. |
| 8448 |
* |
| 8449 |
* @return {String} |
| 8450 |
*/ |
| 8451 |
HashtagMatch.prototype.getAnchorText = function () { |
| 8452 |
return '#' + this.hashtag; |
| 8453 |
}; |
| 8454 |
return HashtagMatch; |
| 8455 |
}(Match)); |
| 8456 |
|
| 8457 |
/** |
| 8458 |
* @class Autolinker.match.Mention |
| 8459 |
* @extends Autolinker.match.Match |
| 8460 |
* |
| 8461 |
* Represents a Mention match found in an input string which should be Autolinked. |
| 8462 |
* |
| 8463 |
* See this class's superclass ({@link Autolinker.match.Match}) for more details. |
| 8464 |
*/ |
| 8465 |
var MentionMatch = /** @class */ (function (_super) { |
| 8466 |
__extends(MentionMatch, _super); |
| 8467 |
/** |
| 8468 |
* @method constructor |
| 8469 |
* @param {Object} cfg The configuration properties for the Match |
| 8470 |
* instance, specified in an Object (map). |
| 8471 |
*/ |
| 8472 |
function MentionMatch(cfg) { |
| 8473 |
var _this = _super.call(this, cfg) || this; |
| 8474 |
/** |
| 8475 |
* @cfg {String} serviceName |
| 8476 |
* |
| 8477 |
* The service to point mention matches to. See {@link Autolinker#mention} |
| 8478 |
* for available values. |
| 8479 |
*/ |
| 8480 |
_this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8481 |
/** |
| 8482 |
* @cfg {String} mention (required) |
| 8483 |
* |
| 8484 |
* The Mention that was matched, without the '@' character. |
| 8485 |
*/ |
| 8486 |
_this.mention = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8487 |
_this.mention = cfg.mention; |
| 8488 |
_this.serviceName = cfg.serviceName; |
| 8489 |
return _this; |
| 8490 |
} |
| 8491 |
/** |
| 8492 |
* Returns a string name for the type of match that this class represents. |
| 8493 |
* For the case of MentionMatch, returns 'mention'. |
| 8494 |
* |
| 8495 |
* @return {String} |
| 8496 |
*/ |
| 8497 |
MentionMatch.prototype.getType = function () { |
| 8498 |
return 'mention'; |
| 8499 |
}; |
| 8500 |
/** |
| 8501 |
* Returns the mention, without the '@' character. |
| 8502 |
* |
| 8503 |
* @return {String} |
| 8504 |
*/ |
| 8505 |
MentionMatch.prototype.getMention = function () { |
| 8506 |
return this.mention; |
| 8507 |
}; |
| 8508 |
/** |
| 8509 |
* Returns the configured {@link #serviceName} to point the mention to. |
| 8510 |
* Ex: 'instagram', 'twitter', 'soundcloud'. |
| 8511 |
* |
| 8512 |
* @return {String} |
| 8513 |
*/ |
| 8514 |
MentionMatch.prototype.getServiceName = function () { |
| 8515 |
return this.serviceName; |
| 8516 |
}; |
| 8517 |
/** |
| 8518 |
* Returns the anchor href that should be generated for the match. |
| 8519 |
* |
| 8520 |
* @return {String} |
| 8521 |
*/ |
| 8522 |
MentionMatch.prototype.getAnchorHref = function () { |
| 8523 |
switch (this.serviceName) { |
| 8524 |
case 'twitter': |
| 8525 |
return 'https://twitter.com/' + this.mention; |
| 8526 |
case 'instagram': |
| 8527 |
return 'https://instagram.com/' + this.mention; |
| 8528 |
case 'soundcloud': |
| 8529 |
return 'https://soundcloud.com/' + this.mention; |
| 8530 |
default: // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case. |
| 8531 |
throw new Error('Unknown service name to point mention to: ' + this.serviceName); |
| 8532 |
} |
| 8533 |
}; |
| 8534 |
/** |
| 8535 |
* Returns the anchor text that should be generated for the match. |
| 8536 |
* |
| 8537 |
* @return {String} |
| 8538 |
*/ |
| 8539 |
MentionMatch.prototype.getAnchorText = function () { |
| 8540 |
return '@' + this.mention; |
| 8541 |
}; |
| 8542 |
/** |
| 8543 |
* Returns the CSS class suffixes that should be used on a tag built with |
| 8544 |
* the match. See {@link Autolinker.match.Match#getCssClassSuffixes} for |
| 8545 |
* details. |
| 8546 |
* |
| 8547 |
* @return {String[]} |
| 8548 |
*/ |
| 8549 |
MentionMatch.prototype.getCssClassSuffixes = function () { |
| 8550 |
var cssClassSuffixes = _super.prototype.getCssClassSuffixes.call(this), serviceName = this.getServiceName(); |
| 8551 |
if (serviceName) { |
| 8552 |
cssClassSuffixes.push(serviceName); |
| 8553 |
} |
| 8554 |
return cssClassSuffixes; |
| 8555 |
}; |
| 8556 |
return MentionMatch; |
| 8557 |
}(Match)); |
| 8558 |
|
| 8559 |
/** |
| 8560 |
* @class Autolinker.match.Phone |
| 8561 |
* @extends Autolinker.match.Match |
| 8562 |
* |
| 8563 |
* Represents a Phone number match found in an input string which should be |
| 8564 |
* Autolinked. |
| 8565 |
* |
| 8566 |
* See this class's superclass ({@link Autolinker.match.Match}) for more |
| 8567 |
* details. |
| 8568 |
*/ |
| 8569 |
var PhoneMatch = /** @class */ (function (_super) { |
| 8570 |
__extends(PhoneMatch, _super); |
| 8571 |
/** |
| 8572 |
* @method constructor |
| 8573 |
* @param {Object} cfg The configuration properties for the Match |
| 8574 |
* instance, specified in an Object (map). |
| 8575 |
*/ |
| 8576 |
function PhoneMatch(cfg) { |
| 8577 |
var _this = _super.call(this, cfg) || this; |
| 8578 |
/** |
| 8579 |
* @protected |
| 8580 |
* @property {String} number (required) |
| 8581 |
* |
| 8582 |
* The phone number that was matched, without any delimiter characters. |
| 8583 |
* |
| 8584 |
* Note: This is a string to allow for prefixed 0's. |
| 8585 |
*/ |
| 8586 |
_this.number = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8587 |
/** |
| 8588 |
* @protected |
| 8589 |
* @property {Boolean} plusSign (required) |
| 8590 |
* |
| 8591 |
* `true` if the matched phone number started with a '+' sign. We'll include |
| 8592 |
* it in the `tel:` URL if so, as this is needed for international numbers. |
| 8593 |
* |
| 8594 |
* Ex: '+1 (123) 456 7879' |
| 8595 |
*/ |
| 8596 |
_this.plusSign = false; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8597 |
_this.number = cfg.number; |
| 8598 |
_this.plusSign = cfg.plusSign; |
| 8599 |
return _this; |
| 8600 |
} |
| 8601 |
/** |
| 8602 |
* Returns a string name for the type of match that this class represents. |
| 8603 |
* For the case of PhoneMatch, returns 'phone'. |
| 8604 |
* |
| 8605 |
* @return {String} |
| 8606 |
*/ |
| 8607 |
PhoneMatch.prototype.getType = function () { |
| 8608 |
return 'phone'; |
| 8609 |
}; |
| 8610 |
/** |
| 8611 |
* Returns the phone number that was matched as a string, without any |
| 8612 |
* delimiter characters. |
| 8613 |
* |
| 8614 |
* Note: This is a string to allow for prefixed 0's. |
| 8615 |
* |
| 8616 |
* @return {String} |
| 8617 |
*/ |
| 8618 |
PhoneMatch.prototype.getPhoneNumber = function () { |
| 8619 |
return this.number; |
| 8620 |
}; |
| 8621 |
/** |
| 8622 |
* Alias of {@link #getPhoneNumber}, returns the phone number that was |
| 8623 |
* matched as a string, without any delimiter characters. |
| 8624 |
* |
| 8625 |
* Note: This is a string to allow for prefixed 0's. |
| 8626 |
* |
| 8627 |
* @return {String} |
| 8628 |
*/ |
| 8629 |
PhoneMatch.prototype.getNumber = function () { |
| 8630 |
return this.getPhoneNumber(); |
| 8631 |
}; |
| 8632 |
/** |
| 8633 |
* Returns the anchor href that should be generated for the match. |
| 8634 |
* |
| 8635 |
* @return {String} |
| 8636 |
*/ |
| 8637 |
PhoneMatch.prototype.getAnchorHref = function () { |
| 8638 |
return 'tel:' + (this.plusSign ? '+' : '') + this.number; |
| 8639 |
}; |
| 8640 |
/** |
| 8641 |
* Returns the anchor text that should be generated for the match. |
| 8642 |
* |
| 8643 |
* @return {String} |
| 8644 |
*/ |
| 8645 |
PhoneMatch.prototype.getAnchorText = function () { |
| 8646 |
return this.matchedText; |
| 8647 |
}; |
| 8648 |
return PhoneMatch; |
| 8649 |
}(Match)); |
| 8650 |
|
| 8651 |
/** |
| 8652 |
* @class Autolinker.match.Url |
| 8653 |
* @extends Autolinker.match.Match |
| 8654 |
* |
| 8655 |
* Represents a Url match found in an input string which should be Autolinked. |
| 8656 |
* |
| 8657 |
* See this class's superclass ({@link Autolinker.match.Match}) for more details. |
| 8658 |
*/ |
| 8659 |
var UrlMatch = /** @class */ (function (_super) { |
| 8660 |
__extends(UrlMatch, _super); |
| 8661 |
/** |
| 8662 |
* @method constructor |
| 8663 |
* @param {Object} cfg The configuration properties for the Match |
| 8664 |
* instance, specified in an Object (map). |
| 8665 |
*/ |
| 8666 |
function UrlMatch(cfg) { |
| 8667 |
var _this = _super.call(this, cfg) || this; |
| 8668 |
/** |
| 8669 |
* @cfg {String} url (required) |
| 8670 |
* |
| 8671 |
* The url that was matched. |
| 8672 |
*/ |
| 8673 |
_this.url = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8674 |
/** |
| 8675 |
* @cfg {"scheme"/"www"/"tld"} urlMatchType (required) |
| 8676 |
* |
| 8677 |
* The type of URL match that this class represents. This helps to determine |
| 8678 |
* if the match was made in the original text with a prefixed scheme (ex: |
| 8679 |
* 'http://www.google.com'), a prefixed 'www' (ex: 'www.google.com'), or |
| 8680 |
* was matched by a known top-level domain (ex: 'google.com'). |
| 8681 |
*/ |
| 8682 |
_this.urlMatchType = 'scheme'; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8683 |
/** |
| 8684 |
* @cfg {Boolean} protocolUrlMatch (required) |
| 8685 |
* |
| 8686 |
* `true` if the URL is a match which already has a protocol (i.e. |
| 8687 |
* 'http://'), `false` if the match was from a 'www' or known TLD match. |
| 8688 |
*/ |
| 8689 |
_this.protocolUrlMatch = false; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8690 |
/** |
| 8691 |
* @cfg {Boolean} protocolRelativeMatch (required) |
| 8692 |
* |
| 8693 |
* `true` if the URL is a protocol-relative match. A protocol-relative match |
| 8694 |
* is a URL that starts with '//', and will be either http:// or https:// |
| 8695 |
* based on the protocol that the site is loaded under. |
| 8696 |
*/ |
| 8697 |
_this.protocolRelativeMatch = false; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8698 |
/** |
| 8699 |
* @cfg {Object} stripPrefix (required) |
| 8700 |
* |
| 8701 |
* The Object form of {@link Autolinker#cfg-stripPrefix}. |
| 8702 |
*/ |
| 8703 |
_this.stripPrefix = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8704 |
/** |
| 8705 |
* @cfg {Boolean} stripTrailingSlash (required) |
| 8706 |
* @inheritdoc Autolinker#cfg-stripTrailingSlash |
| 8707 |
*/ |
| 8708 |
_this.stripTrailingSlash = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8709 |
/** |
| 8710 |
* @cfg {Boolean} decodePercentEncoding (required) |
| 8711 |
* @inheritdoc Autolinker#cfg-decodePercentEncoding |
| 8712 |
*/ |
| 8713 |
_this.decodePercentEncoding = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 8714 |
/** |
| 8715 |
* @private |
| 8716 |
* @property {RegExp} schemePrefixRegex |
| 8717 |
* |
| 8718 |
* A regular expression used to remove the 'http://' or 'https://' from |
| 8719 |
* URLs. |
| 8720 |
*/ |
| 8721 |
_this.schemePrefixRegex = /^(https?:\/\/)?/i; |
| 8722 |
/** |
| 8723 |
* @private |
| 8724 |
* @property {RegExp} wwwPrefixRegex |
| 8725 |
* |
| 8726 |
* A regular expression used to remove the 'www.' from URLs. |
| 8727 |
*/ |
| 8728 |
_this.wwwPrefixRegex = /^(https?:\/\/)?(www\.)?/i; |
| 8729 |
/** |
| 8730 |
* @private |
| 8731 |
* @property {RegExp} protocolRelativeRegex |
| 8732 |
* |
| 8733 |
* The regular expression used to remove the protocol-relative '//' from the {@link #url} string, for purposes |
| 8734 |
* of {@link #getAnchorText}. A protocol-relative URL is, for example, "//yahoo.com" |
| 8735 |
*/ |
| 8736 |
_this.protocolRelativeRegex = /^\/\//; |
| 8737 |
/** |
| 8738 |
* @private |
| 8739 |
* @property {Boolean} protocolPrepended |
| 8740 |
* |
| 8741 |
* Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the |
| 8742 |
* {@link #url} did not have a protocol) |
| 8743 |
*/ |
| 8744 |
_this.protocolPrepended = false; |
| 8745 |
_this.urlMatchType = cfg.urlMatchType; |
| 8746 |
_this.url = cfg.url; |
| 8747 |
_this.protocolUrlMatch = cfg.protocolUrlMatch; |
| 8748 |
_this.protocolRelativeMatch = cfg.protocolRelativeMatch; |
| 8749 |
_this.stripPrefix = cfg.stripPrefix; |
| 8750 |
_this.stripTrailingSlash = cfg.stripTrailingSlash; |
| 8751 |
_this.decodePercentEncoding = cfg.decodePercentEncoding; |
| 8752 |
return _this; |
| 8753 |
} |
| 8754 |
/** |
| 8755 |
* Returns a string name for the type of match that this class represents. |
| 8756 |
* For the case of UrlMatch, returns 'url'. |
| 8757 |
* |
| 8758 |
* @return {String} |
| 8759 |
*/ |
| 8760 |
UrlMatch.prototype.getType = function () { |
| 8761 |
return 'url'; |
| 8762 |
}; |
| 8763 |
/** |
| 8764 |
* Returns a string name for the type of URL match that this class |
| 8765 |
* represents. |
| 8766 |
* |
| 8767 |
* This helps to determine if the match was made in the original text with a |
| 8768 |
* prefixed scheme (ex: 'http://www.google.com'), a prefixed 'www' (ex: |
| 8769 |
* 'www.google.com'), or was matched by a known top-level domain (ex: |
| 8770 |
* 'google.com'). |
| 8771 |
* |
| 8772 |
* @return {"scheme"/"www"/"tld"} |
| 8773 |
*/ |
| 8774 |
UrlMatch.prototype.getUrlMatchType = function () { |
| 8775 |
return this.urlMatchType; |
| 8776 |
}; |
| 8777 |
/** |
| 8778 |
* Returns the url that was matched, assuming the protocol to be 'http://' if the original |
| 8779 |
* match was missing a protocol. |
| 8780 |
* |
| 8781 |
* @return {String} |
| 8782 |
*/ |
| 8783 |
UrlMatch.prototype.getUrl = function () { |
| 8784 |
var url = this.url; |
| 8785 |
// if the url string doesn't begin with a protocol, assume 'http://' |
| 8786 |
if (!this.protocolRelativeMatch && !this.protocolUrlMatch && !this.protocolPrepended) { |
| 8787 |
url = this.url = 'http://' + url; |
| 8788 |
this.protocolPrepended = true; |
| 8789 |
} |
| 8790 |
return url; |
| 8791 |
}; |
| 8792 |
/** |
| 8793 |
* Returns the anchor href that should be generated for the match. |
| 8794 |
* |
| 8795 |
* @return {String} |
| 8796 |
*/ |
| 8797 |
UrlMatch.prototype.getAnchorHref = function () { |
| 8798 |
var url = this.getUrl(); |
| 8799 |
return url.replace(/&/g, '&'); // any &'s in the URL should be converted back to '&' if they were displayed as & in the source html |
| 8800 |
}; |
| 8801 |
/** |
| 8802 |
* Returns the anchor text that should be generated for the match. |
| 8803 |
* |
| 8804 |
* @return {String} |
| 8805 |
*/ |
| 8806 |
UrlMatch.prototype.getAnchorText = function () { |
| 8807 |
var anchorText = this.getMatchedText(); |
| 8808 |
if (this.protocolRelativeMatch) { |
| 8809 |
// Strip off any protocol-relative '//' from the anchor text |
| 8810 |
anchorText = this.stripProtocolRelativePrefix(anchorText); |
| 8811 |
} |
| 8812 |
if (this.stripPrefix.scheme) { |
| 8813 |
anchorText = this.stripSchemePrefix(anchorText); |
| 8814 |
} |
| 8815 |
if (this.stripPrefix.www) { |
| 8816 |
anchorText = this.stripWwwPrefix(anchorText); |
| 8817 |
} |
| 8818 |
if (this.stripTrailingSlash) { |
| 8819 |
anchorText = this.removeTrailingSlash(anchorText); // remove trailing slash, if there is one |
| 8820 |
} |
| 8821 |
if (this.decodePercentEncoding) { |
| 8822 |
anchorText = this.removePercentEncoding(anchorText); |
| 8823 |
} |
| 8824 |
return anchorText; |
| 8825 |
}; |
| 8826 |
// --------------------------------------- |
| 8827 |
// Utility Functionality |
| 8828 |
/** |
| 8829 |
* Strips the scheme prefix (such as "http://" or "https://") from the given |
| 8830 |
* `url`. |
| 8831 |
* |
| 8832 |
* @private |
| 8833 |
* @param {String} url The text of the anchor that is being generated, for |
| 8834 |
* which to strip off the url scheme. |
| 8835 |
* @return {String} The `url`, with the scheme stripped. |
| 8836 |
*/ |
| 8837 |
UrlMatch.prototype.stripSchemePrefix = function (url) { |
| 8838 |
return url.replace(this.schemePrefixRegex, ''); |
| 8839 |
}; |
| 8840 |
/** |
| 8841 |
* Strips the 'www' prefix from the given `url`. |
| 8842 |
* |
| 8843 |
* @private |
| 8844 |
* @param {String} url The text of the anchor that is being generated, for |
| 8845 |
* which to strip off the 'www' if it exists. |
| 8846 |
* @return {String} The `url`, with the 'www' stripped. |
| 8847 |
*/ |
| 8848 |
UrlMatch.prototype.stripWwwPrefix = function (url) { |
| 8849 |
return url.replace(this.wwwPrefixRegex, '$1'); // leave any scheme ($1), it one exists |
| 8850 |
}; |
| 8851 |
/** |
| 8852 |
* Strips any protocol-relative '//' from the anchor text. |
| 8853 |
* |
| 8854 |
* @private |
| 8855 |
* @param {String} text The text of the anchor that is being generated, for which to strip off the |
| 8856 |
* protocol-relative prefix (such as stripping off "//") |
| 8857 |
* @return {String} The `anchorText`, with the protocol-relative prefix stripped. |
| 8858 |
*/ |
| 8859 |
UrlMatch.prototype.stripProtocolRelativePrefix = function (text) { |
| 8860 |
return text.replace(this.protocolRelativeRegex, ''); |
| 8861 |
}; |
| 8862 |
/** |
| 8863 |
* Removes any trailing slash from the given `anchorText`, in preparation for the text to be displayed. |
| 8864 |
* |
| 8865 |
* @private |
| 8866 |
* @param {String} anchorText The text of the anchor that is being generated, for which to remove any trailing |
| 8867 |
* slash ('/') that may exist. |
| 8868 |
* @return {String} The `anchorText`, with the trailing slash removed. |
| 8869 |
*/ |
| 8870 |
UrlMatch.prototype.removeTrailingSlash = function (anchorText) { |
| 8871 |
if (anchorText.charAt(anchorText.length - 1) === '/') { |
| 8872 |
anchorText = anchorText.slice(0, -1); |
| 8873 |
} |
| 8874 |
return anchorText; |
| 8875 |
}; |
| 8876 |
/** |
| 8877 |
* Decodes percent-encoded characters from the given `anchorText`, in |
| 8878 |
* preparation for the text to be displayed. |
| 8879 |
* |
| 8880 |
* @private |
| 8881 |
* @param {String} anchorText The text of the anchor that is being |
| 8882 |
* generated, for which to decode any percent-encoded characters. |
| 8883 |
* @return {String} The `anchorText`, with the percent-encoded characters |
| 8884 |
* decoded. |
| 8885 |
*/ |
| 8886 |
UrlMatch.prototype.removePercentEncoding = function (anchorText) { |
| 8887 |
// First, convert a few of the known % encodings to the corresponding |
| 8888 |
// HTML entities that could accidentally be interpretted as special |
| 8889 |
// HTML characters |
| 8890 |
var preProcessedEntityAnchorText = anchorText |
| 8891 |
.replace(/%22/gi, '"') // " char |
| 8892 |
.replace(/%26/gi, '&') // & char |
| 8893 |
.replace(/%27/gi, ''') // ' char |
| 8894 |
.replace(/%3C/gi, '<') // < char |
| 8895 |
.replace(/%3E/gi, '>'); // > char |
| 8896 |
try { |
| 8897 |
// Now attempt to decode the rest of the anchor text |
| 8898 |
return decodeURIComponent(preProcessedEntityAnchorText); |
| 8899 |
} |
| 8900 |
catch (e) { // Invalid % escape sequence in the anchor text |
| 8901 |
return preProcessedEntityAnchorText; |
| 8902 |
} |
| 8903 |
}; |
| 8904 |
return UrlMatch; |
| 8905 |
}(Match)); |
| 8906 |
|
| 8907 |
/** |
| 8908 |
* @abstract |
| 8909 |
* @class Autolinker.matcher.Matcher |
| 8910 |
* |
| 8911 |
* An abstract class and interface for individual matchers to find matches in |
| 8912 |
* an input string with linkified versions of them. |
| 8913 |
* |
| 8914 |
* Note that Matchers do not take HTML into account - they must be fed the text |
| 8915 |
* nodes of any HTML string, which is handled by {@link Autolinker#parse}. |
| 8916 |
*/ |
| 8917 |
var Matcher = /** @class */ (function () { |
| 8918 |
/** |
| 8919 |
* @method constructor |
| 8920 |
* @param {Object} cfg The configuration properties for the Matcher |
| 8921 |
* instance, specified in an Object (map). |
| 8922 |
*/ |
| 8923 |
function Matcher(cfg) { |
| 8924 |
/** |
| 8925 |
* @cfg {Autolinker.AnchorTagBuilder} tagBuilder (required) |
| 8926 |
* |
| 8927 |
* Reference to the AnchorTagBuilder instance to use to generate HTML tags |
| 8928 |
* for {@link Autolinker.match.Match Matches}. |
| 8929 |
*/ |
| 8930 |
this.__jsduckDummyDocProp = null; // property used just to get the above doc comment into the ES5 output and documentation generator |
| 8931 |
this.tagBuilder = cfg.tagBuilder; |
| 8932 |
} |
| 8933 |
return Matcher; |
| 8934 |
}()); |
| 8935 |
|
| 8936 |
/* |
| 8937 |
* This file builds and stores a library of the common regular expressions used |
| 8938 |
* by the Autolinker utility. |
| 8939 |
* |
| 8940 |
* Other regular expressions may exist ad-hoc, but these are generally the |
| 8941 |
* regular expressions that are shared between source files. |
| 8942 |
*/ |
| 8943 |
/** |
| 8944 |
* Regular expression to match upper and lowercase ASCII letters |
| 8945 |
*/ |
| 8946 |
var letterRe = /[A-Za-z]/; |
| 8947 |
/** |
| 8948 |
* Regular expression to match ASCII digits |
| 8949 |
*/ |
| 8950 |
var digitRe = /[0-9]/; |
| 8951 |
/** |
| 8952 |
* Regular expression to match whitespace |
| 8953 |
*/ |
| 8954 |
var whitespaceRe = /\s/; |
| 8955 |
/** |
| 8956 |
* Regular expression to match quote characters |
| 8957 |
*/ |
| 8958 |
var quoteRe = /['"]/; |
| 8959 |
/** |
| 8960 |
* Regular expression to match the range of ASCII control characters (0-31), and |
| 8961 |
* the backspace char (127) |
| 8962 |
*/ |
| 8963 |
var controlCharsRe = /[\x00-\x1F\x7F]/; |
| 8964 |
/** |
| 8965 |
* The string form of a regular expression that would match all of the |
| 8966 |
* alphabetic ("letter") chars in the unicode character set when placed in a |
| 8967 |
* RegExp character class (`[]`). This includes all international alphabetic |
| 8968 |
* characters. |
| 8969 |
* |
| 8970 |
* These would be the characters matched by unicode regex engines `\p{L}` |
| 8971 |
* escape ("all letters"). |
| 8972 |
* |
| 8973 |
* Taken from the XRegExp library: http://xregexp.com/ (thanks @https://github.com/slevithan) |
| 8974 |
* Specifically: http://xregexp.com/v/3.2.0/xregexp-all.js, the 'Letter' |
| 8975 |
* regex's bmp |
| 8976 |
* |
| 8977 |
* VERY IMPORTANT: This set of characters is defined inside of a Regular |
| 8978 |
* Expression literal rather than a string literal to prevent UglifyJS from |
| 8979 |
* compressing the unicode escape sequences into their actual unicode |
| 8980 |
* characters. If Uglify compresses these into the unicode characters |
| 8981 |
* themselves, this results in the error "Range out of order in character |
| 8982 |
* class" when these characters are used inside of a Regular Expression |
| 8983 |
* character class (`[]`). See usages of this const. Alternatively, we can set |
| 8984 |
* the UglifyJS option `ascii_only` to true for the build, but that doesn't |
| 8985 |
* help others who are pulling in Autolinker into their own build and running |
| 8986 |
* UglifyJS themselves. |
| 8987 |
*/ |
| 8988 |
var alphaCharsStr = /A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC/ |
| 8989 |
.source; // see note in above variable description |
| 8990 |
/** |
| 8991 |
* The string form of a regular expression that would match all emoji characters |
| 8992 |
* Source: https://www.regextester.com/106421 |
| 8993 |
*/ |
| 8994 |
var emojiStr = /\u00a9\u00ae\u2000-\u3300\ud83c\ud000-\udfff\ud83d\ud000-\udfff\ud83e\ud000-\udfff/ |
| 8995 |
.source; |
| 8996 |
/** |
| 8997 |
* The string form of a regular expression that would match all of the |
| 8998 |
* combining mark characters in the unicode character set when placed in a |
| 8999 |
* RegExp character class (`[]`). |
| 9000 |
* |
| 9001 |
* These would be the characters matched by unicode regex engines `\p{M}` |
| 9002 |
* escape ("all marks"). |
| 9003 |
* |
| 9004 |
* Taken from the XRegExp library: http://xregexp.com/ (thanks @https://github.com/slevithan) |
| 9005 |
* Specifically: http://xregexp.com/v/3.2.0/xregexp-all.js, the 'Mark' |
| 9006 |
* regex's bmp |
| 9007 |
* |
| 9008 |
* VERY IMPORTANT: This set of characters is defined inside of a Regular |
| 9009 |
* Expression literal rather than a string literal to prevent UglifyJS from |
| 9010 |
* compressing the unicode escape sequences into their actual unicode |
| 9011 |
* characters. If Uglify compresses these into the unicode characters |
| 9012 |
* themselves, this results in the error "Range out of order in character |
| 9013 |
* class" when these characters are used inside of a Regular Expression |
| 9014 |
* character class (`[]`). See usages of this const. Alternatively, we can set |
| 9015 |
* the UglifyJS option `ascii_only` to true for the build, but that doesn't |
| 9016 |
* help others who are pulling in Autolinker into their own build and running |
| 9017 |
* UglifyJS themselves. |
| 9018 |
*/ |
| 9019 |
var marksStr = /\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D4-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D01-\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF8\u1CF9\u1DC0-\u1DF5\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F/ |
| 9020 |
.source; // see note in above variable description |
| 9021 |
/** |
| 9022 |
* The string form of a regular expression that would match all of the |
| 9023 |
* alphabetic ("letter") chars, emoji, and combining marks in the unicode character set |
| 9024 |
* when placed in a RegExp character class (`[]`). This includes all |
| 9025 |
* international alphabetic characters. |
| 9026 |
* |
| 9027 |
* These would be the characters matched by unicode regex engines `\p{L}\p{M}` |
| 9028 |
* escapes and emoji characters. |
| 9029 |
*/ |
| 9030 |
var alphaCharsAndMarksStr = alphaCharsStr + emojiStr + marksStr; |
| 9031 |
/** |
| 9032 |
* The string form of a regular expression that would match all of the |
| 9033 |
* decimal number chars in the unicode character set when placed in a RegExp |
| 9034 |
* character class (`[]`). |
| 9035 |
* |
| 9036 |
* These would be the characters matched by unicode regex engines `\p{Nd}` |
| 9037 |
* escape ("all decimal numbers") |
| 9038 |
* |
| 9039 |
* Taken from the XRegExp library: http://xregexp.com/ (thanks @https://github.com/slevithan) |
| 9040 |
* Specifically: http://xregexp.com/v/3.2.0/xregexp-all.js, the 'Decimal_Number' |
| 9041 |
* regex's bmp |
| 9042 |
* |
| 9043 |
* VERY IMPORTANT: This set of characters is defined inside of a Regular |
| 9044 |
* Expression literal rather than a string literal to prevent UglifyJS from |
| 9045 |
* compressing the unicode escape sequences into their actual unicode |
| 9046 |
* characters. If Uglify compresses these into the unicode characters |
| 9047 |
* themselves, this results in the error "Range out of order in character |
| 9048 |
* class" when these characters are used inside of a Regular Expression |
| 9049 |
* character class (`[]`). See usages of this const. Alternatively, we can set |
| 9050 |
* the UglifyJS option `ascii_only` to true for the build, but that doesn't |
| 9051 |
* help others who are pulling in Autolinker into their own build and running |
| 9052 |
* UglifyJS themselves. |
| 9053 |
*/ |
| 9054 |
var decimalNumbersStr = /0-9\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0DE6-\u0DEF\u0E50-\u0E59\u0ED0-\u0ED9\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9\uA900-\uA909\uA9D0-\uA9D9\uA9F0-\uA9F9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19/ |
| 9055 |
.source; // see note in above variable description |
| 9056 |
/** |
| 9057 |
* The string form of a regular expression that would match all of the |
| 9058 |
* letters and decimal number chars in the unicode character set when placed in |
| 9059 |
* a RegExp character class (`[]`). |
| 9060 |
* |
| 9061 |
* These would be the characters matched by unicode regex engines |
| 9062 |
* `[\p{L}\p{Nd}]` escape ("all letters and decimal numbers") |
| 9063 |
*/ |
| 9064 |
var alphaNumericCharsStr = alphaCharsAndMarksStr + decimalNumbersStr; |
| 9065 |
/** |
| 9066 |
* The string form of a regular expression that would match all of the |
| 9067 |
* letters, combining marks, and decimal number chars in the unicode character |
| 9068 |
* set when placed in a RegExp character class (`[]`). |
| 9069 |
* |
| 9070 |
* These would be the characters matched by unicode regex engines |
| 9071 |
* `[\p{L}\p{M}\p{Nd}]` escape ("all letters, combining marks, and decimal |
| 9072 |
* numbers") |
| 9073 |
*/ |
| 9074 |
var alphaNumericAndMarksCharsStr = alphaCharsAndMarksStr + decimalNumbersStr; |
| 9075 |
// Simplified IP regular expression |
| 9076 |
var ipStr = '(?:[' + decimalNumbersStr + ']{1,3}\\.){3}[' + decimalNumbersStr + ']{1,3}'; |
| 9077 |
// Protected domain label which do not allow "-" character on the beginning and the end of a single label |
| 9078 |
var domainLabelStr = '[' + alphaNumericAndMarksCharsStr + '](?:[' + alphaNumericAndMarksCharsStr + '\\-]{0,61}[' + alphaNumericAndMarksCharsStr + '])?'; |
| 9079 |
var getDomainLabelStr = function (group) { |
| 9080 |
return '(?=(' + domainLabelStr + '))\\' + group; |
| 9081 |
}; |
| 9082 |
/** |
| 9083 |
* A function to match domain names of a URL or email address. |
| 9084 |
* Ex: 'google', 'yahoo', 'some-other-company', etc. |
| 9085 |
*/ |
| 9086 |
var getDomainNameStr = function (group) { |
| 9087 |
return '(?:' + getDomainLabelStr(group) + '(?:\\.' + getDomainLabelStr(group + 1) + '){0,126}|' + ipStr + ')'; |
| 9088 |
}; |
| 9089 |
/** |
| 9090 |
* A regular expression that is simply the character class of the characters |
| 9091 |
* that may be used in a domain name, minus the '-' or '.' |
| 9092 |
*/ |
| 9093 |
var domainNameCharRegex = new RegExp("[" + alphaNumericAndMarksCharsStr + "]"); |
| 9094 |
|
| 9095 |
// NOTE: THIS IS A GENERATED FILE |
| 9096 |
// To update with the latest TLD list, run `npm run update-tld-regex` or `yarn update-tld-regex` (depending on which you have installed) |
| 9097 |
var tldRegex = /(?:xn--vermgensberatung-pwb|xn--vermgensberater-ctb|xn--clchc0ea0b2g2a9gcd|xn--w4r85el8fhu5dnra|northwesternmutual|travelersinsurance|vermögensberatung|xn--3oq18vl8pn36a|xn--5su34j936bgsg|xn--bck1b9a5dre4c|xn--mgbai9azgqp6j|xn--mgberp4a5d4ar|xn--xkc2dl3a5ee0h|vermögensberater|xn--fzys8d69uvgm|xn--mgba7c0bbn0a|xn--xkc2al3hye2a|americanexpress|kerryproperties|sandvikcoromant|xn--i1b6b1a6a2e|xn--kcrx77d1x4a|xn--lgbbat1ad8j|xn--mgba3a4f16a|xn--mgbaakc7dvf|xn--mgbc0a9azcg|xn--nqv7fs00ema|afamilycompany|americanfamily|bananarepublic|cancerresearch|cookingchannel|kerrylogistics|weatherchannel|xn--54b7fta0cc|xn--6qq986b3xl|xn--80aqecdr1a|xn--b4w605ferd|xn--fiq228c5hs|xn--h2breg3eve|xn--jlq61u9w7b|xn--mgba3a3ejt|xn--mgbaam7a8h|xn--mgbayh7gpa|xn--mgbb9fbpob|xn--mgbbh1a71e|xn--mgbca7dzdo|xn--mgbi4ecexp|xn--mgbx4cd0ab|xn--rvc1e0am3e|international|lifeinsurance|spreadbetting|travelchannel|wolterskluwer|xn--eckvdtc9d|xn--fpcrj9c3d|xn--fzc2c9e2c|xn--h2brj9c8c|xn--tiq49xqyj|xn--yfro4i67o|xn--ygbi2ammx|construction|lplfinancial|scholarships|versicherung|xn--3e0b707e|xn--45br5cyl|xn--80adxhks|xn--80asehdb|xn--8y0a063a|xn--gckr3f0f|xn--mgb9awbf|xn--mgbab2bd|xn--mgbgu82a|xn--mgbpl2fh|xn--mgbt3dhd|xn--mk1bu44c|xn--ngbc5azd|xn--ngbe9e0a|xn--ogbpf8fl|xn--qcka1pmc|accountants|barclaycard|blackfriday|blockbuster|bridgestone|calvinklein|contractors|creditunion|engineering|enterprises|foodnetwork|investments|kerryhotels|lamborghini|motorcycles|olayangroup|photography|playstation|productions|progressive|redumbrella|rightathome|williamhill|xn--11b4c3d|xn--1ck2e1b|xn--1qqw23a|xn--2scrj9c|xn--3bst00m|xn--3ds443g|xn--3hcrj9c|xn--42c2d9a|xn--45brj9c|xn--55qw42g|xn--6frz82g|xn--80ao21a|xn--9krt00a|xn--cck2b3b|xn--czr694b|xn--d1acj3b|xn--efvy88h|xn--estv75g|xn--fct429k|xn--fjq720a|xn--flw351e|xn--g2xx48c|xn--gecrj9c|xn--gk3at1e|xn--h2brj9c|xn--hxt814e|xn--imr513n|xn--j6w193g|xn--jvr189m|xn--kprw13d|xn--kpry57d|xn--kpu716f|xn--mgbbh1a|xn--mgbtx2b|xn--mix891f|xn--nyqy26a|xn--otu796d|xn--pbt977c|xn--pgbs0dh|xn--q9jyb4c|xn--rhqv96g|xn--rovu88b|xn--s9brj9c|xn--ses554g|xn--t60b56a|xn--vuq861b|xn--w4rs40l|xn--xhq521b|xn--zfr164b|சிங்கப்பூர்|accountant|apartments|associates|basketball|bnpparibas|boehringer|capitalone|consulting|creditcard|cuisinella|eurovision|extraspace|foundation|healthcare|immobilien|industries|management|mitsubishi|nationwide|newholland|nextdirect|onyourside|properties|protection|prudential|realestate|republican|restaurant|schaeffler|swiftcover|tatamotors|technology|telefonica|university|vistaprint|vlaanderen|volkswagen|xn--30rr7y|xn--3pxu8k|xn--45q11c|xn--4gbrim|xn--55qx5d|xn--5tzm5g|xn--80aswg|xn--90a3ac|xn--9dbq2a|xn--9et52u|xn--c2br7g|xn--cg4bki|xn--czrs0t|xn--czru2d|xn--fiq64b|xn--fiqs8s|xn--fiqz9s|xn--io0a7i|xn--kput3i|xn--mxtq1m|xn--o3cw4h|xn--pssy2u|xn--unup4y|xn--wgbh1c|xn--wgbl6a|xn--y9a3aq|accenture|alfaromeo|allfinanz|amsterdam|analytics|aquarelle|barcelona|bloomberg|christmas|community|directory|education|equipment|fairwinds|financial|firestone|fresenius|frontdoor|fujixerox|furniture|goldpoint|hisamitsu|homedepot|homegoods|homesense|honeywell|institute|insurance|kuokgroup|ladbrokes|lancaster|landrover|lifestyle|marketing|marshalls|melbourne|microsoft|panasonic|passagens|pramerica|richardli|scjohnson|shangrila|solutions|statebank|statefarm|stockholm|travelers|vacations|xn--90ais|xn--c1avg|xn--d1alf|xn--e1a4c|xn--fhbei|xn--j1aef|xn--j1amh|xn--l1acc|xn--ngbrx|xn--nqv7f|xn--p1acf|xn--tckwe|xn--vhquv|yodobashi|abudhabi|airforce|allstate|attorney|barclays|barefoot|bargains|baseball|boutique|bradesco|broadway|brussels|budapest|builders|business|capetown|catering|catholic|chrysler|cipriani|cityeats|cleaning|clinique|clothing|commbank|computer|delivery|deloitte|democrat|diamonds|discount|discover|download|engineer|ericsson|esurance|etisalat|everbank|exchange|feedback|fidelity|firmdale|football|frontier|goodyear|grainger|graphics|guardian|hdfcbank|helsinki|holdings|hospital|infiniti|ipiranga|istanbul|jpmorgan|lighting|lundbeck|marriott|maserati|mckinsey|memorial|merckmsd|mortgage|movistar|observer|partners|pharmacy|pictures|plumbing|property|redstone|reliance|saarland|samsclub|security|services|shopping|showtime|softbank|software|stcgroup|supplies|symantec|training|uconnect|vanguard|ventures|verisign|woodside|xn--90ae|xn--node|xn--p1ai|xn--qxam|yokohama|السعودية|abogado|academy|agakhan|alibaba|android|athleta|auction|audible|auspost|avianca|banamex|bauhaus|bentley|bestbuy|booking|brother|bugatti|capital|caravan|careers|cartier|channel|charity|chintai|citadel|clubmed|college|cologne|comcast|company|compare|contact|cooking|corsica|country|coupons|courses|cricket|cruises|dentist|digital|domains|exposed|express|farmers|fashion|ferrari|ferrero|finance|fishing|fitness|flights|florist|flowers|forsale|frogans|fujitsu|gallery|genting|godaddy|grocery|guitars|hamburg|hangout|hitachi|holiday|hosting|hoteles|hotmail|hyundai|iselect|ismaili|jewelry|juniper|kitchen|komatsu|lacaixa|lancome|lanxess|lasalle|latrobe|leclerc|liaison|limited|lincoln|markets|metlife|monster|netbank|netflix|network|neustar|okinawa|oldnavy|organic|origins|philips|pioneer|politie|realtor|recipes|rentals|reviews|rexroth|samsung|sandvik|schmidt|schwarz|science|shiksha|shriram|singles|staples|starhub|storage|support|surgery|systems|temasek|theater|theatre|tickets|tiffany|toshiba|trading|walmart|wanggou|watches|weather|website|wedding|whoswho|windows|winners|xfinity|yamaxun|youtube|zuerich|католик|اتصالات|الجزائر|العليان|پاکستان|كاثوليك|موبايلي|இந்தியா|abarth|abbott|abbvie|active|africa|agency|airbus|airtel|alipay|alsace|alstom|anquan|aramco|author|bayern|beauty|berlin|bharti|blanco|bostik|boston|broker|camera|career|caseih|casino|center|chanel|chrome|church|circle|claims|clinic|coffee|comsec|condos|coupon|credit|cruise|dating|datsun|dealer|degree|dental|design|direct|doctor|dunlop|dupont|durban|emerck|energy|estate|events|expert|family|flickr|futbol|gallup|garden|george|giving|global|google|gratis|health|hermes|hiphop|hockey|hotels|hughes|imamat|insure|intuit|jaguar|joburg|juegos|kaufen|kinder|kindle|kosher|lancia|latino|lawyer|lefrak|living|locker|london|luxury|madrid|maison|makeup|market|mattel|mobile|mobily|monash|mormon|moscow|museum|mutual|nagoya|natura|nissan|nissay|norton|nowruz|office|olayan|online|oracle|orange|otsuka|pfizer|photos|physio|piaget|pictet|quebec|racing|realty|reisen|repair|report|review|rocher|rogers|ryukyu|safety|sakura|sanofi|school|schule|search|secure|select|shouji|soccer|social|stream|studio|supply|suzuki|swatch|sydney|taipei|taobao|target|tattoo|tennis|tienda|tjmaxx|tkmaxx|toyota|travel|unicom|viajes|viking|villas|virgin|vision|voting|voyage|vuelos|walter|warman|webcam|xihuan|yachts|yandex|zappos|москва|онлайн|ابوظبي|ارامكو|الاردن|المغرب|امارات|فلسطين|مليسيا|भारतम्|இலங்கை|ファッション|actor|adult|aetna|amfam|amica|apple|archi|audio|autos|azure|baidu|beats|bible|bingo|black|boats|bosch|build|canon|cards|chase|cheap|cisco|citic|click|cloud|coach|codes|crown|cymru|dabur|dance|deals|delta|dodge|drive|dubai|earth|edeka|email|epost|epson|faith|fedex|final|forex|forum|gallo|games|gifts|gives|glade|glass|globo|gmail|green|gripe|group|gucci|guide|homes|honda|horse|house|hyatt|ikano|intel|irish|iveco|jetzt|koeln|kyoto|lamer|lease|legal|lexus|lilly|linde|lipsy|lixil|loans|locus|lotte|lotto|lupin|macys|mango|media|miami|money|mopar|movie|nadex|nexus|nikon|ninja|nokia|nowtv|omega|osaka|paris|parts|party|phone|photo|pizza|place|poker|praxi|press|prime|promo|quest|radio|rehab|reise|ricoh|rocks|rodeo|rugby|salon|sener|seven|sharp|shell|shoes|skype|sling|smart|smile|solar|space|sport|stada|store|study|style|sucks|swiss|tatar|tires|tirol|tmall|today|tokyo|tools|toray|total|tours|trade|trust|tunes|tushu|ubank|vegas|video|vodka|volvo|wales|watch|weber|weibo|works|world|xerox|yahoo|zippo|ایران|بازار|بھارت|سودان|سورية|همراه|भारोत|संगठन|বাংলা|భారత్|ഭാരതം|嘉里大酒店|aarp|able|adac|aero|aigo|akdn|ally|amex|arab|army|arpa|arte|asda|asia|audi|auto|baby|band|bank|bbva|beer|best|bike|bing|blog|blue|bofa|bond|book|buzz|cafe|call|camp|care|cars|casa|case|cash|cbre|cern|chat|citi|city|club|cool|coop|cyou|data|date|dclk|deal|dell|desi|diet|dish|docs|doha|duck|duns|dvag|erni|fage|fail|fans|farm|fast|fiat|fido|film|fire|fish|flir|food|ford|free|fund|game|gbiz|gent|ggee|gift|gmbh|gold|golf|goog|guge|guru|hair|haus|hdfc|help|here|hgtv|host|hsbc|icbc|ieee|imdb|immo|info|itau|java|jeep|jobs|jprs|kddi|kiwi|kpmg|kred|land|lego|lgbt|lidl|life|like|limo|link|live|loan|loft|love|ltda|luxe|maif|meet|meme|menu|mini|mint|mobi|moda|moto|name|navy|news|next|nico|nike|ollo|open|page|pars|pccw|pics|ping|pink|play|plus|pohl|porn|post|prod|prof|qpon|raid|read|reit|rent|rest|rich|rmit|room|rsvp|ruhr|safe|sale|sarl|save|saxo|scor|scot|seat|seek|sexy|shaw|shia|shop|show|silk|sina|site|skin|sncf|sohu|song|sony|spot|star|surf|talk|taxi|team|tech|teva|tiaa|tips|town|toys|tube|vana|visa|viva|vivo|vote|voto|wang|weir|wien|wiki|wine|work|xbox|yoga|zara|zero|zone|дети|сайт|بارت|بيتك|ڀارت|تونس|شبكة|عراق|عمان|موقع|भारत|ভারত|ভাৰত|ਭਾਰਤ|ભારત|ଭାରତ|ಭಾರತ|ලංකා|グーグル|クラウド|ポイント|大众汽车|组织机构|電訊盈科|香格里拉|aaa|abb|abc|aco|ads|aeg|afl|aig|anz|aol|app|art|aws|axa|bar|bbc|bbt|bcg|bcn|bet|bid|bio|biz|bms|bmw|bnl|bom|boo|bot|box|buy|bzh|cab|cal|cam|car|cat|cba|cbn|cbs|ceb|ceo|cfa|cfd|com|crs|csc|dad|day|dds|dev|dhl|diy|dnp|dog|dot|dtv|dvr|eat|eco|edu|esq|eus|fan|fit|fly|foo|fox|frl|ftr|fun|fyi|gal|gap|gdn|gea|gle|gmo|gmx|goo|gop|got|gov|hbo|hiv|hkt|hot|how|ibm|ice|icu|ifm|inc|ing|ink|int|ist|itv|jcb|jcp|jio|jll|jmp|jnj|jot|joy|kfh|kia|kim|kpn|krd|lat|law|lds|llc|lol|lpl|ltd|man|map|mba|med|men|mil|mit|mlb|mls|mma|moe|moi|mom|mov|msd|mtn|mtr|nab|nba|nec|net|new|nfl|ngo|nhk|now|nra|nrw|ntt|nyc|obi|off|one|ong|onl|ooo|org|ott|ovh|pay|pet|phd|pid|pin|pnc|pro|pru|pub|pwc|qvc|red|ren|ril|rio|rip|run|rwe|sap|sas|sbi|sbs|sca|scb|ses|sew|sex|sfr|ski|sky|soy|srl|srt|stc|tab|tax|tci|tdk|tel|thd|tjx|top|trv|tui|tvs|ubs|uno|uol|ups|vet|vig|vin|vip|wed|win|wme|wow|wtc|wtf|xin|xxx|xyz|you|yun|zip|бел|ком|қаз|мкд|мон|орг|рус|срб|укр|հայ|קום|عرب|قطر|كوم|مصر|कॉम|नेट|คอม|ไทย|ストア|セール|みんな|中文网|天主教|我爱你|新加坡|淡马锡|诺基亚|飞利浦|ac|ad|ae|af|ag|ai|al|am|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw|ελ|бг|ею|рф|გე|닷넷|닷컴|삼성|한국|コム|世界|中信|中国|中國|企业|佛山|信息|健康|八卦|公司|公益|台湾|台灣|商城|商店|商标|嘉里|在线|大拿|娱乐|家電|工行|广东|微博|慈善|手机|手表|招聘|政务|政府|新闻|时尚|書籍|机构|游戏|澳門|点看|珠宝|移动|网址|网店|网站|网络|联通|谷歌|购物|通販|集团|食品|餐厅|香港)/; |
| 9098 |
|
| 9099 |
// For debugging: search for other "For debugging" lines |
| 9100 |
// import CliTable from 'cli-table'; |
| 9101 |
/** |
| 9102 |
* @class Autolinker.matcher.Email |
| 9103 |
* @extends Autolinker.matcher.Matcher |
| 9104 |
* |
| 9105 |
* Matcher to find email matches in an input string. |
| 9106 |
* |
| 9107 |
* See this class's superclass ({@link Autolinker.matcher.Matcher}) for more details. |
| 9108 |
*/ |
| 9109 |
var EmailMatcher = /** @class */ (function (_super) { |
| 9110 |
__extends(EmailMatcher, _super); |
| 9111 |
function EmailMatcher() { |
| 9112 |
var _this = _super !== null && _super.apply(this, arguments) || this; |
| 9113 |
/** |
| 9114 |
* Valid characters that can be used in the "local" part of an email address, |
| 9115 |
* i.e. the "name" part of "[email protected]" |
| 9116 |
*/ |
| 9117 |
_this.localPartCharRegex = new RegExp("[" + alphaNumericAndMarksCharsStr + "!#$%&'*+/=?^_`{|}~-]"); |
| 9118 |
/** |
| 9119 |
* Stricter TLD regex which adds a beginning and end check to ensure |
| 9120 |
* the string is a valid TLD |
| 9121 |
*/ |
| 9122 |
_this.strictTldRegex = new RegExp("^" + tldRegex.source + "$"); |
| 9123 |
return _this; |
| 9124 |
} |
| 9125 |
/** |
| 9126 |
* @inheritdoc |
| 9127 |
*/ |
| 9128 |
EmailMatcher.prototype.parseMatches = function (text) { |
| 9129 |
var tagBuilder = this.tagBuilder, localPartCharRegex = this.localPartCharRegex, strictTldRegex = this.strictTldRegex, matches = [], len = text.length, noCurrentEmailMatch = new CurrentEmailMatch(); |
| 9130 |
// for matching a 'mailto:' prefix |
| 9131 |
var mailtoTransitions = { |
| 9132 |
'm': 'a', |
| 9133 |
'a': 'i', |
| 9134 |
'i': 'l', |
| 9135 |
'l': 't', |
| 9136 |
't': 'o', |
| 9137 |
'o': ':', |
| 9138 |
}; |
| 9139 |
var charIdx = 0, state = 0 /* NonEmailMatch */, currentEmailMatch = noCurrentEmailMatch; |
| 9140 |
// For debugging: search for other "For debugging" lines |
| 9141 |
// const table = new CliTable( { |
| 9142 |
// head: [ 'charIdx', 'char', 'state', 'charIdx', 'currentEmailAddress.idx', 'hasDomainDot' ] |
| 9143 |
// } ); |
| 9144 |
while (charIdx < len) { |
| 9145 |
var char = text.charAt(charIdx); |
| 9146 |
// For debugging: search for other "For debugging" lines |
| 9147 |
// table.push( |
| 9148 |
// [ charIdx, char, State[ state ], charIdx, currentEmailAddress.idx, currentEmailAddress.hasDomainDot ] |
| 9149 |
// ); |
| 9150 |
switch (state) { |
| 9151 |
case 0 /* NonEmailMatch */: |
| 9152 |
stateNonEmailAddress(char); |
| 9153 |
break; |
| 9154 |
case 1 /* Mailto */: |
| 9155 |
stateMailTo(text.charAt(charIdx - 1), char); |
| 9156 |
break; |
| 9157 |
case 2 /* LocalPart */: |
| 9158 |
stateLocalPart(char); |
| 9159 |
break; |
| 9160 |
case 3 /* LocalPartDot */: |
| 9161 |
stateLocalPartDot(char); |
| 9162 |
break; |
| 9163 |
case 4 /* AtSign */: |
| 9164 |
stateAtSign(char); |
| 9165 |
break; |
| 9166 |
case 5 /* DomainChar */: |
| 9167 |
stateDomainChar(char); |
| 9168 |
break; |
| 9169 |
case 6 /* DomainHyphen */: |
| 9170 |
stateDomainHyphen(char); |
| 9171 |
break; |
| 9172 |
case 7 /* DomainDot */: |
| 9173 |
stateDomainDot(char); |
| 9174 |
break; |
| 9175 |
default: |
| 9176 |
throwUnhandledCaseError(state); |
| 9177 |
} |
| 9178 |
// For debugging: search for other "For debugging" lines |
| 9179 |
// table.push( |
| 9180 |
// [ charIdx, char, State[ state ], charIdx, currentEmailAddress.idx, currentEmailAddress.hasDomainDot ] |
| 9181 |
// ); |
| 9182 |
charIdx++; |
| 9183 |
} |
| 9184 |
// Capture any valid match at the end of the string |
| 9185 |
captureMatchIfValidAndReset(); |
| 9186 |
// For debugging: search for other "For debugging" lines |
| 9187 |
//console.log( '\n' + table.toString() ); |
| 9188 |
return matches; |
| 9189 |
// Handles the state when we're not in an email address |
| 9190 |
function stateNonEmailAddress(char) { |
| 9191 |
if (char === 'm') { |
| 9192 |
beginEmailMatch(1 /* Mailto */); |
| 9193 |
} |
| 9194 |
else if (localPartCharRegex.test(char)) { |
| 9195 |
beginEmailMatch(); |
| 9196 |
} |
| 9197 |
} |
| 9198 |
// Handles if we're reading a 'mailto:' prefix on the string |
| 9199 |
function stateMailTo(prevChar, char) { |
| 9200 |
if (prevChar === ':') { |
| 9201 |
// We've reached the end of the 'mailto:' prefix |
| 9202 |
if (localPartCharRegex.test(char)) { |
| 9203 |
state = 2 /* LocalPart */; |
| 9204 |
currentEmailMatch = new CurrentEmailMatch(__assign({}, currentEmailMatch, { hasMailtoPrefix: true })); |
| 9205 |
} |
| 9206 |
else { |
| 9207 |
// we've matched 'mailto:' but didn't get anything meaningful |
| 9208 |
// immediately afterwards (for example, we encountered a |
| 9209 |
// space character, or an '@' character which formed 'mailto:@' |
| 9210 |
resetToNonEmailMatchState(); |
| 9211 |
} |
| 9212 |
} |
| 9213 |
else if (mailtoTransitions[prevChar] === char) ; |
| 9214 |
else if (localPartCharRegex.test(char)) { |
| 9215 |
// We we're reading a prefix of 'mailto:', but encountered a |
| 9216 |
// different character that didn't continue the prefix |
| 9217 |
state = 2 /* LocalPart */; |
| 9218 |
} |
| 9219 |
else if (char === '.') { |
| 9220 |
// We we're reading a prefix of 'mailto:', but encountered a |
| 9221 |
// dot character |
| 9222 |
state = 3 /* LocalPartDot */; |
| 9223 |
} |
| 9224 |
else if (char === '@') { |
| 9225 |
// We we're reading a prefix of 'mailto:', but encountered a |
| 9226 |
// an @ character |
| 9227 |
state = 4 /* AtSign */; |
| 9228 |
} |
| 9229 |
else { |
| 9230 |
// not an email address character, return to "NonEmailAddress" state |
| 9231 |
resetToNonEmailMatchState(); |
| 9232 |
} |
| 9233 |
} |
| 9234 |
// Handles the state when we're currently in the "local part" of an |
| 9235 |
// email address (as opposed to the "domain part") |
| 9236 |
function stateLocalPart(char) { |
| 9237 |
if (char === '.') { |
| 9238 |
state = 3 /* LocalPartDot */; |
| 9239 |
} |
| 9240 |
else if (char === '@') { |
| 9241 |
state = 4 /* AtSign */; |
| 9242 |
} |
| 9243 |
else if (localPartCharRegex.test(char)) ; |
| 9244 |
else { |
| 9245 |
// not an email address character, return to "NonEmailAddress" state |
| 9246 |
resetToNonEmailMatchState(); |
| 9247 |
} |
| 9248 |
} |
| 9249 |
// Handles the state where we've read |
| 9250 |
function stateLocalPartDot(char) { |
| 9251 |
if (char === '.') { |
| 9252 |
// We read a second '.' in a row, not a valid email address |
| 9253 |
// local part |
| 9254 |
resetToNonEmailMatchState(); |
| 9255 |
} |
| 9256 |
else if (char === '@') { |
| 9257 |
// We read the '@' character immediately after a dot ('.'), not |
| 9258 |
// an email address |
| 9259 |
resetToNonEmailMatchState(); |
| 9260 |
} |
| 9261 |
else if (localPartCharRegex.test(char)) { |
| 9262 |
state = 2 /* LocalPart */; |
| 9263 |
} |
| 9264 |
else { |
| 9265 |
// Anything else, not an email address |
| 9266 |
resetToNonEmailMatchState(); |
| 9267 |
} |
| 9268 |
} |
| 9269 |
function stateAtSign(char) { |
| 9270 |
if (domainNameCharRegex.test(char)) { |
| 9271 |
state = 5 /* DomainChar */; |
| 9272 |
} |
| 9273 |
else { |
| 9274 |
// Anything else, not an email address |
| 9275 |
resetToNonEmailMatchState(); |
| 9276 |
} |
| 9277 |
} |
| 9278 |
function stateDomainChar(char) { |
| 9279 |
if (char === '.') { |
| 9280 |
state = 7 /* DomainDot */; |
| 9281 |
} |
| 9282 |
else if (char === '-') { |
| 9283 |
state = 6 /* DomainHyphen */; |
| 9284 |
} |
| 9285 |
else if (domainNameCharRegex.test(char)) ; |
| 9286 |
else { |
| 9287 |
// Anything else, we potentially matched if the criteria has |
| 9288 |
// been met |
| 9289 |
captureMatchIfValidAndReset(); |
| 9290 |
} |
| 9291 |
} |
| 9292 |
function stateDomainHyphen(char) { |
| 9293 |
if (char === '-' || char === '.') { |
| 9294 |
// Not valid to have two hyphens ("--") or hypen+dot ("-.") |
| 9295 |
captureMatchIfValidAndReset(); |
| 9296 |
} |
| 9297 |
else if (domainNameCharRegex.test(char)) { |
| 9298 |
state = 5 /* DomainChar */; |
| 9299 |
} |
| 9300 |
else { |
| 9301 |
// Anything else |
| 9302 |
captureMatchIfValidAndReset(); |
| 9303 |
} |
| 9304 |
} |
| 9305 |
function stateDomainDot(char) { |
| 9306 |
if (char === '.' || char === '-') { |
| 9307 |
// not valid to have two dots ("..") or dot+hypen (".-") |
| 9308 |
captureMatchIfValidAndReset(); |
| 9309 |
} |
| 9310 |
else if (domainNameCharRegex.test(char)) { |
| 9311 |
state = 5 /* DomainChar */; |
| 9312 |
// After having read a '.' and then a valid domain character, |
| 9313 |
// we now know that the domain part of the email is valid, and |
| 9314 |
// we have found at least a partial EmailMatch (however, the |
| 9315 |
// email address may have additional characters from this point) |
| 9316 |
currentEmailMatch = new CurrentEmailMatch(__assign({}, currentEmailMatch, { hasDomainDot: true })); |
| 9317 |
} |
| 9318 |
else { |
| 9319 |
// Anything else |
| 9320 |
captureMatchIfValidAndReset(); |
| 9321 |
} |
| 9322 |
} |
| 9323 |
function beginEmailMatch(newState) { |
| 9324 |
if (newState === void 0) { newState = 2 /* LocalPart */; } |
| 9325 |
state = newState; |
| 9326 |
currentEmailMatch = new CurrentEmailMatch({ idx: charIdx }); |
| 9327 |
} |
| 9328 |
function resetToNonEmailMatchState() { |
| 9329 |
state = 0 /* NonEmailMatch */; |
| 9330 |
currentEmailMatch = noCurrentEmailMatch; |
| 9331 |
} |
| 9332 |
/* |
| 9333 |
* Captures the current email address as an EmailMatch if it's valid, |
| 9334 |
* and resets the state to read another email address. |
| 9335 |
*/ |
| 9336 |
function captureMatchIfValidAndReset() { |
| 9337 |
if (currentEmailMatch.hasDomainDot) { // we need at least one dot in the domain to be considered a valid email address |
| 9338 |
var matchedText = text.slice(currentEmailMatch.idx, charIdx); |
| 9339 |
// If we read a '.' or '-' char that ended the email address |
| 9340 |
// (valid domain name characters, but only valid email address |
| 9341 |
// characters if they are followed by something else), strip |
| 9342 |
// it off now |
| 9343 |
if (/[-.]$/.test(matchedText)) { |
| 9344 |
matchedText = matchedText.slice(0, -1); |
| 9345 |
} |
| 9346 |
var emailAddress = currentEmailMatch.hasMailtoPrefix |
| 9347 |
? matchedText.slice('mailto:'.length) |
| 9348 |
: matchedText; |
| 9349 |
// if the email address has a valid TLD, add it to the list of matches |
| 9350 |
if (doesEmailHaveValidTld(emailAddress)) { |
| 9351 |
matches.push(new EmailMatch({ |
| 9352 |
tagBuilder: tagBuilder, |
| 9353 |
matchedText: matchedText, |
| 9354 |
offset: currentEmailMatch.idx, |
| 9355 |
email: emailAddress |
| 9356 |
})); |
| 9357 |
} |
| 9358 |
} |
| 9359 |
resetToNonEmailMatchState(); |
| 9360 |
/** |
| 9361 |
* Determines if the given email address has a valid TLD or not |
| 9362 |
* @param {string} emailAddress - email address |
| 9363 |
* @return {Boolean} - true is email have valid TLD, false otherwise |
| 9364 |
*/ |
| 9365 |
function doesEmailHaveValidTld(emailAddress) { |
| 9366 |
var emailAddressTld = emailAddress.split('.').pop() || ''; |
| 9367 |
var emailAddressNormalized = emailAddressTld.toLowerCase(); |
| 9368 |
var isValidTld = strictTldRegex.test(emailAddressNormalized); |
| 9369 |
return isValidTld; |
| 9370 |
} |
| 9371 |
} |
| 9372 |
}; |
| 9373 |
return EmailMatcher; |
| 9374 |
}(Matcher)); |
| 9375 |
var CurrentEmailMatch = /** @class */ (function () { |
| 9376 |
function CurrentEmailMatch(cfg) { |
| 9377 |
if (cfg === void 0) { cfg = {}; } |
| 9378 |
this.idx = cfg.idx !== undefined ? cfg.idx : -1; |
| 9379 |
this.hasMailtoPrefix = !!cfg.hasMailtoPrefix; |
| 9380 |
this.hasDomainDot = !!cfg.hasDomainDot; |
| 9381 |
} |
| 9382 |
return CurrentEmailMatch; |
| 9383 |
}()); |
| 9384 |
|
| 9385 |
/** |
| 9386 |
* @private |
| 9387 |
* @class Autolinker.matcher.UrlMatchValidator |
| 9388 |
* @singleton |
| 9389 |
* |
| 9390 |
* Used by Autolinker to filter out false URL positives from the |
| 9391 |
* {@link Autolinker.matcher.Url UrlMatcher}. |
| 9392 |
* |
| 9393 |
* Due to the limitations of regular expressions (including the missing feature |
| 9394 |
* of look-behinds in JS regular expressions), we cannot always determine the |
| 9395 |
* validity of a given match. This class applies a bit of additional logic to |
| 9396 |
* filter out any false positives that have been matched by the |
| 9397 |
* {@link Autolinker.matcher.Url UrlMatcher}. |
| 9398 |
*/ |
| 9399 |
var UrlMatchValidator = /** @class */ (function () { |
| 9400 |
function UrlMatchValidator() { |
| 9401 |
} |
| 9402 |
/** |
| 9403 |
* Determines if a given URL match found by the {@link Autolinker.matcher.Url UrlMatcher} |
| 9404 |
* is valid. Will return `false` for: |
| 9405 |
* |
| 9406 |
* 1) URL matches which do not have at least have one period ('.') in the |
| 9407 |
* domain name (effectively skipping over matches like "abc:def"). |
| 9408 |
* However, URL matches with a protocol will be allowed (ex: 'http://localhost') |
| 9409 |
* 2) URL matches which do not have at least one word character in the |
| 9410 |
* domain name (effectively skipping over matches like "git:1.0"). |
| 9411 |
* 3) A protocol-relative url match (a URL beginning with '//') whose |
| 9412 |
* previous character is a word character (effectively skipping over |
| 9413 |
* strings like "abc//google.com") |
| 9414 |
* |
| 9415 |
* Otherwise, returns `true`. |
| 9416 |
* |
| 9417 |
* @param {String} urlMatch The matched URL, if there was one. Will be an |
| 9418 |
* empty string if the match is not a URL match. |
| 9419 |
* @param {String} protocolUrlMatch The match URL string for a protocol |
| 9420 |
* match. Ex: 'http://yahoo.com'. This is used to match something like |
| 9421 |
* 'http://localhost', where we won't double check that the domain name |
| 9422 |
* has at least one '.' in it. |
| 9423 |
* @return {Boolean} `true` if the match given is valid and should be |
| 9424 |
* processed, or `false` if the match is invalid and/or should just not be |
| 9425 |
* processed. |
| 9426 |
*/ |
| 9427 |
UrlMatchValidator.isValid = function (urlMatch, protocolUrlMatch) { |
| 9428 |
if ((protocolUrlMatch && !this.isValidUriScheme(protocolUrlMatch)) || |
| 9429 |
this.urlMatchDoesNotHaveProtocolOrDot(urlMatch, protocolUrlMatch) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost') |
| 9430 |
(this.urlMatchDoesNotHaveAtLeastOneWordChar(urlMatch, protocolUrlMatch) && // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0" |
| 9431 |
!this.isValidIpAddress(urlMatch)) || // Except if it's an IP address |
| 9432 |
this.containsMultipleDots(urlMatch)) { |
| 9433 |
return false; |
| 9434 |
} |
| 9435 |
return true; |
| 9436 |
}; |
| 9437 |
UrlMatchValidator.isValidIpAddress = function (uriSchemeMatch) { |
| 9438 |
var newRegex = new RegExp(this.hasFullProtocolRegex.source + this.ipRegex.source); |
| 9439 |
var uriScheme = uriSchemeMatch.match(newRegex); |
| 9440 |
return uriScheme !== null; |
| 9441 |
}; |
| 9442 |
UrlMatchValidator.containsMultipleDots = function (urlMatch) { |
| 9443 |
var stringBeforeSlash = urlMatch; |
| 9444 |
if (this.hasFullProtocolRegex.test(urlMatch)) { |
| 9445 |
stringBeforeSlash = urlMatch.split('://')[1]; |
| 9446 |
} |
| 9447 |
return stringBeforeSlash.split('/')[0].indexOf("..") > -1; |
| 9448 |
}; |
| 9449 |
/** |
| 9450 |
* Determines if the URI scheme is a valid scheme to be autolinked. Returns |
| 9451 |
* `false` if the scheme is 'javascript:' or 'vbscript:' |
| 9452 |
* |
| 9453 |
* @private |
| 9454 |
* @param {String} uriSchemeMatch The match URL string for a full URI scheme |
| 9455 |
* match. Ex: 'http://yahoo.com' or 'mailto:[email protected]'. |
| 9456 |
* @return {Boolean} `true` if the scheme is a valid one, `false` otherwise. |
| 9457 |
*/ |
| 9458 |
UrlMatchValidator.isValidUriScheme = function (uriSchemeMatch) { |
| 9459 |
var uriSchemeMatchArr = uriSchemeMatch.match(this.uriSchemeRegex), uriScheme = uriSchemeMatchArr && uriSchemeMatchArr[0].toLowerCase(); |
| 9460 |
return (uriScheme !== 'javascript:' && uriScheme !== 'vbscript:'); |
| 9461 |
}; |
| 9462 |
/** |
| 9463 |
* Determines if a URL match does not have either: |
| 9464 |
* |
| 9465 |
* a) a full protocol (i.e. 'http://'), or |
| 9466 |
* b) at least one dot ('.') in the domain name (for a non-full-protocol |
| 9467 |
* match). |
| 9468 |
* |
| 9469 |
* Either situation is considered an invalid URL (ex: 'git:d' does not have |
| 9470 |
* either the '://' part, or at least one dot in the domain name. If the |
| 9471 |
* match was 'git:abc.com', we would consider this valid.) |
| 9472 |
* |
| 9473 |
* @private |
| 9474 |
* @param {String} urlMatch The matched URL, if there was one. Will be an |
| 9475 |
* empty string if the match is not a URL match. |
| 9476 |
* @param {String} protocolUrlMatch The match URL string for a protocol |
| 9477 |
* match. Ex: 'http://yahoo.com'. This is used to match something like |
| 9478 |
* 'http://localhost', where we won't double check that the domain name |
| 9479 |
* has at least one '.' in it. |
| 9480 |
* @return {Boolean} `true` if the URL match does not have a full protocol, |
| 9481 |
* or at least one dot ('.') in a non-full-protocol match. |
| 9482 |
*/ |
| 9483 |
UrlMatchValidator.urlMatchDoesNotHaveProtocolOrDot = function (urlMatch, protocolUrlMatch) { |
| 9484 |
return (!!urlMatch && (!protocolUrlMatch || !this.hasFullProtocolRegex.test(protocolUrlMatch)) && urlMatch.indexOf('.') === -1); |
| 9485 |
}; |
| 9486 |
/** |
| 9487 |
* Determines if a URL match does not have at least one word character after |
| 9488 |
* the protocol (i.e. in the domain name). |
| 9489 |
* |
| 9490 |
* At least one letter character must exist in the domain name after a |
| 9491 |
* protocol match. Ex: skip over something like "git:1.0" |
| 9492 |
* |
| 9493 |
* @private |
| 9494 |
* @param {String} urlMatch The matched URL, if there was one. Will be an |
| 9495 |
* empty string if the match is not a URL match. |
| 9496 |
* @param {String} protocolUrlMatch The match URL string for a protocol |
| 9497 |
* match. Ex: 'http://yahoo.com'. This is used to know whether or not we |
| 9498 |
* have a protocol in the URL string, in order to check for a word |
| 9499 |
* character after the protocol separator (':'). |
| 9500 |
* @return {Boolean} `true` if the URL match does not have at least one word |
| 9501 |
* character in it after the protocol, `false` otherwise. |
| 9502 |
*/ |
| 9503 |
UrlMatchValidator.urlMatchDoesNotHaveAtLeastOneWordChar = function (urlMatch, protocolUrlMatch) { |
| 9504 |
if (urlMatch && protocolUrlMatch) { |
| 9505 |
return !this.hasWordCharAfterProtocolRegex.test(urlMatch); |
| 9506 |
} |
| 9507 |
else { |
| 9508 |
return false; |
| 9509 |
} |
| 9510 |
}; |
| 9511 |
/** |
| 9512 |
* Regex to test for a full protocol, with the two trailing slashes. Ex: 'http://' |
| 9513 |
* |
| 9514 |
* @private |
| 9515 |
* @property {RegExp} hasFullProtocolRegex |
| 9516 |
*/ |
| 9517 |
UrlMatchValidator.hasFullProtocolRegex = /^[A-Za-z][-.+A-Za-z0-9]*:\/\//; |
| 9518 |
/** |
| 9519 |
* Regex to find the URI scheme, such as 'mailto:'. |
| 9520 |
* |
| 9521 |
* This is used to filter out 'javascript:' and 'vbscript:' schemes. |
| 9522 |
* |
| 9523 |
* @private |
| 9524 |
* @property {RegExp} uriSchemeRegex |
| 9525 |
*/ |
| 9526 |
UrlMatchValidator.uriSchemeRegex = /^[A-Za-z][-.+A-Za-z0-9]*:/; |
| 9527 |
/** |
| 9528 |
* Regex to determine if at least one word char exists after the protocol (i.e. after the ':') |
| 9529 |
* |
| 9530 |
* @private |
| 9531 |
* @property {RegExp} hasWordCharAfterProtocolRegex |
| 9532 |
*/ |
| 9533 |
UrlMatchValidator.hasWordCharAfterProtocolRegex = new RegExp(":[^\\s]*?[" + alphaCharsStr + "]"); |
| 9534 |
/** |
| 9535 |
* Regex to determine if the string is a valid IP address |
| 9536 |
* |
| 9537 |
* @private |
| 9538 |
* @property {RegExp} ipRegex |
| 9539 |
*/ |
| 9540 |
UrlMatchValidator.ipRegex = /[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?(:[0-9]*)?\/?$/; |
| 9541 |
return UrlMatchValidator; |
| 9542 |
}()); |
| 9543 |
|
| 9544 |
/** |
| 9545 |
* @class Autolinker.matcher.Url |
| 9546 |
* @extends Autolinker.matcher.Matcher |
| 9547 |
* |
| 9548 |
* Matcher to find URL matches in an input string. |
| 9549 |
* |
| 9550 |
* See this class's superclass ({@link Autolinker.matcher.Matcher}) for more details. |
| 9551 |
*/ |
| 9552 |
var UrlMatcher = /** @class */ (function (_super) { |
| 9553 |
__extends(UrlMatcher, _super); |
| 9554 |
/** |
| 9555 |
* @method constructor |
| 9556 |
* @param {Object} cfg The configuration properties for the Match instance, |
| 9557 |
* specified in an Object (map). |
| 9558 |
*/ |
| 9559 |
function UrlMatcher(cfg) { |
| 9560 |
var _this = _super.call(this, cfg) || this; |
| 9561 |
/** |
| 9562 |
* @cfg {Object} stripPrefix (required) |
| 9563 |
* |
| 9564 |
* The Object form of {@link Autolinker#cfg-stripPrefix}. |
| 9565 |
*/ |
| 9566 |
_this.stripPrefix = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 9567 |
/** |
| 9568 |
* @cfg {Boolean} stripTrailingSlash (required) |
| 9569 |
* @inheritdoc Autolinker#stripTrailingSlash |
| 9570 |
*/ |
| 9571 |
_this.stripTrailingSlash = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 9572 |
/** |
| 9573 |
* @cfg {Boolean} decodePercentEncoding (required) |
| 9574 |
* @inheritdoc Autolinker#decodePercentEncoding |
| 9575 |
*/ |
| 9576 |
_this.decodePercentEncoding = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 9577 |
/** |
| 9578 |
* @protected |
| 9579 |
* @property {RegExp} matcherRegex |
| 9580 |
* |
| 9581 |
* The regular expression to match URLs with an optional scheme, port |
| 9582 |
* number, path, query string, and hash anchor. |
| 9583 |
* |
| 9584 |
* Example matches: |
| 9585 |
* |
| 9586 |
* http://google.com |
| 9587 |
* www.google.com |
| 9588 |
* google.com/path/to/file?q1=1&q2=2#myAnchor |
| 9589 |
* |
| 9590 |
* |
| 9591 |
* This regular expression will have the following capturing groups: |
| 9592 |
* |
| 9593 |
* 1. Group that matches a scheme-prefixed URL (i.e. 'http://google.com'). |
| 9594 |
* This is used to match scheme URLs with just a single word, such as |
| 9595 |
* 'http://localhost', where we won't double check that the domain name |
| 9596 |
* has at least one dot ('.') in it. |
| 9597 |
* 2. Group that matches a 'www.' prefixed URL. This is only matched if the |
| 9598 |
* 'www.' text was not prefixed by a scheme (i.e.: not prefixed by |
| 9599 |
* 'http://', 'ftp:', etc.) |
| 9600 |
* 3. A protocol-relative ('//') match for the case of a 'www.' prefixed |
| 9601 |
* URL. Will be an empty string if it is not a protocol-relative match. |
| 9602 |
* We need to know the character before the '//' in order to determine |
| 9603 |
* if it is a valid match or the // was in a string we don't want to |
| 9604 |
* auto-link. |
| 9605 |
* 4. Group that matches a known TLD (top level domain), when a scheme |
| 9606 |
* or 'www.'-prefixed domain is not matched. |
| 9607 |
* 5. A protocol-relative ('//') match for the case of a known TLD prefixed |
| 9608 |
* URL. Will be an empty string if it is not a protocol-relative match. |
| 9609 |
* See #3 for more info. |
| 9610 |
*/ |
| 9611 |
_this.matcherRegex = (function () { |
| 9612 |
var schemeRegex = /(?:[A-Za-z][-.+A-Za-z0-9]{0,63}:(?![A-Za-z][-.+A-Za-z0-9]{0,63}:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex) |
| 9613 |
wwwRegex = /(?:www\.)/, // starting with 'www.' |
| 9614 |
// Allow optional path, query string, and hash anchor, not ending in the following characters: "?!:,.;" |
| 9615 |
// http://blog.codinghorror.com/the-problem-with-urls/ |
| 9616 |
urlSuffixRegex = new RegExp('[/?#](?:[' + alphaNumericAndMarksCharsStr + '\\-+&@#/%=~_()|\'$*\\[\\]?!:,.;\u2713]*[' + alphaNumericAndMarksCharsStr + '\\-+&@#/%=~_()|\'$*\\[\\]\u2713])?'); |
| 9617 |
return new RegExp([ |
| 9618 |
'(?:', |
| 9619 |
'(', |
| 9620 |
schemeRegex.source, |
| 9621 |
getDomainNameStr(2), |
| 9622 |
')', |
| 9623 |
'|', |
| 9624 |
'(', |
| 9625 |
'(//)?', |
| 9626 |
wwwRegex.source, |
| 9627 |
getDomainNameStr(6), |
| 9628 |
')', |
| 9629 |
'|', |
| 9630 |
'(', |
| 9631 |
'(//)?', |
| 9632 |
getDomainNameStr(10) + '\\.', |
| 9633 |
tldRegex.source, |
| 9634 |
'(?![-' + alphaNumericCharsStr + '])', |
| 9635 |
')', |
| 9636 |
')', |
| 9637 |
'(?::[0-9]+)?', |
| 9638 |
'(?:' + urlSuffixRegex.source + ')?' // match for path, query string, and/or hash anchor - optional |
| 9639 |
].join(""), 'gi'); |
| 9640 |
})(); |
| 9641 |
/** |
| 9642 |
* A regular expression to use to check the character before a protocol-relative |
| 9643 |
* URL match. We don't want to match a protocol-relative URL if it is part |
| 9644 |
* of another word. |
| 9645 |
* |
| 9646 |
* For example, we want to match something like "Go to: //google.com", |
| 9647 |
* but we don't want to match something like "abc//google.com" |
| 9648 |
* |
| 9649 |
* This regular expression is used to test the character before the '//'. |
| 9650 |
* |
| 9651 |
* @protected |
| 9652 |
* @type {RegExp} wordCharRegExp |
| 9653 |
*/ |
| 9654 |
_this.wordCharRegExp = new RegExp('[' + alphaNumericAndMarksCharsStr + ']'); |
| 9655 |
_this.stripPrefix = cfg.stripPrefix; |
| 9656 |
_this.stripTrailingSlash = cfg.stripTrailingSlash; |
| 9657 |
_this.decodePercentEncoding = cfg.decodePercentEncoding; |
| 9658 |
return _this; |
| 9659 |
} |
| 9660 |
/** |
| 9661 |
* @inheritdoc |
| 9662 |
*/ |
| 9663 |
UrlMatcher.prototype.parseMatches = function (text) { |
| 9664 |
var matcherRegex = this.matcherRegex, stripPrefix = this.stripPrefix, stripTrailingSlash = this.stripTrailingSlash, decodePercentEncoding = this.decodePercentEncoding, tagBuilder = this.tagBuilder, matches = [], match; |
| 9665 |
var _loop_1 = function () { |
| 9666 |
var matchStr = match[0], schemeUrlMatch = match[1], wwwUrlMatch = match[4], wwwProtocolRelativeMatch = match[5], |
| 9667 |
//tldUrlMatch = match[ 8 ], -- not needed at the moment |
| 9668 |
tldProtocolRelativeMatch = match[9], offset = match.index, protocolRelativeMatch = wwwProtocolRelativeMatch || tldProtocolRelativeMatch, prevChar = text.charAt(offset - 1); |
| 9669 |
if (!UrlMatchValidator.isValid(matchStr, schemeUrlMatch)) { |
| 9670 |
return "continue"; |
| 9671 |
} |
| 9672 |
// If the match is preceded by an '@' character, then it is either |
| 9673 |
// an email address or a username. Skip these types of matches. |
| 9674 |
if (offset > 0 && prevChar === '@') { |
| 9675 |
return "continue"; |
| 9676 |
} |
| 9677 |
// If it's a protocol-relative '//' match, but the character before the '//' |
| 9678 |
// was a word character (i.e. a letter/number), then we found the '//' in the |
| 9679 |
// middle of another word (such as "asdf//asdf.com"). In this case, skip the |
| 9680 |
// match. |
| 9681 |
if (offset > 0 && protocolRelativeMatch && this_1.wordCharRegExp.test(prevChar)) { |
| 9682 |
return "continue"; |
| 9683 |
} |
| 9684 |
// If the URL ends with a question mark, don't include the question |
| 9685 |
// mark as part of the URL. We'll assume the question mark was the |
| 9686 |
// end of a sentence, such as: "Going to google.com?" |
| 9687 |
if (/\?$/.test(matchStr)) { |
| 9688 |
matchStr = matchStr.substr(0, matchStr.length - 1); |
| 9689 |
} |
| 9690 |
// Handle a closing parenthesis or square bracket at the end of the |
| 9691 |
// match, and exclude it if there is not a matching open parenthesis |
| 9692 |
// or square bracket in the match itself. |
| 9693 |
if (this_1.matchHasUnbalancedClosingParen(matchStr)) { |
| 9694 |
matchStr = matchStr.substr(0, matchStr.length - 1); // remove the trailing ")" |
| 9695 |
} |
| 9696 |
else { |
| 9697 |
// Handle an invalid character after the TLD |
| 9698 |
var pos = this_1.matchHasInvalidCharAfterTld(matchStr, schemeUrlMatch); |
| 9699 |
if (pos > -1) { |
| 9700 |
matchStr = matchStr.substr(0, pos); // remove the trailing invalid chars |
| 9701 |
} |
| 9702 |
} |
| 9703 |
// The autolinker accepts many characters in a url's scheme (like `fake://test.com`). |
| 9704 |
// However, in cases where a URL is missing whitespace before an obvious link, |
| 9705 |
// (for example: `nowhitespacehttp://www.test.com`), we only want the match to start |
| 9706 |
// at the http:// part. We will check if the match contains a common scheme and then |
| 9707 |
// shift the match to start from there. |
| 9708 |
var foundCommonScheme = ['http://', 'https://'].find(function (commonScheme) { return !!schemeUrlMatch && schemeUrlMatch.indexOf(commonScheme) !== -1; }); |
| 9709 |
if (foundCommonScheme) { |
| 9710 |
// If we found an overmatched URL, we want to find the index |
| 9711 |
// of where the match should start and shift the match to |
| 9712 |
// start from the beginning of the common scheme |
| 9713 |
var indexOfSchemeStart = matchStr.indexOf(foundCommonScheme); |
| 9714 |
matchStr = matchStr.substr(indexOfSchemeStart); |
| 9715 |
schemeUrlMatch = schemeUrlMatch.substr(indexOfSchemeStart); |
| 9716 |
offset = offset + indexOfSchemeStart; |
| 9717 |
} |
| 9718 |
var urlMatchType = schemeUrlMatch ? 'scheme' : (wwwUrlMatch ? 'www' : 'tld'), protocolUrlMatch = !!schemeUrlMatch; |
| 9719 |
matches.push(new UrlMatch({ |
| 9720 |
tagBuilder: tagBuilder, |
| 9721 |
matchedText: matchStr, |
| 9722 |
offset: offset, |
| 9723 |
urlMatchType: urlMatchType, |
| 9724 |
url: matchStr, |
| 9725 |
protocolUrlMatch: protocolUrlMatch, |
| 9726 |
protocolRelativeMatch: !!protocolRelativeMatch, |
| 9727 |
stripPrefix: stripPrefix, |
| 9728 |
stripTrailingSlash: stripTrailingSlash, |
| 9729 |
decodePercentEncoding: decodePercentEncoding, |
| 9730 |
})); |
| 9731 |
}; |
| 9732 |
var this_1 = this; |
| 9733 |
while ((match = matcherRegex.exec(text)) !== null) { |
| 9734 |
_loop_1(); |
| 9735 |
} |
| 9736 |
return matches; |
| 9737 |
}; |
| 9738 |
/** |
| 9739 |
* Determines if a match found has an unmatched closing parenthesis or |
| 9740 |
* square bracket. If so, the parenthesis or square bracket will be removed |
| 9741 |
* from the match itself, and appended after the generated anchor tag. |
| 9742 |
* |
| 9743 |
* A match may have an extra closing parenthesis at the end of the match |
| 9744 |
* because the regular expression must include parenthesis for URLs such as |
| 9745 |
* "wikipedia.com/something_(disambiguation)", which should be auto-linked. |
| 9746 |
* |
| 9747 |
* However, an extra parenthesis *will* be included when the URL itself is |
| 9748 |
* wrapped in parenthesis, such as in the case of: |
| 9749 |
* "(wikipedia.com/something_(disambiguation))" |
| 9750 |
* In this case, the last closing parenthesis should *not* be part of the |
| 9751 |
* URL itself, and this method will return `true`. |
| 9752 |
* |
| 9753 |
* For square brackets in URLs such as in PHP arrays, the same behavior as |
| 9754 |
* parenthesis discussed above should happen: |
| 9755 |
* "[http://www.example.com/foo.php?bar[]=1&bar[]=2&bar[]=3]" |
| 9756 |
* The closing square bracket should not be part of the URL itself, and this |
| 9757 |
* method will return `true`. |
| 9758 |
* |
| 9759 |
* @protected |
| 9760 |
* @param {String} matchStr The full match string from the {@link #matcherRegex}. |
| 9761 |
* @return {Boolean} `true` if there is an unbalanced closing parenthesis or |
| 9762 |
* square bracket at the end of the `matchStr`, `false` otherwise. |
| 9763 |
*/ |
| 9764 |
UrlMatcher.prototype.matchHasUnbalancedClosingParen = function (matchStr) { |
| 9765 |
var endChar = matchStr.charAt(matchStr.length - 1); |
| 9766 |
var startChar; |
| 9767 |
if (endChar === ')') { |
| 9768 |
startChar = '('; |
| 9769 |
} |
| 9770 |
else if (endChar === ']') { |
| 9771 |
startChar = '['; |
| 9772 |
} |
| 9773 |
else { |
| 9774 |
return false; // not a close parenthesis or square bracket |
| 9775 |
} |
| 9776 |
// Find if there are the same number of open braces as close braces in |
| 9777 |
// the URL string, minus the last character (which we have already |
| 9778 |
// determined to be either ')' or ']' |
| 9779 |
var numOpenBraces = 0; |
| 9780 |
for (var i = 0, len = matchStr.length - 1; i < len; i++) { |
| 9781 |
var char = matchStr.charAt(i); |
| 9782 |
if (char === startChar) { |
| 9783 |
numOpenBraces++; |
| 9784 |
} |
| 9785 |
else if (char === endChar) { |
| 9786 |
numOpenBraces = Math.max(numOpenBraces - 1, 0); |
| 9787 |
} |
| 9788 |
} |
| 9789 |
// If the number of open braces matches the number of close braces in |
| 9790 |
// the URL minus the last character, then the match has *unbalanced* |
| 9791 |
// braces because of the last character. Example of unbalanced braces |
| 9792 |
// from the regex match: |
| 9793 |
// "http://example.com?a[]=1]" |
| 9794 |
if (numOpenBraces === 0) { |
| 9795 |
return true; |
| 9796 |
} |
| 9797 |
return false; |
| 9798 |
}; |
| 9799 |
/** |
| 9800 |
* Determine if there's an invalid character after the TLD in a URL. Valid |
| 9801 |
* characters after TLD are ':/?#'. Exclude scheme matched URLs from this |
| 9802 |
* check. |
| 9803 |
* |
| 9804 |
* @protected |
| 9805 |
* @param {String} urlMatch The matched URL, if there was one. Will be an |
| 9806 |
* empty string if the match is not a URL match. |
| 9807 |
* @param {String} schemeUrlMatch The match URL string for a scheme |
| 9808 |
* match. Ex: 'http://yahoo.com'. This is used to match something like |
| 9809 |
* 'http://localhost', where we won't double check that the domain name |
| 9810 |
* has at least one '.' in it. |
| 9811 |
* @return {Number} the position where the invalid character was found. If |
| 9812 |
* no such character was found, returns -1 |
| 9813 |
*/ |
| 9814 |
UrlMatcher.prototype.matchHasInvalidCharAfterTld = function (urlMatch, schemeUrlMatch) { |
| 9815 |
if (!urlMatch) { |
| 9816 |
return -1; |
| 9817 |
} |
| 9818 |
var offset = 0; |
| 9819 |
if (schemeUrlMatch) { |
| 9820 |
offset = urlMatch.indexOf(':'); |
| 9821 |
urlMatch = urlMatch.slice(offset); |
| 9822 |
} |
| 9823 |
var re = new RegExp("^((.?\/\/)?[-." + alphaNumericAndMarksCharsStr + "]*[-" + alphaNumericAndMarksCharsStr + "]\\.[-" + alphaNumericAndMarksCharsStr + "]+)"); |
| 9824 |
var res = re.exec(urlMatch); |
| 9825 |
if (res === null) { |
| 9826 |
return -1; |
| 9827 |
} |
| 9828 |
offset += res[1].length; |
| 9829 |
urlMatch = urlMatch.slice(res[1].length); |
| 9830 |
if (/^[^-.A-Za-z0-9:\/?#]/.test(urlMatch)) { |
| 9831 |
return offset; |
| 9832 |
} |
| 9833 |
return -1; |
| 9834 |
}; |
| 9835 |
return UrlMatcher; |
| 9836 |
}(Matcher)); |
| 9837 |
|
| 9838 |
/** |
| 9839 |
* @class Autolinker.matcher.Hashtag |
| 9840 |
* @extends Autolinker.matcher.Matcher |
| 9841 |
* |
| 9842 |
* Matcher to find HashtagMatch matches in an input string. |
| 9843 |
*/ |
| 9844 |
var HashtagMatcher = /** @class */ (function (_super) { |
| 9845 |
__extends(HashtagMatcher, _super); |
| 9846 |
/** |
| 9847 |
* @method constructor |
| 9848 |
* @param {Object} cfg The configuration properties for the Match instance, |
| 9849 |
* specified in an Object (map). |
| 9850 |
*/ |
| 9851 |
function HashtagMatcher(cfg) { |
| 9852 |
var _this = _super.call(this, cfg) || this; |
| 9853 |
/** |
| 9854 |
* @cfg {String} serviceName |
| 9855 |
* |
| 9856 |
* The service to point hashtag matches to. See {@link Autolinker#hashtag} |
| 9857 |
* for available values. |
| 9858 |
*/ |
| 9859 |
_this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 9860 |
/** |
| 9861 |
* The regular expression to match Hashtags. Example match: |
| 9862 |
* |
| 9863 |
* #asdf |
| 9864 |
* |
| 9865 |
* @protected |
| 9866 |
* @property {RegExp} matcherRegex |
| 9867 |
*/ |
| 9868 |
_this.matcherRegex = new RegExp("#[_" + alphaNumericAndMarksCharsStr + "]{1,139}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g'); // lookahead used to make sure we don't match something above 139 characters |
| 9869 |
/** |
| 9870 |
* The regular expression to use to check the character before a username match to |
| 9871 |
* make sure we didn't accidentally match an email address. |
| 9872 |
* |
| 9873 |
* For example, the string "[email protected]" should not match "@asdf" as a username. |
| 9874 |
* |
| 9875 |
* @protected |
| 9876 |
* @property {RegExp} nonWordCharRegex |
| 9877 |
*/ |
| 9878 |
_this.nonWordCharRegex = new RegExp('[^' + alphaNumericAndMarksCharsStr + ']'); |
| 9879 |
_this.serviceName = cfg.serviceName; |
| 9880 |
return _this; |
| 9881 |
} |
| 9882 |
/** |
| 9883 |
* @inheritdoc |
| 9884 |
*/ |
| 9885 |
HashtagMatcher.prototype.parseMatches = function (text) { |
| 9886 |
var matcherRegex = this.matcherRegex, nonWordCharRegex = this.nonWordCharRegex, serviceName = this.serviceName, tagBuilder = this.tagBuilder, matches = [], match; |
| 9887 |
while ((match = matcherRegex.exec(text)) !== null) { |
| 9888 |
var offset = match.index, prevChar = text.charAt(offset - 1); |
| 9889 |
// If we found the match at the beginning of the string, or we found the match |
| 9890 |
// and there is a whitespace char in front of it (meaning it is not a '#' char |
| 9891 |
// in the middle of a word), then it is a hashtag match. |
| 9892 |
if (offset === 0 || nonWordCharRegex.test(prevChar)) { |
| 9893 |
var matchedText = match[0], hashtag = match[0].slice(1); // strip off the '#' character at the beginning |
| 9894 |
matches.push(new HashtagMatch({ |
| 9895 |
tagBuilder: tagBuilder, |
| 9896 |
matchedText: matchedText, |
| 9897 |
offset: offset, |
| 9898 |
serviceName: serviceName, |
| 9899 |
hashtag: hashtag |
| 9900 |
})); |
| 9901 |
} |
| 9902 |
} |
| 9903 |
return matches; |
| 9904 |
}; |
| 9905 |
return HashtagMatcher; |
| 9906 |
}(Matcher)); |
| 9907 |
|
| 9908 |
/** |
| 9909 |
* @class Autolinker.matcher.Phone |
| 9910 |
* @extends Autolinker.matcher.Matcher |
| 9911 |
* |
| 9912 |
* Matcher to find Phone number matches in an input string. |
| 9913 |
* |
| 9914 |
* See this class's superclass ({@link Autolinker.matcher.Matcher}) for more |
| 9915 |
* details. |
| 9916 |
*/ |
| 9917 |
var PhoneMatcher = /** @class */ (function (_super) { |
| 9918 |
__extends(PhoneMatcher, _super); |
| 9919 |
function PhoneMatcher() { |
| 9920 |
var _this = _super !== null && _super.apply(this, arguments) || this; |
| 9921 |
/** |
| 9922 |
* The regular expression to match Phone numbers. Example match: |
| 9923 |
* |
| 9924 |
* (123) 456-7890 |
| 9925 |
* |
| 9926 |
* This regular expression has the following capturing groups: |
| 9927 |
* |
| 9928 |
* 1 or 2. The prefixed '+' sign, if there is one. |
| 9929 |
* |
| 9930 |
* @protected |
| 9931 |
* @property {RegExp} matcherRegex |
| 9932 |
*/ |
| 9933 |
_this.matcherRegex = /(?:(?:(?:(\+)?\d{1,3}[-\040.]?)?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]?\d{4})|(?:(\+)(?:9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)[-\040.]?(?:\d[-\040.]?){6,12}\d+))([,;]+[0-9]+#?)*/g; |
| 9934 |
return _this; |
| 9935 |
} |
| 9936 |
// ex: (123) 456-7890, 123 456 7890, 123-456-7890, +18004441234,,;,10226420346#, |
| 9937 |
// +1 (800) 444 1234, 10226420346#, 1-800-444-1234,1022,64,20346# |
| 9938 |
/** |
| 9939 |
* @inheritdoc |
| 9940 |
*/ |
| 9941 |
PhoneMatcher.prototype.parseMatches = function (text) { |
| 9942 |
var matcherRegex = this.matcherRegex, tagBuilder = this.tagBuilder, matches = [], match; |
| 9943 |
while ((match = matcherRegex.exec(text)) !== null) { |
| 9944 |
// Remove non-numeric values from phone number string |
| 9945 |
var matchedText = match[0], cleanNumber = matchedText.replace(/[^0-9,;#]/g, ''), // strip out non-digit characters exclude comma semicolon and # |
| 9946 |
plusSign = !!(match[1] || match[2]), // match[ 1 ] or match[ 2 ] is the prefixed plus sign, if there is one |
| 9947 |
before = match.index == 0 ? '' : text.substr(match.index - 1, 1), after = text.substr(match.index + matchedText.length, 1), contextClear = !before.match(/\d/) && !after.match(/\d/); |
| 9948 |
if (this.testMatch(match[3]) && this.testMatch(matchedText) && contextClear) { |
| 9949 |
matches.push(new PhoneMatch({ |
| 9950 |
tagBuilder: tagBuilder, |
| 9951 |
matchedText: matchedText, |
| 9952 |
offset: match.index, |
| 9953 |
number: cleanNumber, |
| 9954 |
plusSign: plusSign |
| 9955 |
})); |
| 9956 |
} |
| 9957 |
} |
| 9958 |
return matches; |
| 9959 |
}; |
| 9960 |
PhoneMatcher.prototype.testMatch = function (text) { |
| 9961 |
return /\D/.test(text); |
| 9962 |
}; |
| 9963 |
return PhoneMatcher; |
| 9964 |
}(Matcher)); |
| 9965 |
|
| 9966 |
/** |
| 9967 |
* @class Autolinker.matcher.Mention |
| 9968 |
* @extends Autolinker.matcher.Matcher |
| 9969 |
* |
| 9970 |
* Matcher to find/replace username matches in an input string. |
| 9971 |
*/ |
| 9972 |
var MentionMatcher = /** @class */ (function (_super) { |
| 9973 |
__extends(MentionMatcher, _super); |
| 9974 |
/** |
| 9975 |
* @method constructor |
| 9976 |
* @param {Object} cfg The configuration properties for the Match instance, |
| 9977 |
* specified in an Object (map). |
| 9978 |
*/ |
| 9979 |
function MentionMatcher(cfg) { |
| 9980 |
var _this = _super.call(this, cfg) || this; |
| 9981 |
/** |
| 9982 |
* @cfg {'twitter'/'instagram'/'soundcloud'} protected |
| 9983 |
* |
| 9984 |
* The name of service to link @mentions to. |
| 9985 |
* |
| 9986 |
* Valid values are: 'twitter', 'instagram', or 'soundcloud' |
| 9987 |
*/ |
| 9988 |
_this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 9989 |
/** |
| 9990 |
* Hash of regular expression to match username handles. Example match: |
| 9991 |
* |
| 9992 |
* @asdf |
| 9993 |
* |
| 9994 |
* @private |
| 9995 |
* @property {Object} matcherRegexes |
| 9996 |
*/ |
| 9997 |
_this.matcherRegexes = { |
| 9998 |
'twitter': new RegExp("@[_" + alphaNumericAndMarksCharsStr + "]{1,50}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g'), |
| 9999 |
'instagram': new RegExp("@[_." + alphaNumericAndMarksCharsStr + "]{1,30}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g'), |
| 10000 |
'soundcloud': new RegExp("@[-_." + alphaNumericAndMarksCharsStr + "]{1,50}(?![-_" + alphaNumericAndMarksCharsStr + "])", 'g') // lookahead used to make sure we don't match something above 50 characters |
| 10001 |
}; |
| 10002 |
/** |
| 10003 |
* The regular expression to use to check the character before a username match to |
| 10004 |
* make sure we didn't accidentally match an email address. |
| 10005 |
* |
| 10006 |
* For example, the string "[email protected]" should not match "@asdf" as a username. |
| 10007 |
* |
| 10008 |
* @private |
| 10009 |
* @property {RegExp} nonWordCharRegex |
| 10010 |
*/ |
| 10011 |
_this.nonWordCharRegex = new RegExp('[^' + alphaNumericAndMarksCharsStr + ']'); |
| 10012 |
_this.serviceName = cfg.serviceName; |
| 10013 |
return _this; |
| 10014 |
} |
| 10015 |
/** |
| 10016 |
* @inheritdoc |
| 10017 |
*/ |
| 10018 |
MentionMatcher.prototype.parseMatches = function (text) { |
| 10019 |
var serviceName = this.serviceName, matcherRegex = this.matcherRegexes[this.serviceName], nonWordCharRegex = this.nonWordCharRegex, tagBuilder = this.tagBuilder, matches = [], match; |
| 10020 |
if (!matcherRegex) { |
| 10021 |
return matches; |
| 10022 |
} |
| 10023 |
while ((match = matcherRegex.exec(text)) !== null) { |
| 10024 |
var offset = match.index, prevChar = text.charAt(offset - 1); |
| 10025 |
// If we found the match at the beginning of the string, or we found the match |
| 10026 |
// and there is a whitespace char in front of it (meaning it is not an email |
| 10027 |
// address), then it is a username match. |
| 10028 |
if (offset === 0 || nonWordCharRegex.test(prevChar)) { |
| 10029 |
var matchedText = match[0].replace(/\.+$/g, ''), // strip off trailing . |
| 10030 |
mention = matchedText.slice(1); // strip off the '@' character at the beginning |
| 10031 |
matches.push(new MentionMatch({ |
| 10032 |
tagBuilder: tagBuilder, |
| 10033 |
matchedText: matchedText, |
| 10034 |
offset: offset, |
| 10035 |
serviceName: serviceName, |
| 10036 |
mention: mention |
| 10037 |
})); |
| 10038 |
} |
| 10039 |
} |
| 10040 |
return matches; |
| 10041 |
}; |
| 10042 |
return MentionMatcher; |
| 10043 |
}(Matcher)); |
| 10044 |
|
| 10045 |
// For debugging: search for other "For debugging" lines |
| 10046 |
// import CliTable from 'cli-table'; |
| 10047 |
/** |
| 10048 |
* Parses an HTML string, calling the callbacks to notify of tags and text. |
| 10049 |
* |
| 10050 |
* ## History |
| 10051 |
* |
| 10052 |
* This file previously used a regular expression to find html tags in the input |
| 10053 |
* text. Unfortunately, we ran into a bunch of catastrophic backtracking issues |
| 10054 |
* with certain input text, causing Autolinker to either hang or just take a |
| 10055 |
* really long time to parse the string. |
| 10056 |
* |
| 10057 |
* The current code is intended to be a O(n) algorithm that walks through |
| 10058 |
* the string in one pass, and tries to be as cheap as possible. We don't need |
| 10059 |
* to implement the full HTML spec, but rather simply determine where the string |
| 10060 |
* looks like an HTML tag, and where it looks like text (so that we can autolink |
| 10061 |
* that). |
| 10062 |
* |
| 10063 |
* This state machine parser is intended just to be a simple but performant |
| 10064 |
* parser of HTML for the subset of requirements we have. We simply need to: |
| 10065 |
* |
| 10066 |
* 1. Determine where HTML tags are |
| 10067 |
* 2. Determine the tag name (Autolinker specifically only cares about <a>, |
| 10068 |
* <script>, and <style> tags, so as not to link any text within them) |
| 10069 |
* |
| 10070 |
* We don't need to: |
| 10071 |
* |
| 10072 |
* 1. Create a parse tree |
| 10073 |
* 2. Auto-close tags with invalid markup |
| 10074 |
* 3. etc. |
| 10075 |
* |
| 10076 |
* The other intention behind this is that we didn't want to add external |
| 10077 |
* dependencies on the Autolinker utility which would increase its size. For |
| 10078 |
* instance, adding htmlparser2 adds 125kb to the minified output file, |
| 10079 |
* increasing its final size from 47kb to 172kb (at the time of writing). It |
| 10080 |
* also doesn't work exactly correctly, treating the string "<3 blah blah blah" |
| 10081 |
* as an HTML tag. |
| 10082 |
* |
| 10083 |
* Reference for HTML spec: |
| 10084 |
* |
| 10085 |
* https://www.w3.org/TR/html51/syntax.html#sec-tokenization |
| 10086 |
* |
| 10087 |
* @param {String} html The HTML to parse |
| 10088 |
* @param {Object} callbacks |
| 10089 |
* @param {Function} callbacks.onOpenTag Callback function to call when an open |
| 10090 |
* tag is parsed. Called with the tagName as its argument. |
| 10091 |
* @param {Function} callbacks.onCloseTag Callback function to call when a close |
| 10092 |
* tag is parsed. Called with the tagName as its argument. If a self-closing |
| 10093 |
* tag is found, `onCloseTag` is called immediately after `onOpenTag`. |
| 10094 |
* @param {Function} callbacks.onText Callback function to call when text (i.e |
| 10095 |
* not an HTML tag) is parsed. Called with the text (string) as its first |
| 10096 |
* argument, and offset (number) into the string as its second. |
| 10097 |
*/ |
| 10098 |
function parseHtml(html, _a) { |
| 10099 |
var onOpenTag = _a.onOpenTag, onCloseTag = _a.onCloseTag, onText = _a.onText, onComment = _a.onComment, onDoctype = _a.onDoctype; |
| 10100 |
var noCurrentTag = new CurrentTag(); |
| 10101 |
var charIdx = 0, len = html.length, state = 0 /* Data */, currentDataIdx = 0, // where the current data start index is |
| 10102 |
currentTag = noCurrentTag; // describes the current tag that is being read |
| 10103 |
// For debugging: search for other "For debugging" lines |
| 10104 |
// const table = new CliTable( { |
| 10105 |
// head: [ 'charIdx', 'char', 'state', 'currentDataIdx', 'currentOpenTagIdx', 'tag.type' ] |
| 10106 |
// } ); |
| 10107 |
while (charIdx < len) { |
| 10108 |
var char = html.charAt(charIdx); |
| 10109 |
// For debugging: search for other "For debugging" lines |
| 10110 |
// ALSO: Temporarily remove the 'const' keyword on the State enum |
| 10111 |
// table.push( |
| 10112 |
// [ charIdx, char, State[ state ], currentDataIdx, currentTag.idx, currentTag.idx === -1 ? '' : currentTag.type ] |
| 10113 |
// ); |
| 10114 |
switch (state) { |
| 10115 |
case 0 /* Data */: |
| 10116 |
stateData(char); |
| 10117 |
break; |
| 10118 |
case 1 /* TagOpen */: |
| 10119 |
stateTagOpen(char); |
| 10120 |
break; |
| 10121 |
case 2 /* EndTagOpen */: |
| 10122 |
stateEndTagOpen(char); |
| 10123 |
break; |
| 10124 |
case 3 /* TagName */: |
| 10125 |
stateTagName(char); |
| 10126 |
break; |
| 10127 |
case 4 /* BeforeAttributeName */: |
| 10128 |
stateBeforeAttributeName(char); |
| 10129 |
break; |
| 10130 |
case 5 /* AttributeName */: |
| 10131 |
stateAttributeName(char); |
| 10132 |
break; |
| 10133 |
case 6 /* AfterAttributeName */: |
| 10134 |
stateAfterAttributeName(char); |
| 10135 |
break; |
| 10136 |
case 7 /* BeforeAttributeValue */: |
| 10137 |
stateBeforeAttributeValue(char); |
| 10138 |
break; |
| 10139 |
case 8 /* AttributeValueDoubleQuoted */: |
| 10140 |
stateAttributeValueDoubleQuoted(char); |
| 10141 |
break; |
| 10142 |
case 9 /* AttributeValueSingleQuoted */: |
| 10143 |
stateAttributeValueSingleQuoted(char); |
| 10144 |
break; |
| 10145 |
case 10 /* AttributeValueUnquoted */: |
| 10146 |
stateAttributeValueUnquoted(char); |
| 10147 |
break; |
| 10148 |
case 11 /* AfterAttributeValueQuoted */: |
| 10149 |
stateAfterAttributeValueQuoted(char); |
| 10150 |
break; |
| 10151 |
case 12 /* SelfClosingStartTag */: |
| 10152 |
stateSelfClosingStartTag(char); |
| 10153 |
break; |
| 10154 |
case 13 /* MarkupDeclarationOpenState */: |
| 10155 |
stateMarkupDeclarationOpen(); |
| 10156 |
break; |
| 10157 |
case 14 /* CommentStart */: |
| 10158 |
stateCommentStart(char); |
| 10159 |
break; |
| 10160 |
case 15 /* CommentStartDash */: |
| 10161 |
stateCommentStartDash(char); |
| 10162 |
break; |
| 10163 |
case 16 /* Comment */: |
| 10164 |
stateComment(char); |
| 10165 |
break; |
| 10166 |
case 17 /* CommentEndDash */: |
| 10167 |
stateCommentEndDash(char); |
| 10168 |
break; |
| 10169 |
case 18 /* CommentEnd */: |
| 10170 |
stateCommentEnd(char); |
| 10171 |
break; |
| 10172 |
case 19 /* CommentEndBang */: |
| 10173 |
stateCommentEndBang(char); |
| 10174 |
break; |
| 10175 |
case 20 /* Doctype */: |
| 10176 |
stateDoctype(char); |
| 10177 |
break; |
| 10178 |
default: |
| 10179 |
throwUnhandledCaseError(state); |
| 10180 |
} |
| 10181 |
// For debugging: search for other "For debugging" lines |
| 10182 |
// ALSO: Temporarily remove the 'const' keyword on the State enum |
| 10183 |
// table.push( |
| 10184 |
// [ charIdx, char, State[ state ], currentDataIdx, currentTag.idx, currentTag.idx === -1 ? '' : currentTag.type ] |
| 10185 |
// ); |
| 10186 |
charIdx++; |
| 10187 |
} |
| 10188 |
if (currentDataIdx < charIdx) { |
| 10189 |
emitText(); |
| 10190 |
} |
| 10191 |
// For debugging: search for other "For debugging" lines |
| 10192 |
// console.log( '\n' + table.toString() ); |
| 10193 |
// Called when non-tags are being read (i.e. the text around HTML †ags) |
| 10194 |
// https://www.w3.org/TR/html51/syntax.html#data-state |
| 10195 |
function stateData(char) { |
| 10196 |
if (char === '<') { |
| 10197 |
startNewTag(); |
| 10198 |
} |
| 10199 |
} |
| 10200 |
// Called after a '<' is read from the Data state |
| 10201 |
// https://www.w3.org/TR/html51/syntax.html#tag-open-state |
| 10202 |
function stateTagOpen(char) { |
| 10203 |
if (char === '!') { |
| 10204 |
state = 13 /* MarkupDeclarationOpenState */; |
| 10205 |
} |
| 10206 |
else if (char === '/') { |
| 10207 |
state = 2 /* EndTagOpen */; |
| 10208 |
currentTag = new CurrentTag(__assign({}, currentTag, { isClosing: true })); |
| 10209 |
} |
| 10210 |
else if (char === '<') { |
| 10211 |
// start of another tag (ignore the previous, incomplete one) |
| 10212 |
startNewTag(); |
| 10213 |
} |
| 10214 |
else if (letterRe.test(char)) { |
| 10215 |
// tag name start (and no '/' read) |
| 10216 |
state = 3 /* TagName */; |
| 10217 |
currentTag = new CurrentTag(__assign({}, currentTag, { isOpening: true })); |
| 10218 |
} |
| 10219 |
else { |
| 10220 |
// Any other |
| 10221 |
state = 0 /* Data */; |
| 10222 |
currentTag = noCurrentTag; |
| 10223 |
} |
| 10224 |
} |
| 10225 |
// After a '<x', '</x' sequence is read (where 'x' is a letter character), |
| 10226 |
// this is to continue reading the tag name |
| 10227 |
// https://www.w3.org/TR/html51/syntax.html#tag-name-state |
| 10228 |
function stateTagName(char) { |
| 10229 |
if (whitespaceRe.test(char)) { |
| 10230 |
currentTag = new CurrentTag(__assign({}, currentTag, { name: captureTagName() })); |
| 10231 |
state = 4 /* BeforeAttributeName */; |
| 10232 |
} |
| 10233 |
else if (char === '<') { |
| 10234 |
// start of another tag (ignore the previous, incomplete one) |
| 10235 |
startNewTag(); |
| 10236 |
} |
| 10237 |
else if (char === '/') { |
| 10238 |
currentTag = new CurrentTag(__assign({}, currentTag, { name: captureTagName() })); |
| 10239 |
state = 12 /* SelfClosingStartTag */; |
| 10240 |
} |
| 10241 |
else if (char === '>') { |
| 10242 |
currentTag = new CurrentTag(__assign({}, currentTag, { name: captureTagName() })); |
| 10243 |
emitTagAndPreviousTextNode(); // resets to Data state as well |
| 10244 |
} |
| 10245 |
else if (!letterRe.test(char) && !digitRe.test(char) && char !== ':') { |
| 10246 |
// Anything else that does not form an html tag. Note: the colon |
| 10247 |
// character is accepted for XML namespaced tags |
| 10248 |
resetToDataState(); |
| 10249 |
} |
| 10250 |
} |
| 10251 |
// Called after the '/' is read from a '</' sequence |
| 10252 |
// https://www.w3.org/TR/html51/syntax.html#end-tag-open-state |
| 10253 |
function stateEndTagOpen(char) { |
| 10254 |
if (char === '>') { // parse error. Encountered "</>". Skip it without treating as a tag |
| 10255 |
resetToDataState(); |
| 10256 |
} |
| 10257 |
else if (letterRe.test(char)) { |
| 10258 |
state = 3 /* TagName */; |
| 10259 |
} |
| 10260 |
else { |
| 10261 |
// some other non-tag-like character, don't treat this as a tag |
| 10262 |
resetToDataState(); |
| 10263 |
} |
| 10264 |
} |
| 10265 |
// https://www.w3.org/TR/html51/syntax.html#before-attribute-name-state |
| 10266 |
function stateBeforeAttributeName(char) { |
| 10267 |
if (whitespaceRe.test(char)) ; |
| 10268 |
else if (char === '/') { |
| 10269 |
state = 12 /* SelfClosingStartTag */; |
| 10270 |
} |
| 10271 |
else if (char === '>') { |
| 10272 |
emitTagAndPreviousTextNode(); // resets to Data state as well |
| 10273 |
} |
| 10274 |
else if (char === '<') { |
| 10275 |
// start of another tag (ignore the previous, incomplete one) |
| 10276 |
startNewTag(); |
| 10277 |
} |
| 10278 |
else if (char === "=" || quoteRe.test(char) || controlCharsRe.test(char)) { |
| 10279 |
// "Parse error" characters that, according to the spec, should be |
| 10280 |
// appended to the attribute name, but we'll treat these characters |
| 10281 |
// as not forming a real HTML tag |
| 10282 |
resetToDataState(); |
| 10283 |
} |
| 10284 |
else { |
| 10285 |
// Any other char, start of a new attribute name |
| 10286 |
state = 5 /* AttributeName */; |
| 10287 |
} |
| 10288 |
} |
| 10289 |
// https://www.w3.org/TR/html51/syntax.html#attribute-name-state |
| 10290 |
function stateAttributeName(char) { |
| 10291 |
if (whitespaceRe.test(char)) { |
| 10292 |
state = 6 /* AfterAttributeName */; |
| 10293 |
} |
| 10294 |
else if (char === '/') { |
| 10295 |
state = 12 /* SelfClosingStartTag */; |
| 10296 |
} |
| 10297 |
else if (char === '=') { |
| 10298 |
state = 7 /* BeforeAttributeValue */; |
| 10299 |
} |
| 10300 |
else if (char === '>') { |
| 10301 |
emitTagAndPreviousTextNode(); // resets to Data state as well |
| 10302 |
} |
| 10303 |
else if (char === '<') { |
| 10304 |
// start of another tag (ignore the previous, incomplete one) |
| 10305 |
startNewTag(); |
| 10306 |
} |
| 10307 |
else if (quoteRe.test(char)) { |
| 10308 |
// "Parse error" characters that, according to the spec, should be |
| 10309 |
// appended to the attribute name, but we'll treat these characters |
| 10310 |
// as not forming a real HTML tag |
| 10311 |
resetToDataState(); |
| 10312 |
} |
| 10313 |
} |
| 10314 |
// https://www.w3.org/TR/html51/syntax.html#after-attribute-name-state |
| 10315 |
function stateAfterAttributeName(char) { |
| 10316 |
if (whitespaceRe.test(char)) ; |
| 10317 |
else if (char === '/') { |
| 10318 |
state = 12 /* SelfClosingStartTag */; |
| 10319 |
} |
| 10320 |
else if (char === '=') { |
| 10321 |
state = 7 /* BeforeAttributeValue */; |
| 10322 |
} |
| 10323 |
else if (char === '>') { |
| 10324 |
emitTagAndPreviousTextNode(); |
| 10325 |
} |
| 10326 |
else if (char === '<') { |
| 10327 |
// start of another tag (ignore the previous, incomplete one) |
| 10328 |
startNewTag(); |
| 10329 |
} |
| 10330 |
else if (quoteRe.test(char)) { |
| 10331 |
// "Parse error" characters that, according to the spec, should be |
| 10332 |
// appended to the attribute name, but we'll treat these characters |
| 10333 |
// as not forming a real HTML tag |
| 10334 |
resetToDataState(); |
| 10335 |
} |
| 10336 |
else { |
| 10337 |
// Any other character, start a new attribute in the current tag |
| 10338 |
state = 5 /* AttributeName */; |
| 10339 |
} |
| 10340 |
} |
| 10341 |
// https://www.w3.org/TR/html51/syntax.html#before-attribute-value-state |
| 10342 |
function stateBeforeAttributeValue(char) { |
| 10343 |
if (whitespaceRe.test(char)) ; |
| 10344 |
else if (char === "\"") { |
| 10345 |
state = 8 /* AttributeValueDoubleQuoted */; |
| 10346 |
} |
| 10347 |
else if (char === "'") { |
| 10348 |
state = 9 /* AttributeValueSingleQuoted */; |
| 10349 |
} |
| 10350 |
else if (/[>=`]/.test(char)) { |
| 10351 |
// Invalid chars after an '=' for an attribute value, don't count |
| 10352 |
// the current tag as an HTML tag |
| 10353 |
resetToDataState(); |
| 10354 |
} |
| 10355 |
else if (char === '<') { |
| 10356 |
// start of another tag (ignore the previous, incomplete one) |
| 10357 |
startNewTag(); |
| 10358 |
} |
| 10359 |
else { |
| 10360 |
// Any other character, consider it an unquoted attribute value |
| 10361 |
state = 10 /* AttributeValueUnquoted */; |
| 10362 |
} |
| 10363 |
} |
| 10364 |
// https://www.w3.org/TR/html51/syntax.html#attribute-value-double-quoted-state |
| 10365 |
function stateAttributeValueDoubleQuoted(char) { |
| 10366 |
if (char === "\"") { // end the current double-quoted attribute |
| 10367 |
state = 11 /* AfterAttributeValueQuoted */; |
| 10368 |
} |
| 10369 |
} |
| 10370 |
// https://www.w3.org/TR/html51/syntax.html#attribute-value-single-quoted-state |
| 10371 |
function stateAttributeValueSingleQuoted(char) { |
| 10372 |
if (char === "'") { // end the current single-quoted attribute |
| 10373 |
state = 11 /* AfterAttributeValueQuoted */; |
| 10374 |
} |
| 10375 |
} |
| 10376 |
// https://www.w3.org/TR/html51/syntax.html#attribute-value-unquoted-state |
| 10377 |
function stateAttributeValueUnquoted(char) { |
| 10378 |
if (whitespaceRe.test(char)) { |
| 10379 |
state = 4 /* BeforeAttributeName */; |
| 10380 |
} |
| 10381 |
else if (char === '>') { |
| 10382 |
emitTagAndPreviousTextNode(); |
| 10383 |
} |
| 10384 |
else if (char === '<') { |
| 10385 |
// start of another tag (ignore the previous, incomplete one) |
| 10386 |
startNewTag(); |
| 10387 |
} |
| 10388 |
} |
| 10389 |
// https://www.w3.org/TR/html51/syntax.html#after-attribute-value-quoted-state |
| 10390 |
function stateAfterAttributeValueQuoted(char) { |
| 10391 |
if (whitespaceRe.test(char)) { |
| 10392 |
state = 4 /* BeforeAttributeName */; |
| 10393 |
} |
| 10394 |
else if (char === '/') { |
| 10395 |
state = 12 /* SelfClosingStartTag */; |
| 10396 |
} |
| 10397 |
else if (char === '>') { |
| 10398 |
emitTagAndPreviousTextNode(); |
| 10399 |
} |
| 10400 |
else if (char === '<') { |
| 10401 |
// start of another tag (ignore the previous, incomplete one) |
| 10402 |
startNewTag(); |
| 10403 |
} |
| 10404 |
else { |
| 10405 |
// Any other character, "parse error". Spec says to switch to the |
| 10406 |
// BeforeAttributeState and re-consume the character, as it may be |
| 10407 |
// the start of a new attribute name |
| 10408 |
state = 4 /* BeforeAttributeName */; |
| 10409 |
reconsumeCurrentCharacter(); |
| 10410 |
} |
| 10411 |
} |
| 10412 |
// A '/' has just been read in the current tag (presumably for '/>'), and |
| 10413 |
// this handles the next character |
| 10414 |
// https://www.w3.org/TR/html51/syntax.html#self-closing-start-tag-state |
| 10415 |
function stateSelfClosingStartTag(char) { |
| 10416 |
if (char === '>') { |
| 10417 |
currentTag = new CurrentTag(__assign({}, currentTag, { isClosing: true })); |
| 10418 |
emitTagAndPreviousTextNode(); // resets to Data state as well |
| 10419 |
} |
| 10420 |
else { |
| 10421 |
state = 4 /* BeforeAttributeName */; |
| 10422 |
} |
| 10423 |
} |
| 10424 |
// https://www.w3.org/TR/html51/syntax.html#markup-declaration-open-state |
| 10425 |
// (HTML Comments or !DOCTYPE) |
| 10426 |
function stateMarkupDeclarationOpen(char) { |
| 10427 |
if (html.substr(charIdx, 2) === '--') { // html comment |
| 10428 |
charIdx += 2; // "consume" characters |
| 10429 |
currentTag = new CurrentTag(__assign({}, currentTag, { type: 'comment' })); |
| 10430 |
state = 14 /* CommentStart */; |
| 10431 |
} |
| 10432 |
else if (html.substr(charIdx, 7).toUpperCase() === 'DOCTYPE') { |
| 10433 |
charIdx += 7; // "consume" characters |
| 10434 |
currentTag = new CurrentTag(__assign({}, currentTag, { type: 'doctype' })); |
| 10435 |
state = 20 /* Doctype */; |
| 10436 |
} |
| 10437 |
else { |
| 10438 |
// At this point, the spec specifies that the state machine should |
| 10439 |
// enter the "bogus comment" state, in which case any character(s) |
| 10440 |
// after the '<!' that were read should become an HTML comment up |
| 10441 |
// until the first '>' that is read (or EOF). Instead, we'll assume |
| 10442 |
// that a user just typed '<!' as part of text data |
| 10443 |
resetToDataState(); |
| 10444 |
} |
| 10445 |
} |
| 10446 |
// Handles after the sequence '<!--' has been read |
| 10447 |
// https://www.w3.org/TR/html51/syntax.html#comment-start-state |
| 10448 |
function stateCommentStart(char) { |
| 10449 |
if (char === '-') { |
| 10450 |
// We've read the sequence '<!---' at this point (3 dashes) |
| 10451 |
state = 15 /* CommentStartDash */; |
| 10452 |
} |
| 10453 |
else if (char === '>') { |
| 10454 |
// At this point, we'll assume the comment wasn't a real comment |
| 10455 |
// so we'll just emit it as data. We basically read the sequence |
| 10456 |
// '<!-->' |
| 10457 |
resetToDataState(); |
| 10458 |
} |
| 10459 |
else { |
| 10460 |
// Any other char, take it as part of the comment |
| 10461 |
state = 16 /* Comment */; |
| 10462 |
} |
| 10463 |
} |
| 10464 |
// We've read the sequence '<!---' at this point (3 dashes) |
| 10465 |
// https://www.w3.org/TR/html51/syntax.html#comment-start-dash-state |
| 10466 |
function stateCommentStartDash(char) { |
| 10467 |
if (char === '-') { |
| 10468 |
// We've read '<!----' (4 dashes) at this point |
| 10469 |
state = 18 /* CommentEnd */; |
| 10470 |
} |
| 10471 |
else if (char === '>') { |
| 10472 |
// At this point, we'll assume the comment wasn't a real comment |
| 10473 |
// so we'll just emit it as data. We basically read the sequence |
| 10474 |
// '<!--->' |
| 10475 |
resetToDataState(); |
| 10476 |
} |
| 10477 |
else { |
| 10478 |
// Anything else, take it as a valid comment |
| 10479 |
state = 16 /* Comment */; |
| 10480 |
} |
| 10481 |
} |
| 10482 |
// Currently reading the comment's text (data) |
| 10483 |
// https://www.w3.org/TR/html51/syntax.html#comment-state |
| 10484 |
function stateComment(char) { |
| 10485 |
if (char === '-') { |
| 10486 |
state = 17 /* CommentEndDash */; |
| 10487 |
} |
| 10488 |
} |
| 10489 |
// When we we've read the first dash inside a comment, it may signal the |
| 10490 |
// end of the comment if we read another dash |
| 10491 |
// https://www.w3.org/TR/html51/syntax.html#comment-end-dash-state |
| 10492 |
function stateCommentEndDash(char) { |
| 10493 |
if (char === '-') { |
| 10494 |
state = 18 /* CommentEnd */; |
| 10495 |
} |
| 10496 |
else { |
| 10497 |
// Wasn't a dash, must still be part of the comment |
| 10498 |
state = 16 /* Comment */; |
| 10499 |
} |
| 10500 |
} |
| 10501 |
// After we've read two dashes inside a comment, it may signal the end of |
| 10502 |
// the comment if we then read a '>' char |
| 10503 |
// https://www.w3.org/TR/html51/syntax.html#comment-end-state |
| 10504 |
function stateCommentEnd(char) { |
| 10505 |
if (char === '>') { |
| 10506 |
emitTagAndPreviousTextNode(); |
| 10507 |
} |
| 10508 |
else if (char === '!') { |
| 10509 |
state = 19 /* CommentEndBang */; |
| 10510 |
} |
| 10511 |
else if (char === '-') ; |
| 10512 |
else { |
| 10513 |
// Anything else, switch back to the comment state since we didn't |
| 10514 |
// read the full "end comment" sequence (i.e. '-->') |
| 10515 |
state = 16 /* Comment */; |
| 10516 |
} |
| 10517 |
} |
| 10518 |
// We've read the sequence '--!' inside of a comment |
| 10519 |
// https://www.w3.org/TR/html51/syntax.html#comment-end-bang-state |
| 10520 |
function stateCommentEndBang(char) { |
| 10521 |
if (char === '-') { |
| 10522 |
// We read the sequence '--!-' inside of a comment. The last dash |
| 10523 |
// could signify that the comment is going to close |
| 10524 |
state = 17 /* CommentEndDash */; |
| 10525 |
} |
| 10526 |
else if (char === '>') { |
| 10527 |
// End of comment with the sequence '--!>' |
| 10528 |
emitTagAndPreviousTextNode(); |
| 10529 |
} |
| 10530 |
else { |
| 10531 |
// The '--!' was not followed by a '>', continue reading the |
| 10532 |
// comment's text |
| 10533 |
state = 16 /* Comment */; |
| 10534 |
} |
| 10535 |
} |
| 10536 |
/** |
| 10537 |
* For DOCTYPES in particular, we don't care about the attributes. Just |
| 10538 |
* advance to the '>' character and emit the tag, unless we find a '<' |
| 10539 |
* character in which case we'll start a new tag. |
| 10540 |
* |
| 10541 |
* Example doctype tag: |
| 10542 |
* <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 10543 |
* |
| 10544 |
* Actual spec: https://www.w3.org/TR/html51/syntax.html#doctype-state |
| 10545 |
*/ |
| 10546 |
function stateDoctype(char) { |
| 10547 |
if (char === '>') { |
| 10548 |
emitTagAndPreviousTextNode(); |
| 10549 |
} |
| 10550 |
else if (char === '<') { |
| 10551 |
startNewTag(); |
| 10552 |
} |
| 10553 |
} |
| 10554 |
/** |
| 10555 |
* Resets the state back to the Data state, and removes the current tag. |
| 10556 |
* |
| 10557 |
* We'll generally run this function whenever a "parse error" is |
| 10558 |
* encountered, where the current tag that is being read no longer looks |
| 10559 |
* like a real HTML tag. |
| 10560 |
*/ |
| 10561 |
function resetToDataState() { |
| 10562 |
state = 0 /* Data */; |
| 10563 |
currentTag = noCurrentTag; |
| 10564 |
} |
| 10565 |
/** |
| 10566 |
* Starts a new HTML tag at the current index, ignoring any previous HTML |
| 10567 |
* tag that was being read. |
| 10568 |
* |
| 10569 |
* We'll generally run this function whenever we read a new '<' character, |
| 10570 |
* including when we read a '<' character inside of an HTML tag that we were |
| 10571 |
* previously reading. |
| 10572 |
*/ |
| 10573 |
function startNewTag() { |
| 10574 |
state = 1 /* TagOpen */; |
| 10575 |
currentTag = new CurrentTag({ idx: charIdx }); |
| 10576 |
} |
| 10577 |
/** |
| 10578 |
* Once we've decided to emit an open tag, that means we can also emit the |
| 10579 |
* text node before it. |
| 10580 |
*/ |
| 10581 |
function emitTagAndPreviousTextNode() { |
| 10582 |
var textBeforeTag = html.slice(currentDataIdx, currentTag.idx); |
| 10583 |
if (textBeforeTag) { |
| 10584 |
// the html tag was the first element in the html string, or two |
| 10585 |
// tags next to each other, in which case we should not emit a text |
| 10586 |
// node |
| 10587 |
onText(textBeforeTag, currentDataIdx); |
| 10588 |
} |
| 10589 |
if (currentTag.type === 'comment') { |
| 10590 |
onComment(currentTag.idx); |
| 10591 |
} |
| 10592 |
else if (currentTag.type === 'doctype') { |
| 10593 |
onDoctype(currentTag.idx); |
| 10594 |
} |
| 10595 |
else { |
| 10596 |
if (currentTag.isOpening) { |
| 10597 |
onOpenTag(currentTag.name, currentTag.idx); |
| 10598 |
} |
| 10599 |
if (currentTag.isClosing) { // note: self-closing tags will emit both opening and closing |
| 10600 |
onCloseTag(currentTag.name, currentTag.idx); |
| 10601 |
} |
| 10602 |
} |
| 10603 |
// Since we just emitted a tag, reset to the data state for the next char |
| 10604 |
resetToDataState(); |
| 10605 |
currentDataIdx = charIdx + 1; |
| 10606 |
} |
| 10607 |
function emitText() { |
| 10608 |
var text = html.slice(currentDataIdx, charIdx); |
| 10609 |
onText(text, currentDataIdx); |
| 10610 |
currentDataIdx = charIdx + 1; |
| 10611 |
} |
| 10612 |
/** |
| 10613 |
* Captures the tag name from the start of the tag to the current character |
| 10614 |
* index, and converts it to lower case |
| 10615 |
*/ |
| 10616 |
function captureTagName() { |
| 10617 |
var startIdx = currentTag.idx + (currentTag.isClosing ? 2 : 1); |
| 10618 |
return html.slice(startIdx, charIdx).toLowerCase(); |
| 10619 |
} |
| 10620 |
/** |
| 10621 |
* Causes the main loop to re-consume the current character, such as after |
| 10622 |
* encountering a "parse error" that changed state and needs to reconsume |
| 10623 |
* the same character in that new state. |
| 10624 |
*/ |
| 10625 |
function reconsumeCurrentCharacter() { |
| 10626 |
charIdx--; |
| 10627 |
} |
| 10628 |
} |
| 10629 |
var CurrentTag = /** @class */ (function () { |
| 10630 |
function CurrentTag(cfg) { |
| 10631 |
if (cfg === void 0) { cfg = {}; } |
| 10632 |
this.idx = cfg.idx !== undefined ? cfg.idx : -1; |
| 10633 |
this.type = cfg.type || 'tag'; |
| 10634 |
this.name = cfg.name || ''; |
| 10635 |
this.isOpening = !!cfg.isOpening; |
| 10636 |
this.isClosing = !!cfg.isClosing; |
| 10637 |
} |
| 10638 |
return CurrentTag; |
| 10639 |
}()); |
| 10640 |
|
| 10641 |
/** |
| 10642 |
* @class Autolinker |
| 10643 |
* @extends Object |
| 10644 |
* |
| 10645 |
* Utility class used to process a given string of text, and wrap the matches in |
| 10646 |
* the appropriate anchor (<a>) tags to turn them into links. |
| 10647 |
* |
| 10648 |
* Any of the configuration options may be provided in an Object provided |
| 10649 |
* to the Autolinker constructor, which will configure how the {@link #link link()} |
| 10650 |
* method will process the links. |
| 10651 |
* |
| 10652 |
* For example: |
| 10653 |
* |
| 10654 |
* var autolinker = new Autolinker( { |
| 10655 |
* newWindow : false, |
| 10656 |
* truncate : 30 |
| 10657 |
* } ); |
| 10658 |
* |
| 10659 |
* var html = autolinker.link( "Joe went to www.yahoo.com" ); |
| 10660 |
* // produces: 'Joe went to <a href="http://www.yahoo.com">yahoo.com</a>' |
| 10661 |
* |
| 10662 |
* |
| 10663 |
* The {@link #static-link static link()} method may also be used to inline |
| 10664 |
* options into a single call, which may be more convenient for one-off uses. |
| 10665 |
* For example: |
| 10666 |
* |
| 10667 |
* var html = Autolinker.link( "Joe went to www.yahoo.com", { |
| 10668 |
* newWindow : false, |
| 10669 |
* truncate : 30 |
| 10670 |
* } ); |
| 10671 |
* // produces: 'Joe went to <a href="http://www.yahoo.com">yahoo.com</a>' |
| 10672 |
* |
| 10673 |
* |
| 10674 |
* ## Custom Replacements of Links |
| 10675 |
* |
| 10676 |
* If the configuration options do not provide enough flexibility, a {@link #replaceFn} |
| 10677 |
* may be provided to fully customize the output of Autolinker. This function is |
| 10678 |
* called once for each URL/Email/Phone#/Hashtag/Mention (Twitter, Instagram, Soundcloud) |
| 10679 |
* match that is encountered. |
| 10680 |
* |
| 10681 |
* For example: |
| 10682 |
* |
| 10683 |
* var input = "..."; // string with URLs, Email Addresses, Phone #s, Hashtags, and Mentions (Twitter, Instagram, Soundcloud) |
| 10684 |
* |
| 10685 |
* var linkedText = Autolinker.link( input, { |
| 10686 |
* replaceFn : function( match ) { |
| 10687 |
* console.log( "href = ", match.getAnchorHref() ); |
| 10688 |
* console.log( "text = ", match.getAnchorText() ); |
| 10689 |
* |
| 10690 |
* switch( match.getType() ) { |
| 10691 |
* case 'url' : |
| 10692 |
* console.log( "url: ", match.getUrl() ); |
| 10693 |
* |
| 10694 |
* if( match.getUrl().indexOf( 'mysite.com' ) === -1 ) { |
| 10695 |
* var tag = match.buildTag(); // returns an `Autolinker.HtmlTag` instance, which provides mutator methods for easy changes |
| 10696 |
* tag.setAttr( 'rel', 'nofollow' ); |
| 10697 |
* tag.addClass( 'external-link' ); |
| 10698 |
* |
| 10699 |
* return tag; |
| 10700 |
* |
| 10701 |
* } else { |
| 10702 |
* return true; // let Autolinker perform its normal anchor tag replacement |
| 10703 |
* } |
| 10704 |
* |
| 10705 |
* case 'email' : |
| 10706 |
* var email = match.getEmail(); |
| 10707 |
* console.log( "email: ", email ); |
| 10708 |
* |
| 10709 |
* if( email === "[email protected]" ) { |
| 10710 |
* return false; // don't auto-link this particular email address; leave as-is |
| 10711 |
* } else { |
| 10712 |
* return; // no return value will have Autolinker perform its normal anchor tag replacement (same as returning `true`) |
| 10713 |
* } |
| 10714 |
* |
| 10715 |
* case 'phone' : |
| 10716 |
* var phoneNumber = match.getPhoneNumber(); |
| 10717 |
* console.log( phoneNumber ); |
| 10718 |
* |
| 10719 |
* return '<a href="http://newplace.to.link.phone.numbers.to/">' + phoneNumber + '</a>'; |
| 10720 |
* |
| 10721 |
* case 'hashtag' : |
| 10722 |
* var hashtag = match.getHashtag(); |
| 10723 |
* console.log( hashtag ); |
| 10724 |
* |
| 10725 |
* return '<a href="http://newplace.to.link.hashtag.handles.to/">' + hashtag + '</a>'; |
| 10726 |
* |
| 10727 |
* case 'mention' : |
| 10728 |
* var mention = match.getMention(); |
| 10729 |
* console.log( mention ); |
| 10730 |
* |
| 10731 |
* return '<a href="http://newplace.to.link.mention.to/">' + mention + '</a>'; |
| 10732 |
* } |
| 10733 |
* } |
| 10734 |
* } ); |
| 10735 |
* |
| 10736 |
* |
| 10737 |
* The function may return the following values: |
| 10738 |
* |
| 10739 |
* - `true` (Boolean): Allow Autolinker to replace the match as it normally |
| 10740 |
* would. |
| 10741 |
* - `false` (Boolean): Do not replace the current match at all - leave as-is. |
| 10742 |
* - Any String: If a string is returned from the function, the string will be |
| 10743 |
* used directly as the replacement HTML for the match. |
| 10744 |
* - An {@link Autolinker.HtmlTag} instance, which can be used to build/modify |
| 10745 |
* an HTML tag before writing out its HTML text. |
| 10746 |
*/ |
| 10747 |
var Autolinker = /** @class */ (function () { |
| 10748 |
/** |
| 10749 |
* @method constructor |
| 10750 |
* @param {Object} [cfg] The configuration options for the Autolinker instance, |
| 10751 |
* specified in an Object (map). |
| 10752 |
*/ |
| 10753 |
function Autolinker(cfg) { |
| 10754 |
if (cfg === void 0) { cfg = {}; } |
| 10755 |
/** |
| 10756 |
* The Autolinker version number exposed on the instance itself. |
| 10757 |
* |
| 10758 |
* Ex: 0.25.1 |
| 10759 |
*/ |
| 10760 |
this.version = Autolinker.version; |
| 10761 |
/** |
| 10762 |
* @cfg {Boolean/Object} [urls] |
| 10763 |
* |
| 10764 |
* `true` if URLs should be automatically linked, `false` if they should not |
| 10765 |
* be. Defaults to `true`. |
| 10766 |
* |
| 10767 |
* Examples: |
| 10768 |
* |
| 10769 |
* urls: true |
| 10770 |
* |
| 10771 |
* // or |
| 10772 |
* |
| 10773 |
* urls: { |
| 10774 |
* schemeMatches : true, |
| 10775 |
* wwwMatches : true, |
| 10776 |
* tldMatches : true |
| 10777 |
* } |
| 10778 |
* |
| 10779 |
* As shown above, this option also accepts an Object form with 3 properties |
| 10780 |
* to allow for more customization of what exactly gets linked. All default |
| 10781 |
* to `true`: |
| 10782 |
* |
| 10783 |
* @cfg {Boolean} [urls.schemeMatches] `true` to match URLs found prefixed |
| 10784 |
* with a scheme, i.e. `http://google.com`, or `other+scheme://google.com`, |
| 10785 |
* `false` to prevent these types of matches. |
| 10786 |
* @cfg {Boolean} [urls.wwwMatches] `true` to match urls found prefixed with |
| 10787 |
* `'www.'`, i.e. `www.google.com`. `false` to prevent these types of |
| 10788 |
* matches. Note that if the URL had a prefixed scheme, and |
| 10789 |
* `schemeMatches` is true, it will still be linked. |
| 10790 |
* @cfg {Boolean} [urls.tldMatches] `true` to match URLs with known top |
| 10791 |
* level domains (.com, .net, etc.) that are not prefixed with a scheme or |
| 10792 |
* `'www.'`. This option attempts to match anything that looks like a URL |
| 10793 |
* in the given text. Ex: `google.com`, `asdf.org/?page=1`, etc. `false` |
| 10794 |
* to prevent these types of matches. |
| 10795 |
*/ |
| 10796 |
this.urls = {}; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10797 |
/** |
| 10798 |
* @cfg {Boolean} [email=true] |
| 10799 |
* |
| 10800 |
* `true` if email addresses should be automatically linked, `false` if they |
| 10801 |
* should not be. |
| 10802 |
*/ |
| 10803 |
this.email = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10804 |
/** |
| 10805 |
* @cfg {Boolean} [phone=true] |
| 10806 |
* |
| 10807 |
* `true` if Phone numbers ("(555)555-5555") should be automatically linked, |
| 10808 |
* `false` if they should not be. |
| 10809 |
*/ |
| 10810 |
this.phone = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10811 |
/** |
| 10812 |
* @cfg {Boolean/String} [hashtag=false] |
| 10813 |
* |
| 10814 |
* A string for the service name to have hashtags (ex: "#myHashtag") |
| 10815 |
* auto-linked to. The currently-supported values are: |
| 10816 |
* |
| 10817 |
* - 'twitter' |
| 10818 |
* - 'facebook' |
| 10819 |
* - 'instagram' |
| 10820 |
* |
| 10821 |
* Pass `false` to skip auto-linking of hashtags. |
| 10822 |
*/ |
| 10823 |
this.hashtag = false; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10824 |
/** |
| 10825 |
* @cfg {String/Boolean} [mention=false] |
| 10826 |
* |
| 10827 |
* A string for the service name to have mentions (ex: "@myuser") |
| 10828 |
* auto-linked to. The currently supported values are: |
| 10829 |
* |
| 10830 |
* - 'twitter' |
| 10831 |
* - 'instagram' |
| 10832 |
* - 'soundcloud' |
| 10833 |
* |
| 10834 |
* Defaults to `false` to skip auto-linking of mentions. |
| 10835 |
*/ |
| 10836 |
this.mention = false; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10837 |
/** |
| 10838 |
* @cfg {Boolean} [newWindow=true] |
| 10839 |
* |
| 10840 |
* `true` if the links should open in a new window, `false` otherwise. |
| 10841 |
*/ |
| 10842 |
this.newWindow = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10843 |
/** |
| 10844 |
* @cfg {Boolean/Object} [stripPrefix=true] |
| 10845 |
* |
| 10846 |
* `true` if 'http://' (or 'https://') and/or the 'www.' should be stripped |
| 10847 |
* from the beginning of URL links' text, `false` otherwise. Defaults to |
| 10848 |
* `true`. |
| 10849 |
* |
| 10850 |
* Examples: |
| 10851 |
* |
| 10852 |
* stripPrefix: true |
| 10853 |
* |
| 10854 |
* // or |
| 10855 |
* |
| 10856 |
* stripPrefix: { |
| 10857 |
* scheme : true, |
| 10858 |
* www : true |
| 10859 |
* } |
| 10860 |
* |
| 10861 |
* As shown above, this option also accepts an Object form with 2 properties |
| 10862 |
* to allow for more customization of what exactly is prevented from being |
| 10863 |
* displayed. Both default to `true`: |
| 10864 |
* |
| 10865 |
* @cfg {Boolean} [stripPrefix.scheme] `true` to prevent the scheme part of |
| 10866 |
* a URL match from being displayed to the user. Example: |
| 10867 |
* `'http://google.com'` will be displayed as `'google.com'`. `false` to |
| 10868 |
* not strip the scheme. NOTE: Only an `'http://'` or `'https://'` scheme |
| 10869 |
* will be removed, so as not to remove a potentially dangerous scheme |
| 10870 |
* (such as `'file://'` or `'javascript:'`) |
| 10871 |
* @cfg {Boolean} [stripPrefix.www] www (Boolean): `true` to prevent the |
| 10872 |
* `'www.'` part of a URL match from being displayed to the user. Ex: |
| 10873 |
* `'www.google.com'` will be displayed as `'google.com'`. `false` to not |
| 10874 |
* strip the `'www'`. |
| 10875 |
*/ |
| 10876 |
this.stripPrefix = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10877 |
/** |
| 10878 |
* @cfg {Boolean} [stripTrailingSlash=true] |
| 10879 |
* |
| 10880 |
* `true` to remove the trailing slash from URL matches, `false` to keep |
| 10881 |
* the trailing slash. |
| 10882 |
* |
| 10883 |
* Example when `true`: `http://google.com/` will be displayed as |
| 10884 |
* `http://google.com`. |
| 10885 |
*/ |
| 10886 |
this.stripTrailingSlash = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10887 |
/** |
| 10888 |
* @cfg {Boolean} [decodePercentEncoding=true] |
| 10889 |
* |
| 10890 |
* `true` to decode percent-encoded characters in URL matches, `false` to keep |
| 10891 |
* the percent-encoded characters. |
| 10892 |
* |
| 10893 |
* Example when `true`: `https://en.wikipedia.org/wiki/San_Jos%C3%A9` will |
| 10894 |
* be displayed as `https://en.wikipedia.org/wiki/San_José`. |
| 10895 |
*/ |
| 10896 |
this.decodePercentEncoding = true; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10897 |
/** |
| 10898 |
* @cfg {Number/Object} [truncate=0] |
| 10899 |
* |
| 10900 |
* ## Number Form |
| 10901 |
* |
| 10902 |
* A number for how many characters matched text should be truncated to |
| 10903 |
* inside the text of a link. If the matched text is over this number of |
| 10904 |
* characters, it will be truncated to this length by adding a two period |
| 10905 |
* ellipsis ('..') to the end of the string. |
| 10906 |
* |
| 10907 |
* For example: A url like 'http://www.yahoo.com/some/long/path/to/a/file' |
| 10908 |
* truncated to 25 characters might look something like this: |
| 10909 |
* 'yahoo.com/some/long/pat..' |
| 10910 |
* |
| 10911 |
* Example Usage: |
| 10912 |
* |
| 10913 |
* truncate: 25 |
| 10914 |
* |
| 10915 |
* |
| 10916 |
* Defaults to `0` for "no truncation." |
| 10917 |
* |
| 10918 |
* |
| 10919 |
* ## Object Form |
| 10920 |
* |
| 10921 |
* An Object may also be provided with two properties: `length` (Number) and |
| 10922 |
* `location` (String). `location` may be one of the following: 'end' |
| 10923 |
* (default), 'middle', or 'smart'. |
| 10924 |
* |
| 10925 |
* Example Usage: |
| 10926 |
* |
| 10927 |
* truncate: { length: 25, location: 'middle' } |
| 10928 |
* |
| 10929 |
* @cfg {Number} [truncate.length=0] How many characters to allow before |
| 10930 |
* truncation will occur. Defaults to `0` for "no truncation." |
| 10931 |
* @cfg {"end"/"middle"/"smart"} [truncate.location="end"] |
| 10932 |
* |
| 10933 |
* - 'end' (default): will truncate up to the number of characters, and then |
| 10934 |
* add an ellipsis at the end. Ex: 'yahoo.com/some/long/pat..' |
| 10935 |
* - 'middle': will truncate and add the ellipsis in the middle. Ex: |
| 10936 |
* 'yahoo.com/s..th/to/a/file' |
| 10937 |
* - 'smart': for URLs where the algorithm attempts to strip out unnecessary |
| 10938 |
* parts first (such as the 'www.', then URL scheme, hash, etc.), |
| 10939 |
* attempting to make the URL human-readable before looking for a good |
| 10940 |
* point to insert the ellipsis if it is still too long. Ex: |
| 10941 |
* 'yahoo.com/some..to/a/file'. For more details, see |
| 10942 |
* {@link Autolinker.truncate.TruncateSmart}. |
| 10943 |
*/ |
| 10944 |
this.truncate = { length: 0, location: 'end' }; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10945 |
/** |
| 10946 |
* @cfg {String} className |
| 10947 |
* |
| 10948 |
* A CSS class name to add to the generated links. This class will be added |
| 10949 |
* to all links, as well as this class plus match suffixes for styling |
| 10950 |
* url/email/phone/hashtag/mention links differently. |
| 10951 |
* |
| 10952 |
* For example, if this config is provided as "myLink", then: |
| 10953 |
* |
| 10954 |
* - URL links will have the CSS classes: "myLink myLink-url" |
| 10955 |
* - Email links will have the CSS classes: "myLink myLink-email", and |
| 10956 |
* - Phone links will have the CSS classes: "myLink myLink-phone" |
| 10957 |
* - Hashtag links will have the CSS classes: "myLink myLink-hashtag" |
| 10958 |
* - Mention links will have the CSS classes: "myLink myLink-mention myLink-[type]" |
| 10959 |
* where [type] is either "instagram", "twitter" or "soundcloud" |
| 10960 |
*/ |
| 10961 |
this.className = ''; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10962 |
/** |
| 10963 |
* @cfg {Function} replaceFn |
| 10964 |
* |
| 10965 |
* A function to individually process each match found in the input string. |
| 10966 |
* |
| 10967 |
* See the class's description for usage. |
| 10968 |
* |
| 10969 |
* The `replaceFn` can be called with a different context object (`this` |
| 10970 |
* reference) using the {@link #context} cfg. |
| 10971 |
* |
| 10972 |
* This function is called with the following parameter: |
| 10973 |
* |
| 10974 |
* @cfg {Autolinker.match.Match} replaceFn.match The Match instance which |
| 10975 |
* can be used to retrieve information about the match that the `replaceFn` |
| 10976 |
* is currently processing. See {@link Autolinker.match.Match} subclasses |
| 10977 |
* for details. |
| 10978 |
*/ |
| 10979 |
this.replaceFn = null; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10980 |
/** |
| 10981 |
* @cfg {Object} context |
| 10982 |
* |
| 10983 |
* The context object (`this` reference) to call the `replaceFn` with. |
| 10984 |
* |
| 10985 |
* Defaults to this Autolinker instance. |
| 10986 |
*/ |
| 10987 |
this.context = undefined; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 10988 |
/** |
| 10989 |
* @private |
| 10990 |
* @property {Autolinker.matcher.Matcher[]} matchers |
| 10991 |
* |
| 10992 |
* The {@link Autolinker.matcher.Matcher} instances for this Autolinker |
| 10993 |
* instance. |
| 10994 |
* |
| 10995 |
* This is lazily created in {@link #getMatchers}. |
| 10996 |
*/ |
| 10997 |
this.matchers = null; |
| 10998 |
/** |
| 10999 |
* @private |
| 11000 |
* @property {Autolinker.AnchorTagBuilder} tagBuilder |
| 11001 |
* |
| 11002 |
* The AnchorTagBuilder instance used to build match replacement anchor tags. |
| 11003 |
* Note: this is lazily instantiated in the {@link #getTagBuilder} method. |
| 11004 |
*/ |
| 11005 |
this.tagBuilder = null; |
| 11006 |
// Note: when `this.something` is used in the rhs of these assignments, |
| 11007 |
// it refers to the default values set above the constructor |
| 11008 |
this.urls = this.normalizeUrlsCfg(cfg.urls); |
| 11009 |
this.email = typeof cfg.email === 'boolean' ? cfg.email : this.email; |
| 11010 |
this.phone = typeof cfg.phone === 'boolean' ? cfg.phone : this.phone; |
| 11011 |
this.hashtag = cfg.hashtag || this.hashtag; |
| 11012 |
this.mention = cfg.mention || this.mention; |
| 11013 |
this.newWindow = typeof cfg.newWindow === 'boolean' ? cfg.newWindow : this.newWindow; |
| 11014 |
this.stripPrefix = this.normalizeStripPrefixCfg(cfg.stripPrefix); |
| 11015 |
this.stripTrailingSlash = typeof cfg.stripTrailingSlash === 'boolean' ? cfg.stripTrailingSlash : this.stripTrailingSlash; |
| 11016 |
this.decodePercentEncoding = typeof cfg.decodePercentEncoding === 'boolean' ? cfg.decodePercentEncoding : this.decodePercentEncoding; |
| 11017 |
// Validate the value of the `mention` cfg |
| 11018 |
var mention = this.mention; |
| 11019 |
if (mention !== false && mention !== 'twitter' && mention !== 'instagram' && mention !== 'soundcloud') { |
| 11020 |
throw new Error("invalid `mention` cfg - see docs"); |
| 11021 |
} |
| 11022 |
// Validate the value of the `hashtag` cfg |
| 11023 |
var hashtag = this.hashtag; |
| 11024 |
if (hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' && hashtag !== 'instagram') { |
| 11025 |
throw new Error("invalid `hashtag` cfg - see docs"); |
| 11026 |
} |
| 11027 |
this.truncate = this.normalizeTruncateCfg(cfg.truncate); |
| 11028 |
this.className = cfg.className || this.className; |
| 11029 |
this.replaceFn = cfg.replaceFn || this.replaceFn; |
| 11030 |
this.context = cfg.context || this; |
| 11031 |
} |
| 11032 |
/** |
| 11033 |
* Automatically links URLs, Email addresses, Phone Numbers, Twitter handles, |
| 11034 |
* Hashtags, and Mentions found in the given chunk of HTML. Does not link URLs |
| 11035 |
* found within HTML tags. |
| 11036 |
* |
| 11037 |
* For instance, if given the text: `You should go to http://www.yahoo.com`, |
| 11038 |
* then the result will be `You should go to <a href="http://www.yahoo.com">http://www.yahoo.com</a>` |
| 11039 |
* |
| 11040 |
* Example: |
| 11041 |
* |
| 11042 |
* var linkedText = Autolinker.link( "Go to google.com", { newWindow: false } ); |
| 11043 |
* // Produces: "Go to <a href="http://google.com">google.com</a>" |
| 11044 |
* |
| 11045 |
* @static |
| 11046 |
* @param {String} textOrHtml The HTML or text to find matches within (depending |
| 11047 |
* on if the {@link #urls}, {@link #email}, {@link #phone}, {@link #mention}, |
| 11048 |
* {@link #hashtag}, and {@link #mention} options are enabled). |
| 11049 |
* @param {Object} [options] Any of the configuration options for the Autolinker |
| 11050 |
* class, specified in an Object (map). See the class description for an |
| 11051 |
* example call. |
| 11052 |
* @return {String} The HTML text, with matches automatically linked. |
| 11053 |
*/ |
| 11054 |
Autolinker.link = function (textOrHtml, options) { |
| 11055 |
var autolinker = new Autolinker(options); |
| 11056 |
return autolinker.link(textOrHtml); |
| 11057 |
}; |
| 11058 |
/** |
| 11059 |
* Parses the input `textOrHtml` looking for URLs, email addresses, phone |
| 11060 |
* numbers, username handles, and hashtags (depending on the configuration |
| 11061 |
* of the Autolinker instance), and returns an array of {@link Autolinker.match.Match} |
| 11062 |
* objects describing those matches (without making any replacements). |
| 11063 |
* |
| 11064 |
* Note that if parsing multiple pieces of text, it is slightly more efficient |
| 11065 |
* to create an Autolinker instance, and use the instance-level {@link #parse} |
| 11066 |
* method. |
| 11067 |
* |
| 11068 |
* Example: |
| 11069 |
* |
| 11070 |
* var matches = Autolinker.parse( "Hello google.com, I am [email protected]", { |
| 11071 |
* urls: true, |
| 11072 |
* email: true |
| 11073 |
* } ); |
| 11074 |
* |
| 11075 |
* console.log( matches.length ); // 2 |
| 11076 |
* console.log( matches[ 0 ].getType() ); // 'url' |
| 11077 |
* console.log( matches[ 0 ].getUrl() ); // 'google.com' |
| 11078 |
* console.log( matches[ 1 ].getType() ); // 'email' |
| 11079 |
* console.log( matches[ 1 ].getEmail() ); // '[email protected]' |
| 11080 |
* |
| 11081 |
* @static |
| 11082 |
* @param {String} textOrHtml The HTML or text to find matches within |
| 11083 |
* (depending on if the {@link #urls}, {@link #email}, {@link #phone}, |
| 11084 |
* {@link #hashtag}, and {@link #mention} options are enabled). |
| 11085 |
* @param {Object} [options] Any of the configuration options for the Autolinker |
| 11086 |
* class, specified in an Object (map). See the class description for an |
| 11087 |
* example call. |
| 11088 |
* @return {Autolinker.match.Match[]} The array of Matches found in the |
| 11089 |
* given input `textOrHtml`. |
| 11090 |
*/ |
| 11091 |
Autolinker.parse = function (textOrHtml, options) { |
| 11092 |
var autolinker = new Autolinker(options); |
| 11093 |
return autolinker.parse(textOrHtml); |
| 11094 |
}; |
| 11095 |
/** |
| 11096 |
* Normalizes the {@link #urls} config into an Object with 3 properties: |
| 11097 |
* `schemeMatches`, `wwwMatches`, and `tldMatches`, all Booleans. |
| 11098 |
* |
| 11099 |
* See {@link #urls} config for details. |
| 11100 |
* |
| 11101 |
* @private |
| 11102 |
* @param {Boolean/Object} urls |
| 11103 |
* @return {Object} |
| 11104 |
*/ |
| 11105 |
Autolinker.prototype.normalizeUrlsCfg = function (urls) { |
| 11106 |
if (urls == null) |
| 11107 |
urls = true; // default to `true` |
| 11108 |
if (typeof urls === 'boolean') { |
| 11109 |
return { schemeMatches: urls, wwwMatches: urls, tldMatches: urls }; |
| 11110 |
} |
| 11111 |
else { // object form |
| 11112 |
return { |
| 11113 |
schemeMatches: typeof urls.schemeMatches === 'boolean' ? urls.schemeMatches : true, |
| 11114 |
wwwMatches: typeof urls.wwwMatches === 'boolean' ? urls.wwwMatches : true, |
| 11115 |
tldMatches: typeof urls.tldMatches === 'boolean' ? urls.tldMatches : true |
| 11116 |
}; |
| 11117 |
} |
| 11118 |
}; |
| 11119 |
/** |
| 11120 |
* Normalizes the {@link #stripPrefix} config into an Object with 2 |
| 11121 |
* properties: `scheme`, and `www` - both Booleans. |
| 11122 |
* |
| 11123 |
* See {@link #stripPrefix} config for details. |
| 11124 |
* |
| 11125 |
* @private |
| 11126 |
* @param {Boolean/Object} stripPrefix |
| 11127 |
* @return {Object} |
| 11128 |
*/ |
| 11129 |
Autolinker.prototype.normalizeStripPrefixCfg = function (stripPrefix) { |
| 11130 |
if (stripPrefix == null) |
| 11131 |
stripPrefix = true; // default to `true` |
| 11132 |
if (typeof stripPrefix === 'boolean') { |
| 11133 |
return { scheme: stripPrefix, www: stripPrefix }; |
| 11134 |
} |
| 11135 |
else { // object form |
| 11136 |
return { |
| 11137 |
scheme: typeof stripPrefix.scheme === 'boolean' ? stripPrefix.scheme : true, |
| 11138 |
www: typeof stripPrefix.www === 'boolean' ? stripPrefix.www : true |
| 11139 |
}; |
| 11140 |
} |
| 11141 |
}; |
| 11142 |
/** |
| 11143 |
* Normalizes the {@link #truncate} config into an Object with 2 properties: |
| 11144 |
* `length` (Number), and `location` (String). |
| 11145 |
* |
| 11146 |
* See {@link #truncate} config for details. |
| 11147 |
* |
| 11148 |
* @private |
| 11149 |
* @param {Number/Object} truncate |
| 11150 |
* @return {Object} |
| 11151 |
*/ |
| 11152 |
Autolinker.prototype.normalizeTruncateCfg = function (truncate) { |
| 11153 |
if (typeof truncate === 'number') { |
| 11154 |
return { length: truncate, location: 'end' }; |
| 11155 |
} |
| 11156 |
else { // object, or undefined/null |
| 11157 |
return defaults(truncate || {}, { |
| 11158 |
length: Number.POSITIVE_INFINITY, |
| 11159 |
location: 'end' |
| 11160 |
}); |
| 11161 |
} |
| 11162 |
}; |
| 11163 |
/** |
| 11164 |
* Parses the input `textOrHtml` looking for URLs, email addresses, phone |
| 11165 |
* numbers, username handles, and hashtags (depending on the configuration |
| 11166 |
* of the Autolinker instance), and returns an array of {@link Autolinker.match.Match} |
| 11167 |
* objects describing those matches (without making any replacements). |
| 11168 |
* |
| 11169 |
* This method is used by the {@link #link} method, but can also be used to |
| 11170 |
* simply do parsing of the input in order to discover what kinds of links |
| 11171 |
* there are and how many. |
| 11172 |
* |
| 11173 |
* Example usage: |
| 11174 |
* |
| 11175 |
* var autolinker = new Autolinker( { |
| 11176 |
* urls: true, |
| 11177 |
* email: true |
| 11178 |
* } ); |
| 11179 |
* |
| 11180 |
* var matches = autolinker.parse( "Hello google.com, I am [email protected]" ); |
| 11181 |
* |
| 11182 |
* console.log( matches.length ); // 2 |
| 11183 |
* console.log( matches[ 0 ].getType() ); // 'url' |
| 11184 |
* console.log( matches[ 0 ].getUrl() ); // 'google.com' |
| 11185 |
* console.log( matches[ 1 ].getType() ); // 'email' |
| 11186 |
* console.log( matches[ 1 ].getEmail() ); // '[email protected]' |
| 11187 |
* |
| 11188 |
* @param {String} textOrHtml The HTML or text to find matches within |
| 11189 |
* (depending on if the {@link #urls}, {@link #email}, {@link #phone}, |
| 11190 |
* {@link #hashtag}, and {@link #mention} options are enabled). |
| 11191 |
* @return {Autolinker.match.Match[]} The array of Matches found in the |
| 11192 |
* given input `textOrHtml`. |
| 11193 |
*/ |
| 11194 |
Autolinker.prototype.parse = function (textOrHtml) { |
| 11195 |
var _this = this; |
| 11196 |
var skipTagNames = ['a', 'style', 'script'], skipTagsStackCount = 0, // used to only Autolink text outside of anchor/script/style tags. We don't want to autolink something that is already linked inside of an <a> tag, for instance |
| 11197 |
matches = []; |
| 11198 |
// Find all matches within the `textOrHtml` (but not matches that are |
| 11199 |
// already nested within <a>, <style> and <script> tags) |
| 11200 |
parseHtml(textOrHtml, { |
| 11201 |
onOpenTag: function (tagName) { |
| 11202 |
if (skipTagNames.indexOf(tagName) >= 0) { |
| 11203 |
skipTagsStackCount++; |
| 11204 |
} |
| 11205 |
}, |
| 11206 |
onText: function (text, offset) { |
| 11207 |
// Only process text nodes that are not within an <a>, <style> or <script> tag |
| 11208 |
if (skipTagsStackCount === 0) { |
| 11209 |
// "Walk around" common HTML entities. An ' ' (for example) |
| 11210 |
// could be at the end of a URL, but we don't want to |
| 11211 |
// include the trailing '&' in the URL. See issue #76 |
| 11212 |
// TODO: Handle HTML entities separately in parseHtml() and |
| 11213 |
// don't emit them as "text" except for & entities |
| 11214 |
var htmlCharacterEntitiesRegex = /( | |<|<|>|>|"|"|')/gi; |
| 11215 |
var textSplit = splitAndCapture(text, htmlCharacterEntitiesRegex); |
| 11216 |
var currentOffset_1 = offset; |
| 11217 |
textSplit.forEach(function (splitText, i) { |
| 11218 |
// even number matches are text, odd numbers are html entities |
| 11219 |
if (i % 2 === 0) { |
| 11220 |
var textNodeMatches = _this.parseText(splitText, currentOffset_1); |
| 11221 |
matches.push.apply(matches, textNodeMatches); |
| 11222 |
} |
| 11223 |
currentOffset_1 += splitText.length; |
| 11224 |
}); |
| 11225 |
} |
| 11226 |
}, |
| 11227 |
onCloseTag: function (tagName) { |
| 11228 |
if (skipTagNames.indexOf(tagName) >= 0) { |
| 11229 |
skipTagsStackCount = Math.max(skipTagsStackCount - 1, 0); // attempt to handle extraneous </a> tags by making sure the stack count never goes below 0 |
| 11230 |
} |
| 11231 |
}, |
| 11232 |
onComment: function (offset) { }, |
| 11233 |
onDoctype: function (offset) { }, |
| 11234 |
}); |
| 11235 |
// After we have found all matches, remove subsequent matches that |
| 11236 |
// overlap with a previous match. This can happen for instance with URLs, |
| 11237 |
// where the url 'google.com/#link' would match '#link' as a hashtag. |
| 11238 |
matches = this.compactMatches(matches); |
| 11239 |
// And finally, remove matches for match types that have been turned |
| 11240 |
// off. We needed to have all match types turned on initially so that |
| 11241 |
// things like hashtags could be filtered out if they were really just |
| 11242 |
// part of a URL match (for instance, as a named anchor). |
| 11243 |
matches = this.removeUnwantedMatches(matches); |
| 11244 |
return matches; |
| 11245 |
}; |
| 11246 |
/** |
| 11247 |
* After we have found all matches, we need to remove matches that overlap |
| 11248 |
* with a previous match. This can happen for instance with URLs, where the |
| 11249 |
* url 'google.com/#link' would match '#link' as a hashtag. Because the |
| 11250 |
* '#link' part is contained in a larger match that comes before the HashTag |
| 11251 |
* match, we'll remove the HashTag match. |
| 11252 |
* |
| 11253 |
* @private |
| 11254 |
* @param {Autolinker.match.Match[]} matches |
| 11255 |
* @return {Autolinker.match.Match[]} |
| 11256 |
*/ |
| 11257 |
Autolinker.prototype.compactMatches = function (matches) { |
| 11258 |
// First, the matches need to be sorted in order of offset |
| 11259 |
matches.sort(function (a, b) { return a.getOffset() - b.getOffset(); }); |
| 11260 |
for (var i = 0; i < matches.length - 1; i++) { |
| 11261 |
var match = matches[i], offset = match.getOffset(), matchedTextLength = match.getMatchedText().length, endIdx = offset + matchedTextLength; |
| 11262 |
if (i + 1 < matches.length) { |
| 11263 |
// Remove subsequent matches that equal offset with current match |
| 11264 |
if (matches[i + 1].getOffset() === offset) { |
| 11265 |
var removeIdx = matches[i + 1].getMatchedText().length > matchedTextLength ? i : i + 1; |
| 11266 |
matches.splice(removeIdx, 1); |
| 11267 |
continue; |
| 11268 |
} |
| 11269 |
// Remove subsequent matches that overlap with the current match |
| 11270 |
if (matches[i + 1].getOffset() < endIdx) { |
| 11271 |
matches.splice(i + 1, 1); |
| 11272 |
} |
| 11273 |
} |
| 11274 |
} |
| 11275 |
return matches; |
| 11276 |
}; |
| 11277 |
/** |
| 11278 |
* Removes matches for matchers that were turned off in the options. For |
| 11279 |
* example, if {@link #hashtag hashtags} were not to be matched, we'll |
| 11280 |
* remove them from the `matches` array here. |
| 11281 |
* |
| 11282 |
* Note: we *must* use all Matchers on the input string, and then filter |
| 11283 |
* them out later. For example, if the options were `{ url: false, hashtag: true }`, |
| 11284 |
* we wouldn't want to match the text '#link' as a HashTag inside of the text |
| 11285 |
* 'google.com/#link'. The way the algorithm works is that we match the full |
| 11286 |
* URL first (which prevents the accidental HashTag match), and then we'll |
| 11287 |
* simply throw away the URL match. |
| 11288 |
* |
| 11289 |
* @private |
| 11290 |
* @param {Autolinker.match.Match[]} matches The array of matches to remove |
| 11291 |
* the unwanted matches from. Note: this array is mutated for the |
| 11292 |
* removals. |
| 11293 |
* @return {Autolinker.match.Match[]} The mutated input `matches` array. |
| 11294 |
*/ |
| 11295 |
Autolinker.prototype.removeUnwantedMatches = function (matches) { |
| 11296 |
if (!this.hashtag) |
| 11297 |
remove(matches, function (match) { return match.getType() === 'hashtag'; }); |
| 11298 |
if (!this.email) |
| 11299 |
remove(matches, function (match) { return match.getType() === 'email'; }); |
| 11300 |
if (!this.phone) |
| 11301 |
remove(matches, function (match) { return match.getType() === 'phone'; }); |
| 11302 |
if (!this.mention) |
| 11303 |
remove(matches, function (match) { return match.getType() === 'mention'; }); |
| 11304 |
if (!this.urls.schemeMatches) { |
| 11305 |
remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'scheme'; }); |
| 11306 |
} |
| 11307 |
if (!this.urls.wwwMatches) { |
| 11308 |
remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'www'; }); |
| 11309 |
} |
| 11310 |
if (!this.urls.tldMatches) { |
| 11311 |
remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'tld'; }); |
| 11312 |
} |
| 11313 |
return matches; |
| 11314 |
}; |
| 11315 |
/** |
| 11316 |
* Parses the input `text` looking for URLs, email addresses, phone |
| 11317 |
* numbers, username handles, and hashtags (depending on the configuration |
| 11318 |
* of the Autolinker instance), and returns an array of {@link Autolinker.match.Match} |
| 11319 |
* objects describing those matches. |
| 11320 |
* |
| 11321 |
* This method processes a **non-HTML string**, and is used to parse and |
| 11322 |
* match within the text nodes of an HTML string. This method is used |
| 11323 |
* internally by {@link #parse}. |
| 11324 |
* |
| 11325 |
* @private |
| 11326 |
* @param {String} text The text to find matches within (depending on if the |
| 11327 |
* {@link #urls}, {@link #email}, {@link #phone}, |
| 11328 |
* {@link #hashtag}, and {@link #mention} options are enabled). This must be a non-HTML string. |
| 11329 |
* @param {Number} [offset=0] The offset of the text node within the |
| 11330 |
* original string. This is used when parsing with the {@link #parse} |
| 11331 |
* method to generate correct offsets within the {@link Autolinker.match.Match} |
| 11332 |
* instances, but may be omitted if calling this method publicly. |
| 11333 |
* @return {Autolinker.match.Match[]} The array of Matches found in the |
| 11334 |
* given input `text`. |
| 11335 |
*/ |
| 11336 |
Autolinker.prototype.parseText = function (text, offset) { |
| 11337 |
if (offset === void 0) { offset = 0; } |
| 11338 |
offset = offset || 0; |
| 11339 |
var matchers = this.getMatchers(), matches = []; |
| 11340 |
for (var i = 0, numMatchers = matchers.length; i < numMatchers; i++) { |
| 11341 |
var textMatches = matchers[i].parseMatches(text); |
| 11342 |
// Correct the offset of each of the matches. They are originally |
| 11343 |
// the offset of the match within the provided text node, but we |
| 11344 |
// need to correct them to be relative to the original HTML input |
| 11345 |
// string (i.e. the one provided to #parse). |
| 11346 |
for (var j = 0, numTextMatches = textMatches.length; j < numTextMatches; j++) { |
| 11347 |
textMatches[j].setOffset(offset + textMatches[j].getOffset()); |
| 11348 |
} |
| 11349 |
matches.push.apply(matches, textMatches); |
| 11350 |
} |
| 11351 |
return matches; |
| 11352 |
}; |
| 11353 |
/** |
| 11354 |
* Automatically links URLs, Email addresses, Phone numbers, Hashtags, |
| 11355 |
* and Mentions (Twitter, Instagram, Soundcloud) found in the given chunk of HTML. Does not link |
| 11356 |
* URLs found within HTML tags. |
| 11357 |
* |
| 11358 |
* For instance, if given the text: `You should go to http://www.yahoo.com`, |
| 11359 |
* then the result will be `You should go to |
| 11360 |
* <a href="http://www.yahoo.com">http://www.yahoo.com</a>` |
| 11361 |
* |
| 11362 |
* This method finds the text around any HTML elements in the input |
| 11363 |
* `textOrHtml`, which will be the text that is processed. Any original HTML |
| 11364 |
* elements will be left as-is, as well as the text that is already wrapped |
| 11365 |
* in anchor (<a>) tags. |
| 11366 |
* |
| 11367 |
* @param {String} textOrHtml The HTML or text to autolink matches within |
| 11368 |
* (depending on if the {@link #urls}, {@link #email}, {@link #phone}, {@link #hashtag}, and {@link #mention} options are enabled). |
| 11369 |
* @return {String} The HTML, with matches automatically linked. |
| 11370 |
*/ |
| 11371 |
Autolinker.prototype.link = function (textOrHtml) { |
| 11372 |
if (!textOrHtml) { |
| 11373 |
return ""; |
| 11374 |
} // handle `null` and `undefined` |
| 11375 |
var matches = this.parse(textOrHtml), newHtml = [], lastIndex = 0; |
| 11376 |
for (var i = 0, len = matches.length; i < len; i++) { |
| 11377 |
var match = matches[i]; |
| 11378 |
newHtml.push(textOrHtml.substring(lastIndex, match.getOffset())); |
| 11379 |
newHtml.push(this.createMatchReturnVal(match)); |
| 11380 |
lastIndex = match.getOffset() + match.getMatchedText().length; |
| 11381 |
} |
| 11382 |
newHtml.push(textOrHtml.substring(lastIndex)); // handle the text after the last match |
| 11383 |
return newHtml.join(''); |
| 11384 |
}; |
| 11385 |
/** |
| 11386 |
* Creates the return string value for a given match in the input string. |
| 11387 |
* |
| 11388 |
* This method handles the {@link #replaceFn}, if one was provided. |
| 11389 |
* |
| 11390 |
* @private |
| 11391 |
* @param {Autolinker.match.Match} match The Match object that represents |
| 11392 |
* the match. |
| 11393 |
* @return {String} The string that the `match` should be replaced with. |
| 11394 |
* This is usually the anchor tag string, but may be the `matchStr` itself |
| 11395 |
* if the match is not to be replaced. |
| 11396 |
*/ |
| 11397 |
Autolinker.prototype.createMatchReturnVal = function (match) { |
| 11398 |
// Handle a custom `replaceFn` being provided |
| 11399 |
var replaceFnResult; |
| 11400 |
if (this.replaceFn) { |
| 11401 |
replaceFnResult = this.replaceFn.call(this.context, match); // Autolinker instance is the context |
| 11402 |
} |
| 11403 |
if (typeof replaceFnResult === 'string') { |
| 11404 |
return replaceFnResult; // `replaceFn` returned a string, use that |
| 11405 |
} |
| 11406 |
else if (replaceFnResult === false) { |
| 11407 |
return match.getMatchedText(); // no replacement for the match |
| 11408 |
} |
| 11409 |
else if (replaceFnResult instanceof HtmlTag) { |
| 11410 |
return replaceFnResult.toAnchorString(); |
| 11411 |
} |
| 11412 |
else { // replaceFnResult === true, or no/unknown return value from function |
| 11413 |
// Perform Autolinker's default anchor tag generation |
| 11414 |
var anchorTag = match.buildTag(); // returns an Autolinker.HtmlTag instance |
| 11415 |
return anchorTag.toAnchorString(); |
| 11416 |
} |
| 11417 |
}; |
| 11418 |
/** |
| 11419 |
* Lazily instantiates and returns the {@link Autolinker.matcher.Matcher} |
| 11420 |
* instances for this Autolinker instance. |
| 11421 |
* |
| 11422 |
* @private |
| 11423 |
* @return {Autolinker.matcher.Matcher[]} |
| 11424 |
*/ |
| 11425 |
Autolinker.prototype.getMatchers = function () { |
| 11426 |
if (!this.matchers) { |
| 11427 |
var tagBuilder = this.getTagBuilder(); |
| 11428 |
var matchers = [ |
| 11429 |
new HashtagMatcher({ tagBuilder: tagBuilder, serviceName: this.hashtag }), |
| 11430 |
new EmailMatcher({ tagBuilder: tagBuilder }), |
| 11431 |
new PhoneMatcher({ tagBuilder: tagBuilder }), |
| 11432 |
new MentionMatcher({ tagBuilder: tagBuilder, serviceName: this.mention }), |
| 11433 |
new UrlMatcher({ tagBuilder: tagBuilder, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding }) |
| 11434 |
]; |
| 11435 |
return (this.matchers = matchers); |
| 11436 |
} |
| 11437 |
else { |
| 11438 |
return this.matchers; |
| 11439 |
} |
| 11440 |
}; |
| 11441 |
/** |
| 11442 |
* Returns the {@link #tagBuilder} instance for this Autolinker instance, |
| 11443 |
* lazily instantiating it if it does not yet exist. |
| 11444 |
* |
| 11445 |
* @private |
| 11446 |
* @return {Autolinker.AnchorTagBuilder} |
| 11447 |
*/ |
| 11448 |
Autolinker.prototype.getTagBuilder = function () { |
| 11449 |
var tagBuilder = this.tagBuilder; |
| 11450 |
if (!tagBuilder) { |
| 11451 |
tagBuilder = this.tagBuilder = new AnchorTagBuilder({ |
| 11452 |
newWindow: this.newWindow, |
| 11453 |
truncate: this.truncate, |
| 11454 |
className: this.className |
| 11455 |
}); |
| 11456 |
} |
| 11457 |
return tagBuilder; |
| 11458 |
}; |
| 11459 |
/** |
| 11460 |
* @static |
| 11461 |
* @property {String} version |
| 11462 |
* |
| 11463 |
* The Autolinker version number in the form major.minor.patch |
| 11464 |
* |
| 11465 |
* Ex: 0.25.1 |
| 11466 |
*/ |
| 11467 |
Autolinker.version = '3.11.0'; |
| 11468 |
/** |
| 11469 |
* For backwards compatibility with Autolinker 1.x, the AnchorTagBuilder |
| 11470 |
* class is provided as a static on the Autolinker class. |
| 11471 |
*/ |
| 11472 |
Autolinker.AnchorTagBuilder = AnchorTagBuilder; |
| 11473 |
/** |
| 11474 |
* For backwards compatibility with Autolinker 1.x, the HtmlTag class is |
| 11475 |
* provided as a static on the Autolinker class. |
| 11476 |
*/ |
| 11477 |
Autolinker.HtmlTag = HtmlTag; |
| 11478 |
/** |
| 11479 |
* For backwards compatibility with Autolinker 1.x, the Matcher classes are |
| 11480 |
* provided as statics on the Autolinker class. |
| 11481 |
*/ |
| 11482 |
Autolinker.matcher = { |
| 11483 |
Email: EmailMatcher, |
| 11484 |
Hashtag: HashtagMatcher, |
| 11485 |
Matcher: Matcher, |
| 11486 |
Mention: MentionMatcher, |
| 11487 |
Phone: PhoneMatcher, |
| 11488 |
Url: UrlMatcher |
| 11489 |
}; |
| 11490 |
/** |
| 11491 |
* For backwards compatibility with Autolinker 1.x, the Match classes are |
| 11492 |
* provided as statics on the Autolinker class. |
| 11493 |
*/ |
| 11494 |
Autolinker.match = { |
| 11495 |
Email: EmailMatch, |
| 11496 |
Hashtag: HashtagMatch, |
| 11497 |
Match: Match, |
| 11498 |
Mention: MentionMatch, |
| 11499 |
Phone: PhoneMatch, |
| 11500 |
Url: UrlMatch |
| 11501 |
}; |
| 11502 |
return Autolinker; |
| 11503 |
}()); |
| 11504 |
|
| 11505 |
// Autoconvert URL-like texts to links |
| 11506 |
|
| 11507 |
|
| 11508 |
var LINK_SCAN_RE = /www|@|\:\/\//; |
| 11509 |
|
| 11510 |
|
| 11511 |
function isLinkOpen(str) { |
| 11512 |
return /^<a[>\s]/i.test(str); |
| 11513 |
} |
| 11514 |
function isLinkClose(str) { |
| 11515 |
return /^<\/a\s*>/i.test(str); |
| 11516 |
} |
| 11517 |
|
| 11518 |
// Stupid fabric to avoid singletons, for thread safety. |
| 11519 |
// Required for engines like Nashorn. |
| 11520 |
// |
| 11521 |
function createLinkifier() { |
| 11522 |
var links = []; |
| 11523 |
var autolinker = new Autolinker({ |
| 11524 |
stripPrefix: false, |
| 11525 |
url: true, |
| 11526 |
email: true, |
| 11527 |
replaceFn: function (match) { |
| 11528 |
// Only collect matched strings but don't change anything. |
| 11529 |
switch (match.getType()) { |
| 11530 |
/*eslint default-case:0*/ |
| 11531 |
case 'url': |
| 11532 |
links.push({ |
| 11533 |
text: match.matchedText, |
| 11534 |
url: match.getUrl() |
| 11535 |
}); |
| 11536 |
break; |
| 11537 |
case 'email': |
| 11538 |
links.push({ |
| 11539 |
text: match.matchedText, |
| 11540 |
// normalize email protocol |
| 11541 |
url: 'mailto:' + match.getEmail().replace(/^mailto:/i, '') |
| 11542 |
}); |
| 11543 |
break; |
| 11544 |
} |
| 11545 |
return false; |
| 11546 |
} |
| 11547 |
}); |
| 11548 |
|
| 11549 |
return { |
| 11550 |
links: links, |
| 11551 |
autolinker: autolinker |
| 11552 |
}; |
| 11553 |
} |
| 11554 |
|
| 11555 |
|
| 11556 |
function parseTokens(state) { |
| 11557 |
var i, j, l, tokens, token, text, nodes, ln, pos, level, htmlLinkLevel, |
| 11558 |
blockTokens = state.tokens, |
| 11559 |
linkifier = null, links, autolinker; |
| 11560 |
|
| 11561 |
for (j = 0, l = blockTokens.length; j < l; j++) { |
| 11562 |
if (blockTokens[j].type !== 'inline') { continue; } |
| 11563 |
tokens = blockTokens[j].children; |
| 11564 |
|
| 11565 |
htmlLinkLevel = 0; |
| 11566 |
|
| 11567 |
// We scan from the end, to keep position when new tags added. |
| 11568 |
// Use reversed logic in links start/end match |
| 11569 |
for (i = tokens.length - 1; i >= 0; i--) { |
| 11570 |
token = tokens[i]; |
| 11571 |
|
| 11572 |
// Skip content of markdown links |
| 11573 |
if (token.type === 'link_close') { |
| 11574 |
i--; |
| 11575 |
while (tokens[i].level !== token.level && tokens[i].type !== 'link_open') { |
| 11576 |
i--; |
| 11577 |
} |
| 11578 |
continue; |
| 11579 |
} |
| 11580 |
|
| 11581 |
// Skip content of html tag links |
| 11582 |
if (token.type === 'htmltag') { |
| 11583 |
if (isLinkOpen(token.content) && htmlLinkLevel > 0) { |
| 11584 |
htmlLinkLevel--; |
| 11585 |
} |
| 11586 |
if (isLinkClose(token.content)) { |
| 11587 |
htmlLinkLevel++; |
| 11588 |
} |
| 11589 |
} |
| 11590 |
if (htmlLinkLevel > 0) { continue; } |
| 11591 |
|
| 11592 |
if (token.type === 'text' && LINK_SCAN_RE.test(token.content)) { |
| 11593 |
|
| 11594 |
// Init linkifier in lazy manner, only if required. |
| 11595 |
if (!linkifier) { |
| 11596 |
linkifier = createLinkifier(); |
| 11597 |
links = linkifier.links; |
| 11598 |
autolinker = linkifier.autolinker; |
| 11599 |
} |
| 11600 |
|
| 11601 |
text = token.content; |
| 11602 |
links.length = 0; |
| 11603 |
autolinker.link(text); |
| 11604 |
|
| 11605 |
if (!links.length) { continue; } |
| 11606 |
|
| 11607 |
// Now split string to nodes |
| 11608 |
nodes = []; |
| 11609 |
level = token.level; |
| 11610 |
|
| 11611 |
for (ln = 0; ln < links.length; ln++) { |
| 11612 |
|
| 11613 |
if (!state.inline.validateLink(links[ln].url)) { continue; } |
| 11614 |
|
| 11615 |
pos = text.indexOf(links[ln].text); |
| 11616 |
|
| 11617 |
if (pos) { |
| 11618 |
nodes.push({ |
| 11619 |
type: 'text', |
| 11620 |
content: text.slice(0, pos), |
| 11621 |
level: level |
| 11622 |
}); |
| 11623 |
} |
| 11624 |
nodes.push({ |
| 11625 |
type: 'link_open', |
| 11626 |
href: links[ln].url, |
| 11627 |
title: '', |
| 11628 |
level: level++ |
| 11629 |
}); |
| 11630 |
nodes.push({ |
| 11631 |
type: 'text', |
| 11632 |
content: links[ln].text, |
| 11633 |
level: level |
| 11634 |
}); |
| 11635 |
nodes.push({ |
| 11636 |
type: 'link_close', |
| 11637 |
level: --level |
| 11638 |
}); |
| 11639 |
text = text.slice(pos + links[ln].text.length); |
| 11640 |
} |
| 11641 |
if (text.length) { |
| 11642 |
nodes.push({ |
| 11643 |
type: 'text', |
| 11644 |
content: text, |
| 11645 |
level: level |
| 11646 |
}); |
| 11647 |
} |
| 11648 |
|
| 11649 |
// replace current node |
| 11650 |
blockTokens[j].children = tokens = [].concat(tokens.slice(0, i), nodes, tokens.slice(i + 1)); |
| 11651 |
} |
| 11652 |
} |
| 11653 |
} |
| 11654 |
} |
| 11655 |
function linkify(md) { |
| 11656 |
md.core.ruler.push('linkify', parseTokens); |
| 11657 |
} |
| 11658 |
|
| 11659 |
exports.Remarkable = Remarkable; |
| 11660 |
exports.linkify = linkify; |
| 11661 |
exports.utils = utils; |
| 11662 |
|
| 11663 |
Object.defineProperty(exports, '__esModule', { value: true }); |
| 11664 |
|
| 11665 |
})); |