You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5459 lines
169 KiB

  1. ;/*! showdown v 2.0.0-alpha1 - 24-10-2018 */
  2. (function(){
  3. /**
  4. * Created by Tivie on 13-07-2015.
  5. */
  6. function getDefaultOpts (simple) {
  7. 'use strict';
  8. var defaultOptions = {
  9. omitExtraWLInCodeBlocks: {
  10. defaultValue: false,
  11. describe: 'Omit the default extra whiteline added to code blocks',
  12. type: 'boolean'
  13. },
  14. noHeaderId: {
  15. defaultValue: false,
  16. describe: 'Turn on/off generated header id',
  17. type: 'boolean'
  18. },
  19. prefixHeaderId: {
  20. defaultValue: false,
  21. describe: 'Add a prefix to the generated header ids. Passing a string will prefix that string to the header id. Setting to true will add a generic \'section-\' prefix',
  22. type: 'string'
  23. },
  24. rawPrefixHeaderId: {
  25. defaultValue: false,
  26. describe: 'Setting this option to true will prevent showdown from modifying the prefix. This might result in malformed IDs (if, for instance, the " char is used in the prefix)',
  27. type: 'boolean'
  28. },
  29. ghCompatibleHeaderId: {
  30. defaultValue: false,
  31. describe: 'Generate header ids compatible with github style (spaces are replaced with dashes, a bunch of non alphanumeric chars are removed)',
  32. type: 'boolean'
  33. },
  34. rawHeaderId: {
  35. defaultValue: false,
  36. describe: 'Remove only spaces, \' and " from generated header ids (including prefixes), replacing them with dashes (-). WARNING: This might result in malformed ids',
  37. type: 'boolean'
  38. },
  39. headerLevelStart: {
  40. defaultValue: false,
  41. describe: 'The header blocks level start',
  42. type: 'integer'
  43. },
  44. parseImgDimensions: {
  45. defaultValue: false,
  46. describe: 'Turn on/off image dimension parsing',
  47. type: 'boolean'
  48. },
  49. simplifiedAutoLink: {
  50. defaultValue: false,
  51. describe: 'Turn on/off GFM autolink style',
  52. type: 'boolean'
  53. },
  54. literalMidWordUnderscores: {
  55. defaultValue: false,
  56. describe: 'Parse midword underscores as literal underscores',
  57. type: 'boolean'
  58. },
  59. literalMidWordAsterisks: {
  60. defaultValue: false,
  61. describe: 'Parse midword asterisks as literal asterisks',
  62. type: 'boolean'
  63. },
  64. strikethrough: {
  65. defaultValue: false,
  66. describe: 'Turn on/off strikethrough support',
  67. type: 'boolean'
  68. },
  69. tables: {
  70. defaultValue: false,
  71. describe: 'Turn on/off tables support',
  72. type: 'boolean'
  73. },
  74. tablesHeaderId: {
  75. defaultValue: false,
  76. describe: 'Add an id to table headers',
  77. type: 'boolean'
  78. },
  79. ghCodeBlocks: {
  80. defaultValue: true,
  81. describe: 'Turn on/off GFM fenced code blocks support',
  82. type: 'boolean'
  83. },
  84. tasklists: {
  85. defaultValue: false,
  86. describe: 'Turn on/off GFM tasklist support',
  87. type: 'boolean'
  88. },
  89. smoothLivePreview: {
  90. defaultValue: false,
  91. describe: 'Prevents weird effects in live previews due to incomplete input',
  92. type: 'boolean'
  93. },
  94. smartIndentationFix: {
  95. defaultValue: false,
  96. description: 'Tries to smartly fix indentation in es6 strings',
  97. type: 'boolean'
  98. },
  99. disableForced4SpacesIndentedSublists: {
  100. defaultValue: false,
  101. description: 'Disables the requirement of indenting nested sublists by 4 spaces',
  102. type: 'boolean'
  103. },
  104. simpleLineBreaks: {
  105. defaultValue: false,
  106. description: 'Parses simple line breaks as <br> (GFM Style)',
  107. type: 'boolean'
  108. },
  109. requireSpaceBeforeHeadingText: {
  110. defaultValue: false,
  111. description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
  112. type: 'boolean'
  113. },
  114. ghMentions: {
  115. defaultValue: false,
  116. description: 'Enables github @mentions',
  117. type: 'boolean'
  118. },
  119. ghMentionsLink: {
  120. defaultValue: 'https://github.com/{u}',
  121. description: 'Changes the link generated by @mentions. Only applies if ghMentions option is enabled.',
  122. type: 'string'
  123. },
  124. encodeEmails: {
  125. defaultValue: true,
  126. description: 'Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities',
  127. type: 'boolean'
  128. },
  129. openLinksInNewWindow: {
  130. defaultValue: false,
  131. description: 'Open all links in new windows',
  132. type: 'boolean'
  133. },
  134. backslashEscapesHTMLTags: {
  135. defaultValue: false,
  136. description: 'Support for HTML Tag escaping. ex: \<div>foo\</div>',
  137. type: 'boolean'
  138. },
  139. emoji: {
  140. defaultValue: false,
  141. description: 'Enable emoji support. Ex: `this is a :smile: emoji`',
  142. type: 'boolean'
  143. },
  144. underline: {
  145. defaultValue: false,
  146. description: 'Enable support for underline. Syntax is double or triple underscores: `__underline word__`. With this option enabled, underscores no longer parses into `<em>` and `<strong>`',
  147. type: 'boolean'
  148. },
  149. completeHTMLDocument: {
  150. defaultValue: false,
  151. description: 'Outputs a complete html document, including `<html>`, `<head>` and `<body>` tags',
  152. type: 'boolean'
  153. },
  154. metadata: {
  155. defaultValue: false,
  156. description: 'Enable support for document metadata (defined at the top of the document between `«««` and `»»»` or between `---` and `---`).',
  157. type: 'boolean'
  158. },
  159. splitAdjacentBlockquotes: {
  160. defaultValue: false,
  161. description: 'Split adjacent blockquote blocks',
  162. type: 'boolean'
  163. }
  164. };
  165. if (simple === false) {
  166. return JSON.parse(JSON.stringify(defaultOptions));
  167. }
  168. var ret = {};
  169. for (var opt in defaultOptions) {
  170. if (defaultOptions.hasOwnProperty(opt)) {
  171. ret[opt] = defaultOptions[opt].defaultValue;
  172. }
  173. }
  174. return ret;
  175. }
  176. function allOptionsOn () {
  177. 'use strict';
  178. var options = getDefaultOpts(true),
  179. ret = {};
  180. for (var opt in options) {
  181. if (options.hasOwnProperty(opt)) {
  182. ret[opt] = true;
  183. }
  184. }
  185. return ret;
  186. }
  187. /**
  188. * Created by Tivie on 06-01-2015.
  189. */
  190. // Private properties
  191. var showdown = {},
  192. parsers = {},
  193. extensions = {},
  194. globalOptions = getDefaultOpts(true),
  195. setFlavor = 'vanilla',
  196. flavor = {
  197. github: {
  198. omitExtraWLInCodeBlocks: true,
  199. simplifiedAutoLink: true,
  200. literalMidWordUnderscores: true,
  201. strikethrough: true,
  202. tables: true,
  203. tablesHeaderId: true,
  204. ghCodeBlocks: true,
  205. tasklists: true,
  206. disableForced4SpacesIndentedSublists: true,
  207. simpleLineBreaks: true,
  208. requireSpaceBeforeHeadingText: true,
  209. ghCompatibleHeaderId: true,
  210. ghMentions: true,
  211. backslashEscapesHTMLTags: true,
  212. emoji: true,
  213. splitAdjacentBlockquotes: true
  214. },
  215. original: {
  216. noHeaderId: true,
  217. ghCodeBlocks: false
  218. },
  219. ghost: {
  220. omitExtraWLInCodeBlocks: true,
  221. parseImgDimensions: true,
  222. simplifiedAutoLink: true,
  223. literalMidWordUnderscores: true,
  224. strikethrough: true,
  225. tables: true,
  226. tablesHeaderId: true,
  227. ghCodeBlocks: true,
  228. tasklists: true,
  229. smoothLivePreview: true,
  230. simpleLineBreaks: true,
  231. requireSpaceBeforeHeadingText: true,
  232. ghMentions: false,
  233. encodeEmails: true
  234. },
  235. vanilla: getDefaultOpts(true),
  236. allOn: allOptionsOn()
  237. };
  238. /**
  239. * helper namespace
  240. * @type {{}}
  241. */
  242. showdown.helper = {};
  243. /**
  244. * TODO LEGACY SUPPORT CODE
  245. * @type {{}}
  246. */
  247. showdown.extensions = {};
  248. /**
  249. * Set a global option
  250. * @static
  251. * @param {string} key
  252. * @param {*} value
  253. * @returns {showdown}
  254. */
  255. showdown.setOption = function (key, value) {
  256. 'use strict';
  257. globalOptions[key] = value;
  258. return this;
  259. };
  260. /**
  261. * Get a global option
  262. * @static
  263. * @param {string} key
  264. * @returns {*}
  265. */
  266. showdown.getOption = function (key) {
  267. 'use strict';
  268. return globalOptions[key];
  269. };
  270. /**
  271. * Get the global options
  272. * @static
  273. * @returns {{}}
  274. */
  275. showdown.getOptions = function () {
  276. 'use strict';
  277. return globalOptions;
  278. };
  279. /**
  280. * Reset global options to the default values
  281. * @static
  282. */
  283. showdown.resetOptions = function () {
  284. 'use strict';
  285. globalOptions = getDefaultOpts(true);
  286. };
  287. /**
  288. * Set the flavor showdown should use as default
  289. * @param {string} name
  290. */
  291. showdown.setFlavor = function (name) {
  292. 'use strict';
  293. if (!flavor.hasOwnProperty(name)) {
  294. throw Error(name + ' flavor was not found');
  295. }
  296. showdown.resetOptions();
  297. var preset = flavor[name];
  298. setFlavor = name;
  299. for (var option in preset) {
  300. if (preset.hasOwnProperty(option)) {
  301. globalOptions[option] = preset[option];
  302. }
  303. }
  304. };
  305. /**
  306. * Get the currently set flavor
  307. * @returns {string}
  308. */
  309. showdown.getFlavor = function () {
  310. 'use strict';
  311. return setFlavor;
  312. };
  313. /**
  314. * Get the options of a specified flavor. Returns undefined if the flavor was not found
  315. * @param {string} name Name of the flavor
  316. * @returns {{}|undefined}
  317. */
  318. showdown.getFlavorOptions = function (name) {
  319. 'use strict';
  320. if (flavor.hasOwnProperty(name)) {
  321. return flavor[name];
  322. }
  323. };
  324. /**
  325. * Get the default options
  326. * @static
  327. * @param {boolean} [simple=true]
  328. * @returns {{}}
  329. */
  330. showdown.getDefaultOptions = function (simple) {
  331. 'use strict';
  332. return getDefaultOpts(simple);
  333. };
  334. /**
  335. * Get or set a subParser
  336. *
  337. * subParser(name) - Get a registered subParser
  338. * subParser(name, func) - Register a subParser
  339. * @static
  340. * @param {string} name
  341. * @param {function} [func]
  342. * @returns {*}
  343. */
  344. showdown.subParser = function (name, func) {
  345. 'use strict';
  346. if (showdown.helper.isString(name)) {
  347. if (typeof func !== 'undefined') {
  348. parsers[name] = func;
  349. } else {
  350. if (parsers.hasOwnProperty(name)) {
  351. return parsers[name];
  352. } else {
  353. throw Error('SubParser named ' + name + ' not registered!');
  354. }
  355. }
  356. } else {
  357. throw Error('showdown.subParser function first argument must be a string (the name of the subparser)');
  358. }
  359. };
  360. /**
  361. * Gets or registers an extension
  362. * @static
  363. * @param {string} name
  364. * @param {object|function=} ext
  365. * @returns {*}
  366. */
  367. showdown.extension = function (name, ext) {
  368. 'use strict';
  369. if (!showdown.helper.isString(name)) {
  370. throw Error('Extension \'name\' must be a string');
  371. }
  372. name = showdown.helper.stdExtName(name);
  373. // Getter
  374. if (showdown.helper.isUndefined(ext)) {
  375. if (!extensions.hasOwnProperty(name)) {
  376. throw Error('Extension named ' + name + ' is not registered!');
  377. }
  378. return extensions[name];
  379. // Setter
  380. } else {
  381. // Expand extension if it's wrapped in a function
  382. if (typeof ext === 'function') {
  383. ext = ext();
  384. }
  385. // Ensure extension is an array
  386. if (!showdown.helper.isArray(ext)) {
  387. ext = [ext];
  388. }
  389. var validExtension = validate(ext, name);
  390. if (validExtension.valid) {
  391. extensions[name] = ext;
  392. } else {
  393. throw Error(validExtension.error);
  394. }
  395. }
  396. };
  397. /**
  398. * Gets all extensions registered
  399. * @returns {{}}
  400. */
  401. showdown.getAllExtensions = function () {
  402. 'use strict';
  403. return extensions;
  404. };
  405. /**
  406. * Remove an extension
  407. * @param {string} name
  408. */
  409. showdown.removeExtension = function (name) {
  410. 'use strict';
  411. delete extensions[name];
  412. };
  413. /**
  414. * Removes all extensions
  415. */
  416. showdown.resetExtensions = function () {
  417. 'use strict';
  418. extensions = {};
  419. };
  420. /**
  421. * Validate extension
  422. * @param {array} extension
  423. * @param {string} name
  424. * @returns {{valid: boolean, error: string}}
  425. */
  426. function validate (extension, name) {
  427. 'use strict';
  428. var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension',
  429. ret = {
  430. valid: true,
  431. error: ''
  432. };
  433. if (!showdown.helper.isArray(extension)) {
  434. extension = [extension];
  435. }
  436. for (var i = 0; i < extension.length; ++i) {
  437. var baseMsg = errMsg + ' sub-extension ' + i + ': ',
  438. ext = extension[i];
  439. if (typeof ext !== 'object') {
  440. ret.valid = false;
  441. ret.error = baseMsg + 'must be an object, but ' + typeof ext + ' given';
  442. return ret;
  443. }
  444. if (!showdown.helper.isString(ext.type)) {
  445. ret.valid = false;
  446. ret.error = baseMsg + 'property "type" must be a string, but ' + typeof ext.type + ' given';
  447. return ret;
  448. }
  449. var type = ext.type = ext.type.toLowerCase();
  450. // normalize extension type
  451. if (type === 'language') {
  452. type = ext.type = 'lang';
  453. }
  454. if (type === 'html') {
  455. type = ext.type = 'output';
  456. }
  457. if (type !== 'lang' && type !== 'output' && type !== 'listener') {
  458. ret.valid = false;
  459. ret.error = baseMsg + 'type ' + type + ' is not recognized. Valid values: "lang/language", "output/html" or "listener"';
  460. return ret;
  461. }
  462. if (type === 'listener') {
  463. if (showdown.helper.isUndefined(ext.listeners)) {
  464. ret.valid = false;
  465. ret.error = baseMsg + '. Extensions of type "listener" must have a property called "listeners"';
  466. return ret;
  467. }
  468. } else {
  469. if (showdown.helper.isUndefined(ext.filter) && showdown.helper.isUndefined(ext.regex)) {
  470. ret.valid = false;
  471. ret.error = baseMsg + type + ' extensions must define either a "regex" property or a "filter" method';
  472. return ret;
  473. }
  474. }
  475. if (ext.listeners) {
  476. if (typeof ext.listeners !== 'object') {
  477. ret.valid = false;
  478. ret.error = baseMsg + '"listeners" property must be an object but ' + typeof ext.listeners + ' given';
  479. return ret;
  480. }
  481. for (var ln in ext.listeners) {
  482. if (ext.listeners.hasOwnProperty(ln)) {
  483. if (typeof ext.listeners[ln] !== 'function') {
  484. ret.valid = false;
  485. ret.error = baseMsg + '"listeners" property must be an hash of [event name]: [callback]. listeners.' + ln +
  486. ' must be a function but ' + typeof ext.listeners[ln] + ' given';
  487. return ret;
  488. }
  489. }
  490. }
  491. }
  492. if (ext.filter) {
  493. if (typeof ext.filter !== 'function') {
  494. ret.valid = false;
  495. ret.error = baseMsg + '"filter" must be a function, but ' + typeof ext.filter + ' given';
  496. return ret;
  497. }
  498. } else if (ext.regex) {
  499. if (showdown.helper.isString(ext.regex)) {
  500. ext.regex = new RegExp(ext.regex, 'g');
  501. }
  502. if (!(ext.regex instanceof RegExp)) {
  503. ret.valid = false;
  504. ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' + typeof ext.regex + ' given';
  505. return ret;
  506. }
  507. if (showdown.helper.isUndefined(ext.replace)) {
  508. ret.valid = false;
  509. ret.error = baseMsg + '"regex" extensions must implement a replace string or function';
  510. return ret;
  511. }
  512. }
  513. }
  514. return ret;
  515. }
  516. /**
  517. * Validate extension
  518. * @param {object} ext
  519. * @returns {boolean}
  520. */
  521. showdown.validateExtension = function (ext) {
  522. 'use strict';
  523. var validateExtension = validate(ext, null);
  524. if (!validateExtension.valid) {
  525. console.warn(validateExtension.error);
  526. return false;
  527. }
  528. return true;
  529. };
  530. /**
  531. * showdownjs helper functions
  532. */
  533. if (!showdown.hasOwnProperty('helper')) {
  534. showdown.helper = {};
  535. }
  536. if (typeof this.document === 'undefined' && typeof this.window === 'undefined') {
  537. var jsdom = require('jsdom');
  538. this.window = new jsdom.JSDOM('', {}).window; // jshint ignore:line
  539. }
  540. showdown.helper.document = this.window.document;
  541. /**
  542. * Check if var is string
  543. * @static
  544. * @param {string} a
  545. * @returns {boolean}
  546. */
  547. showdown.helper.isString = function (a) {
  548. 'use strict';
  549. return (typeof a === 'string' || a instanceof String);
  550. };
  551. /**
  552. * Check if var is a function
  553. * @static
  554. * @param {*} a
  555. * @returns {boolean}
  556. */
  557. showdown.helper.isFunction = function (a) {
  558. 'use strict';
  559. var getType = {};
  560. return a && getType.toString.call(a) === '[object Function]';
  561. };
  562. /**
  563. * isArray helper function
  564. * @static
  565. * @param {*} a
  566. * @returns {boolean}
  567. */
  568. showdown.helper.isArray = function (a) {
  569. 'use strict';
  570. return Array.isArray(a);
  571. };
  572. /**
  573. * Check if value is undefined
  574. * @static
  575. * @param {*} value The value to check.
  576. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  577. */
  578. showdown.helper.isUndefined = function (value) {
  579. 'use strict';
  580. return typeof value === 'undefined';
  581. };
  582. /**
  583. * ForEach helper function
  584. * Iterates over Arrays and Objects (own properties only)
  585. * @static
  586. * @param {*} obj
  587. * @param {function} callback Accepts 3 params: 1. value, 2. key, 3. the original array/object
  588. */
  589. showdown.helper.forEach = function (obj, callback) {
  590. 'use strict';
  591. // check if obj is defined
  592. if (showdown.helper.isUndefined(obj)) {
  593. throw new Error('obj param is required');
  594. }
  595. if (showdown.helper.isUndefined(callback)) {
  596. throw new Error('callback param is required');
  597. }
  598. if (!showdown.helper.isFunction(callback)) {
  599. throw new Error('callback param must be a function/closure');
  600. }
  601. if (typeof obj.forEach === 'function') {
  602. obj.forEach(callback);
  603. } else if (showdown.helper.isArray(obj)) {
  604. for (var i = 0; i < obj.length; i++) {
  605. callback(obj[i], i, obj);
  606. }
  607. } else if (typeof (obj) === 'object') {
  608. for (var prop in obj) {
  609. if (obj.hasOwnProperty(prop)) {
  610. callback(obj[prop], prop, obj);
  611. }
  612. }
  613. } else {
  614. throw new Error('obj does not seem to be an array or an iterable object');
  615. }
  616. };
  617. /**
  618. * Standardidize extension name
  619. * @static
  620. * @param {string} s extension name
  621. * @returns {string}
  622. */
  623. showdown.helper.stdExtName = function (s) {
  624. 'use strict';
  625. return s.replace(/[_?*+\/\\.^-]/g, '').replace(/\s/g, '').toLowerCase();
  626. };
  627. function escapeCharactersCallback (wholeMatch, m1) {
  628. 'use strict';
  629. var charCodeToEscape = m1.charCodeAt(0);
  630. return '¨E' + charCodeToEscape + 'E';
  631. }
  632. /**
  633. * Callback used to escape characters when passing through String.replace
  634. * @static
  635. * @param {string} wholeMatch
  636. * @param {string} m1
  637. * @returns {string}
  638. */
  639. showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
  640. /**
  641. * Escape characters in a string
  642. * @static
  643. * @param {string} text
  644. * @param {string} charsToEscape
  645. * @param {boolean} afterBackslash
  646. * @returns {XML|string|void|*}
  647. */
  648. showdown.helper.escapeCharacters = function (text, charsToEscape, afterBackslash) {
  649. 'use strict';
  650. // First we have to escape the escape characters so that
  651. // we can build a character class out of them
  652. var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
  653. if (afterBackslash) {
  654. regexString = '\\\\' + regexString;
  655. }
  656. var regex = new RegExp(regexString, 'g');
  657. text = text.replace(regex, escapeCharactersCallback);
  658. return text;
  659. };
  660. var rgxFindMatchPos = function (str, left, right, flags) {
  661. 'use strict';
  662. var f = flags || '',
  663. g = f.indexOf('g') > -1,
  664. x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
  665. l = new RegExp(left, f.replace(/g/g, '')),
  666. pos = [],
  667. t, s, m, start, end;
  668. do {
  669. t = 0;
  670. while ((m = x.exec(str))) {
  671. if (l.test(m[0])) {
  672. if (!(t++)) {
  673. s = x.lastIndex;
  674. start = s - m[0].length;
  675. }
  676. } else if (t) {
  677. if (!--t) {
  678. end = m.index + m[0].length;
  679. var obj = {
  680. left: {start: start, end: s},
  681. match: {start: s, end: m.index},
  682. right: {start: m.index, end: end},
  683. wholeMatch: {start: start, end: end}
  684. };
  685. pos.push(obj);
  686. if (!g) {
  687. return pos;
  688. }
  689. }
  690. }
  691. }
  692. } while (t && (x.lastIndex = s));
  693. return pos;
  694. };
  695. /**
  696. * matchRecursiveRegExp
  697. *
  698. * (c) 2007 Steven Levithan <stevenlevithan.com>
  699. * MIT License
  700. *
  701. * Accepts a string to search, a left and right format delimiter
  702. * as regex patterns, and optional regex flags. Returns an array
  703. * of matches, allowing nested instances of left/right delimiters.
  704. * Use the "g" flag to return all matches, otherwise only the
  705. * first is returned. Be careful to ensure that the left and
  706. * right format delimiters produce mutually exclusive matches.
  707. * Backreferences are not supported within the right delimiter
  708. * due to how it is internally combined with the left delimiter.
  709. * When matching strings whose format delimiters are unbalanced
  710. * to the left or right, the output is intentionally as a
  711. * conventional regex library with recursion support would
  712. * produce, e.g. "<<x>" and "<x>>" both produce ["x"] when using
  713. * "<" and ">" as the delimiters (both strings contain a single,
  714. * balanced instance of "<x>").
  715. *
  716. * examples:
  717. * matchRecursiveRegExp("test", "\\(", "\\)")
  718. * returns: []
  719. * matchRecursiveRegExp("<t<<e>><s>>t<>", "<", ">", "g")
  720. * returns: ["t<<e>><s>", ""]
  721. * matchRecursiveRegExp("<div id=\"x\">test</div>", "<div\\b[^>]*>", "</div>", "gi")
  722. * returns: ["test"]
  723. */
  724. showdown.helper.matchRecursiveRegExp = function (str, left, right, flags) {
  725. 'use strict';
  726. var matchPos = rgxFindMatchPos (str, left, right, flags),
  727. results = [];
  728. for (var i = 0; i < matchPos.length; ++i) {
  729. results.push([
  730. str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
  731. str.slice(matchPos[i].match.start, matchPos[i].match.end),
  732. str.slice(matchPos[i].left.start, matchPos[i].left.end),
  733. str.slice(matchPos[i].right.start, matchPos[i].right.end)
  734. ]);
  735. }
  736. return results;
  737. };
  738. /**
  739. *
  740. * @param {string} str
  741. * @param {string|function} replacement
  742. * @param {string} left
  743. * @param {string} right
  744. * @param {string} flags
  745. * @returns {string}
  746. */
  747. showdown.helper.replaceRecursiveRegExp = function (str, replacement, left, right, flags) {
  748. 'use strict';
  749. if (!showdown.helper.isFunction(replacement)) {
  750. var repStr = replacement;
  751. replacement = function () {
  752. return repStr;
  753. };
  754. }
  755. var matchPos = rgxFindMatchPos(str, left, right, flags),
  756. finalStr = str,
  757. lng = matchPos.length;
  758. if (lng > 0) {
  759. var bits = [];
  760. if (matchPos[0].wholeMatch.start !== 0) {
  761. bits.push(str.slice(0, matchPos[0].wholeMatch.start));
  762. }
  763. for (var i = 0; i < lng; ++i) {
  764. bits.push(
  765. replacement(
  766. str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
  767. str.slice(matchPos[i].match.start, matchPos[i].match.end),
  768. str.slice(matchPos[i].left.start, matchPos[i].left.end),
  769. str.slice(matchPos[i].right.start, matchPos[i].right.end)
  770. )
  771. );
  772. if (i < lng - 1) {
  773. bits.push(str.slice(matchPos[i].wholeMatch.end, matchPos[i + 1].wholeMatch.start));
  774. }
  775. }
  776. if (matchPos[lng - 1].wholeMatch.end < str.length) {
  777. bits.push(str.slice(matchPos[lng - 1].wholeMatch.end));
  778. }
  779. finalStr = bits.join('');
  780. }
  781. return finalStr;
  782. };
  783. /**
  784. * Returns the index within the passed String object of the first occurrence of the specified regex,
  785. * starting the search at fromIndex. Returns -1 if the value is not found.
  786. *
  787. * @param {string} str string to search
  788. * @param {RegExp} regex Regular expression to search
  789. * @param {int} [fromIndex = 0] Index to start the search
  790. * @returns {Number}
  791. * @throws InvalidArgumentError
  792. */
  793. showdown.helper.regexIndexOf = function (str, regex, fromIndex) {
  794. 'use strict';
  795. if (!showdown.helper.isString(str)) {
  796. throw 'InvalidArgumentError: first parameter of showdown.helper.regexIndexOf function must be a string';
  797. }
  798. if (regex instanceof RegExp === false) {
  799. throw 'InvalidArgumentError: second parameter of showdown.helper.regexIndexOf function must be an instance of RegExp';
  800. }
  801. var indexOf = str.substring(fromIndex || 0).search(regex);
  802. return (indexOf >= 0) ? (indexOf + (fromIndex || 0)) : indexOf;
  803. };
  804. /**
  805. * Splits the passed string object at the defined index, and returns an array composed of the two substrings
  806. * @param {string} str string to split
  807. * @param {int} index index to split string at
  808. * @returns {[string,string]}
  809. * @throws InvalidArgumentError
  810. */
  811. showdown.helper.splitAtIndex = function (str, index) {
  812. 'use strict';
  813. if (!showdown.helper.isString(str)) {
  814. throw 'InvalidArgumentError: first parameter of showdown.helper.regexIndexOf function must be a string';
  815. }
  816. return [str.substring(0, index), str.substring(index)];
  817. };
  818. /**
  819. * Obfuscate an e-mail address through the use of Character Entities,
  820. * transforming ASCII characters into their equivalent decimal or hex entities.
  821. *
  822. * Since it has a random component, subsequent calls to this function produce different results
  823. *
  824. * @param {string} mail
  825. * @returns {string}
  826. */
  827. showdown.helper.encodeEmailAddress = function (mail) {
  828. 'use strict';
  829. var encode = [
  830. function (ch) {
  831. return '&#' + ch.charCodeAt(0) + ';';
  832. },
  833. function (ch) {
  834. return '&#x' + ch.charCodeAt(0).toString(16) + ';';
  835. },
  836. function (ch) {
  837. return ch;
  838. }
  839. ];
  840. mail = mail.replace(/./g, function (ch) {
  841. if (ch === '@') {
  842. // this *must* be encoded. I insist.
  843. ch = encode[Math.floor(Math.random() * 2)](ch);
  844. } else {
  845. var r = Math.random();
  846. // roughly 10% raw, 45% hex, 45% dec
  847. ch = (
  848. r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch)
  849. );
  850. }
  851. return ch;
  852. });
  853. return mail;
  854. };
  855. /**
  856. *
  857. * @param str
  858. * @param targetLength
  859. * @param padString
  860. * @returns {string}
  861. */
  862. showdown.helper.padEnd = function padEnd (str, targetLength, padString) {
  863. 'use strict';
  864. /*jshint bitwise: false*/
  865. // eslint-disable-next-line space-infix-ops
  866. targetLength = targetLength>>0; //floor if number or convert non-number to 0;
  867. /*jshint bitwise: true*/
  868. padString = String(padString || ' ');
  869. if (str.length > targetLength) {
  870. return String(str);
  871. } else {
  872. targetLength = targetLength - str.length;
  873. if (targetLength > padString.length) {
  874. padString += padString.repeat(targetLength / padString.length); //append to original to ensure we are longer than needed
  875. }
  876. return String(str) + padString.slice(0,targetLength);
  877. }
  878. };
  879. /**
  880. * Unescape HTML entities
  881. * @param txt
  882. * @returns {string}
  883. */
  884. showdown.helper.unescapeHTMLEntities = function (txt) {
  885. 'use strict';
  886. return txt
  887. .replace(/&quot;/g, '"')
  888. .replace(/&lt;/g, '<')
  889. .replace(/&gt;/g, '>')
  890. .replace(/&amp;/g, '&');
  891. };
  892. showdown.helper._hashHTMLSpan = function (html, globals) {
  893. return '¨C' + (globals.gHtmlSpans.push(html) - 1) + 'C';
  894. };
  895. /**
  896. * Showdown's Event Object
  897. * @param {string} name Name of the event
  898. * @param {string} text Text
  899. * @param {{}} params optional. params of the event
  900. * @constructor
  901. */
  902. showdown.helper.Event = function (name, text, params) {
  903. 'use strict';
  904. var regexp = params.regexp || null;
  905. var matches = params.matches || {};
  906. var options = params.options || {};
  907. var converter = params.converter || null;
  908. var globals = params.globals || {};
  909. /**
  910. * Get the name of the event
  911. * @returns {string}
  912. */
  913. this.getName = function () {
  914. return name;
  915. };
  916. this.getEventName = function () {
  917. return name;
  918. };
  919. this._stopExecution = false;
  920. this.parsedText = params.parsedText || null;
  921. this.getRegexp = function () {
  922. return regexp;
  923. };
  924. this.getOptions = function () {
  925. return options;
  926. };
  927. this.getConverter = function () {
  928. return converter;
  929. };
  930. this.getGlobals = function () {
  931. return globals;
  932. };
  933. this.getCapturedText = function () {
  934. return text;
  935. };
  936. this.getText = function () {
  937. return text;
  938. };
  939. this.setText = function (newText) {
  940. text = newText;
  941. };
  942. this.getMatches = function () {
  943. return matches;
  944. };
  945. this.setMatches = function (newMatches) {
  946. matches = newMatches;
  947. };
  948. this.preventDefault = function (bool) {
  949. this._stopExecution = !bool;
  950. };
  951. };
  952. /**
  953. * POLYFILLS
  954. */
  955. // use this instead of builtin is undefined for IE8 compatibility
  956. if (typeof(console) === 'undefined') {
  957. console = {
  958. warn: function (msg) {
  959. 'use strict';
  960. alert(msg);
  961. },
  962. log: function (msg) {
  963. 'use strict';
  964. alert(msg);
  965. },
  966. error: function (msg) {
  967. 'use strict';
  968. throw msg;
  969. }
  970. };
  971. }
  972. /**
  973. * Common regexes.
  974. * We declare some common regexes to improve performance
  975. */
  976. showdown.helper.regexes = {
  977. asteriskDashTildeAndColon: /([*_:~])/g,
  978. asteriskDashAndTilde: /([*_~])/g
  979. };
  980. /**
  981. * EMOJIS LIST
  982. */
  983. showdown.helper.emojis = {
  984. '+1':'\ud83d\udc4d',
  985. '-1':'\ud83d\udc4e',
  986. '100':'\ud83d\udcaf',
  987. '1234':'\ud83d\udd22',
  988. '1st_place_medal':'\ud83e\udd47',
  989. '2nd_place_medal':'\ud83e\udd48',
  990. '3rd_place_medal':'\ud83e\udd49',
  991. '8ball':'\ud83c\udfb1',
  992. 'a':'\ud83c\udd70\ufe0f',
  993. 'ab':'\ud83c\udd8e',
  994. 'abc':'\ud83d\udd24',
  995. 'abcd':'\ud83d\udd21',
  996. 'accept':'\ud83c\ude51',
  997. 'aerial_tramway':'\ud83d\udea1',
  998. 'airplane':'\u2708\ufe0f',
  999. 'alarm_clock':'\u23f0',
  1000. 'alembic':'\u2697\ufe0f',
  1001. 'alien':'\ud83d\udc7d',
  1002. 'ambulance':'\ud83d\ude91',
  1003. 'amphora':'\ud83c\udffa',
  1004. 'anchor':'\u2693\ufe0f',
  1005. 'angel':'\ud83d\udc7c',
  1006. 'anger':'\ud83d\udca2',
  1007. 'angry':'\ud83d\ude20',
  1008. 'anguished':'\ud83d\ude27',
  1009. 'ant':'\ud83d\udc1c',
  1010. 'apple':'\ud83c\udf4e',
  1011. 'aquarius':'\u2652\ufe0f',
  1012. 'aries':'\u2648\ufe0f',
  1013. 'arrow_backward':'\u25c0\ufe0f',
  1014. 'arrow_double_down':'\u23ec',
  1015. 'arrow_double_up':'\u23eb',
  1016. 'arrow_down':'\u2b07\ufe0f',
  1017. 'arrow_down_small':'\ud83d\udd3d',
  1018. 'arrow_forward':'\u25b6\ufe0f',
  1019. 'arrow_heading_down':'\u2935\ufe0f',
  1020. 'arrow_heading_up':'\u2934\ufe0f',
  1021. 'arrow_left':'\u2b05\ufe0f',
  1022. 'arrow_lower_left':'\u2199\ufe0f',
  1023. 'arrow_lower_right':'\u2198\ufe0f',
  1024. 'arrow_right':'\u27a1\ufe0f',
  1025. 'arrow_right_hook':'\u21aa\ufe0f',
  1026. 'arrow_up':'\u2b06\ufe0f',
  1027. 'arrow_up_down':'\u2195\ufe0f',
  1028. 'arrow_up_small':'\ud83d\udd3c',
  1029. 'arrow_upper_left':'\u2196\ufe0f',
  1030. 'arrow_upper_right':'\u2197\ufe0f',
  1031. 'arrows_clockwise':'\ud83d\udd03',
  1032. 'arrows_counterclockwise':'\ud83d\udd04',
  1033. 'art':'\ud83c\udfa8',
  1034. 'articulated_lorry':'\ud83d\ude9b',
  1035. 'artificial_satellite':'\ud83d\udef0',
  1036. 'astonished':'\ud83d\ude32',
  1037. 'athletic_shoe':'\ud83d\udc5f',
  1038. 'atm':'\ud83c\udfe7',
  1039. 'atom_symbol':'\u269b\ufe0f',
  1040. 'avocado':'\ud83e\udd51',
  1041. 'b':'\ud83c\udd71\ufe0f',
  1042. 'baby':'\ud83d\udc76',
  1043. 'baby_bottle':'\ud83c\udf7c',
  1044. 'baby_chick':'\ud83d\udc24',
  1045. 'baby_symbol':'\ud83d\udebc',
  1046. 'back':'\ud83d\udd19',
  1047. 'bacon':'\ud83e\udd53',
  1048. 'badminton':'\ud83c\udff8',
  1049. 'baggage_claim':'\ud83d\udec4',
  1050. 'baguette_bread':'\ud83e\udd56',
  1051. 'balance_scale':'\u2696\ufe0f',
  1052. 'balloon':'\ud83c\udf88',
  1053. 'ballot_box':'\ud83d\uddf3',
  1054. 'ballot_box_with_check':'\u2611\ufe0f',
  1055. 'bamboo':'\ud83c\udf8d',
  1056. 'banana':'\ud83c\udf4c',
  1057. 'bangbang':'\u203c\ufe0f',
  1058. 'bank':'\ud83c\udfe6',
  1059. 'bar_chart':'\ud83d\udcca',
  1060. 'barber':'\ud83d\udc88',
  1061. 'baseball':'\u26be\ufe0f',
  1062. 'basketball':'\ud83c\udfc0',
  1063. 'basketball_man':'\u26f9\ufe0f',
  1064. 'basketball_woman':'\u26f9\ufe0f&zwj;\u2640\ufe0f',
  1065. 'bat':'\ud83e\udd87',
  1066. 'bath':'\ud83d\udec0',
  1067. 'bathtub':'\ud83d\udec1',
  1068. 'battery':'\ud83d\udd0b',
  1069. 'beach_umbrella':'\ud83c\udfd6',
  1070. 'bear':'\ud83d\udc3b',
  1071. 'bed':'\ud83d\udecf',
  1072. 'bee':'\ud83d\udc1d',
  1073. 'beer':'\ud83c\udf7a',
  1074. 'beers':'\ud83c\udf7b',
  1075. 'beetle':'\ud83d\udc1e',
  1076. 'beginner':'\ud83d\udd30',
  1077. 'bell':'\ud83d\udd14',
  1078. 'bellhop_bell':'\ud83d\udece',
  1079. 'bento':'\ud83c\udf71',
  1080. 'biking_man':'\ud83d\udeb4',
  1081. 'bike':'\ud83d\udeb2',
  1082. 'biking_woman':'\ud83d\udeb4&zwj;\u2640\ufe0f',
  1083. 'bikini':'\ud83d\udc59',
  1084. 'biohazard':'\u2623\ufe0f',
  1085. 'bird':'\ud83d\udc26',
  1086. 'birthday':'\ud83c\udf82',
  1087. 'black_circle':'\u26ab\ufe0f',
  1088. 'black_flag':'\ud83c\udff4',
  1089. 'black_heart':'\ud83d\udda4',
  1090. 'black_joker':'\ud83c\udccf',
  1091. 'black_large_square':'\u2b1b\ufe0f',
  1092. 'black_medium_small_square':'\u25fe\ufe0f',
  1093. 'black_medium_square':'\u25fc\ufe0f',
  1094. 'black_nib':'\u2712\ufe0f',
  1095. 'black_small_square':'\u25aa\ufe0f',
  1096. 'black_square_button':'\ud83d\udd32',
  1097. 'blonde_man':'\ud83d\udc71',
  1098. 'blonde_woman':'\ud83d\udc71&zwj;\u2640\ufe0f',
  1099. 'blossom':'\ud83c\udf3c',
  1100. 'blowfish':'\ud83d\udc21',
  1101. 'blue_book':'\ud83d\udcd8',
  1102. 'blue_car':'\ud83d\ude99',
  1103. 'blue_heart':'\ud83d\udc99',
  1104. 'blush':'\ud83d\ude0a',
  1105. 'boar':'\ud83d\udc17',
  1106. 'boat':'\u26f5\ufe0f',
  1107. 'bomb':'\ud83d\udca3',
  1108. 'book':'\ud83d\udcd6',
  1109. 'bookmark':'\ud83d\udd16',
  1110. 'bookmark_tabs':'\ud83d\udcd1',
  1111. 'books':'\ud83d\udcda',
  1112. 'boom':'\ud83d\udca5',
  1113. 'boot':'\ud83d\udc62',
  1114. 'bouquet':'\ud83d\udc90',
  1115. 'bowing_man':'\ud83d\ude47',
  1116. 'bow_and_arrow':'\ud83c\udff9',
  1117. 'bowing_woman':'\ud83d\ude47&zwj;\u2640\ufe0f',
  1118. 'bowling':'\ud83c\udfb3',
  1119. 'boxing_glove':'\ud83e\udd4a',
  1120. 'boy':'\ud83d\udc66',
  1121. 'bread':'\ud83c\udf5e',
  1122. 'bride_with_veil':'\ud83d\udc70',
  1123. 'bridge_at_night':'\ud83c\udf09',
  1124. 'briefcase':'\ud83d\udcbc',
  1125. 'broken_heart':'\ud83d\udc94',
  1126. 'bug':'\ud83d\udc1b',
  1127. 'building_construction':'\ud83c\udfd7',
  1128. 'bulb':'\ud83d\udca1',
  1129. 'bullettrain_front':'\ud83d\ude85',
  1130. 'bullettrain_side':'\ud83d\ude84',
  1131. 'burrito':'\ud83c\udf2f',
  1132. 'bus':'\ud83d\ude8c',
  1133. 'business_suit_levitating':'\ud83d\udd74',
  1134. 'busstop':'\ud83d\ude8f',
  1135. 'bust_in_silhouette':'\ud83d\udc64',
  1136. 'busts_in_silhouette':'\ud83d\udc65',
  1137. 'butterfly':'\ud83e\udd8b',
  1138. 'cactus':'\ud83c\udf35',
  1139. 'cake':'\ud83c\udf70',
  1140. 'calendar':'\ud83d\udcc6',
  1141. 'call_me_hand':'\ud83e\udd19',
  1142. 'calling':'\ud83d\udcf2',
  1143. 'camel':'\ud83d\udc2b',
  1144. 'camera':'\ud83d\udcf7',
  1145. 'camera_flash':'\ud83d\udcf8',
  1146. 'camping':'\ud83c\udfd5',
  1147. 'cancer':'\u264b\ufe0f',
  1148. 'candle':'\ud83d\udd6f',
  1149. 'candy':'\ud83c\udf6c',
  1150. 'canoe':'\ud83d\udef6',
  1151. 'capital_abcd':'\ud83d\udd20',
  1152. 'capricorn':'\u2651\ufe0f',
  1153. 'car':'\ud83d\ude97',
  1154. 'card_file_box':'\ud83d\uddc3',
  1155. 'card_index':'\ud83d\udcc7',
  1156. 'card_index_dividers':'\ud83d\uddc2',
  1157. 'carousel_horse':'\ud83c\udfa0',
  1158. 'carrot':'\ud83e\udd55',
  1159. 'cat':'\ud83d\udc31',
  1160. 'cat2':'\ud83d\udc08',
  1161. 'cd':'\ud83d\udcbf',
  1162. 'chains':'\u26d3',
  1163. 'champagne':'\ud83c\udf7e',
  1164. 'chart':'\ud83d\udcb9',
  1165. 'chart_with_downwards_trend':'\ud83d\udcc9',
  1166. 'chart_with_upwards_trend':'\ud83d\udcc8',
  1167. 'checkered_flag':'\ud83c\udfc1',
  1168. 'cheese':'\ud83e\uddc0',
  1169. 'cherries':'\ud83c\udf52',
  1170. 'cherry_blossom':'\ud83c\udf38',
  1171. 'chestnut':'\ud83c\udf30',
  1172. 'chicken':'\ud83d\udc14',
  1173. 'children_crossing':'\ud83d\udeb8',
  1174. 'chipmunk':'\ud83d\udc3f',
  1175. 'chocolate_bar':'\ud83c\udf6b',
  1176. 'christmas_tree':'\ud83c\udf84',
  1177. 'church':'\u26ea\ufe0f',
  1178. 'cinema':'\ud83c\udfa6',
  1179. 'circus_tent':'\ud83c\udfaa',
  1180. 'city_sunrise':'\ud83c\udf07',
  1181. 'city_sunset':'\ud83c\udf06',
  1182. 'cityscape':'\ud83c\udfd9',
  1183. 'cl':'\ud83c\udd91',
  1184. 'clamp':'\ud83d\udddc',
  1185. 'clap':'\ud83d\udc4f',
  1186. 'clapper':'\ud83c\udfac',
  1187. 'classical_building':'\ud83c\udfdb',
  1188. 'clinking_glasses':'\ud83e\udd42',
  1189. 'clipboard':'\ud83d\udccb',
  1190. 'clock1':'\ud83d\udd50',
  1191. 'clock10':'\ud83d\udd59',
  1192. 'clock1030':'\ud83d\udd65',
  1193. 'clock11':'\ud83d\udd5a',
  1194. 'clock1130':'\ud83d\udd66',
  1195. 'clock12':'\ud83d\udd5b',
  1196. 'clock1230':'\ud83d\udd67',
  1197. 'clock130':'\ud83d\udd5c',
  1198. 'clock2':'\ud83d\udd51',
  1199. 'clock230':'\ud83d\udd5d',
  1200. 'clock3':'\ud83d\udd52',
  1201. 'clock330':'\ud83d\udd5e',
  1202. 'clock4':'\ud83d\udd53',
  1203. 'clock430':'\ud83d\udd5f',
  1204. 'clock5':'\ud83d\udd54',
  1205. 'clock530':'\ud83d\udd60',
  1206. 'clock6':'\ud83d\udd55',
  1207. 'clock630':'\ud83d\udd61',
  1208. 'clock7':'\ud83d\udd56',
  1209. 'clock730':'\ud83d\udd62',
  1210. 'clock8':'\ud83d\udd57',
  1211. 'clock830':'\ud83d\udd63',
  1212. 'clock9':'\ud83d\udd58',
  1213. 'clock930':'\ud83d\udd64',
  1214. 'closed_book':'\ud83d\udcd5',
  1215. 'closed_lock_with_key':'\ud83d\udd10',
  1216. 'closed_umbrella':'\ud83c\udf02',
  1217. 'cloud':'\u2601\ufe0f',
  1218. 'cloud_with_lightning':'\ud83c\udf29',
  1219. 'cloud_with_lightning_and_rain':'\u26c8',
  1220. 'cloud_with_rain':'\ud83c\udf27',
  1221. 'cloud_with_snow':'\ud83c\udf28',
  1222. 'clown_face':'\ud83e\udd21',
  1223. 'clubs':'\u2663\ufe0f',
  1224. 'cocktail':'\ud83c\udf78',
  1225. 'coffee':'\u2615\ufe0f',
  1226. 'coffin':'\u26b0\ufe0f',
  1227. 'cold_sweat':'\ud83d\ude30',
  1228. 'comet':'\u2604\ufe0f',
  1229. 'computer':'\ud83d\udcbb',
  1230. 'computer_mouse':'\ud83d\uddb1',
  1231. 'confetti_ball':'\ud83c\udf8a',
  1232. 'confounded':'\ud83d\ude16',
  1233. 'confused':'\ud83d\ude15',
  1234. 'congratulations':'\u3297\ufe0f',
  1235. 'construction':'\ud83d\udea7',
  1236. 'construction_worker_man':'\ud83d\udc77',
  1237. 'construction_worker_woman':'\ud83d\udc77&zwj;\u2640\ufe0f',
  1238. 'control_knobs':'\ud83c\udf9b',
  1239. 'convenience_store':'\ud83c\udfea',
  1240. 'cookie':'\ud83c\udf6a',
  1241. 'cool':'\ud83c\udd92',
  1242. 'policeman':'\ud83d\udc6e',
  1243. 'copyright':'\u00a9\ufe0f',
  1244. 'corn':'\ud83c\udf3d',
  1245. 'couch_and_lamp':'\ud83d\udecb',
  1246. 'couple':'\ud83d\udc6b',
  1247. 'couple_with_heart_woman_man':'\ud83d\udc91',
  1248. 'couple_with_heart_man_man':'\ud83d\udc68&zwj;\u2764\ufe0f&zwj;\ud83d\udc68',
  1249. 'couple_with_heart_woman_woman':'\ud83d\udc69&zwj;\u2764\ufe0f&zwj;\ud83d\udc69',
  1250. 'couplekiss_man_man':'\ud83d\udc68&zwj;\u2764\ufe0f&zwj;\ud83d\udc8b&zwj;\ud83d\udc68',
  1251. 'couplekiss_man_woman':'\ud83d\udc8f',
  1252. 'couplekiss_woman_woman':'\ud83d\udc69&zwj;\u2764\ufe0f&zwj;\ud83d\udc8b&zwj;\ud83d\udc69',
  1253. 'cow':'\ud83d\udc2e',
  1254. 'cow2':'\ud83d\udc04',
  1255. 'cowboy_hat_face':'\ud83e\udd20',
  1256. 'crab':'\ud83e\udd80',
  1257. 'crayon':'\ud83d\udd8d',
  1258. 'credit_card':'\ud83d\udcb3',
  1259. 'crescent_moon':'\ud83c\udf19',
  1260. 'cricket':'\ud83c\udfcf',
  1261. 'crocodile':'\ud83d\udc0a',
  1262. 'croissant':'\ud83e\udd50',
  1263. 'crossed_fingers':'\ud83e\udd1e',
  1264. 'crossed_flags':'\ud83c\udf8c',
  1265. 'crossed_swords':'\u2694\ufe0f',
  1266. 'crown':'\ud83d\udc51',
  1267. 'cry':'\ud83d\ude22',
  1268. 'crying_cat_face':'\ud83d\ude3f',
  1269. 'crystal_ball':'\ud83d\udd2e',
  1270. 'cucumber':'\ud83e\udd52',
  1271. 'cupid':'\ud83d\udc98',
  1272. 'curly_loop':'\u27b0',
  1273. 'currency_exchange':'\ud83d\udcb1',
  1274. 'curry':'\ud83c\udf5b',
  1275. 'custard':'\ud83c\udf6e',
  1276. 'customs':'\ud83d\udec3',
  1277. 'cyclone':'\ud83c\udf00',
  1278. 'dagger':'\ud83d\udde1',
  1279. 'dancer':'\ud83d\udc83',
  1280. 'dancing_women':'\ud83d\udc6f',
  1281. 'dancing_men':'\ud83d\udc6f&zwj;\u2642\ufe0f',
  1282. 'dango':'\ud83c\udf61',
  1283. 'dark_sunglasses':'\ud83d\udd76',
  1284. 'dart':'\ud83c\udfaf',
  1285. 'dash':'\ud83d\udca8',
  1286. 'date':'\ud83d\udcc5',
  1287. 'deciduous_tree':'\ud83c\udf33',
  1288. 'deer':'\ud83e\udd8c',
  1289. 'department_store':'\ud83c\udfec',
  1290. 'derelict_house':'\ud83c\udfda',
  1291. 'desert':'\ud83c\udfdc',
  1292. 'desert_island':'\ud83c\udfdd',
  1293. 'desktop_computer':'\ud83d\udda5',
  1294. 'male_detective':'\ud83d\udd75\ufe0f',
  1295. 'diamond_shape_with_a_dot_inside':'\ud83d\udca0',
  1296. 'diamonds':'\u2666\ufe0f',
  1297. 'disappointed':'\ud83d\ude1e',
  1298. 'disappointed_relieved':'\ud83d\ude25',
  1299. 'dizzy':'\ud83d\udcab',
  1300. 'dizzy_face':'\ud83d\ude35',
  1301. 'do_not_litter':'\ud83d\udeaf',
  1302. 'dog':'\ud83d\udc36',
  1303. 'dog2':'\ud83d\udc15',
  1304. 'dollar':'\ud83d\udcb5',
  1305. 'dolls':'\ud83c\udf8e',
  1306. 'dolphin':'\ud83d\udc2c',
  1307. 'door':'\ud83d\udeaa',
  1308. 'doughnut':'\ud83c\udf69',
  1309. 'dove':'\ud83d\udd4a',
  1310. 'dragon':'\ud83d\udc09',
  1311. 'dragon_face':'\ud83d\udc32',
  1312. 'dress':'\ud83d\udc57',
  1313. 'dromedary_camel':'\ud83d\udc2a',
  1314. 'drooling_face':'\ud83e\udd24',
  1315. 'droplet':'\ud83d\udca7',
  1316. 'drum':'\ud83e\udd41',
  1317. 'duck':'\ud83e\udd86',
  1318. 'dvd':'\ud83d\udcc0',
  1319. 'e-mail':'\ud83d\udce7',
  1320. 'eagle':'\ud83e\udd85',
  1321. 'ear':'\ud83d\udc42',
  1322. 'ear_of_rice':'\ud83c\udf3e',
  1323. 'earth_africa':'\ud83c\udf0d',
  1324. 'earth_americas':'\ud83c\udf0e',
  1325. 'earth_asia':'\ud83c\udf0f',
  1326. 'egg':'\ud83e\udd5a',
  1327. 'eggplant':'\ud83c\udf46',
  1328. 'eight_pointed_black_star':'\u2734\ufe0f',
  1329. 'eight_spoked_asterisk':'\u2733\ufe0f',
  1330. 'electric_plug':'\ud83d\udd0c',
  1331. 'elephant':'\ud83d\udc18',
  1332. 'email':'\u2709\ufe0f',
  1333. 'end':'\ud83d\udd1a',
  1334. 'envelope_with_arrow':'\ud83d\udce9',
  1335. 'euro':'\ud83d\udcb6',
  1336. 'european_castle':'\ud83c\udff0',
  1337. 'european_post_office':'\ud83c\udfe4',
  1338. 'evergreen_tree':'\ud83c\udf32',
  1339. 'exclamation':'\u2757\ufe0f',
  1340. 'expressionless':'\ud83d\ude11',
  1341. 'eye':'\ud83d\udc41',
  1342. 'eye_speech_bubble':'\ud83d\udc41&zwj;\ud83d\udde8',
  1343. 'eyeglasses':'\ud83d\udc53',
  1344. 'eyes':'\ud83d\udc40',
  1345. 'face_with_head_bandage':'\ud83e\udd15',
  1346. 'face_with_thermometer':'\ud83e\udd12',
  1347. 'fist_oncoming':'\ud83d\udc4a',
  1348. 'factory':'\ud83c\udfed',
  1349. 'fallen_leaf':'\ud83c\udf42',
  1350. 'family_man_woman_boy':'\ud83d\udc6a',
  1351. 'family_man_boy':'\ud83d\udc68&zwj;\ud83d\udc66',
  1352. 'family_man_boy_boy':'\ud83d\udc68&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1353. 'family_man_girl':'\ud83d\udc68&zwj;\ud83d\udc67',
  1354. 'family_man_girl_boy':'\ud83d\udc68&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1355. 'family_man_girl_girl':'\ud83d\udc68&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1356. 'family_man_man_boy':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc66',
  1357. 'family_man_man_boy_boy':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1358. 'family_man_man_girl':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc67',
  1359. 'family_man_man_girl_boy':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1360. 'family_man_man_girl_girl':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1361. 'family_man_woman_boy_boy':'\ud83d\udc68&zwj;\ud83d\udc69&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1362. 'family_man_woman_girl':'\ud83d\udc68&zwj;\ud83d\udc69&zwj;\ud83d\udc67',
  1363. 'family_man_woman_girl_boy':'\ud83d\udc68&zwj;\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1364. 'family_man_woman_girl_girl':'\ud83d\udc68&zwj;\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1365. 'family_woman_boy':'\ud83d\udc69&zwj;\ud83d\udc66',
  1366. 'family_woman_boy_boy':'\ud83d\udc69&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1367. 'family_woman_girl':'\ud83d\udc69&zwj;\ud83d\udc67',
  1368. 'family_woman_girl_boy':'\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1369. 'family_woman_girl_girl':'\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1370. 'family_woman_woman_boy':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc66',
  1371. 'family_woman_woman_boy_boy':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1372. 'family_woman_woman_girl':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc67',
  1373. 'family_woman_woman_girl_boy':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1374. 'family_woman_woman_girl_girl':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1375. 'fast_forward':'\u23e9',
  1376. 'fax':'\ud83d\udce0',
  1377. 'fearful':'\ud83d\ude28',
  1378. 'feet':'\ud83d\udc3e',
  1379. 'female_detective':'\ud83d\udd75\ufe0f&zwj;\u2640\ufe0f',
  1380. 'ferris_wheel':'\ud83c\udfa1',
  1381. 'ferry':'\u26f4',
  1382. 'field_hockey':'\ud83c\udfd1',
  1383. 'file_cabinet':'\ud83d\uddc4',
  1384. 'file_folder':'\ud83d\udcc1',
  1385. 'film_projector':'\ud83d\udcfd',
  1386. 'film_strip':'\ud83c\udf9e',
  1387. 'fire':'\ud83d\udd25',
  1388. 'fire_engine':'\ud83d\ude92',
  1389. 'fireworks':'\ud83c\udf86',
  1390. 'first_quarter_moon':'\ud83c\udf13',
  1391. 'first_quarter_moon_with_face':'\ud83c\udf1b',
  1392. 'fish':'\ud83d\udc1f',
  1393. 'fish_cake':'\ud83c\udf65',
  1394. 'fishing_pole_and_fish':'\ud83c\udfa3',
  1395. 'fist_raised':'\u270a',
  1396. 'fist_left':'\ud83e\udd1b',
  1397. 'fist_right':'\ud83e\udd1c',
  1398. 'flags':'\ud83c\udf8f',
  1399. 'flashlight':'\ud83d\udd26',
  1400. 'fleur_de_lis':'\u269c\ufe0f',
  1401. 'flight_arrival':'\ud83d\udeec',
  1402. 'flight_departure':'\ud83d\udeeb',
  1403. 'floppy_disk':'\ud83d\udcbe',
  1404. 'flower_playing_cards':'\ud83c\udfb4',
  1405. 'flushed':'\ud83d\ude33',
  1406. 'fog':'\ud83c\udf2b',
  1407. 'foggy':'\ud83c\udf01',
  1408. 'football':'\ud83c\udfc8',
  1409. 'footprints':'\ud83d\udc63',
  1410. 'fork_and_knife':'\ud83c\udf74',
  1411. 'fountain':'\u26f2\ufe0f',
  1412. 'fountain_pen':'\ud83d\udd8b',
  1413. 'four_leaf_clover':'\ud83c\udf40',
  1414. 'fox_face':'\ud83e\udd8a',
  1415. 'framed_picture':'\ud83d\uddbc',
  1416. 'free':'\ud83c\udd93',
  1417. 'fried_egg':'\ud83c\udf73',
  1418. 'fried_shrimp':'\ud83c\udf64',
  1419. 'fries':'\ud83c\udf5f',
  1420. 'frog':'\ud83d\udc38',
  1421. 'frowning':'\ud83d\ude26',
  1422. 'frowning_face':'\u2639\ufe0f',
  1423. 'frowning_man':'\ud83d\ude4d&zwj;\u2642\ufe0f',
  1424. 'frowning_woman':'\ud83d\ude4d',
  1425. 'middle_finger':'\ud83d\udd95',
  1426. 'fuelpump':'\u26fd\ufe0f',
  1427. 'full_moon':'\ud83c\udf15',
  1428. 'full_moon_with_face':'\ud83c\udf1d',
  1429. 'funeral_urn':'\u26b1\ufe0f',
  1430. 'game_die':'\ud83c\udfb2',
  1431. 'gear':'\u2699\ufe0f',
  1432. 'gem':'\ud83d\udc8e',
  1433. 'gemini':'\u264a\ufe0f',
  1434. 'ghost':'\ud83d\udc7b',
  1435. 'gift':'\ud83c\udf81',
  1436. 'gift_heart':'\ud83d\udc9d',
  1437. 'girl':'\ud83d\udc67',
  1438. 'globe_with_meridians':'\ud83c\udf10',
  1439. 'goal_net':'\ud83e\udd45',
  1440. 'goat':'\ud83d\udc10',
  1441. 'golf':'\u26f3\ufe0f',
  1442. 'golfing_man':'\ud83c\udfcc\ufe0f',
  1443. 'golfing_woman':'\ud83c\udfcc\ufe0f&zwj;\u2640\ufe0f',
  1444. 'gorilla':'\ud83e\udd8d',
  1445. 'grapes':'\ud83c\udf47',
  1446. 'green_apple':'\ud83c\udf4f',
  1447. 'green_book':'\ud83d\udcd7',
  1448. 'green_heart':'\ud83d\udc9a',
  1449. 'green_salad':'\ud83e\udd57',
  1450. 'grey_exclamation':'\u2755',
  1451. 'grey_question':'\u2754',
  1452. 'grimacing':'\ud83d\ude2c',
  1453. 'grin':'\ud83d\ude01',
  1454. 'grinning':'\ud83d\ude00',
  1455. 'guardsman':'\ud83d\udc82',
  1456. 'guardswoman':'\ud83d\udc82&zwj;\u2640\ufe0f',
  1457. 'guitar':'\ud83c\udfb8',
  1458. 'gun':'\ud83d\udd2b',
  1459. 'haircut_woman':'\ud83d\udc87',
  1460. 'haircut_man':'\ud83d\udc87&zwj;\u2642\ufe0f',
  1461. 'hamburger':'\ud83c\udf54',
  1462. 'hammer':'\ud83d\udd28',
  1463. 'hammer_and_pick':'\u2692',
  1464. 'hammer_and_wrench':'\ud83d\udee0',
  1465. 'hamster':'\ud83d\udc39',
  1466. 'hand':'\u270b',
  1467. 'handbag':'\ud83d\udc5c',
  1468. 'handshake':'\ud83e\udd1d',
  1469. 'hankey':'\ud83d\udca9',
  1470. 'hatched_chick':'\ud83d\udc25',
  1471. 'hatching_chick':'\ud83d\udc23',
  1472. 'headphones':'\ud83c\udfa7',
  1473. 'hear_no_evil':'\ud83d\ude49',
  1474. 'heart':'\u2764\ufe0f',
  1475. 'heart_decoration':'\ud83d\udc9f',
  1476. 'heart_eyes':'\ud83d\ude0d',
  1477. 'heart_eyes_cat':'\ud83d\ude3b',
  1478. 'heartbeat':'\ud83d\udc93',
  1479. 'heartpulse':'\ud83d\udc97',
  1480. 'hearts':'\u2665\ufe0f',
  1481. 'heavy_check_mark':'\u2714\ufe0f',
  1482. 'heavy_division_sign':'\u2797',
  1483. 'heavy_dollar_sign':'\ud83d\udcb2',
  1484. 'heavy_heart_exclamation':'\u2763\ufe0f',
  1485. 'heavy_minus_sign':'\u2796',
  1486. 'heavy_multiplication_x':'\u2716\ufe0f',
  1487. 'heavy_plus_sign':'\u2795',
  1488. 'helicopter':'\ud83d\ude81',
  1489. 'herb':'\ud83c\udf3f',
  1490. 'hibiscus':'\ud83c\udf3a',
  1491. 'high_brightness':'\ud83d\udd06',
  1492. 'high_heel':'\ud83d\udc60',
  1493. 'hocho':'\ud83d\udd2a',
  1494. 'hole':'\ud83d\udd73',
  1495. 'honey_pot':'\ud83c\udf6f',
  1496. 'horse':'\ud83d\udc34',
  1497. 'horse_racing':'\ud83c\udfc7',
  1498. 'hospital':'\ud83c\udfe5',
  1499. 'hot_pepper':'\ud83c\udf36',
  1500. 'hotdog':'\ud83c\udf2d',
  1501. 'hotel':'\ud83c\udfe8',
  1502. 'hotsprings':'\u2668\ufe0f',
  1503. 'hourglass':'\u231b\ufe0f',
  1504. 'hourglass_flowing_sand':'\u23f3',
  1505. 'house':'\ud83c\udfe0',
  1506. 'house_with_garden':'\ud83c\udfe1',
  1507. 'houses':'\ud83c\udfd8',
  1508. 'hugs':'\ud83e\udd17',
  1509. 'hushed':'\ud83d\ude2f',
  1510. 'ice_cream':'\ud83c\udf68',
  1511. 'ice_hockey':'\ud83c\udfd2',
  1512. 'ice_skate':'\u26f8',
  1513. 'icecream':'\ud83c\udf66',
  1514. 'id':'\ud83c\udd94',
  1515. 'ideograph_advantage':'\ud83c\ude50',
  1516. 'imp':'\ud83d\udc7f',
  1517. 'inbox_tray':'\ud83d\udce5',
  1518. 'incoming_envelope':'\ud83d\udce8',
  1519. 'tipping_hand_woman':'\ud83d\udc81',
  1520. 'information_source':'\u2139\ufe0f',
  1521. 'innocent':'\ud83d\ude07',
  1522. 'interrobang':'\u2049\ufe0f',
  1523. 'iphone':'\ud83d\udcf1',
  1524. 'izakaya_lantern':'\ud83c\udfee',
  1525. 'jack_o_lantern':'\ud83c\udf83',
  1526. 'japan':'\ud83d\uddfe',
  1527. 'japanese_castle':'\ud83c\udfef',
  1528. 'japanese_goblin':'\ud83d\udc7a',
  1529. 'japanese_ogre':'\ud83d\udc79',
  1530. 'jeans':'\ud83d\udc56',
  1531. 'joy':'\ud83d\ude02',
  1532. 'joy_cat':'\ud83d\ude39',
  1533. 'joystick':'\ud83d\udd79',
  1534. 'kaaba':'\ud83d\udd4b',
  1535. 'key':'\ud83d\udd11',
  1536. 'keyboard':'\u2328\ufe0f',
  1537. 'keycap_ten':'\ud83d\udd1f',
  1538. 'kick_scooter':'\ud83d\udef4',
  1539. 'kimono':'\ud83d\udc58',
  1540. 'kiss':'\ud83d\udc8b',
  1541. 'kissing':'\ud83d\ude17',
  1542. 'kissing_cat':'\ud83d\ude3d',
  1543. 'kissing_closed_eyes':'\ud83d\ude1a',
  1544. 'kissing_heart':'\ud83d\ude18',
  1545. 'kissing_smiling_eyes':'\ud83d\ude19',
  1546. 'kiwi_fruit':'\ud83e\udd5d',
  1547. 'koala':'\ud83d\udc28',
  1548. 'koko':'\ud83c\ude01',
  1549. 'label':'\ud83c\udff7',
  1550. 'large_blue_circle':'\ud83d\udd35',
  1551. 'large_blue_diamond':'\ud83d\udd37',
  1552. 'large_orange_diamond':'\ud83d\udd36',
  1553. 'last_quarter_moon':'\ud83c\udf17',
  1554. 'last_quarter_moon_with_face':'\ud83c\udf1c',
  1555. 'latin_cross':'\u271d\ufe0f',
  1556. 'laughing':'\ud83d\ude06',
  1557. 'leaves':'\ud83c\udf43',
  1558. 'ledger':'\ud83d\udcd2',
  1559. 'left_luggage':'\ud83d\udec5',
  1560. 'left_right_arrow':'\u2194\ufe0f',
  1561. 'leftwards_arrow_with_hook':'\u21a9\ufe0f',
  1562. 'lemon':'\ud83c\udf4b',
  1563. 'leo':'\u264c\ufe0f',
  1564. 'leopard':'\ud83d\udc06',
  1565. 'level_slider':'\ud83c\udf9a',
  1566. 'libra':'\u264e\ufe0f',
  1567. 'light_rail':'\ud83d\ude88',
  1568. 'link':'\ud83d\udd17',
  1569. 'lion':'\ud83e\udd81',
  1570. 'lips':'\ud83d\udc44',
  1571. 'lipstick':'\ud83d\udc84',
  1572. 'lizard':'\ud83e\udd8e',
  1573. 'lock':'\ud83d\udd12',
  1574. 'lock_with_ink_pen':'\ud83d\udd0f',
  1575. 'lollipop':'\ud83c\udf6d',
  1576. 'loop':'\u27bf',
  1577. 'loud_sound':'\ud83d\udd0a',
  1578. 'loudspeaker':'\ud83d\udce2',
  1579. 'love_hotel':'\ud83c\udfe9',
  1580. 'love_letter':'\ud83d\udc8c',
  1581. 'low_brightness':'\ud83d\udd05',
  1582. 'lying_face':'\ud83e\udd25',
  1583. 'm':'\u24c2\ufe0f',
  1584. 'mag':'\ud83d\udd0d',
  1585. 'mag_right':'\ud83d\udd0e',
  1586. 'mahjong':'\ud83c\udc04\ufe0f',
  1587. 'mailbox':'\ud83d\udceb',
  1588. 'mailbox_closed':'\ud83d\udcea',
  1589. 'mailbox_with_mail':'\ud83d\udcec',
  1590. 'mailbox_with_no_mail':'\ud83d\udced',
  1591. 'man':'\ud83d\udc68',
  1592. 'man_artist':'\ud83d\udc68&zwj;\ud83c\udfa8',
  1593. 'man_astronaut':'\ud83d\udc68&zwj;\ud83d\ude80',
  1594. 'man_cartwheeling':'\ud83e\udd38&zwj;\u2642\ufe0f',
  1595. 'man_cook':'\ud83d\udc68&zwj;\ud83c\udf73',
  1596. 'man_dancing':'\ud83d\udd7a',
  1597. 'man_facepalming':'\ud83e\udd26&zwj;\u2642\ufe0f',
  1598. 'man_factory_worker':'\ud83d\udc68&zwj;\ud83c\udfed',
  1599. 'man_farmer':'\ud83d\udc68&zwj;\ud83c\udf3e',
  1600. 'man_firefighter':'\ud83d\udc68&zwj;\ud83d\ude92',
  1601. 'man_health_worker':'\ud83d\udc68&zwj;\u2695\ufe0f',
  1602. 'man_in_tuxedo':'\ud83e\udd35',
  1603. 'man_judge':'\ud83d\udc68&zwj;\u2696\ufe0f',
  1604. 'man_juggling':'\ud83e\udd39&zwj;\u2642\ufe0f',
  1605. 'man_mechanic':'\ud83d\udc68&zwj;\ud83d\udd27',
  1606. 'man_office_worker':'\ud83d\udc68&zwj;\ud83d\udcbc',
  1607. 'man_pilot':'\ud83d\udc68&zwj;\u2708\ufe0f',
  1608. 'man_playing_handball':'\ud83e\udd3e&zwj;\u2642\ufe0f',
  1609. 'man_playing_water_polo':'\ud83e\udd3d&zwj;\u2642\ufe0f',
  1610. 'man_scientist':'\ud83d\udc68&zwj;\ud83d\udd2c',
  1611. 'man_shrugging':'\ud83e\udd37&zwj;\u2642\ufe0f',
  1612. 'man_singer':'\ud83d\udc68&zwj;\ud83c\udfa4',
  1613. 'man_student':'\ud83d\udc68&zwj;\ud83c\udf93',
  1614. 'man_teacher':'\ud83d\udc68&zwj;\ud83c\udfeb',
  1615. 'man_technologist':'\ud83d\udc68&zwj;\ud83d\udcbb',
  1616. 'man_with_gua_pi_mao':'\ud83d\udc72',
  1617. 'man_with_turban':'\ud83d\udc73',
  1618. 'tangerine':'\ud83c\udf4a',
  1619. 'mans_shoe':'\ud83d\udc5e',
  1620. 'mantelpiece_clock':'\ud83d\udd70',
  1621. 'maple_leaf':'\ud83c\udf41',
  1622. 'martial_arts_uniform':'\ud83e\udd4b',
  1623. 'mask':'\ud83d\ude37',
  1624. 'massage_woman':'\ud83d\udc86',
  1625. 'massage_man':'\ud83d\udc86&zwj;\u2642\ufe0f',
  1626. 'meat_on_bone':'\ud83c\udf56',
  1627. 'medal_military':'\ud83c\udf96',
  1628. 'medal_sports':'\ud83c\udfc5',
  1629. 'mega':'\ud83d\udce3',
  1630. 'melon':'\ud83c\udf48',
  1631. 'memo':'\ud83d\udcdd',
  1632. 'men_wrestling':'\ud83e\udd3c&zwj;\u2642\ufe0f',
  1633. 'menorah':'\ud83d\udd4e',
  1634. 'mens':'\ud83d\udeb9',
  1635. 'metal':'\ud83e\udd18',
  1636. 'metro':'\ud83d\ude87',
  1637. 'microphone':'\ud83c\udfa4',
  1638. 'microscope':'\ud83d\udd2c',
  1639. 'milk_glass':'\ud83e\udd5b',
  1640. 'milky_way':'\ud83c\udf0c',
  1641. 'minibus':'\ud83d\ude90',
  1642. 'minidisc':'\ud83d\udcbd',
  1643. 'mobile_phone_off':'\ud83d\udcf4',
  1644. 'money_mouth_face':'\ud83e\udd11',
  1645. 'money_with_wings':'\ud83d\udcb8',
  1646. 'moneybag':'\ud83d\udcb0',
  1647. 'monkey':'\ud83d\udc12',
  1648. 'monkey_face':'\ud83d\udc35',
  1649. 'monorail':'\ud83d\ude9d',
  1650. 'moon':'\ud83c\udf14',
  1651. 'mortar_board':'\ud83c\udf93',
  1652. 'mosque':'\ud83d\udd4c',
  1653. 'motor_boat':'\ud83d\udee5',
  1654. 'motor_scooter':'\ud83d\udef5',
  1655. 'motorcycle':'\ud83c\udfcd',
  1656. 'motorway':'\ud83d\udee3',
  1657. 'mount_fuji':'\ud83d\uddfb',
  1658. 'mountain':'\u26f0',
  1659. 'mountain_biking_man':'\ud83d\udeb5',
  1660. 'mountain_biking_woman':'\ud83d\udeb5&zwj;\u2640\ufe0f',
  1661. 'mountain_cableway':'\ud83d\udea0',
  1662. 'mountain_railway':'\ud83d\ude9e',
  1663. 'mountain_snow':'\ud83c\udfd4',
  1664. 'mouse':'\ud83d\udc2d',
  1665. 'mouse2':'\ud83d\udc01',
  1666. 'movie_camera':'\ud83c\udfa5',
  1667. 'moyai':'\ud83d\uddff',
  1668. 'mrs_claus':'\ud83e\udd36',
  1669. 'muscle':'\ud83d\udcaa',
  1670. 'mushroom':'\ud83c\udf44',
  1671. 'musical_keyboard':'\ud83c\udfb9',
  1672. 'musical_note':'\ud83c\udfb5',
  1673. 'musical_score':'\ud83c\udfbc',
  1674. 'mute':'\ud83d\udd07',
  1675. 'nail_care':'\ud83d\udc85',
  1676. 'name_badge':'\ud83d\udcdb',
  1677. 'national_park':'\ud83c\udfde',
  1678. 'nauseated_face':'\ud83e\udd22',
  1679. 'necktie':'\ud83d\udc54',
  1680. 'negative_squared_cross_mark':'\u274e',
  1681. 'nerd_face':'\ud83e\udd13',
  1682. 'neutral_face':'\ud83d\ude10',
  1683. 'new':'\ud83c\udd95',
  1684. 'new_moon':'\ud83c\udf11',
  1685. 'new_moon_with_face':'\ud83c\udf1a',
  1686. 'newspaper':'\ud83d\udcf0',
  1687. 'newspaper_roll':'\ud83d\uddde',
  1688. 'next_track_button':'\u23ed',
  1689. 'ng':'\ud83c\udd96',
  1690. 'no_good_man':'\ud83d\ude45&zwj;\u2642\ufe0f',
  1691. 'no_good_woman':'\ud83d\ude45',
  1692. 'night_with_stars':'\ud83c\udf03',
  1693. 'no_bell':'\ud83d\udd15',
  1694. 'no_bicycles':'\ud83d\udeb3',
  1695. 'no_entry':'\u26d4\ufe0f',
  1696. 'no_entry_sign':'\ud83d\udeab',
  1697. 'no_mobile_phones':'\ud83d\udcf5',
  1698. 'no_mouth':'\ud83d\ude36',
  1699. 'no_pedestrians':'\ud83d\udeb7',
  1700. 'no_smoking':'\ud83d\udead',
  1701. 'non-potable_water':'\ud83d\udeb1',
  1702. 'nose':'\ud83d\udc43',
  1703. 'notebook':'\ud83d\udcd3',
  1704. 'notebook_with_decorative_cover':'\ud83d\udcd4',
  1705. 'notes':'\ud83c\udfb6',
  1706. 'nut_and_bolt':'\ud83d\udd29',
  1707. 'o':'\u2b55\ufe0f',
  1708. 'o2':'\ud83c\udd7e\ufe0f',
  1709. 'ocean':'\ud83c\udf0a',
  1710. 'octopus':'\ud83d\udc19',
  1711. 'oden':'\ud83c\udf62',
  1712. 'office':'\ud83c\udfe2',
  1713. 'oil_drum':'\ud83d\udee2',
  1714. 'ok':'\ud83c\udd97',
  1715. 'ok_hand':'\ud83d\udc4c',
  1716. 'ok_man':'\ud83d\ude46&zwj;\u2642\ufe0f',
  1717. 'ok_woman':'\ud83d\ude46',
  1718. 'old_key':'\ud83d\udddd',
  1719. 'older_man':'\ud83d\udc74',
  1720. 'older_woman':'\ud83d\udc75',
  1721. 'om':'\ud83d\udd49',
  1722. 'on':'\ud83d\udd1b',
  1723. 'oncoming_automobile':'\ud83d\ude98',
  1724. 'oncoming_bus':'\ud83d\ude8d',
  1725. 'oncoming_police_car':'\ud83d\ude94',
  1726. 'oncoming_taxi':'\ud83d\ude96',
  1727. 'open_file_folder':'\ud83d\udcc2',
  1728. 'open_hands':'\ud83d\udc50',
  1729. 'open_mouth':'\ud83d\ude2e',
  1730. 'open_umbrella':'\u2602\ufe0f',
  1731. 'ophiuchus':'\u26ce',
  1732. 'orange_book':'\ud83d\udcd9',
  1733. 'orthodox_cross':'\u2626\ufe0f',
  1734. 'outbox_tray':'\ud83d\udce4',
  1735. 'owl':'\ud83e\udd89',
  1736. 'ox':'\ud83d\udc02',
  1737. 'package':'\ud83d\udce6',
  1738. 'page_facing_up':'\ud83d\udcc4',
  1739. 'page_with_curl':'\ud83d\udcc3',
  1740. 'pager':'\ud83d\udcdf',
  1741. 'paintbrush':'\ud83d\udd8c',
  1742. 'palm_tree':'\ud83c\udf34',
  1743. 'pancakes':'\ud83e\udd5e',
  1744. 'panda_face':'\ud83d\udc3c',
  1745. 'paperclip':'\ud83d\udcce',
  1746. 'paperclips':'\ud83d\udd87',
  1747. 'parasol_on_ground':'\u26f1',
  1748. 'parking':'\ud83c\udd7f\ufe0f',
  1749. 'part_alternation_mark':'\u303d\ufe0f',
  1750. 'partly_sunny':'\u26c5\ufe0f',
  1751. 'passenger_ship':'\ud83d\udef3',
  1752. 'passport_control':'\ud83d\udec2',
  1753. 'pause_button':'\u23f8',
  1754. 'peace_symbol':'\u262e\ufe0f',
  1755. 'peach':'\ud83c\udf51',
  1756. 'peanuts':'\ud83e\udd5c',
  1757. 'pear':'\ud83c\udf50',
  1758. 'pen':'\ud83d\udd8a',
  1759. 'pencil2':'\u270f\ufe0f',
  1760. 'penguin':'\ud83d\udc27',
  1761. 'pensive':'\ud83d\ude14',
  1762. 'performing_arts':'\ud83c\udfad',
  1763. 'persevere':'\ud83d\ude23',
  1764. 'person_fencing':'\ud83e\udd3a',
  1765. 'pouting_woman':'\ud83d\ude4e',
  1766. 'phone':'\u260e\ufe0f',
  1767. 'pick':'\u26cf',
  1768. 'pig':'\ud83d\udc37',
  1769. 'pig2':'\ud83d\udc16',
  1770. 'pig_nose':'\ud83d\udc3d',
  1771. 'pill':'\ud83d\udc8a',
  1772. 'pineapple':'\ud83c\udf4d',
  1773. 'ping_pong':'\ud83c\udfd3',
  1774. 'pisces':'\u2653\ufe0f',
  1775. 'pizza':'\ud83c\udf55',
  1776. 'place_of_worship':'\ud83d\uded0',
  1777. 'plate_with_cutlery':'\ud83c\udf7d',
  1778. 'play_or_pause_button':'\u23ef',
  1779. 'point_down':'\ud83d\udc47',
  1780. 'point_left':'\ud83d\udc48',
  1781. 'point_right':'\ud83d\udc49',
  1782. 'point_up':'\u261d\ufe0f',
  1783. 'point_up_2':'\ud83d\udc46',
  1784. 'police_car':'\ud83d\ude93',
  1785. 'policewoman':'\ud83d\udc6e&zwj;\u2640\ufe0f',
  1786. 'poodle':'\ud83d\udc29',
  1787. 'popcorn':'\ud83c\udf7f',
  1788. 'post_office':'\ud83c\udfe3',
  1789. 'postal_horn':'\ud83d\udcef',
  1790. 'postbox':'\ud83d\udcee',
  1791. 'potable_water':'\ud83d\udeb0',
  1792. 'potato':'\ud83e\udd54',
  1793. 'pouch':'\ud83d\udc5d',
  1794. 'poultry_leg':'\ud83c\udf57',
  1795. 'pound':'\ud83d\udcb7',
  1796. 'rage':'\ud83d\ude21',
  1797. 'pouting_cat':'\ud83d\ude3e',
  1798. 'pouting_man':'\ud83d\ude4e&zwj;\u2642\ufe0f',
  1799. 'pray':'\ud83d\ude4f',
  1800. 'prayer_beads':'\ud83d\udcff',
  1801. 'pregnant_woman':'\ud83e\udd30',
  1802. 'previous_track_button':'\u23ee',
  1803. 'prince':'\ud83e\udd34',
  1804. 'princess':'\ud83d\udc78',
  1805. 'printer':'\ud83d\udda8',
  1806. 'purple_heart':'\ud83d\udc9c',
  1807. 'purse':'\ud83d\udc5b',
  1808. 'pushpin':'\ud83d\udccc',
  1809. 'put_litter_in_its_place':'\ud83d\udeae',
  1810. 'question':'\u2753',
  1811. 'rabbit':'\ud83d\udc30',
  1812. 'rabbit2':'\ud83d\udc07',
  1813. 'racehorse':'\ud83d\udc0e',
  1814. 'racing_car':'\ud83c\udfce',
  1815. 'radio':'\ud83d\udcfb',
  1816. 'radio_button':'\ud83d\udd18',
  1817. 'radioactive':'\u2622\ufe0f',
  1818. 'railway_car':'\ud83d\ude83',
  1819. 'railway_track':'\ud83d\udee4',
  1820. 'rainbow':'\ud83c\udf08',
  1821. 'rainbow_flag':'\ud83c\udff3\ufe0f&zwj;\ud83c\udf08',
  1822. 'raised_back_of_hand':'\ud83e\udd1a',
  1823. 'raised_hand_with_fingers_splayed':'\ud83d\udd90',
  1824. 'raised_hands':'\ud83d\ude4c',
  1825. 'raising_hand_woman':'\ud83d\ude4b',
  1826. 'raising_hand_man':'\ud83d\ude4b&zwj;\u2642\ufe0f',
  1827. 'ram':'\ud83d\udc0f',
  1828. 'ramen':'\ud83c\udf5c',
  1829. 'rat':'\ud83d\udc00',
  1830. 'record_button':'\u23fa',
  1831. 'recycle':'\u267b\ufe0f',
  1832. 'red_circle':'\ud83d\udd34',
  1833. 'registered':'\u00ae\ufe0f',
  1834. 'relaxed':'\u263a\ufe0f',
  1835. 'relieved':'\ud83d\ude0c',
  1836. 'reminder_ribbon':'\ud83c\udf97',
  1837. 'repeat':'\ud83d\udd01',
  1838. 'repeat_one':'\ud83d\udd02',
  1839. 'rescue_worker_helmet':'\u26d1',
  1840. 'restroom':'\ud83d\udebb',
  1841. 'revolving_hearts':'\ud83d\udc9e',
  1842. 'rewind':'\u23ea',
  1843. 'rhinoceros':'\ud83e\udd8f',
  1844. 'ribbon':'\ud83c\udf80',
  1845. 'rice':'\ud83c\udf5a',
  1846. 'rice_ball':'\ud83c\udf59',
  1847. 'rice_cracker':'\ud83c\udf58',
  1848. 'rice_scene':'\ud83c\udf91',
  1849. 'right_anger_bubble':'\ud83d\uddef',
  1850. 'ring':'\ud83d\udc8d',
  1851. 'robot':'\ud83e\udd16',
  1852. 'rocket':'\ud83d\ude80',
  1853. 'rofl':'\ud83e\udd23',
  1854. 'roll_eyes':'\ud83d\ude44',
  1855. 'roller_coaster':'\ud83c\udfa2',
  1856. 'rooster':'\ud83d\udc13',
  1857. 'rose':'\ud83c\udf39',
  1858. 'rosette':'\ud83c\udff5',
  1859. 'rotating_light':'\ud83d\udea8',
  1860. 'round_pushpin':'\ud83d\udccd',
  1861. 'rowing_man':'\ud83d\udea3',
  1862. 'rowing_woman':'\ud83d\udea3&zwj;\u2640\ufe0f',
  1863. 'rugby_football':'\ud83c\udfc9',
  1864. 'running_man':'\ud83c\udfc3',
  1865. 'running_shirt_with_sash':'\ud83c\udfbd',
  1866. 'running_woman':'\ud83c\udfc3&zwj;\u2640\ufe0f',
  1867. 'sa':'\ud83c\ude02\ufe0f',
  1868. 'sagittarius':'\u2650\ufe0f',
  1869. 'sake':'\ud83c\udf76',
  1870. 'sandal':'\ud83d\udc61',
  1871. 'santa':'\ud83c\udf85',
  1872. 'satellite':'\ud83d\udce1',
  1873. 'saxophone':'\ud83c\udfb7',
  1874. 'school':'\ud83c\udfeb',
  1875. 'school_satchel':'\ud83c\udf92',
  1876. 'scissors':'\u2702\ufe0f',
  1877. 'scorpion':'\ud83e\udd82',
  1878. 'scorpius':'\u264f\ufe0f',
  1879. 'scream':'\ud83d\ude31',
  1880. 'scream_cat':'\ud83d\ude40',
  1881. 'scroll':'\ud83d\udcdc',
  1882. 'seat':'\ud83d\udcba',
  1883. 'secret':'\u3299\ufe0f',
  1884. 'see_no_evil':'\ud83d\ude48',
  1885. 'seedling':'\ud83c\udf31',
  1886. 'selfie':'\ud83e\udd33',
  1887. 'shallow_pan_of_food':'\ud83e\udd58',
  1888. 'shamrock':'\u2618\ufe0f',
  1889. 'shark':'\ud83e\udd88',
  1890. 'shaved_ice':'\ud83c\udf67',
  1891. 'sheep':'\ud83d\udc11',
  1892. 'shell':'\ud83d\udc1a',
  1893. 'shield':'\ud83d\udee1',
  1894. 'shinto_shrine':'\u26e9',
  1895. 'ship':'\ud83d\udea2',
  1896. 'shirt':'\ud83d\udc55',
  1897. 'shopping':'\ud83d\udecd',
  1898. 'shopping_cart':'\ud83d\uded2',
  1899. 'shower':'\ud83d\udebf',
  1900. 'shrimp':'\ud83e\udd90',
  1901. 'signal_strength':'\ud83d\udcf6',
  1902. 'six_pointed_star':'\ud83d\udd2f',
  1903. 'ski':'\ud83c\udfbf',
  1904. 'skier':'\u26f7',
  1905. 'skull':'\ud83d\udc80',
  1906. 'skull_and_crossbones':'\u2620\ufe0f',
  1907. 'sleeping':'\ud83d\ude34',
  1908. 'sleeping_bed':'\ud83d\udecc',
  1909. 'sleepy':'\ud83d\ude2a',
  1910. 'slightly_frowning_face':'\ud83d\ude41',
  1911. 'slightly_smiling_face':'\ud83d\ude42',
  1912. 'slot_machine':'\ud83c\udfb0',
  1913. 'small_airplane':'\ud83d\udee9',
  1914. 'small_blue_diamond':'\ud83d\udd39',
  1915. 'small_orange_diamond':'\ud83d\udd38',
  1916. 'small_red_triangle':'\ud83d\udd3a',
  1917. 'small_red_triangle_down':'\ud83d\udd3b',
  1918. 'smile':'\ud83d\ude04',
  1919. 'smile_cat':'\ud83d\ude38',
  1920. 'smiley':'\ud83d\ude03',
  1921. 'smiley_cat':'\ud83d\ude3a',
  1922. 'smiling_imp':'\ud83d\ude08',
  1923. 'smirk':'\ud83d\ude0f',
  1924. 'smirk_cat':'\ud83d\ude3c',
  1925. 'smoking':'\ud83d\udeac',
  1926. 'snail':'\ud83d\udc0c',
  1927. 'snake':'\ud83d\udc0d',
  1928. 'sneezing_face':'\ud83e\udd27',
  1929. 'snowboarder':'\ud83c\udfc2',
  1930. 'snowflake':'\u2744\ufe0f',
  1931. 'snowman':'\u26c4\ufe0f',
  1932. 'snowman_with_snow':'\u2603\ufe0f',
  1933. 'sob':'\ud83d\ude2d',
  1934. 'soccer':'\u26bd\ufe0f',
  1935. 'soon':'\ud83d\udd1c',
  1936. 'sos':'\ud83c\udd98',
  1937. 'sound':'\ud83d\udd09',
  1938. 'space_invader':'\ud83d\udc7e',
  1939. 'spades':'\u2660\ufe0f',
  1940. 'spaghetti':'\ud83c\udf5d',
  1941. 'sparkle':'\u2747\ufe0f',
  1942. 'sparkler':'\ud83c\udf87',
  1943. 'sparkles':'\u2728',
  1944. 'sparkling_heart':'\ud83d\udc96',
  1945. 'speak_no_evil':'\ud83d\ude4a',
  1946. 'speaker':'\ud83d\udd08',
  1947. 'speaking_head':'\ud83d\udde3',
  1948. 'speech_balloon':'\ud83d\udcac',
  1949. 'speedboat':'\ud83d\udea4',
  1950. 'spider':'\ud83d\udd77',
  1951. 'spider_web':'\ud83d\udd78',
  1952. 'spiral_calendar':'\ud83d\uddd3',
  1953. 'spiral_notepad':'\ud83d\uddd2',
  1954. 'spoon':'\ud83e\udd44',
  1955. 'squid':'\ud83e\udd91',
  1956. 'stadium':'\ud83c\udfdf',
  1957. 'star':'\u2b50\ufe0f',
  1958. 'star2':'\ud83c\udf1f',
  1959. 'star_and_crescent':'\u262a\ufe0f',
  1960. 'star_of_david':'\u2721\ufe0f',
  1961. 'stars':'\ud83c\udf20',
  1962. 'station':'\ud83d\ude89',
  1963. 'statue_of_liberty':'\ud83d\uddfd',
  1964. 'steam_locomotive':'\ud83d\ude82',
  1965. 'stew':'\ud83c\udf72',
  1966. 'stop_button':'\u23f9',
  1967. 'stop_sign':'\ud83d\uded1',
  1968. 'stopwatch':'\u23f1',
  1969. 'straight_ruler':'\ud83d\udccf',
  1970. 'strawberry':'\ud83c\udf53',
  1971. 'stuck_out_tongue':'\ud83d\ude1b',
  1972. 'stuck_out_tongue_closed_eyes':'\ud83d\ude1d',
  1973. 'stuck_out_tongue_winking_eye':'\ud83d\ude1c',
  1974. 'studio_microphone':'\ud83c\udf99',
  1975. 'stuffed_flatbread':'\ud83e\udd59',
  1976. 'sun_behind_large_cloud':'\ud83c\udf25',
  1977. 'sun_behind_rain_cloud':'\ud83c\udf26',
  1978. 'sun_behind_small_cloud':'\ud83c\udf24',
  1979. 'sun_with_face':'\ud83c\udf1e',
  1980. 'sunflower':'\ud83c\udf3b',
  1981. 'sunglasses':'\ud83d\ude0e',
  1982. 'sunny':'\u2600\ufe0f',
  1983. 'sunrise':'\ud83c\udf05',
  1984. 'sunrise_over_mountains':'\ud83c\udf04',
  1985. 'surfing_man':'\ud83c\udfc4',
  1986. 'surfing_woman':'\ud83c\udfc4&zwj;\u2640\ufe0f',
  1987. 'sushi':'\ud83c\udf63',
  1988. 'suspension_railway':'\ud83d\ude9f',
  1989. 'sweat':'\ud83d\ude13',
  1990. 'sweat_drops':'\ud83d\udca6',
  1991. 'sweat_smile':'\ud83d\ude05',
  1992. 'sweet_potato':'\ud83c\udf60',
  1993. 'swimming_man':'\ud83c\udfca',
  1994. 'swimming_woman':'\ud83c\udfca&zwj;\u2640\ufe0f',
  1995. 'symbols':'\ud83d\udd23',
  1996. 'synagogue':'\ud83d\udd4d',
  1997. 'syringe':'\ud83d\udc89',
  1998. 'taco':'\ud83c\udf2e',
  1999. 'tada':'\ud83c\udf89',
  2000. 'tanabata_tree':'\ud83c\udf8b',
  2001. 'taurus':'\u2649\ufe0f',
  2002. 'taxi':'\ud83d\ude95',
  2003. 'tea':'\ud83c\udf75',
  2004. 'telephone_receiver':'\ud83d\udcde',
  2005. 'telescope':'\ud83d\udd2d',
  2006. 'tennis':'\ud83c\udfbe',
  2007. 'tent':'\u26fa\ufe0f',
  2008. 'thermometer':'\ud83c\udf21',
  2009. 'thinking':'\ud83e\udd14',
  2010. 'thought_balloon':'\ud83d\udcad',
  2011. 'ticket':'\ud83c\udfab',
  2012. 'tickets':'\ud83c\udf9f',
  2013. 'tiger':'\ud83d\udc2f',
  2014. 'tiger2':'\ud83d\udc05',
  2015. 'timer_clock':'\u23f2',
  2016. 'tipping_hand_man':'\ud83d\udc81&zwj;\u2642\ufe0f',
  2017. 'tired_face':'\ud83d\ude2b',
  2018. 'tm':'\u2122\ufe0f',
  2019. 'toilet':'\ud83d\udebd',
  2020. 'tokyo_tower':'\ud83d\uddfc',
  2021. 'tomato':'\ud83c\udf45',
  2022. 'tongue':'\ud83d\udc45',
  2023. 'top':'\ud83d\udd1d',
  2024. 'tophat':'\ud83c\udfa9',
  2025. 'tornado':'\ud83c\udf2a',
  2026. 'trackball':'\ud83d\uddb2',
  2027. 'tractor':'\ud83d\ude9c',
  2028. 'traffic_light':'\ud83d\udea5',
  2029. 'train':'\ud83d\ude8b',
  2030. 'train2':'\ud83d\ude86',
  2031. 'tram':'\ud83d\ude8a',
  2032. 'triangular_flag_on_post':'\ud83d\udea9',
  2033. 'triangular_ruler':'\ud83d\udcd0',
  2034. 'trident':'\ud83d\udd31',
  2035. 'triumph':'\ud83d\ude24',
  2036. 'trolleybus':'\ud83d\ude8e',
  2037. 'trophy':'\ud83c\udfc6',
  2038. 'tropical_drink':'\ud83c\udf79',
  2039. 'tropical_fish':'\ud83d\udc20',
  2040. 'truck':'\ud83d\ude9a',
  2041. 'trumpet':'\ud83c\udfba',
  2042. 'tulip':'\ud83c\udf37',
  2043. 'tumbler_glass':'\ud83e\udd43',
  2044. 'turkey':'\ud83e\udd83',
  2045. 'turtle':'\ud83d\udc22',
  2046. 'tv':'\ud83d\udcfa',
  2047. 'twisted_rightwards_arrows':'\ud83d\udd00',
  2048. 'two_hearts':'\ud83d\udc95',
  2049. 'two_men_holding_hands':'\ud83d\udc6c',
  2050. 'two_women_holding_hands':'\ud83d\udc6d',
  2051. 'u5272':'\ud83c\ude39',
  2052. 'u5408':'\ud83c\ude34',
  2053. 'u55b6':'\ud83c\ude3a',
  2054. 'u6307':'\ud83c\ude2f\ufe0f',
  2055. 'u6708':'\ud83c\ude37\ufe0f',
  2056. 'u6709':'\ud83c\ude36',
  2057. 'u6e80':'\ud83c\ude35',
  2058. 'u7121':'\ud83c\ude1a\ufe0f',
  2059. 'u7533':'\ud83c\ude38',
  2060. 'u7981':'\ud83c\ude32',
  2061. 'u7a7a':'\ud83c\ude33',
  2062. 'umbrella':'\u2614\ufe0f',
  2063. 'unamused':'\ud83d\ude12',
  2064. 'underage':'\ud83d\udd1e',
  2065. 'unicorn':'\ud83e\udd84',
  2066. 'unlock':'\ud83d\udd13',
  2067. 'up':'\ud83c\udd99',
  2068. 'upside_down_face':'\ud83d\ude43',
  2069. 'v':'\u270c\ufe0f',
  2070. 'vertical_traffic_light':'\ud83d\udea6',
  2071. 'vhs':'\ud83d\udcfc',
  2072. 'vibration_mode':'\ud83d\udcf3',
  2073. 'video_camera':'\ud83d\udcf9',
  2074. 'video_game':'\ud83c\udfae',
  2075. 'violin':'\ud83c\udfbb',
  2076. 'virgo':'\u264d\ufe0f',
  2077. 'volcano':'\ud83c\udf0b',
  2078. 'volleyball':'\ud83c\udfd0',
  2079. 'vs':'\ud83c\udd9a',
  2080. 'vulcan_salute':'\ud83d\udd96',
  2081. 'walking_man':'\ud83d\udeb6',
  2082. 'walking_woman':'\ud83d\udeb6&zwj;\u2640\ufe0f',
  2083. 'waning_crescent_moon':'\ud83c\udf18',
  2084. 'waning_gibbous_moon':'\ud83c\udf16',
  2085. 'warning':'\u26a0\ufe0f',
  2086. 'wastebasket':'\ud83d\uddd1',
  2087. 'watch':'\u231a\ufe0f',
  2088. 'water_buffalo':'\ud83d\udc03',
  2089. 'watermelon':'\ud83c\udf49',
  2090. 'wave':'\ud83d\udc4b',
  2091. 'wavy_dash':'\u3030\ufe0f',
  2092. 'waxing_crescent_moon':'\ud83c\udf12',
  2093. 'wc':'\ud83d\udebe',
  2094. 'weary':'\ud83d\ude29',
  2095. 'wedding':'\ud83d\udc92',
  2096. 'weight_lifting_man':'\ud83c\udfcb\ufe0f',
  2097. 'weight_lifting_woman':'\ud83c\udfcb\ufe0f&zwj;\u2640\ufe0f',
  2098. 'whale':'\ud83d\udc33',
  2099. 'whale2':'\ud83d\udc0b',
  2100. 'wheel_of_dharma':'\u2638\ufe0f',
  2101. 'wheelchair':'\u267f\ufe0f',
  2102. 'white_check_mark':'\u2705',
  2103. 'white_circle':'\u26aa\ufe0f',
  2104. 'white_flag':'\ud83c\udff3\ufe0f',
  2105. 'white_flower':'\ud83d\udcae',
  2106. 'white_large_square':'\u2b1c\ufe0f',
  2107. 'white_medium_small_square':'\u25fd\ufe0f',
  2108. 'white_medium_square':'\u25fb\ufe0f',
  2109. 'white_small_square':'\u25ab\ufe0f',
  2110. 'white_square_button':'\ud83d\udd33',
  2111. 'wilted_flower':'\ud83e\udd40',
  2112. 'wind_chime':'\ud83c\udf90',
  2113. 'wind_face':'\ud83c\udf2c',
  2114. 'wine_glass':'\ud83c\udf77',
  2115. 'wink':'\ud83d\ude09',
  2116. 'wolf':'\ud83d\udc3a',
  2117. 'woman':'\ud83d\udc69',
  2118. 'woman_artist':'\ud83d\udc69&zwj;\ud83c\udfa8',
  2119. 'woman_astronaut':'\ud83d\udc69&zwj;\ud83d\ude80',
  2120. 'woman_cartwheeling':'\ud83e\udd38&zwj;\u2640\ufe0f',
  2121. 'woman_cook':'\ud83d\udc69&zwj;\ud83c\udf73',
  2122. 'woman_facepalming':'\ud83e\udd26&zwj;\u2640\ufe0f',
  2123. 'woman_factory_worker':'\ud83d\udc69&zwj;\ud83c\udfed',
  2124. 'woman_farmer':'\ud83d\udc69&zwj;\ud83c\udf3e',
  2125. 'woman_firefighter':'\ud83d\udc69&zwj;\ud83d\ude92',
  2126. 'woman_health_worker':'\ud83d\udc69&zwj;\u2695\ufe0f',
  2127. 'woman_judge':'\ud83d\udc69&zwj;\u2696\ufe0f',
  2128. 'woman_juggling':'\ud83e\udd39&zwj;\u2640\ufe0f',
  2129. 'woman_mechanic':'\ud83d\udc69&zwj;\ud83d\udd27',
  2130. 'woman_office_worker':'\ud83d\udc69&zwj;\ud83d\udcbc',
  2131. 'woman_pilot':'\ud83d\udc69&zwj;\u2708\ufe0f',
  2132. 'woman_playing_handball':'\ud83e\udd3e&zwj;\u2640\ufe0f',
  2133. 'woman_playing_water_polo':'\ud83e\udd3d&zwj;\u2640\ufe0f',
  2134. 'woman_scientist':'\ud83d\udc69&zwj;\ud83d\udd2c',
  2135. 'woman_shrugging':'\ud83e\udd37&zwj;\u2640\ufe0f',
  2136. 'woman_singer':'\ud83d\udc69&zwj;\ud83c\udfa4',
  2137. 'woman_student':'\ud83d\udc69&zwj;\ud83c\udf93',
  2138. 'woman_teacher':'\ud83d\udc69&zwj;\ud83c\udfeb',
  2139. 'woman_technologist':'\ud83d\udc69&zwj;\ud83d\udcbb',
  2140. 'woman_with_turban':'\ud83d\udc73&zwj;\u2640\ufe0f',
  2141. 'womans_clothes':'\ud83d\udc5a',
  2142. 'womans_hat':'\ud83d\udc52',
  2143. 'women_wrestling':'\ud83e\udd3c&zwj;\u2640\ufe0f',
  2144. 'womens':'\ud83d\udeba',
  2145. 'world_map':'\ud83d\uddfa',
  2146. 'worried':'\ud83d\ude1f',
  2147. 'wrench':'\ud83d\udd27',
  2148. 'writing_hand':'\u270d\ufe0f',
  2149. 'x':'\u274c',
  2150. 'yellow_heart':'\ud83d\udc9b',
  2151. 'yen':'\ud83d\udcb4',
  2152. 'yin_yang':'\u262f\ufe0f',
  2153. 'yum':'\ud83d\ude0b',
  2154. 'zap':'\u26a1\ufe0f',
  2155. 'zipper_mouth_face':'\ud83e\udd10',
  2156. 'zzz':'\ud83d\udca4',
  2157. /* special emojis :P */
  2158. 'octocat': '<img width="20" height="20" align="absmiddle" src="https://assets-cdn.github.com/images/icons/emoji/octocat.png">',
  2159. 'showdown': '<img width="20" height="20" align="absmiddle" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAS1BMVEX///8jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS3b1q3b1q3b1q3b1q3b1q3b1q3b1q3b1q0565CIAAAAGXRSTlMAQHCAYCCw/+DQwPCQUBAwoHCAEP+wwFBgS2fvBgAAAUZJREFUeAHs1cGy7BAUheFFsEDw/k97VTq3T6ge2EmdM+pvrP6Iwd74XV9Kb52xuMU4/uc1YNgZLFOeV8FGdhGrNk5SEgUyPxAEdj4LlMRDyhVAMVEa2M7TBSeVZAFPdqHgzSZJwPKgcLFLAooHDJo4EDCw4gAtBoJA5UFj4Ng5LOGLwVXZuoIlji/jeQHFk7+baHxrCjeUwB9+s88KndvlhcyBN5BSkYNQIVVb4pV+Npm7hhuKDs/uMP5KxT3WzSNNLIuuoDpMmuAVMruMSeDyQBi24DTr43LAY7ILA1QYaWkgfHzFthYYzg67SQsCbB8GhJUEGCtO9n0rSaCLxgJQjS/JSgMTg2eBDEHAJ+H350AsjYNYscrErgI2e/l+mdR967TCX/v6N0EhPECYCP0i+IAoYQOE8BogNhQMEMdrgAQWHaMAAGi5I5euoY9NAAAAAElFTkSuQmCC">'
  2160. };
  2161. /**
  2162. * These are all the transformations that form block-level
  2163. * tags like paragraphs, headers, and list items.
  2164. */
  2165. showdown.subParser('makehtml.blockGamut', function (text, options, globals) {
  2166. 'use strict';
  2167. text = globals.converter._dispatch('makehtml.blockGamut.before', text, options, globals).getText();
  2168. // we parse blockquotes first so that we can have headings and hrs
  2169. // inside blockquotes
  2170. text = showdown.subParser('makehtml.blockQuotes')(text, options, globals);
  2171. text = showdown.subParser('makehtml.headers')(text, options, globals);
  2172. // Do Horizontal Rules:
  2173. text = showdown.subParser('makehtml.horizontalRule')(text, options, globals);
  2174. text = showdown.subParser('makehtml.lists')(text, options, globals);
  2175. text = showdown.subParser('makehtml.codeBlocks')(text, options, globals);
  2176. text = showdown.subParser('makehtml.tables')(text, options, globals);
  2177. // We already ran _HashHTMLBlocks() before, in Markdown(), but that
  2178. // was to escape raw HTML in the original Markdown source. This time,
  2179. // we're escaping the markup we've just created, so that we don't wrap
  2180. // <p> tags around block-level tags.
  2181. text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals);
  2182. text = showdown.subParser('makehtml.paragraphs')(text, options, globals);
  2183. text = globals.converter._dispatch('makehtml.blockGamut.after', text, options, globals).getText();
  2184. return text;
  2185. });
  2186. showdown.subParser('makehtml.blockQuotes', function (text, options, globals) {
  2187. 'use strict';
  2188. text = globals.converter._dispatch('makehtml.blockQuotes.before', text, options, globals).getText();
  2189. // add a couple extra lines after the text and endtext mark
  2190. text = text + '\n\n';
  2191. var rgx = /(^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+/gm;
  2192. if (options.splitAdjacentBlockquotes) {
  2193. rgx = /^ {0,3}>[\s\S]*?(?:\n\n)/gm;
  2194. }
  2195. text = text.replace(rgx, function (bq) {
  2196. // attacklab: hack around Konqueror 3.5.4 bug:
  2197. // "----------bug".replace(/^-/g,"") == "bug"
  2198. bq = bq.replace(/^[ \t]*>[ \t]?/gm, ''); // trim one level of quoting
  2199. // attacklab: clean up hack
  2200. bq = bq.replace(/¨0/g, '');
  2201. bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines
  2202. bq = showdown.subParser('makehtml.githubCodeBlocks')(bq, options, globals);
  2203. bq = showdown.subParser('makehtml.blockGamut')(bq, options, globals); // recurse
  2204. bq = bq.replace(/(^|\n)/g, '$1 ');
  2205. // These leading spaces screw with <pre> content, so we need to fix that:
  2206. bq = bq.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm, function (wholeMatch, m1) {
  2207. var pre = m1;
  2208. // attacklab: hack around Konqueror 3.5.4 bug:
  2209. pre = pre.replace(/^ /mg, '¨0');
  2210. pre = pre.replace(/¨0/g, '');
  2211. return pre;
  2212. });
  2213. return showdown.subParser('makehtml.hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals);
  2214. });
  2215. text = globals.converter._dispatch('makehtml.blockQuotes.after', text, options, globals).getText();
  2216. return text;
  2217. });
  2218. /**
  2219. * Process Markdown `<pre><code>` blocks.
  2220. */
  2221. showdown.subParser('makehtml.codeBlocks', function (text, options, globals) {
  2222. 'use strict';
  2223. text = globals.converter._dispatch('makehtml.codeBlocks.before', text, options, globals).getText();
  2224. // sentinel workarounds for lack of \A and \Z, safari\khtml bug
  2225. text += '¨0';
  2226. var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=¨0))/g;
  2227. text = text.replace(pattern, function (wholeMatch, m1, m2) {
  2228. var codeblock = m1,
  2229. nextChar = m2,
  2230. end = '\n';
  2231. codeblock = showdown.subParser('makehtml.outdent')(codeblock, options, globals);
  2232. codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals);
  2233. codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals);
  2234. codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
  2235. codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
  2236. if (options.omitExtraWLInCodeBlocks) {
  2237. end = '';
  2238. }
  2239. codeblock = '<pre><code>' + codeblock + end + '</code></pre>';
  2240. return showdown.subParser('makehtml.hashBlock')(codeblock, options, globals) + nextChar;
  2241. });
  2242. // strip sentinel
  2243. text = text.replace(/¨0/, '');
  2244. text = globals.converter._dispatch('makehtml.codeBlocks.after', text, options, globals).getText();
  2245. return text;
  2246. });
  2247. /**
  2248. *
  2249. * * Backtick quotes are used for <code></code> spans.
  2250. *
  2251. * * You can use multiple backticks as the delimiters if you want to
  2252. * include literal backticks in the code span. So, this input:
  2253. *
  2254. * Just type ``foo `bar` baz`` at the prompt.
  2255. *
  2256. * Will translate to:
  2257. *
  2258. * <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
  2259. *
  2260. * There's no arbitrary limit to the number of backticks you
  2261. * can use as delimters. If you need three consecutive backticks
  2262. * in your code, use four for delimiters, etc.
  2263. *
  2264. * * You can use spaces to get literal backticks at the edges:
  2265. *
  2266. * ... type `` `bar` `` ...
  2267. *
  2268. * Turns to:
  2269. *
  2270. * ... type <code>`bar`</code> ...
  2271. */
  2272. showdown.subParser('makehtml.codeSpans', function (text, options, globals) {
  2273. 'use strict';
  2274. text = globals.converter._dispatch('makehtml.codeSpans.before', text, options, globals).getText();
  2275. if (typeof(text) === 'undefined') {
  2276. text = '';
  2277. }
  2278. text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
  2279. function (wholeMatch, m1, m2, m3) {
  2280. var c = m3;
  2281. c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
  2282. c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
  2283. c = showdown.subParser('makehtml.encodeCode')(c, options, globals);
  2284. c = m1 + '<code>' + c + '</code>';
  2285. c = showdown.subParser('makehtml.hashHTMLSpans')(c, options, globals);
  2286. return c;
  2287. }
  2288. );
  2289. text = globals.converter._dispatch('makehtml.codeSpans.after', text, options, globals).getText();
  2290. return text;
  2291. });
  2292. /**
  2293. * Create a full HTML document from the processed markdown
  2294. */
  2295. showdown.subParser('makehtml.completeHTMLDocument', function (text, options, globals) {
  2296. 'use strict';
  2297. if (!options.completeHTMLDocument) {
  2298. return text;
  2299. }
  2300. text = globals.converter._dispatch('makehtml.completeHTMLDocument.before', text, options, globals).getText();
  2301. var doctype = 'html',
  2302. doctypeParsed = '<!DOCTYPE HTML>\n',
  2303. title = '',
  2304. charset = '<meta charset="utf-8">\n',
  2305. lang = '',
  2306. metadata = '';
  2307. if (typeof globals.metadata.parsed.doctype !== 'undefined') {
  2308. doctypeParsed = '<!DOCTYPE ' + globals.metadata.parsed.doctype + '>\n';
  2309. doctype = globals.metadata.parsed.doctype.toString().toLowerCase();
  2310. if (doctype === 'html' || doctype === 'html5') {
  2311. charset = '<meta charset="utf-8">';
  2312. }
  2313. }
  2314. for (var meta in globals.metadata.parsed) {
  2315. if (globals.metadata.parsed.hasOwnProperty(meta)) {
  2316. switch (meta.toLowerCase()) {
  2317. case 'doctype':
  2318. break;
  2319. case 'title':
  2320. title = '<title>' + globals.metadata.parsed.title + '</title>\n';
  2321. break;
  2322. case 'charset':
  2323. if (doctype === 'html' || doctype === 'html5') {
  2324. charset = '<meta charset="' + globals.metadata.parsed.charset + '">\n';
  2325. } else {
  2326. charset = '<meta name="charset" content="' + globals.metadata.parsed.charset + '">\n';
  2327. }
  2328. break;
  2329. case 'language':
  2330. case 'lang':
  2331. lang = ' lang="' + globals.metadata.parsed[meta] + '"';
  2332. metadata += '<meta name="' + meta + '" content="' + globals.metadata.parsed[meta] + '">\n';
  2333. break;
  2334. default:
  2335. metadata += '<meta name="' + meta + '" content="' + globals.metadata.parsed[meta] + '">\n';
  2336. }
  2337. }
  2338. }
  2339. text = doctypeParsed + '<html' + lang + '>\n<head>\n' + title + charset + metadata + '</head>\n<body>\n' + text.trim() + '\n</body>\n</html>';
  2340. text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals).getText();
  2341. return text;
  2342. });
  2343. /**
  2344. * Convert all tabs to spaces
  2345. */
  2346. showdown.subParser('makehtml.detab', function (text, options, globals) {
  2347. 'use strict';
  2348. text = globals.converter._dispatch('makehtml.detab.before', text, options, globals).getText();
  2349. // expand first n-1 tabs
  2350. text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
  2351. // replace the nth with two sentinels
  2352. text = text.replace(/\t/g, '¨A¨B');
  2353. // use the sentinel to anchor our regex so it doesn't explode
  2354. text = text.replace(/¨B(.+?)¨A/g, function (wholeMatch, m1) {
  2355. var leadingText = m1,
  2356. numSpaces = 4 - leadingText.length % 4; // g_tab_width
  2357. // there *must* be a better way to do this:
  2358. for (var i = 0; i < numSpaces; i++) {
  2359. leadingText += ' ';
  2360. }
  2361. return leadingText;
  2362. });
  2363. // clean up sentinels
  2364. text = text.replace(/¨A/g, ' '); // g_tab_width
  2365. text = text.replace(/¨B/g, '');
  2366. text = globals.converter._dispatch('makehtml.detab.after', text, options, globals).getText();
  2367. return text;
  2368. });
  2369. showdown.subParser('makehtml.ellipsis', function (text, options, globals) {
  2370. 'use strict';
  2371. text = globals.converter._dispatch('makehtml.ellipsis.before', text, options, globals).getText();
  2372. text = text.replace(/\.\.\./g, '…');
  2373. text = globals.converter._dispatch('makehtml.ellipsis.after', text, options, globals).getText();
  2374. return text;
  2375. });
  2376. /**
  2377. * These are all the transformations that occur *within* block-level
  2378. * tags like paragraphs, headers, and list items.
  2379. */
  2380. showdown.subParser('makehtml.emoji', function (text, options, globals) {
  2381. 'use strict';
  2382. if (!options.emoji) {
  2383. return text;
  2384. }
  2385. text = globals.converter._dispatch('makehtml.emoji.before', text, options, globals).getText();
  2386. var emojiRgx = /:([\S]+?):/g;
  2387. text = text.replace(emojiRgx, function (wm, emojiCode) {
  2388. if (showdown.helper.emojis.hasOwnProperty(emojiCode)) {
  2389. return showdown.helper.emojis[emojiCode];
  2390. }
  2391. return wm;
  2392. });
  2393. text = globals.converter._dispatch('makehtml.emoji.after', text, options, globals).getText();
  2394. return text;
  2395. });
  2396. /**
  2397. * Smart processing for ampersands and angle brackets that need to be encoded.
  2398. */
  2399. showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, globals) {
  2400. 'use strict';
  2401. text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.before', text, options, globals).getText();
  2402. // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
  2403. // http://bumppo.net/projects/amputator/
  2404. text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&amp;');
  2405. // Encode naked <'s
  2406. text = text.replace(/<(?![a-z\/?$!])/gi, '&lt;');
  2407. // Encode <
  2408. text = text.replace(/</g, '&lt;');
  2409. // Encode >
  2410. text = text.replace(/>/g, '&gt;');
  2411. text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.after', text, options, globals).getText();
  2412. return text;
  2413. });
  2414. /**
  2415. * Returns the string, with after processing the following backslash escape sequences.
  2416. *
  2417. * attacklab: The polite way to do this is with the new escapeCharacters() function:
  2418. *
  2419. * text = escapeCharacters(text,"\\",true);
  2420. * text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
  2421. *
  2422. * ...but we're sidestepping its use of the (slow) RegExp constructor
  2423. * as an optimization for Firefox. This function gets called a LOT.
  2424. */
  2425. showdown.subParser('makehtml.encodeBackslashEscapes', function (text, options, globals) {
  2426. 'use strict';
  2427. text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.before', text, options, globals).getText();
  2428. text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
  2429. text = text.replace(/\\([`*_{}\[\]()>#+.!~=|:-])/g, showdown.helper.escapeCharactersCallback);
  2430. text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.after', text, options, globals).getText();
  2431. return text;
  2432. });
  2433. /**
  2434. * Encode/escape certain characters inside Markdown code runs.
  2435. * The point is that in code, these characters are literals,
  2436. * and lose their special Markdown meanings.
  2437. */
  2438. showdown.subParser('makehtml.encodeCode', function (text, options, globals) {
  2439. 'use strict';
  2440. text = globals.converter._dispatch('makehtml.encodeCode.before', text, options, globals).getText();
  2441. // Encode all ampersands; HTML entities are not
  2442. // entities within a Markdown code span.
  2443. text = text
  2444. .replace(/&/g, '&amp;')
  2445. // Do the angle bracket song and dance:
  2446. .replace(/</g, '&lt;')
  2447. .replace(/>/g, '&gt;')
  2448. // Now, escape characters that are magic in Markdown:
  2449. .replace(/([*_{}\[\]\\=~-])/g, showdown.helper.escapeCharactersCallback);
  2450. text = globals.converter._dispatch('makehtml.encodeCode.after', text, options, globals).getText();
  2451. return text;
  2452. });
  2453. /**
  2454. * Within tags -- meaning between < and > -- encode [\ ` * _ ~ =] so they
  2455. * don't conflict with their use in Markdown for code, italics and strong.
  2456. */
  2457. showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (text, options, globals) {
  2458. 'use strict';
  2459. text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.before', text, options, globals).getText();
  2460. // Build a regex to find HTML tags.
  2461. var tags = /<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi,
  2462. comments = /<!(--(?:(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>/gi;
  2463. text = text.replace(tags, function (wholeMatch) {
  2464. return wholeMatch
  2465. .replace(/(.)<\/?code>(?=.)/g, '$1`')
  2466. .replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
  2467. });
  2468. text = text.replace(comments, function (wholeMatch) {
  2469. return wholeMatch
  2470. .replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
  2471. });
  2472. text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.after', text, options, globals).getText();
  2473. return text;
  2474. });
  2475. /**
  2476. * Handle github codeblocks prior to running HashHTML so that
  2477. * HTML contained within the codeblock gets escaped properly
  2478. * Example:
  2479. * ```ruby
  2480. * def hello_world(x)
  2481. * puts "Hello, #{x}"
  2482. * end
  2483. * ```
  2484. */
  2485. showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals) {
  2486. 'use strict';
  2487. // early exit if option is not enabled
  2488. if (!options.ghCodeBlocks) {
  2489. return text;
  2490. }
  2491. text = globals.converter._dispatch('makehtml.githubCodeBlocks.before', text, options, globals).getText();
  2492. text += '¨0';
  2493. text = text.replace(/(?:^|\n)(?: {0,3})(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n(?: {0,3})\1/g, function (wholeMatch, delim, language, codeblock) {
  2494. var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
  2495. // First parse the github code block
  2496. codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals);
  2497. codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals);
  2498. codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
  2499. codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
  2500. codeblock = '<pre><code' + (language ? ' class="' + language + ' language-' + language + '"' : '') + '>' + codeblock + end + '</code></pre>';
  2501. codeblock = showdown.subParser('makehtml.hashBlock')(codeblock, options, globals);
  2502. // Since GHCodeblocks can be false positives, we need to
  2503. // store the primitive text and the parsed text in a global var,
  2504. // and then return a token
  2505. return '\n\n¨G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
  2506. });
  2507. // attacklab: strip sentinel
  2508. text = text.replace(/¨0/, '');
  2509. return globals.converter._dispatch('makehtml.githubCodeBlocks.after', text, options, globals).getText();
  2510. });
  2511. showdown.subParser('makehtml.hashBlock', function (text, options, globals) {
  2512. 'use strict';
  2513. text = globals.converter._dispatch('makehtml.hashBlock.before', text, options, globals).getText();
  2514. text = text.replace(/(^\n+|\n+$)/g, '');
  2515. text = '\n\n¨K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
  2516. text = globals.converter._dispatch('makehtml.hashBlock.after', text, options, globals).getText();
  2517. return text;
  2518. });
  2519. /**
  2520. * Hash and escape <code> elements that should not be parsed as markdown
  2521. */
  2522. showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) {
  2523. 'use strict';
  2524. text = globals.converter._dispatch('makehtml.hashCodeTags.before', text, options, globals).getText();
  2525. var repFunc = function (wholeMatch, match, left, right) {
  2526. var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right;
  2527. return '¨C' + (globals.gHtmlSpans.push(codeblock) - 1) + 'C';
  2528. };
  2529. // Hash naked <code>
  2530. text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '<code\\b[^>]*>', '</code>', 'gim');
  2531. text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals).getText();
  2532. return text;
  2533. });
  2534. showdown.subParser('makehtml.hashElement', function (text, options, globals) {
  2535. 'use strict';
  2536. return function (wholeMatch, m1) {
  2537. var blockText = m1;
  2538. // Undo double lines
  2539. blockText = blockText.replace(/\n\n/g, '\n');
  2540. blockText = blockText.replace(/^\n/, '');
  2541. // strip trailing blank lines
  2542. blockText = blockText.replace(/\n+$/g, '');
  2543. // Replace the element text with a marker ("¨KxK" where x is its key)
  2544. blockText = '\n\n¨K' + (globals.gHtmlBlocks.push(blockText) - 1) + 'K\n\n';
  2545. return blockText;
  2546. };
  2547. });
  2548. showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals) {
  2549. 'use strict';
  2550. text = globals.converter._dispatch('makehtml.hashHTMLBlocks.before', text, options, globals).getText();
  2551. var blockTags = [
  2552. 'pre',
  2553. 'div',
  2554. 'h1',
  2555. 'h2',
  2556. 'h3',
  2557. 'h4',
  2558. 'h5',
  2559. 'h6',
  2560. 'blockquote',
  2561. 'table',
  2562. 'dl',
  2563. 'ol',
  2564. 'ul',
  2565. 'script',
  2566. 'noscript',
  2567. 'form',
  2568. 'fieldset',
  2569. 'iframe',
  2570. 'math',
  2571. 'style',
  2572. 'section',
  2573. 'header',
  2574. 'footer',
  2575. 'nav',
  2576. 'article',
  2577. 'aside',
  2578. 'address',
  2579. 'audio',
  2580. 'canvas',
  2581. 'figure',
  2582. 'hgroup',
  2583. 'output',
  2584. 'video',
  2585. 'p'
  2586. ],
  2587. repFunc = function (wholeMatch, match, left, right) {
  2588. var txt = wholeMatch;
  2589. // check if this html element is marked as markdown
  2590. // if so, it's contents should be parsed as markdown
  2591. if (left.search(/\bmarkdown\b/) !== -1) {
  2592. txt = left + globals.converter.makeHtml(match) + right;
  2593. }
  2594. return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
  2595. };
  2596. if (options.backslashEscapesHTMLTags) {
  2597. // encode backslash escaped HTML tags
  2598. text = text.replace(/\\<(\/?[^>]+?)>/g, function (wm, inside) {
  2599. return '&lt;' + inside + '&gt;';
  2600. });
  2601. }
  2602. // hash HTML Blocks
  2603. for (var i = 0; i < blockTags.length; ++i) {
  2604. var opTagPos,
  2605. rgx1 = new RegExp('^ {0,3}(<' + blockTags[i] + '\\b[^>]*>)', 'im'),
  2606. patLeft = '<' + blockTags[i] + '\\b[^>]*>',
  2607. patRight = '</' + blockTags[i] + '>';
  2608. // 1. Look for the first position of the first opening HTML tag in the text
  2609. while ((opTagPos = showdown.helper.regexIndexOf(text, rgx1)) !== -1) {
  2610. // if the HTML tag is \ escaped, we need to escape it and break
  2611. //2. Split the text in that position
  2612. var subTexts = showdown.helper.splitAtIndex(text, opTagPos),
  2613. //3. Match recursively
  2614. newSubText1 = showdown.helper.replaceRecursiveRegExp(subTexts[1], repFunc, patLeft, patRight, 'im');
  2615. // prevent an infinite loop
  2616. if (newSubText1 === subTexts[1]) {
  2617. break;
  2618. }
  2619. text = subTexts[0].concat(newSubText1);
  2620. }
  2621. }
  2622. // HR SPECIAL CASE
  2623. text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
  2624. showdown.subParser('makehtml.hashElement')(text, options, globals));
  2625. // Special case for standalone HTML comments
  2626. text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
  2627. return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
  2628. }, '^ {0,3}<!--', '-->', 'gm');
  2629. // PHP and ASP-style processor instructions (<?...?> and <%...%>)
  2630. text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
  2631. showdown.subParser('makehtml.hashElement')(text, options, globals));
  2632. text = globals.converter._dispatch('makehtml.hashHTMLBlocks.after', text, options, globals).getText();
  2633. return text;
  2634. });
  2635. /**
  2636. * Hash span elements that should not be parsed as markdown
  2637. */
  2638. showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) {
  2639. 'use strict';
  2640. text = globals.converter._dispatch('makehtml.hashHTMLSpans.before', text, options, globals).getText();
  2641. // Hash Self Closing tags
  2642. text = text.replace(/<[^>]+?\/>/gi, function (wm) {
  2643. return showdown.helper._hashHTMLSpan(wm, globals);
  2644. });
  2645. // Hash tags without properties
  2646. text = text.replace(/<([^>]+?)>[\s\S]*?<\/\1>/g, function (wm) {
  2647. return showdown.helper._hashHTMLSpan(wm, globals);
  2648. });
  2649. // Hash tags with properties
  2650. text = text.replace(/<([^>]+?)\s[^>]+?>[\s\S]*?<\/\1>/g, function (wm) {
  2651. return showdown.helper._hashHTMLSpan(wm, globals);
  2652. });
  2653. // Hash self closing tags without />
  2654. text = text.replace(/<[^>]+?>/gi, function (wm) {
  2655. return showdown.helper._hashHTMLSpan(wm, globals);
  2656. });
  2657. text = globals.converter._dispatch('makehtml.hashHTMLSpans.after', text, options, globals).getText();
  2658. return text;
  2659. });
  2660. /**
  2661. * Unhash HTML spans
  2662. */
  2663. showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals) {
  2664. 'use strict';
  2665. text = globals.converter._dispatch('makehtml.unhashHTMLSpans.before', text, options, globals).getText();
  2666. for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
  2667. var repText = globals.gHtmlSpans[i],
  2668. // limiter to prevent infinite loop (assume 10 as limit for recurse)
  2669. limit = 0;
  2670. while (/¨C(\d+)C/.test(repText)) {
  2671. var num = RegExp.$1;
  2672. repText = repText.replace('¨C' + num + 'C', globals.gHtmlSpans[num]);
  2673. if (limit === 10) {
  2674. console.error('maximum nesting of 10 spans reached!!!');
  2675. break;
  2676. }
  2677. ++limit;
  2678. }
  2679. text = text.replace('¨C' + i + 'C', repText);
  2680. }
  2681. text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals).getText();
  2682. return text;
  2683. });
  2684. /**
  2685. * Hash and escape <pre><code> elements that should not be parsed as markdown
  2686. */
  2687. showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals) {
  2688. 'use strict';
  2689. text = globals.converter._dispatch('makehtml.hashPreCodeTags.before', text, options, globals).getText();
  2690. var repFunc = function (wholeMatch, match, left, right) {
  2691. // encode html entities
  2692. var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right;
  2693. return '\n\n¨G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
  2694. };
  2695. // Hash <pre><code>
  2696. text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<pre\\b[^>]*>\\s*<code\\b[^>]*>', '^ {0,3}</code>\\s*</pre>', 'gim');
  2697. text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals).getText();
  2698. return text;
  2699. });
  2700. showdown.subParser('makehtml.headers', function (text, options, globals) {
  2701. 'use strict';
  2702. text = globals.converter._dispatch('makehtml.headers.before', text, options, globals).getText();
  2703. var headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
  2704. // Set text-style headers:
  2705. // Header 1
  2706. // ========
  2707. //
  2708. // Header 2
  2709. // --------
  2710. //
  2711. setextRegexH1 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n={2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n=+[ \t]*\n+/gm,
  2712. setextRegexH2 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n-+[ \t]*\n+/gm;
  2713. text = text.replace(setextRegexH1, function (wholeMatch, m1) {
  2714. var spanGamut = showdown.subParser('makehtml.spanGamut')(m1, options, globals),
  2715. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
  2716. hLevel = headerLevelStart,
  2717. hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
  2718. return showdown.subParser('makehtml.hashBlock')(hashBlock, options, globals);
  2719. });
  2720. text = text.replace(setextRegexH2, function (matchFound, m1) {
  2721. var spanGamut = showdown.subParser('makehtml.spanGamut')(m1, options, globals),
  2722. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
  2723. hLevel = headerLevelStart + 1,
  2724. hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
  2725. return showdown.subParser('makehtml.hashBlock')(hashBlock, options, globals);
  2726. });
  2727. // atx-style headers:
  2728. // # Header 1
  2729. // ## Header 2
  2730. // ## Header 2 with closing hashes ##
  2731. // ...
  2732. // ###### Header 6
  2733. //
  2734. var atxStyle = (options.requireSpaceBeforeHeadingText) ? /^(#{1,6})[ \t]+(.+?)[ \t]*#*\n+/gm : /^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm;
  2735. text = text.replace(atxStyle, function (wholeMatch, m1, m2) {
  2736. var hText = m2;
  2737. if (options.customizedHeaderId) {
  2738. hText = m2.replace(/\s?\{([^{]+?)}\s*$/, '');
  2739. }
  2740. var span = showdown.subParser('makehtml.spanGamut')(hText, options, globals),
  2741. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
  2742. hLevel = headerLevelStart - 1 + m1.length,
  2743. header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
  2744. return showdown.subParser('makehtml.hashBlock')(header, options, globals);
  2745. });
  2746. function headerId (m) {
  2747. var title,
  2748. prefix;
  2749. // It is separate from other options to allow combining prefix and customized
  2750. if (options.customizedHeaderId) {
  2751. var match = m.match(/\{([^{]+?)}\s*$/);
  2752. if (match && match[1]) {
  2753. m = match[1];
  2754. }
  2755. }
  2756. title = m;
  2757. // Prefix id to prevent causing inadvertent pre-existing style matches.
  2758. if (showdown.helper.isString(options.prefixHeaderId)) {
  2759. prefix = options.prefixHeaderId;
  2760. } else if (options.prefixHeaderId === true) {
  2761. prefix = 'section-';
  2762. } else {
  2763. prefix = '';
  2764. }
  2765. if (!options.rawPrefixHeaderId) {
  2766. title = prefix + title;
  2767. }
  2768. if (options.ghCompatibleHeaderId) {
  2769. title = title
  2770. .replace(/ /g, '-')
  2771. // replace previously escaped chars (&, ¨ and $)
  2772. .replace(/&amp;/g, '')
  2773. .replace(/¨T/g, '')
  2774. .replace(/¨D/g, '')
  2775. // replace rest of the chars (&~$ are repeated as they might have been escaped)
  2776. // borrowed from github's redcarpet (some they should produce similar results)
  2777. .replace(/[&+$,\/:;=?@"#{}|^¨~\[\]`\\*)(%.!'<>]/g, '')
  2778. .toLowerCase();
  2779. } else if (options.rawHeaderId) {
  2780. title = title
  2781. .replace(/ /g, '-')
  2782. // replace previously escaped chars (&, ¨ and $)
  2783. .replace(/&amp;/g, '&')
  2784. .replace(/¨T/g, '¨')
  2785. .replace(/¨D/g, '$')
  2786. // replace " and '
  2787. .replace(/["']/g, '-')
  2788. .toLowerCase();
  2789. } else {
  2790. title = title
  2791. .replace(/[^\w]/g, '')
  2792. .toLowerCase();
  2793. }
  2794. if (options.rawPrefixHeaderId) {
  2795. title = prefix + title;
  2796. }
  2797. if (globals.hashLinkCounts[title]) {
  2798. title = title + '-' + (globals.hashLinkCounts[title]++);
  2799. } else {
  2800. globals.hashLinkCounts[title] = 1;
  2801. }
  2802. return title;
  2803. }
  2804. text = globals.converter._dispatch('makehtml.headers.after', text, options, globals).getText();
  2805. return text;
  2806. });
  2807. /**
  2808. * Turn Markdown horizontal rule shortcuts into <hr /> tags.
  2809. *
  2810. * Any 3 or more unindented consecutive hyphens, asterisks or underscores with or without a space beetween them
  2811. * in a single line is considered a horizontal rule
  2812. */
  2813. showdown.subParser('makehtml.horizontalRule', function (text, options, globals) {
  2814. 'use strict';
  2815. text = globals.converter._dispatch('makehtml.horizontalRule.before', text, options, globals).getText();
  2816. var key = showdown.subParser('makehtml.hashBlock')('<hr />', options, globals);
  2817. text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
  2818. text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
  2819. text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
  2820. text = globals.converter._dispatch('makehtml.horizontalRule.after', text, options, globals).getText();
  2821. return text;
  2822. });
  2823. /**
  2824. * Turn Markdown image shortcuts into <img> tags.
  2825. */
  2826. showdown.subParser('makehtml.images', function (text, options, globals) {
  2827. 'use strict';
  2828. text = globals.converter._dispatch('makehtml.images.before', text, options, globals).getText();
  2829. var inlineRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<?([\S]+?(?:\([\S]*?\)[\S]*?)?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g,
  2830. crazyRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<([^>]*)>(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(?:(["'])([^"]*?)\6))?[ \t]?\)/g,
  2831. base64RegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<?(data:.+?\/.+?;base64,[A-Za-z0-9+/=\n]+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g,
  2832. referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[([\s\S]*?)]()()()()()/g,
  2833. refShortcutRegExp = /!\[([^\[\]]+)]()()()()()/g;
  2834. function writeImageTagBase64 (wholeMatch, altText, linkId, url, width, height, m5, title) {
  2835. url = url.replace(/\s/g, '');
  2836. return writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title);
  2837. }
  2838. function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
  2839. var gUrls = globals.gUrls,
  2840. gTitles = globals.gTitles,
  2841. gDims = globals.gDimensions;
  2842. linkId = linkId.toLowerCase();
  2843. if (!title) {
  2844. title = '';
  2845. }
  2846. // Special case for explicit empty url
  2847. if (wholeMatch.search(/\(<?\s*>? ?(['"].*['"])?\)$/m) > -1) {
  2848. url = '';
  2849. } else if (url === '' || url === null) {
  2850. if (linkId === '' || linkId === null) {
  2851. // lower-case and turn embedded newlines into spaces
  2852. linkId = altText.toLowerCase().replace(/ ?\n/g, ' ');
  2853. }
  2854. url = '#' + linkId;
  2855. if (!showdown.helper.isUndefined(gUrls[linkId])) {
  2856. url = gUrls[linkId];
  2857. if (!showdown.helper.isUndefined(gTitles[linkId])) {
  2858. title = gTitles[linkId];
  2859. }
  2860. if (!showdown.helper.isUndefined(gDims[linkId])) {
  2861. width = gDims[linkId].width;
  2862. height = gDims[linkId].height;
  2863. }
  2864. } else {
  2865. return wholeMatch;
  2866. }
  2867. }
  2868. altText = altText
  2869. .replace(/"/g, '&quot;')
  2870. //altText = showdown.helper.escapeCharacters(altText, '*_', false);
  2871. .replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  2872. //url = showdown.helper.escapeCharacters(url, '*_', false);
  2873. url = url.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  2874. var result = '<img src="' + url + '" alt="' + altText + '"';
  2875. if (title && showdown.helper.isString(title)) {
  2876. title = title
  2877. .replace(/"/g, '&quot;')
  2878. //title = showdown.helper.escapeCharacters(title, '*_', false);
  2879. .replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  2880. result += ' title="' + title + '"';
  2881. }
  2882. if (width && height) {
  2883. width = (width === '*') ? 'auto' : width;
  2884. height = (height === '*') ? 'auto' : height;
  2885. result += ' width="' + width + '"';
  2886. result += ' height="' + height + '"';
  2887. }
  2888. result += ' />';
  2889. return result;
  2890. }
  2891. // First, handle reference-style labeled images: ![alt text][id]
  2892. text = text.replace(referenceRegExp, writeImageTag);
  2893. // Next, handle inline images: ![alt text](url =<width>x<height> "optional title")
  2894. // base64 encoded images
  2895. text = text.replace(base64RegExp, writeImageTagBase64);
  2896. // cases with crazy urls like ./image/cat1).png
  2897. text = text.replace(crazyRegExp, writeImageTag);
  2898. // normal cases
  2899. text = text.replace(inlineRegExp, writeImageTag);
  2900. // handle reference-style shortcuts: ![img text]
  2901. text = text.replace(refShortcutRegExp, writeImageTag);
  2902. text = globals.converter._dispatch('makehtml.images.after', text, options, globals).getText();
  2903. return text;
  2904. });
  2905. showdown.subParser('makehtml.italicsAndBold', function (text, options, globals) {
  2906. 'use strict';
  2907. text = globals.converter._dispatch('makehtml.italicsAndBold.before', text, options, globals).getText();
  2908. // it's faster to have 3 separate regexes for each case than have just one
  2909. // because of backtracing, in some cases, it could lead to an exponential effect
  2910. // called "catastrophic backtrace". Ominous!
  2911. function parseInside (txt, left, right) {
  2912. return left + txt + right;
  2913. }
  2914. // Parse underscores
  2915. if (options.literalMidWordUnderscores) {
  2916. text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) {
  2917. return parseInside (txt, '<strong><em>', '</em></strong>');
  2918. });
  2919. text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) {
  2920. return parseInside (txt, '<strong>', '</strong>');
  2921. });
  2922. text = text.replace(/\b_(\S[\s\S]*?)_\b/g, function (wm, txt) {
  2923. return parseInside (txt, '<em>', '</em>');
  2924. });
  2925. } else {
  2926. text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) {
  2927. return (/\S$/.test(m)) ? parseInside (m, '<strong><em>', '</em></strong>') : wm;
  2928. });
  2929. text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
  2930. return (/\S$/.test(m)) ? parseInside (m, '<strong>', '</strong>') : wm;
  2931. });
  2932. text = text.replace(/_([^\s_][\s\S]*?)_/g, function (wm, m) {
  2933. // !/^_[^_]/.test(m) - test if it doesn't start with __ (since it seems redundant, we removed it)
  2934. return (/\S$/.test(m)) ? parseInside (m, '<em>', '</em>') : wm;
  2935. });
  2936. }
  2937. // Now parse asterisks
  2938. /*
  2939. if (options.literalMidWordAsterisks) {
  2940. text = text.replace(/([^*]|^)\B\*\*\*(\S[\s\S]+?)\*\*\*\B(?!\*)/g, function (wm, lead, txt) {
  2941. return parseInside (txt, lead + '<strong><em>', '</em></strong>');
  2942. });
  2943. text = text.replace(/([^*]|^)\B\*\*(\S[\s\S]+?)\*\*\B(?!\*)/g, function (wm, lead, txt) {
  2944. return parseInside (txt, lead + '<strong>', '</strong>');
  2945. });
  2946. text = text.replace(/([^*]|^)\B\*(\S[\s\S]+?)\*\B(?!\*)/g, function (wm, lead, txt) {
  2947. return parseInside (txt, lead + '<em>', '</em>');
  2948. });
  2949. } else {
  2950. */
  2951. text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {
  2952. return (/\S$/.test(m)) ? parseInside (m, '<strong><em>', '</em></strong>') : wm;
  2953. });
  2954. text = text.replace(/\*\*(\S[\s\S]*?)\*\*/g, function (wm, m) {
  2955. return (/\S$/.test(m)) ? parseInside (m, '<strong>', '</strong>') : wm;
  2956. });
  2957. text = text.replace(/\*([^\s*][\s\S]*?)\*/g, function (wm, m) {
  2958. // !/^\*[^*]/.test(m) - test if it doesn't start with ** (since it seems redundant, we removed it)
  2959. return (/\S$/.test(m)) ? parseInside (m, '<em>', '</em>') : wm;
  2960. });
  2961. //}
  2962. text = globals.converter._dispatch('makehtml.italicsAndBold.after', text, options, globals).getText();
  2963. return text;
  2964. });
  2965. ////
  2966. // makehtml/links.js
  2967. // Copyright (c) 2018 ShowdownJS
  2968. //
  2969. // Transforms MD links into `<a>` html anchors
  2970. //
  2971. // A link contains link text (the visible text), a link destination (the URI that is the link destination), and
  2972. // optionally a link title. There are two basic kinds of links in Markdown.
  2973. // In inline links the destination and title are given immediately after the link text.
  2974. // In reference links the destination and title are defined elsewhere in the document.
  2975. //
  2976. // ***Author:***
  2977. // - Estevão Soares dos Santos (Tivie) <https://github.com/tivie>
  2978. ////
  2979. (function () {
  2980. /**
  2981. * Helper function: Wrapper function to pass as second replace parameter
  2982. *
  2983. * @param {RegExp} rgx
  2984. * @param {string} evtRootName
  2985. * @param {{}} options
  2986. * @param {{}} globals
  2987. * @returns {Function}
  2988. */
  2989. function replaceAnchorTag (rgx, evtRootName, options, globals, emptyCase) {
  2990. emptyCase = !!emptyCase;
  2991. return function (wholeMatch, text, id, url, m5, m6, title) {
  2992. // bail we we find 2 newlines somewhere
  2993. if (/\n\n/.test(wholeMatch)) {
  2994. return wholeMatch;
  2995. }
  2996. var evt = createEvent(rgx, evtRootName + '.captureStart', wholeMatch, text, id, url, title, options, globals);
  2997. return writeAnchorTag(evt, options, globals, emptyCase);
  2998. };
  2999. }
  3000. /**
  3001. * TODO Normalize this
  3002. * Helper function: Create a capture event
  3003. * @param {RegExp} rgx
  3004. * @param {String} evtName Event name
  3005. * @param {String} wholeMatch
  3006. * @param {String} text
  3007. * @param {String} id
  3008. * @param {String} url
  3009. * @param {String} title
  3010. * @param {{}} options
  3011. * @param {{}} globals
  3012. * @returns {showdown.helper.Event|*}
  3013. */
  3014. function createEvent (rgx, evtName, wholeMatch, text, id, url, title, options, globals) {
  3015. return globals.converter._dispatch(evtName, wholeMatch, options, globals, {
  3016. regexp: rgx,
  3017. matches: {
  3018. wholeMatch: wholeMatch,
  3019. text: text,
  3020. id: id,
  3021. url: url,
  3022. title: title
  3023. }
  3024. });
  3025. }
  3026. /**
  3027. * Helper Function: Normalize and write an anchor tag based on passed parameters
  3028. * @param evt
  3029. * @param options
  3030. * @param globals
  3031. * @param {boolean} emptyCase
  3032. * @returns {string}
  3033. */
  3034. function writeAnchorTag (evt, options, globals, emptyCase) {
  3035. var wholeMatch = evt.getMatches().wholeMatch;
  3036. var text = evt.getMatches().text;
  3037. var id = evt.getMatches().id;
  3038. var url = evt.getMatches().url;
  3039. var title = evt.getMatches().title;
  3040. var target = '';
  3041. if (!title) {
  3042. title = '';
  3043. }
  3044. id = (id) ? id.toLowerCase() : '';
  3045. if (emptyCase) {
  3046. url = '';
  3047. } else if (!url) {
  3048. if (!id) {
  3049. // lower-case and turn embedded newlines into spaces
  3050. id = text.toLowerCase().replace(/ ?\n/g, ' ');
  3051. }
  3052. url = '#' + id;
  3053. if (!showdown.helper.isUndefined(globals.gUrls[id])) {
  3054. url = globals.gUrls[id];
  3055. if (!showdown.helper.isUndefined(globals.gTitles[id])) {
  3056. title = globals.gTitles[id];
  3057. }
  3058. } else {
  3059. return wholeMatch;
  3060. }
  3061. }
  3062. //url = showdown.helper.escapeCharacters(url, '*_:~', false); // replaced line to improve performance
  3063. url = url.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  3064. if (title !== '' && title !== null) {
  3065. title = title.replace(/"/g, '&quot;');
  3066. //title = showdown.helper.escapeCharacters(title, '*_', false); // replaced line to improve performance
  3067. title = title.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  3068. title = ' title="' + title + '"';
  3069. }
  3070. // optionLinksInNewWindow only applies
  3071. // to external links. Hash links (#) open in same page
  3072. if (options.openLinksInNewWindow && !/^#/.test(url)) {
  3073. // escaped _
  3074. target = ' target="¨E95Eblank"';
  3075. }
  3076. // Text can be a markdown element, so we run through the appropriate parsers
  3077. text = showdown.subParser('makehtml.codeSpans')(text, options, globals);
  3078. text = showdown.subParser('makehtml.emoji')(text, options, globals);
  3079. text = showdown.subParser('makehtml.underline')(text, options, globals);
  3080. text = showdown.subParser('makehtml.italicsAndBold')(text, options, globals);
  3081. text = showdown.subParser('makehtml.strikethrough')(text, options, globals);
  3082. text = showdown.subParser('makehtml.ellipsis')(text, options, globals);
  3083. text = showdown.subParser('makehtml.hashHTMLSpans')(text, options, globals);
  3084. //evt = createEvent(rgx, evtRootName + '.captureEnd', wholeMatch, text, id, url, title, options, globals);
  3085. var result = '<a href="' + url + '"' + title + target + '>' + text + '</a>';
  3086. //evt = createEvent(rgx, evtRootName + '.beforeHash', wholeMatch, text, id, url, title, options, globals);
  3087. result = showdown.subParser('makehtml.hashHTMLSpans')(result, options, globals);
  3088. return result;
  3089. }
  3090. var evtRootName = 'makehtml.links';
  3091. /**
  3092. * Turn Markdown link shortcuts into XHTML <a> tags.
  3093. */
  3094. showdown.subParser('makehtml.links', function (text, options, globals) {
  3095. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3096. // 1. Handle reference-style links: [link text] [id]
  3097. text = showdown.subParser('makehtml.links.reference')(text, options, globals);
  3098. // 2. Handle inline-style links: [link text](url "optional title")
  3099. text = showdown.subParser('makehtml.links.inline')(text, options, globals);
  3100. // 3. Handle reference-style shortcuts: [link text]
  3101. // These must come last in case there's a [link text][1] or [link text](/foo)
  3102. text = showdown.subParser('makehtml.links.referenceShortcut')(text, options, globals);
  3103. // 4. Handle angle brackets links -> `<http://example.com/>`
  3104. // Must come after links, because you can use < and > delimiters in inline links like [this](<url>).
  3105. text = showdown.subParser('makehtml.links.angleBrackets')(text, options, globals);
  3106. // 5. Handle GithubMentions (if option is enabled)
  3107. text = showdown.subParser('makehtml.links.ghMentions')(text, options, globals);
  3108. // 6. Handle <a> tags and img tags
  3109. text = text.replace(/<a\s[^>]*>[\s\S]*<\/a>/g, function (wholeMatch) {
  3110. return showdown.helper._hashHTMLSpan(wholeMatch, globals);
  3111. });
  3112. text = text.replace(/<img\s[^>]*\/?>/g, function (wholeMatch) {
  3113. return showdown.helper._hashHTMLSpan(wholeMatch, globals);
  3114. });
  3115. // 7. Handle naked links (if option is enabled)
  3116. text = showdown.subParser('makehtml.links.naked')(text, options, globals);
  3117. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3118. return text;
  3119. });
  3120. /**
  3121. * TODO WRITE THIS DOCUMENTATION
  3122. */
  3123. showdown.subParser('makehtml.links.inline', function (text, options, globals) {
  3124. var evtRootName = evtRootName + '.inline';
  3125. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3126. // 1. Look for empty cases: []() and [empty]() and []("title")
  3127. var rgxEmpty = /\[(.*?)]()()()()\(<? ?>? ?(?:["'](.*)["'])?\)/g;
  3128. text = text.replace(rgxEmpty, replaceAnchorTag(rgxEmpty, evtRootName, options, globals, true));
  3129. // 2. Look for cases with crazy urls like ./image/cat1).png
  3130. var rgxCrazy = /\[((?:\[[^\]]*]|[^\[\]])*)]()\s?\([ \t]?<([^>]*)>(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g;
  3131. text = text.replace(rgxCrazy, replaceAnchorTag(rgxCrazy, evtRootName, options, globals));
  3132. // 3. inline links with no title or titles wrapped in ' or ":
  3133. // [text](url.com) || [text](<url.com>) || [text](url.com "title") || [text](<url.com> "title")
  3134. //var rgx2 = /\[[ ]*[\s]?[ ]*([^\n\[\]]*?)[ ]*[\s]?[ ]*] ?()\(<?[ ]*[\s]?[ ]*([^\s'"]*)>?(?:[ ]*[\n]?[ ]*()(['"])(.*?)\5)?[ ]*[\s]?[ ]*\)/; // this regex is too slow!!!
  3135. var rgx2 = /\[([\S ]*?)]\s?()\( *<?([^\s'"]*?(?:\([\S]*?\)[\S]*?)?)>?\s*(?:()(['"])(.*?)\5)? *\)/g;
  3136. text = text.replace(rgx2, replaceAnchorTag(rgx2, evtRootName, options, globals));
  3137. // 4. inline links with titles wrapped in (): [foo](bar.com (title))
  3138. var rgx3 = /\[([\S ]*?)]\s?()\( *<?([^\s'"]*?(?:\([\S]*?\)[\S]*?)?)>?\s+()()\((.*?)\) *\)/g;
  3139. text = text.replace(rgx3, replaceAnchorTag(rgx3, evtRootName, options, globals));
  3140. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3141. return text;
  3142. });
  3143. /**
  3144. * TODO WRITE THIS DOCUMENTATION
  3145. */
  3146. showdown.subParser('makehtml.links.reference', function (text, options, globals) {
  3147. var evtRootName = evtRootName + '.reference';
  3148. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3149. var rgx = /\[((?:\[[^\]]*]|[^\[\]])*)] ?(?:\n *)?\[(.*?)]()()()()/g;
  3150. text = text.replace(rgx, replaceAnchorTag(rgx, evtRootName, options, globals));
  3151. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3152. return text;
  3153. });
  3154. /**
  3155. * TODO WRITE THIS DOCUMENTATION
  3156. */
  3157. showdown.subParser('makehtml.links.referenceShortcut', function (text, options, globals) {
  3158. var evtRootName = evtRootName + '.referenceShortcut';
  3159. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3160. var rgx = /\[([^\[\]]+)]()()()()()/g;
  3161. text = text.replace(rgx, replaceAnchorTag(rgx, evtRootName, options, globals));
  3162. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3163. return text;
  3164. });
  3165. /**
  3166. * TODO WRITE THIS DOCUMENTATION
  3167. */
  3168. showdown.subParser('makehtml.links.ghMentions', function (text, options, globals) {
  3169. var evtRootName = evtRootName + 'ghMentions';
  3170. if (!options.ghMentions) {
  3171. return text;
  3172. }
  3173. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3174. var rgx = /(^|\s)(\\)?(@([a-z\d]+(?:[a-z\d._-]+?[a-z\d]+)*))/gi;
  3175. text = text.replace(rgx, function (wholeMatch, st, escape, mentions, username) {
  3176. // bail if the mentions was escaped
  3177. if (escape === '\\') {
  3178. return st + mentions;
  3179. }
  3180. // check if options.ghMentionsLink is a string
  3181. // TODO Validation should be done at initialization not at runtime
  3182. if (!showdown.helper.isString(options.ghMentionsLink)) {
  3183. throw new Error('ghMentionsLink option must be a string');
  3184. }
  3185. var url = options.ghMentionsLink.replace(/{u}/g, username);
  3186. var evt = createEvent(rgx, evtRootName + '.captureStart', wholeMatch, mentions, null, url, null, options, globals);
  3187. // captureEnd Event is triggered inside writeAnchorTag function
  3188. return st + writeAnchorTag(evt, options, globals);
  3189. });
  3190. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3191. return text;
  3192. });
  3193. /**
  3194. * TODO WRITE THIS DOCUMENTATION
  3195. */
  3196. showdown.subParser('makehtml.links.angleBrackets', function (text, options, globals) {
  3197. var evtRootName = 'makehtml.links.angleBrackets';
  3198. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3199. // 1. Parse links first
  3200. var urlRgx = /<(((?:https?|ftp):\/\/|www\.)[^'">\s]+)>/gi;
  3201. text = text.replace(urlRgx, function (wholeMatch, url, urlStart) {
  3202. var text = url;
  3203. url = (urlStart === 'www.') ? 'http://' + url : url;
  3204. var evt = createEvent(urlRgx, evtRootName + '.captureStart', wholeMatch, text, null, url, null, options, globals);
  3205. return writeAnchorTag(evt, options, globals);
  3206. });
  3207. // 2. Then Mail Addresses
  3208. var mailRgx = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
  3209. text = text.replace(mailRgx, function (wholeMatch, mail) {
  3210. var url = 'mailto:';
  3211. mail = showdown.subParser('makehtml.unescapeSpecialChars')(mail, options, globals);
  3212. if (options.encodeEmails) {
  3213. url = showdown.helper.encodeEmailAddress(url + mail);
  3214. mail = showdown.helper.encodeEmailAddress(mail);
  3215. } else {
  3216. url = url + mail;
  3217. }
  3218. var evt = createEvent(mailRgx, evtRootName + '.captureStart', wholeMatch, mail, null, url, null, options, globals);
  3219. return writeAnchorTag(evt, options, globals);
  3220. });
  3221. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3222. return text;
  3223. });
  3224. /**
  3225. * TODO MAKE THIS WORK (IT'S NOT ACTIVATED)
  3226. * TODO WRITE THIS DOCUMENTATION
  3227. */
  3228. showdown.subParser('makehtml.links.naked', function (text, options, globals) {
  3229. if (!options.simplifiedAutoLink) {
  3230. return text;
  3231. }
  3232. var evtRootName = 'makehtml.links.naked';
  3233. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3234. // 2. Now we check for
  3235. // we also include leading markdown magic chars [_*~] for cases like __https://www.google.com/foobar__
  3236. var urlRgx = /([_*~]*?)(((?:https?|ftp):\/\/|www\.)[^\s<>"'`´.-][^\s<>"'`´]*?\.[a-z\d.]+[^\s<>"']*)\1/gi;
  3237. text = text.replace(urlRgx, function (wholeMatch, leadingMDChars, url, urlPrefix) {
  3238. // we now will start traversing the url from the front to back, looking for punctuation chars [_*~,;:.!?\)\]]
  3239. var len = url.length;
  3240. var suffix = '';
  3241. for (var i = len - 1; i >= 0; --i) {
  3242. var char = url.charAt(i);
  3243. if (/[_*~,;:.!?]/.test(char)) {
  3244. // it's a punctuation char
  3245. // we remove it from the url
  3246. url = url.slice(0, -1);
  3247. // and prepend it to the suffix
  3248. suffix = char + suffix;
  3249. } else if (/\)/.test(char)) {
  3250. var opPar = url.match(/\(/g) || [];
  3251. var clPar = url.match(/\)/g);
  3252. // it's a curved parenthesis so we need to check for "balance" (kinda)
  3253. if (opPar.length < clPar.length) {
  3254. // there are more closing Parenthesis than opening so chop it!!!!!
  3255. url = url.slice(0, -1);
  3256. // and prepend it to the suffix
  3257. suffix = char + suffix;
  3258. } else {
  3259. // it's (kinda) balanced so our work is done
  3260. break;
  3261. }
  3262. } else if (/]/.test(char)) {
  3263. var opPar2 = url.match(/\[/g) || [];
  3264. var clPar2 = url.match(/\]/g);
  3265. // it's a squared parenthesis so we need to check for "balance" (kinda)
  3266. if (opPar2.length < clPar2.length) {
  3267. // there are more closing Parenthesis than opening so chop it!!!!!
  3268. url = url.slice(0, -1);
  3269. // and prepend it to the suffix
  3270. suffix = char + suffix;
  3271. } else {
  3272. // it's (kinda) balanced so our work is done
  3273. break;
  3274. }
  3275. } else {
  3276. // it's not a punctuation or a parenthesis so our work is done
  3277. break;
  3278. }
  3279. }
  3280. // we copy the treated url to the text variable
  3281. var text = url;
  3282. // finally, if it's a www shortcut, we prepend http
  3283. url = (urlPrefix === 'www.') ? 'http://' + url : url;
  3284. // url part is done so let's take care of text now
  3285. // we need to escape the text (because of links such as www.example.com/foo__bar__baz)
  3286. text = text.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  3287. // finally we dispatch the event
  3288. var evt = createEvent(urlRgx, evtRootName + '.captureStart', wholeMatch, text, null, url, null, options, globals);
  3289. // and return the link tag, with the leadingMDChars and suffix. The leadingMDChars are added at the end too because
  3290. // we consumed those characters in the regexp
  3291. return leadingMDChars + writeAnchorTag(evt, options, globals) + suffix + leadingMDChars;
  3292. });
  3293. // 2. Then mails
  3294. var mailRgx = /(^|\s)(?:mailto:)?([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?=$|\s)/gmi;
  3295. text = text.replace(mailRgx, function (wholeMatch, leadingChar, mail) {
  3296. var url = 'mailto:';
  3297. mail = showdown.subParser('makehtml.unescapeSpecialChars')(mail, options, globals);
  3298. if (options.encodeEmails) {
  3299. url = showdown.helper.encodeEmailAddress(url + mail);
  3300. mail = showdown.helper.encodeEmailAddress(mail);
  3301. } else {
  3302. url = url + mail;
  3303. }
  3304. var evt = createEvent(mailRgx, evtRootName + '.captureStart', wholeMatch, mail, null, url, null, options, globals);
  3305. return leadingChar + writeAnchorTag(evt, options, globals);
  3306. });
  3307. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3308. return text;
  3309. });
  3310. })();
  3311. /**
  3312. * Form HTML ordered (numbered) and unordered (bulleted) lists.
  3313. */
  3314. showdown.subParser('makehtml.lists', function (text, options, globals) {
  3315. 'use strict';
  3316. /**
  3317. * Process the contents of a single ordered or unordered list, splitting it
  3318. * into individual list items.
  3319. * @param {string} listStr
  3320. * @param {boolean} trimTrailing
  3321. * @returns {string}
  3322. */
  3323. function processListItems (listStr, trimTrailing) {
  3324. // The $g_list_level global keeps track of when we're inside a list.
  3325. // Each time we enter a list, we increment it; when we leave a list,
  3326. // we decrement. If it's zero, we're not in a list anymore.
  3327. //
  3328. // We do this because when we're not inside a list, we want to treat
  3329. // something like this:
  3330. //
  3331. // I recommend upgrading to version
  3332. // 8. Oops, now this line is treated
  3333. // as a sub-list.
  3334. //
  3335. // As a single paragraph, despite the fact that the second line starts
  3336. // with a digit-period-space sequence.
  3337. //
  3338. // Whereas when we're inside a list (or sub-list), that line will be
  3339. // treated as the start of a sub-list. What a kludge, huh? This is
  3340. // an aspect of Markdown's syntax that's hard to parse perfectly
  3341. // without resorting to mind-reading. Perhaps the solution is to
  3342. // change the syntax rules such that sub-lists must start with a
  3343. // starting cardinal number; e.g. "1." or "a.".
  3344. globals.gListLevel++;
  3345. // trim trailing blank lines:
  3346. listStr = listStr.replace(/\n{2,}$/, '\n');
  3347. // attacklab: add sentinel to emulate \z
  3348. listStr += '¨0';
  3349. var rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0| {0,3}([*+-]|\d+[.])[ \t]+))/gm,
  3350. isParagraphed = (/\n[ \t]*\n(?!¨0)/.test(listStr));
  3351. // Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation,
  3352. // which is a syntax breaking change
  3353. // activating this option reverts to old behavior
  3354. // This will be removed in version 2.0
  3355. if (options.disableForced4SpacesIndentedSublists) {
  3356. rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0|\2([*+-]|\d+[.])[ \t]+))/gm;
  3357. }
  3358. listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) {
  3359. checked = (checked && checked.trim() !== '');
  3360. var item = showdown.subParser('makehtml.outdent')(m4, options, globals),
  3361. bulletStyle = '';
  3362. // Support for github tasklists
  3363. if (taskbtn && options.tasklists) {
  3364. bulletStyle = ' class="task-list-item" style="list-style-type: none;"';
  3365. item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () {
  3366. var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"';
  3367. if (checked) {
  3368. otp += ' checked';
  3369. }
  3370. otp += '>';
  3371. return otp;
  3372. });
  3373. }
  3374. // ISSUE #312
  3375. // This input: - - - a
  3376. // causes trouble to the parser, since it interprets it as:
  3377. // <ul><li><li><li>a</li></li></li></ul>
  3378. // instead of:
  3379. // <ul><li>- - a</li></ul>
  3380. // So, to prevent it, we will put a marker (¨A)in the beginning of the line
  3381. // Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser
  3382. item = item.replace(/^([-*+]|\d\.)[ \t]+[\S\n ]*/g, function (wm2) {
  3383. return '¨A' + wm2;
  3384. });
  3385. // SPECIAL CASE: an heading followed by a paragraph of text that is not separated by a double newline
  3386. // or/nor indented. ex:
  3387. //
  3388. // - # foo
  3389. // bar is great
  3390. //
  3391. // While this does now follow the spec per se, not allowing for this might cause confusion since
  3392. // header blocks don't need double newlines after
  3393. if (/^#+.+\n.+/.test(item)) {
  3394. item = item.replace(/^(#+.+)$/m, '$1\n');
  3395. }
  3396. // m1 - Leading line or
  3397. // Has a double return (multi paragraph)
  3398. if (m1 || (item.search(/\n{2,}/) > -1)) {
  3399. item = showdown.subParser('makehtml.githubCodeBlocks')(item, options, globals);
  3400. item = showdown.subParser('makehtml.blockGamut')(item, options, globals);
  3401. } else {
  3402. // Recursion for sub-lists:
  3403. item = showdown.subParser('makehtml.lists')(item, options, globals);
  3404. item = item.replace(/\n$/, ''); // chomp(item)
  3405. item = showdown.subParser('makehtml.hashHTMLBlocks')(item, options, globals);
  3406. // Colapse double linebreaks
  3407. item = item.replace(/\n\n+/g, '\n\n');
  3408. if (isParagraphed) {
  3409. item = showdown.subParser('makehtml.paragraphs')(item, options, globals);
  3410. } else {
  3411. item = showdown.subParser('makehtml.spanGamut')(item, options, globals);
  3412. }
  3413. }
  3414. // now we need to remove the marker (¨A)
  3415. item = item.replace('¨A', '');
  3416. // we can finally wrap the line in list item tags
  3417. item = '<li' + bulletStyle + '>' + item + '</li>\n';
  3418. return item;
  3419. });
  3420. // attacklab: strip sentinel
  3421. listStr = listStr.replace(/¨0/g, '');
  3422. globals.gListLevel--;
  3423. if (trimTrailing) {
  3424. listStr = listStr.replace(/\s+$/, '');
  3425. }
  3426. return listStr;
  3427. }
  3428. function styleStartNumber (list, listType) {
  3429. // check if ol and starts by a number different than 1
  3430. if (listType === 'ol') {
  3431. var res = list.match(/^ *(\d+)\./);
  3432. if (res && res[1] !== '1') {
  3433. return ' start="' + res[1] + '"';
  3434. }
  3435. }
  3436. return '';
  3437. }
  3438. /**
  3439. * Check and parse consecutive lists (better fix for issue #142)
  3440. * @param {string} list
  3441. * @param {string} listType
  3442. * @param {boolean} trimTrailing
  3443. * @returns {string}
  3444. */
  3445. function parseConsecutiveLists (list, listType, trimTrailing) {
  3446. // check if we caught 2 or more consecutive lists by mistake
  3447. // we use the counterRgx, meaning if listType is UL we look for OL and vice versa
  3448. var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
  3449. ulRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?[*+-][ \t]/gm : /^ {0,3}[*+-][ \t]/gm,
  3450. counterRxg = (listType === 'ul') ? olRgx : ulRgx,
  3451. result = '';
  3452. if (list.search(counterRxg) !== -1) {
  3453. (function parseCL (txt) {
  3454. var pos = txt.search(counterRxg),
  3455. style = styleStartNumber(list, listType);
  3456. if (pos !== -1) {
  3457. // slice
  3458. result += '\n\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
  3459. // invert counterType and listType
  3460. listType = (listType === 'ul') ? 'ol' : 'ul';
  3461. counterRxg = (listType === 'ul') ? olRgx : ulRgx;
  3462. //recurse
  3463. parseCL(txt.slice(pos));
  3464. } else {
  3465. result += '\n\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
  3466. }
  3467. })(list);
  3468. } else {
  3469. var style = styleStartNumber(list, listType);
  3470. result = '\n\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
  3471. }
  3472. return result;
  3473. }
  3474. // Start of list parsing
  3475. var subListRgx = /^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
  3476. var mainListRgx = /(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
  3477. text = globals.converter._dispatch('lists.before', text, options, globals).getText();
  3478. // add sentinel to hack around khtml/safari bug:
  3479. // http://bugs.webkit.org/show_bug.cgi?id=11231
  3480. text += '¨0';
  3481. if (globals.gListLevel) {
  3482. text = text.replace(subListRgx, function (wholeMatch, list, m2) {
  3483. var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
  3484. return parseConsecutiveLists(list, listType, true);
  3485. });
  3486. } else {
  3487. text = text.replace(mainListRgx, function (wholeMatch, m1, list, m3) {
  3488. var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
  3489. return parseConsecutiveLists(list, listType, false);
  3490. });
  3491. }
  3492. // strip sentinel
  3493. text = text.replace(/¨0/, '');
  3494. text = globals.converter._dispatch('makehtml.lists.after', text, options, globals).getText();
  3495. return text;
  3496. });
  3497. /**
  3498. * Parse metadata at the top of the document
  3499. */
  3500. showdown.subParser('makehtml.metadata', function (text, options, globals) {
  3501. 'use strict';
  3502. if (!options.metadata) {
  3503. return text;
  3504. }
  3505. text = globals.converter._dispatch('makehtml.metadata.before', text, options, globals).getText();
  3506. function parseMetadataContents (content) {
  3507. // raw is raw so it's not changed in any way
  3508. globals.metadata.raw = content;
  3509. // escape chars forbidden in html attributes
  3510. // double quotes
  3511. content = content
  3512. // ampersand first
  3513. .replace(/&/g, '&amp;')
  3514. // double quotes
  3515. .replace(/"/g, '&quot;');
  3516. content = content.replace(/\n {4}/g, ' ');
  3517. content.replace(/^([\S ]+): +([\s\S]+?)$/gm, function (wm, key, value) {
  3518. globals.metadata.parsed[key] = value;
  3519. return '';
  3520. });
  3521. }
  3522. text = text.replace(/^\s*«««+(\S*?)\n([\s\S]+?)\n»»»+\n/, function (wholematch, format, content) {
  3523. parseMetadataContents(content);
  3524. return '¨M';
  3525. });
  3526. text = text.replace(/^\s*---+(\S*?)\n([\s\S]+?)\n---+\n/, function (wholematch, format, content) {
  3527. if (format) {
  3528. globals.metadata.format = format;
  3529. }
  3530. parseMetadataContents(content);
  3531. return '¨M';
  3532. });
  3533. text = text.replace(/¨M/g, '');
  3534. text = globals.converter._dispatch('makehtml.metadata.after', text, options, globals).getText();
  3535. return text;
  3536. });
  3537. /**
  3538. * Remove one level of line-leading tabs or spaces
  3539. */
  3540. showdown.subParser('makehtml.outdent', function (text, options, globals) {
  3541. 'use strict';
  3542. text = globals.converter._dispatch('makehtml.outdent.before', text, options, globals).getText();
  3543. // attacklab: hack around Konqueror 3.5.4 bug:
  3544. // "----------bug".replace(/^-/g,"") == "bug"
  3545. text = text.replace(/^(\t|[ ]{1,4})/gm, '¨0'); // attacklab: g_tab_width
  3546. // attacklab: clean up hack
  3547. text = text.replace(/¨0/g, '');
  3548. text = globals.converter._dispatch('makehtml.outdent.after', text, options, globals).getText();
  3549. return text;
  3550. });
  3551. /**
  3552. *
  3553. */
  3554. showdown.subParser('makehtml.paragraphs', function (text, options, globals) {
  3555. 'use strict';
  3556. text = globals.converter._dispatch('makehtml.paragraphs.before', text, options, globals).getText();
  3557. // Strip leading and trailing lines:
  3558. text = text.replace(/^\n+/g, '');
  3559. text = text.replace(/\n+$/g, '');
  3560. var grafs = text.split(/\n{2,}/g),
  3561. grafsOut = [],
  3562. end = grafs.length; // Wrap <p> tags
  3563. for (var i = 0; i < end; i++) {
  3564. var str = grafs[i];
  3565. // if this is an HTML marker, copy it
  3566. if (str.search(/¨(K|G)(\d+)\1/g) >= 0) {
  3567. grafsOut.push(str);
  3568. // test for presence of characters to prevent empty lines being parsed
  3569. // as paragraphs (resulting in undesired extra empty paragraphs)
  3570. } else if (str.search(/\S/) >= 0) {
  3571. str = showdown.subParser('makehtml.spanGamut')(str, options, globals);
  3572. str = str.replace(/^([ \t]*)/g, '<p>');
  3573. str += '</p>';
  3574. grafsOut.push(str);
  3575. }
  3576. }
  3577. /** Unhashify HTML blocks */
  3578. end = grafsOut.length;
  3579. for (i = 0; i < end; i++) {
  3580. var blockText = '',
  3581. grafsOutIt = grafsOut[i],
  3582. codeFlag = false;
  3583. // if this is a marker for an html block...
  3584. // use RegExp.test instead of string.search because of QML bug
  3585. while (/¨(K|G)(\d+)\1/.test(grafsOutIt)) {
  3586. var delim = RegExp.$1,
  3587. num = RegExp.$2;
  3588. if (delim === 'K') {
  3589. blockText = globals.gHtmlBlocks[num];
  3590. } else {
  3591. // we need to check if ghBlock is a false positive
  3592. if (codeFlag) {
  3593. // use encoded version of all text
  3594. blockText = showdown.subParser('makehtml.encodeCode')(globals.ghCodeBlocks[num].text, options, globals);
  3595. } else {
  3596. blockText = globals.ghCodeBlocks[num].codeblock;
  3597. }
  3598. }
  3599. blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
  3600. grafsOutIt = grafsOutIt.replace(/(\n\n)?¨(K|G)\d+\2(\n\n)?/, blockText);
  3601. // Check if grafsOutIt is a pre->code
  3602. if (/^<pre\b[^>]*>\s*<code\b[^>]*>/.test(grafsOutIt)) {
  3603. codeFlag = true;
  3604. }
  3605. }
  3606. grafsOut[i] = grafsOutIt;
  3607. }
  3608. text = grafsOut.join('\n');
  3609. // Strip leading and trailing lines:
  3610. text = text.replace(/^\n+/g, '');
  3611. text = text.replace(/\n+$/g, '');
  3612. return globals.converter._dispatch('makehtml.paragraphs.after', text, options, globals).getText();
  3613. });
  3614. /**
  3615. * Run extension
  3616. */
  3617. showdown.subParser('makehtml.runExtension', function (ext, text, options, globals) {
  3618. 'use strict';
  3619. if (ext.filter) {
  3620. text = ext.filter(text, globals.converter, options);
  3621. } else if (ext.regex) {
  3622. // TODO remove this when old extension loading mechanism is deprecated
  3623. var re = ext.regex;
  3624. if (!(re instanceof RegExp)) {
  3625. re = new RegExp(re, 'g');
  3626. }
  3627. text = text.replace(re, ext.replace);
  3628. }
  3629. return text;
  3630. });
  3631. /**
  3632. * These are all the transformations that occur *within* block-level
  3633. * tags like paragraphs, headers, and list items.
  3634. */
  3635. showdown.subParser('makehtml.spanGamut', function (text, options, globals) {
  3636. 'use strict';
  3637. text = globals.converter._dispatch('makehtml.span.before', text, options, globals).getText();
  3638. text = showdown.subParser('makehtml.codeSpans')(text, options, globals);
  3639. text = showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes')(text, options, globals);
  3640. text = showdown.subParser('makehtml.encodeBackslashEscapes')(text, options, globals);
  3641. // Process link and image tags. Images must come first,
  3642. // because ![foo][f] looks like a link.
  3643. text = showdown.subParser('makehtml.images')(text, options, globals);
  3644. text = globals.converter._dispatch('smakehtml.links.before', text, options, globals).getText();
  3645. text = showdown.subParser('makehtml.links')(text, options, globals);
  3646. text = globals.converter._dispatch('smakehtml.links.after', text, options, globals).getText();
  3647. //text = showdown.subParser('makehtml.autoLinks')(text, options, globals);
  3648. //text = showdown.subParser('makehtml.simplifiedAutoLinks')(text, options, globals);
  3649. text = showdown.subParser('makehtml.emoji')(text, options, globals);
  3650. text = showdown.subParser('makehtml.underline')(text, options, globals);
  3651. text = showdown.subParser('makehtml.italicsAndBold')(text, options, globals);
  3652. text = showdown.subParser('makehtml.strikethrough')(text, options, globals);
  3653. text = showdown.subParser('makehtml.ellipsis')(text, options, globals);
  3654. // we need to hash HTML tags inside spans
  3655. text = showdown.subParser('makehtml.hashHTMLSpans')(text, options, globals);
  3656. // now we encode amps and angles
  3657. text = showdown.subParser('makehtml.encodeAmpsAndAngles')(text, options, globals);
  3658. // Do hard breaks
  3659. if (options.simpleLineBreaks) {
  3660. // GFM style hard breaks
  3661. // only add line breaks if the text does not contain a block (special case for lists)
  3662. if (!/\n\n¨K/.test(text)) {
  3663. text = text.replace(/\n+/g, '<br />\n');
  3664. }
  3665. } else {
  3666. // Vanilla hard breaks
  3667. text = text.replace(/ +\n/g, '<br />\n');
  3668. }
  3669. text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals).getText();
  3670. return text;
  3671. });
  3672. showdown.subParser('makehtml.strikethrough', function (text, options, globals) {
  3673. 'use strict';
  3674. if (options.strikethrough) {
  3675. text = globals.converter._dispatch('makehtml.strikethrough.before', text, options, globals).getText();
  3676. text = text.replace(/(?:~){2}([\s\S]+?)(?:~){2}/g, function (wm, txt) { return '<del>' + txt + '</del>'; });
  3677. text = globals.converter._dispatch('makehtml.strikethrough.after', text, options, globals).getText();
  3678. }
  3679. return text;
  3680. });
  3681. /**
  3682. * Strips link definitions from text, stores the URLs and titles in
  3683. * hash references.
  3684. * Link defs are in the form: ^[id]: url "optional title"
  3685. */
  3686. showdown.subParser('makehtml.stripLinkDefinitions', function (text, options, globals) {
  3687. 'use strict';
  3688. var regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?([^>\s]+)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=¨0))/gm,
  3689. base64Regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(data:.+?\/.+?;base64,[A-Za-z0-9+/=\n]+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n\n|(?=¨0)|(?=\n\[))/gm;
  3690. // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
  3691. text += '¨0';
  3692. var replaceFunc = function (wholeMatch, linkId, url, width, height, blankLines, title) {
  3693. linkId = linkId.toLowerCase();
  3694. if (url.match(/^data:.+?\/.+?;base64,/)) {
  3695. // remove newlines
  3696. globals.gUrls[linkId] = url.replace(/\s/g, '');
  3697. } else {
  3698. globals.gUrls[linkId] = showdown.subParser('makehtml.encodeAmpsAndAngles')(url, options, globals); // Link IDs are case-insensitive
  3699. }
  3700. if (blankLines) {
  3701. // Oops, found blank lines, so it's not a title.
  3702. // Put back the parenthetical statement we stole.
  3703. return blankLines + title;
  3704. } else {
  3705. if (title) {
  3706. globals.gTitles[linkId] = title.replace(/"|'/g, '&quot;');
  3707. }
  3708. if (options.parseImgDimensions && width && height) {
  3709. globals.gDimensions[linkId] = {
  3710. width: width,
  3711. height: height
  3712. };
  3713. }
  3714. }
  3715. // Completely remove the definition from the text
  3716. return '';
  3717. };
  3718. // first we try to find base64 link references
  3719. text = text.replace(base64Regex, replaceFunc);
  3720. text = text.replace(regex, replaceFunc);
  3721. // attacklab: strip sentinel
  3722. text = text.replace(/¨0/, '');
  3723. return text;
  3724. });
  3725. showdown.subParser('makehtml.tables', function (text, options, globals) {
  3726. 'use strict';
  3727. if (!options.tables) {
  3728. return text;
  3729. }
  3730. var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|¨0)/gm,
  3731. //singeColTblRgx = /^ {0,3}\|.+\|\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n(?: {0,3}\|.+\|\n)+(?:\n\n|¨0)/gm;
  3732. singeColTblRgx = /^ {0,3}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|¨0)/gm;
  3733. function parseStyles (sLine) {
  3734. if (/^:[ \t]*--*$/.test(sLine)) {
  3735. return ' style="text-align:left;"';
  3736. } else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) {
  3737. return ' style="text-align:right;"';
  3738. } else if (/^:[ \t]*--*[ \t]*:$/.test(sLine)) {
  3739. return ' style="text-align:center;"';
  3740. } else {
  3741. return '';
  3742. }
  3743. }
  3744. function parseHeaders (header, style) {
  3745. var id = '';
  3746. header = header.trim();
  3747. // support both tablesHeaderId and tableHeaderId due to error in documentation so we don't break backwards compatibility
  3748. if (options.tablesHeaderId || options.tableHeaderId) {
  3749. id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
  3750. }
  3751. header = showdown.subParser('makehtml.spanGamut')(header, options, globals);
  3752. return '<th' + id + style + '>' + header + '</th>\n';
  3753. }
  3754. function parseCells (cell, style) {
  3755. var subText = showdown.subParser('makehtml.spanGamut')(cell, options, globals);
  3756. return '<td' + style + '>' + subText + '</td>\n';
  3757. }
  3758. function buildTable (headers, cells) {
  3759. var tb = '<table>\n<thead>\n<tr>\n',
  3760. tblLgn = headers.length;
  3761. for (var i = 0; i < tblLgn; ++i) {
  3762. tb += headers[i];
  3763. }
  3764. tb += '</tr>\n</thead>\n<tbody>\n';
  3765. for (i = 0; i < cells.length; ++i) {
  3766. tb += '<tr>\n';
  3767. for (var ii = 0; ii < tblLgn; ++ii) {
  3768. tb += cells[i][ii];
  3769. }
  3770. tb += '</tr>\n';
  3771. }
  3772. tb += '</tbody>\n</table>\n';
  3773. return tb;
  3774. }
  3775. function parseTable (rawTable) {
  3776. var i, tableLines = rawTable.split('\n');
  3777. for (i = 0; i < tableLines.length; ++i) {
  3778. // strip wrong first and last column if wrapped tables are used
  3779. if (/^ {0,3}\|/.test(tableLines[i])) {
  3780. tableLines[i] = tableLines[i].replace(/^ {0,3}\|/, '');
  3781. }
  3782. if (/\|[ \t]*$/.test(tableLines[i])) {
  3783. tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
  3784. }
  3785. // parse code spans first, but we only support one line code spans
  3786. tableLines[i] = showdown.subParser('makehtml.codeSpans')(tableLines[i], options, globals);
  3787. }
  3788. var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}),
  3789. rawStyles = tableLines[1].split('|').map(function (s) { return s.trim();}),
  3790. rawCells = [],
  3791. headers = [],
  3792. styles = [],
  3793. cells = [];
  3794. tableLines.shift();
  3795. tableLines.shift();
  3796. for (i = 0; i < tableLines.length; ++i) {
  3797. if (tableLines[i].trim() === '') {
  3798. continue;
  3799. }
  3800. rawCells.push(
  3801. tableLines[i]
  3802. .split('|')
  3803. .map(function (s) {
  3804. return s.trim();
  3805. })
  3806. );
  3807. }
  3808. if (rawHeaders.length < rawStyles.length) {
  3809. return rawTable;
  3810. }
  3811. for (i = 0; i < rawStyles.length; ++i) {
  3812. styles.push(parseStyles(rawStyles[i]));
  3813. }
  3814. for (i = 0; i < rawHeaders.length; ++i) {
  3815. if (showdown.helper.isUndefined(styles[i])) {
  3816. styles[i] = '';
  3817. }
  3818. headers.push(parseHeaders(rawHeaders[i], styles[i]));
  3819. }
  3820. for (i = 0; i < rawCells.length; ++i) {
  3821. var row = [];
  3822. for (var ii = 0; ii < headers.length; ++ii) {
  3823. if (showdown.helper.isUndefined(rawCells[i][ii])) {
  3824. }
  3825. row.push(parseCells(rawCells[i][ii], styles[ii]));
  3826. }
  3827. cells.push(row);
  3828. }
  3829. return buildTable(headers, cells);
  3830. }
  3831. text = globals.converter._dispatch('makehtml.tables.before', text, options, globals).getText();
  3832. // find escaped pipe characters
  3833. text = text.replace(/\\(\|)/g, showdown.helper.escapeCharactersCallback);
  3834. // parse multi column tables
  3835. text = text.replace(tableRgx, parseTable);
  3836. // parse one column tables
  3837. text = text.replace(singeColTblRgx, parseTable);
  3838. text = globals.converter._dispatch('makehtml.tables.after', text, options, globals).getText();
  3839. return text;
  3840. });
  3841. showdown.subParser('makehtml.underline', function (text, options, globals) {
  3842. 'use strict';
  3843. if (!options.underline) {
  3844. return text;
  3845. }
  3846. text = globals.converter._dispatch('makehtml.underline.before', text, options, globals).getText();
  3847. if (options.literalMidWordUnderscores) {
  3848. text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) {
  3849. return '<u>' + txt + '</u>';
  3850. });
  3851. text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) {
  3852. return '<u>' + txt + '</u>';
  3853. });
  3854. } else {
  3855. text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) {
  3856. return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm;
  3857. });
  3858. text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
  3859. return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm;
  3860. });
  3861. }
  3862. // escape remaining underscores to prevent them being parsed by italic and bold
  3863. text = text.replace(/(_)/g, showdown.helper.escapeCharactersCallback);
  3864. text = globals.converter._dispatch('makehtml.underline.after', text, options, globals).getText();
  3865. return text;
  3866. });
  3867. /**
  3868. * Swap back in all the special characters we've hidden.
  3869. */
  3870. showdown.subParser('makehtml.unescapeSpecialChars', function (text, options, globals) {
  3871. 'use strict';
  3872. text = globals.converter._dispatch('makehtml.unescapeSpecialChars.before', text, options, globals).getText();
  3873. text = text.replace(/¨E(\d+)E/g, function (wholeMatch, m1) {
  3874. var charCodeToReplace = parseInt(m1);
  3875. return String.fromCharCode(charCodeToReplace);
  3876. });
  3877. text = globals.converter._dispatch('makehtml.unescapeSpecialChars.after', text, options, globals).getText();
  3878. return text;
  3879. });
  3880. showdown.subParser('makeMarkdown.blockquote', function (node, globals) {
  3881. 'use strict';
  3882. var txt = '';
  3883. if (node.hasChildNodes()) {
  3884. var children = node.childNodes,
  3885. childrenLength = children.length;
  3886. for (var i = 0; i < childrenLength; ++i) {
  3887. var innerTxt = showdown.subParser('makeMarkdown.node')(children[i], globals);
  3888. if (innerTxt === '') {
  3889. continue;
  3890. }
  3891. txt += innerTxt;
  3892. }
  3893. }
  3894. // cleanup
  3895. txt = txt.trim();
  3896. txt = '> ' + txt.split('\n').join('\n> ');
  3897. return txt;
  3898. });
  3899. showdown.subParser('makeMarkdown.codeBlock', function (node, globals) {
  3900. 'use strict';
  3901. var lang = node.getAttribute('language'),
  3902. num = node.getAttribute('precodenum');
  3903. return '```' + lang + '\n' + globals.preList[num] + '\n```';
  3904. });
  3905. showdown.subParser('makeMarkdown.codeSpan', function (node) {
  3906. 'use strict';
  3907. return '`' + node.innerHTML + '`';
  3908. });
  3909. showdown.subParser('makeMarkdown.emphasis', function (node, globals) {
  3910. 'use strict';
  3911. var txt = '';
  3912. if (node.hasChildNodes()) {
  3913. txt += '*';
  3914. var children = node.childNodes,
  3915. childrenLength = children.length;
  3916. for (var i = 0; i < childrenLength; ++i) {
  3917. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  3918. }
  3919. txt += '*';
  3920. }
  3921. return txt;
  3922. });
  3923. showdown.subParser('makeMarkdown.header', function (node, globals, headerLevel) {
  3924. 'use strict';
  3925. var headerMark = new Array(headerLevel + 1).join('#'),
  3926. txt = '';
  3927. if (node.hasChildNodes()) {
  3928. txt = headerMark + ' ';
  3929. var children = node.childNodes,
  3930. childrenLength = children.length;
  3931. for (var i = 0; i < childrenLength; ++i) {
  3932. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  3933. }
  3934. }
  3935. return txt;
  3936. });
  3937. showdown.subParser('makeMarkdown.hr', function () {
  3938. 'use strict';
  3939. return '---';
  3940. });
  3941. showdown.subParser('makeMarkdown.image', function (node) {
  3942. 'use strict';
  3943. var txt = '';
  3944. if (node.hasAttribute('src')) {
  3945. txt += '![' + node.getAttribute('alt') + '](';
  3946. txt += '<' + node.getAttribute('src') + '>';
  3947. if (node.hasAttribute('width') && node.hasAttribute('height')) {
  3948. txt += ' =' + node.getAttribute('width') + 'x' + node.getAttribute('height');
  3949. }
  3950. if (node.hasAttribute('title')) {
  3951. txt += ' "' + node.getAttribute('title') + '"';
  3952. }
  3953. txt += ')';
  3954. }
  3955. return txt;
  3956. });
  3957. showdown.subParser('makeMarkdown.links', function (node, globals) {
  3958. 'use strict';
  3959. var txt = '';
  3960. if (node.hasChildNodes() && node.hasAttribute('href')) {
  3961. var children = node.childNodes,
  3962. childrenLength = children.length;
  3963. txt = '[';
  3964. for (var i = 0; i < childrenLength; ++i) {
  3965. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  3966. }
  3967. txt += '](';
  3968. txt += '<' + node.getAttribute('href') + '>';
  3969. if (node.hasAttribute('title')) {
  3970. txt += ' "' + node.getAttribute('title') + '"';
  3971. }
  3972. txt += ')';
  3973. }
  3974. return txt;
  3975. });
  3976. showdown.subParser('makeMarkdown.list', function (node, globals, type) {
  3977. 'use strict';
  3978. var txt = '';
  3979. if (!node.hasChildNodes()) {
  3980. return '';
  3981. }
  3982. var listItems = node.childNodes,
  3983. listItemsLenght = listItems.length,
  3984. listNum = node.getAttribute('start') || 1;
  3985. for (var i = 0; i < listItemsLenght; ++i) {
  3986. if (typeof listItems[i].tagName === 'undefined' || listItems[i].tagName.toLowerCase() !== 'li') {
  3987. continue;
  3988. }
  3989. // define the bullet to use in list
  3990. var bullet = '';
  3991. if (type === 'ol') {
  3992. bullet = listNum.toString() + '. ';
  3993. } else {
  3994. bullet = '- ';
  3995. }
  3996. // parse list item
  3997. txt += bullet + showdown.subParser('makeMarkdown.listItem')(listItems[i], globals);
  3998. ++listNum;
  3999. }
  4000. return txt.trim();
  4001. });
  4002. showdown.subParser('makeMarkdown.listItem', function (node, globals) {
  4003. 'use strict';
  4004. var listItemTxt = '';
  4005. var children = node.childNodes,
  4006. childrenLenght = children.length;
  4007. for (var i = 0; i < childrenLenght; ++i) {
  4008. listItemTxt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4009. }
  4010. // if it's only one liner, we need to add a newline at the end
  4011. if (!/\n$/.test(listItemTxt)) {
  4012. listItemTxt += '\n';
  4013. } else {
  4014. // it's multiparagraph, so we need to indent
  4015. listItemTxt = listItemTxt
  4016. .split('\n')
  4017. .join('\n ')
  4018. .replace(/^ {4}$/gm, '')
  4019. .replace(/\n\n+/g, '\n\n');
  4020. }
  4021. return listItemTxt;
  4022. });
  4023. showdown.subParser('makeMarkdown.node', function (node, globals, spansOnly) {
  4024. 'use strict';
  4025. spansOnly = spansOnly || false;
  4026. var txt = '';
  4027. // edge case of text without wrapper paragraph
  4028. if (node.nodeType === 3) {
  4029. return showdown.subParser('makeMarkdown.txt')(node, globals);
  4030. }
  4031. // HTML comment
  4032. if (node.nodeType === 8) {
  4033. return '<!--' + node.data + '-->\n\n';
  4034. }
  4035. // process only node elements
  4036. if (node.nodeType !== 1) {
  4037. return '';
  4038. }
  4039. var tagName = node.tagName.toLowerCase();
  4040. switch (tagName) {
  4041. //
  4042. // BLOCKS
  4043. //
  4044. case 'h1':
  4045. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 1) + '\n\n'; }
  4046. break;
  4047. case 'h2':
  4048. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 2) + '\n\n'; }
  4049. break;
  4050. case 'h3':
  4051. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 3) + '\n\n'; }
  4052. break;
  4053. case 'h4':
  4054. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 4) + '\n\n'; }
  4055. break;
  4056. case 'h5':
  4057. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 5) + '\n\n'; }
  4058. break;
  4059. case 'h6':
  4060. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 6) + '\n\n'; }
  4061. break;
  4062. case 'p':
  4063. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.paragraph')(node, globals) + '\n\n'; }
  4064. break;
  4065. case 'blockquote':
  4066. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.blockquote')(node, globals) + '\n\n'; }
  4067. break;
  4068. case 'hr':
  4069. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.hr')(node, globals) + '\n\n'; }
  4070. break;
  4071. case 'ol':
  4072. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.list')(node, globals, 'ol') + '\n\n'; }
  4073. break;
  4074. case 'ul':
  4075. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.list')(node, globals, 'ul') + '\n\n'; }
  4076. break;
  4077. case 'precode':
  4078. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.codeBlock')(node, globals) + '\n\n'; }
  4079. break;
  4080. case 'pre':
  4081. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.pre')(node, globals) + '\n\n'; }
  4082. break;
  4083. case 'table':
  4084. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.table')(node, globals) + '\n\n'; }
  4085. break;
  4086. //
  4087. // SPANS
  4088. //
  4089. case 'code':
  4090. txt = showdown.subParser('makeMarkdown.codeSpan')(node, globals);
  4091. break;
  4092. case 'em':
  4093. case 'i':
  4094. txt = showdown.subParser('makeMarkdown.emphasis')(node, globals);
  4095. break;
  4096. case 'strong':
  4097. case 'b':
  4098. txt = showdown.subParser('makeMarkdown.strong')(node, globals);
  4099. break;
  4100. case 'del':
  4101. txt = showdown.subParser('makeMarkdown.strikethrough')(node, globals);
  4102. break;
  4103. case 'a':
  4104. txt = showdown.subParser('makeMarkdown.links')(node, globals);
  4105. break;
  4106. case 'img':
  4107. txt = showdown.subParser('makeMarkdown.image')(node, globals);
  4108. break;
  4109. default:
  4110. txt = node.outerHTML + '\n\n';
  4111. }
  4112. // common normalization
  4113. // TODO eventually
  4114. return txt;
  4115. });
  4116. showdown.subParser('makeMarkdown.paragraph', function (node, globals) {
  4117. 'use strict';
  4118. var txt = '';
  4119. if (node.hasChildNodes()) {
  4120. var children = node.childNodes,
  4121. childrenLength = children.length;
  4122. for (var i = 0; i < childrenLength; ++i) {
  4123. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4124. }
  4125. }
  4126. // some text normalization
  4127. txt = txt.trim();
  4128. return txt;
  4129. });
  4130. showdown.subParser('makeMarkdown.pre', function (node, globals) {
  4131. 'use strict';
  4132. var num = node.getAttribute('prenum');
  4133. return '<pre>' + globals.preList[num] + '</pre>';
  4134. });
  4135. showdown.subParser('makeMarkdown.strikethrough', function (node, globals) {
  4136. 'use strict';
  4137. var txt = '';
  4138. if (node.hasChildNodes()) {
  4139. txt += '~~';
  4140. var children = node.childNodes,
  4141. childrenLength = children.length;
  4142. for (var i = 0; i < childrenLength; ++i) {
  4143. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4144. }
  4145. txt += '~~';
  4146. }
  4147. return txt;
  4148. });
  4149. showdown.subParser('makeMarkdown.strong', function (node, globals) {
  4150. 'use strict';
  4151. var txt = '';
  4152. if (node.hasChildNodes()) {
  4153. txt += '**';
  4154. var children = node.childNodes,
  4155. childrenLength = children.length;
  4156. for (var i = 0; i < childrenLength; ++i) {
  4157. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4158. }
  4159. txt += '**';
  4160. }
  4161. return txt;
  4162. });
  4163. showdown.subParser('makeMarkdown.table', function (node, globals) {
  4164. 'use strict';
  4165. var txt = '',
  4166. tableArray = [[], []],
  4167. headings = node.querySelectorAll('thead>tr>th'),
  4168. rows = node.querySelectorAll('tbody>tr'),
  4169. i, ii;
  4170. for (i = 0; i < headings.length; ++i) {
  4171. var headContent = showdown.subParser('makeMarkdown.tableCell')(headings[i], globals),
  4172. allign = '---';
  4173. if (headings[i].hasAttribute('style')) {
  4174. var style = headings[i].getAttribute('style').toLowerCase().replace(/\s/g, '');
  4175. switch (style) {
  4176. case 'text-align:left;':
  4177. allign = ':---';
  4178. break;
  4179. case 'text-align:right;':
  4180. allign = '---:';
  4181. break;
  4182. case 'text-align:center;':
  4183. allign = ':---:';
  4184. break;
  4185. }
  4186. }
  4187. tableArray[0][i] = headContent.trim();
  4188. tableArray[1][i] = allign;
  4189. }
  4190. for (i = 0; i < rows.length; ++i) {
  4191. var r = tableArray.push([]) - 1,
  4192. cols = rows[i].getElementsByTagName('td');
  4193. for (ii = 0; ii < headings.length; ++ii) {
  4194. var cellContent = ' ';
  4195. if (typeof cols[ii] !== 'undefined') {
  4196. cellContent = showdown.subParser('makeMarkdown.tableCell')(cols[ii], globals);
  4197. }
  4198. tableArray[r].push(cellContent);
  4199. }
  4200. }
  4201. var cellSpacesCount = 3;
  4202. for (i = 0; i < tableArray.length; ++i) {
  4203. for (ii = 0; ii < tableArray[i].length; ++ii) {
  4204. var strLen = tableArray[i][ii].length;
  4205. if (strLen > cellSpacesCount) {
  4206. cellSpacesCount = strLen;
  4207. }
  4208. }
  4209. }
  4210. for (i = 0; i < tableArray.length; ++i) {
  4211. for (ii = 0; ii < tableArray[i].length; ++ii) {
  4212. if (i === 1) {
  4213. if (tableArray[i][ii].slice(-1) === ':') {
  4214. tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii].slice(-1), cellSpacesCount - 1, '-') + ':';
  4215. } else {
  4216. tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii], cellSpacesCount, '-');
  4217. }
  4218. } else {
  4219. tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii], cellSpacesCount);
  4220. }
  4221. }
  4222. txt += '| ' + tableArray[i].join(' | ') + ' |\n';
  4223. }
  4224. return txt.trim();
  4225. });
  4226. showdown.subParser('makeMarkdown.tableCell', function (node, globals) {
  4227. 'use strict';
  4228. var txt = '';
  4229. if (!node.hasChildNodes()) {
  4230. return '';
  4231. }
  4232. var children = node.childNodes,
  4233. childrenLength = children.length;
  4234. for (var i = 0; i < childrenLength; ++i) {
  4235. txt += showdown.subParser('makeMarkdown.node')(children[i], globals, true);
  4236. }
  4237. return txt.trim();
  4238. });
  4239. showdown.subParser('makeMarkdown.txt', function (node) {
  4240. 'use strict';
  4241. var txt = node.nodeValue;
  4242. // multiple spaces are collapsed
  4243. txt = txt.replace(/ +/g, ' ');
  4244. // replace the custom ¨NBSP; with a space
  4245. txt = txt.replace(/¨NBSP;/g, ' ');
  4246. // ", <, > and & should replace escaped html entities
  4247. txt = showdown.helper.unescapeHTMLEntities(txt);
  4248. // escape markdown magic characters
  4249. // emphasis, strong and strikethrough - can appear everywhere
  4250. // we also escape pipe (|) because of tables
  4251. // and escape ` because of code blocks and spans
  4252. txt = txt.replace(/([*_~|`])/g, '\\$1');
  4253. // escape > because of blockquotes
  4254. txt = txt.replace(/^(\s*)>/g, '\\$1>');
  4255. // hash character, only troublesome at the beginning of a line because of headers
  4256. txt = txt.replace(/^#/gm, '\\#');
  4257. // horizontal rules
  4258. txt = txt.replace(/^(\s*)([-=]{3,})(\s*)$/, '$1\\$2$3');
  4259. // dot, because of ordered lists, only troublesome at the beginning of a line when preceded by an integer
  4260. txt = txt.replace(/^( {0,3}\d+)\./gm, '$1\\.');
  4261. // +, * and -, at the beginning of a line becomes a list, so we need to escape them also (asterisk was already escaped)
  4262. txt = txt.replace(/^( {0,3})([+-])/gm, '$1\\$2');
  4263. // images and links, ] followed by ( is problematic, so we escape it
  4264. txt = txt.replace(/]([\s]*)\(/g, '\\]$1\\(');
  4265. // reference URIs must also be escaped
  4266. txt = txt.replace(/^ {0,3}\[([\S \t]*?)]:/gm, '\\[$1]:');
  4267. return txt;
  4268. });
  4269. /**
  4270. * Created by Estevao on 31-05-2015.
  4271. */
  4272. /**
  4273. * Showdown Converter class
  4274. * @class
  4275. * @param {object} [converterOptions]
  4276. * @returns {Converter}
  4277. */
  4278. showdown.Converter = function (converterOptions) {
  4279. 'use strict';
  4280. var
  4281. /**
  4282. * Options used by this converter
  4283. * @private
  4284. * @type {{}}
  4285. */
  4286. options = {},
  4287. /**
  4288. * Language extensions used by this converter
  4289. * @private
  4290. * @type {Array}
  4291. */
  4292. langExtensions = [],
  4293. /**
  4294. * Output modifiers extensions used by this converter
  4295. * @private
  4296. * @type {Array}
  4297. */
  4298. outputModifiers = [],
  4299. /**
  4300. * Event listeners
  4301. * @private
  4302. * @type {{}}
  4303. */
  4304. listeners = {},
  4305. /**
  4306. * The flavor set in this converter
  4307. */
  4308. setConvFlavor = setFlavor,
  4309. /**
  4310. * Metadata of the document
  4311. * @type {{parsed: {}, raw: string, format: string}}
  4312. */
  4313. metadata = {
  4314. parsed: {},
  4315. raw: '',
  4316. format: ''
  4317. };
  4318. _constructor();
  4319. /**
  4320. * Converter constructor
  4321. * @private
  4322. */
  4323. function _constructor () {
  4324. converterOptions = converterOptions || {};
  4325. for (var gOpt in globalOptions) {
  4326. if (globalOptions.hasOwnProperty(gOpt)) {
  4327. options[gOpt] = globalOptions[gOpt];
  4328. }
  4329. }
  4330. // Merge options
  4331. if (typeof converterOptions === 'object') {
  4332. for (var opt in converterOptions) {
  4333. if (converterOptions.hasOwnProperty(opt)) {
  4334. options[opt] = converterOptions[opt];
  4335. }
  4336. }
  4337. } else {
  4338. throw Error('Converter expects the passed parameter to be an object, but ' + typeof converterOptions +
  4339. ' was passed instead.');
  4340. }
  4341. if (options.extensions) {
  4342. showdown.helper.forEach(options.extensions, _parseExtension);
  4343. }
  4344. }
  4345. /**
  4346. * Parse extension
  4347. * @param {*} ext
  4348. * @param {string} [name='']
  4349. * @private
  4350. */
  4351. function _parseExtension (ext, name) {
  4352. name = name || null;
  4353. // If it's a string, the extension was previously loaded
  4354. if (showdown.helper.isString(ext)) {
  4355. ext = showdown.helper.stdExtName(ext);
  4356. name = ext;
  4357. // LEGACY_SUPPORT CODE
  4358. if (showdown.extensions[ext]) {
  4359. console.warn('DEPRECATION WARNING: ' + ext + ' is an old extension that uses a deprecated loading method.' +
  4360. 'Please inform the developer that the extension should be updated!');
  4361. legacyExtensionLoading(showdown.extensions[ext], ext);
  4362. return;
  4363. // END LEGACY SUPPORT CODE
  4364. } else if (!showdown.helper.isUndefined(extensions[ext])) {
  4365. ext = extensions[ext];
  4366. } else {
  4367. throw Error('Extension "' + ext + '" could not be loaded. It was either not found or is not a valid extension.');
  4368. }
  4369. }
  4370. if (typeof ext === 'function') {
  4371. ext = ext();
  4372. }
  4373. if (!showdown.helper.isArray(ext)) {
  4374. ext = [ext];
  4375. }
  4376. var validExt = validate(ext, name);
  4377. if (!validExt.valid) {
  4378. throw Error(validExt.error);
  4379. }
  4380. for (var i = 0; i < ext.length; ++i) {
  4381. switch (ext[i].type) {
  4382. case 'lang':
  4383. langExtensions.push(ext[i]);
  4384. break;
  4385. case 'output':
  4386. outputModifiers.push(ext[i]);
  4387. break;
  4388. }
  4389. if (ext[i].hasOwnProperty('listeners')) {
  4390. for (var ln in ext[i].listeners) {
  4391. if (ext[i].listeners.hasOwnProperty(ln)) {
  4392. listen(ln, ext[i].listeners[ln]);
  4393. }
  4394. }
  4395. }
  4396. }
  4397. }
  4398. /**
  4399. * LEGACY_SUPPORT
  4400. * @param {*} ext
  4401. * @param {string} name
  4402. */
  4403. function legacyExtensionLoading (ext, name) {
  4404. if (typeof ext === 'function') {
  4405. ext = ext(new showdown.Converter());
  4406. }
  4407. if (!showdown.helper.isArray(ext)) {
  4408. ext = [ext];
  4409. }
  4410. var valid = validate(ext, name);
  4411. if (!valid.valid) {
  4412. throw Error(valid.error);
  4413. }
  4414. for (var i = 0; i < ext.length; ++i) {
  4415. switch (ext[i].type) {
  4416. case 'lang':
  4417. langExtensions.push(ext[i]);
  4418. break;
  4419. case 'output':
  4420. outputModifiers.push(ext[i]);
  4421. break;
  4422. default:// should never reach here
  4423. throw Error('Extension loader error: Type unrecognized!!!');
  4424. }
  4425. }
  4426. }
  4427. /**
  4428. * Listen to an event
  4429. * @param {string} name
  4430. * @param {function} callback
  4431. */
  4432. function listen (name, callback) {
  4433. if (!showdown.helper.isString(name)) {
  4434. throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given');
  4435. }
  4436. if (typeof callback !== 'function') {
  4437. throw Error('Invalid argument in converter.listen() method: callback must be a function, but ' + typeof callback + ' given');
  4438. }
  4439. name = name.toLowerCase();
  4440. if (!listeners.hasOwnProperty(name)) {
  4441. listeners[name] = [];
  4442. }
  4443. listeners[name].push(callback);
  4444. }
  4445. function rTrimInputText (text) {
  4446. var rsp = text.match(/^\s*/)[0].length,
  4447. rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
  4448. return text.replace(rgx, '');
  4449. }
  4450. /**
  4451. *
  4452. * @param {string} evtName Event name
  4453. * @param {string} text Text
  4454. * @param {{}} options Converter Options
  4455. * @param {{}} globals Converter globals
  4456. * @param {{}} pParams extra params for event
  4457. * @returns showdown.helper.Event
  4458. * @private
  4459. */
  4460. this._dispatch = function dispatch (evtName, text, options, globals, pParams) {
  4461. evtName = evtName.toLowerCase();
  4462. var params = pParams || {};
  4463. params.converter = this;
  4464. params.text = text;
  4465. params.options = options;
  4466. params.globals = globals;
  4467. var event = new showdown.helper.Event(evtName, text, params);
  4468. if (listeners.hasOwnProperty(evtName)) {
  4469. for (var ei = 0; ei < listeners[evtName].length; ++ei) {
  4470. var nText = listeners[evtName][ei](event);
  4471. if (nText && typeof nText !== 'undefined') {
  4472. event.setText(nText);
  4473. }
  4474. }
  4475. }
  4476. return event;
  4477. };
  4478. /**
  4479. * Listen to an event
  4480. * @param {string} name
  4481. * @param {function} callback
  4482. * @returns {showdown.Converter}
  4483. */
  4484. this.listen = function (name, callback) {
  4485. listen(name, callback);
  4486. return this;
  4487. };
  4488. /**
  4489. * Converts a markdown string into HTML string
  4490. * @param {string} text
  4491. * @returns {*}
  4492. */
  4493. this.makeHtml = function (text) {
  4494. //check if text is not falsy
  4495. if (!text) {
  4496. return text;
  4497. }
  4498. var globals = {
  4499. gHtmlBlocks: [],
  4500. gHtmlMdBlocks: [],
  4501. gHtmlSpans: [],
  4502. gUrls: {},
  4503. gTitles: {},
  4504. gDimensions: {},
  4505. gListLevel: 0,
  4506. hashLinkCounts: {},
  4507. langExtensions: langExtensions,
  4508. outputModifiers: outputModifiers,
  4509. converter: this,
  4510. ghCodeBlocks: [],
  4511. metadata: {
  4512. parsed: {},
  4513. raw: '',
  4514. format: ''
  4515. }
  4516. };
  4517. // This lets us use ¨ trema as an escape char to avoid md5 hashes
  4518. // The choice of character is arbitrary; anything that isn't
  4519. // magic in Markdown will work.
  4520. text = text.replace(/¨/g, '¨T');
  4521. // Replace $ with ¨D
  4522. // RegExp interprets $ as a special character
  4523. // when it's in a replacement string
  4524. text = text.replace(/\$/g, '¨D');
  4525. // Standardize line endings
  4526. text = text.replace(/\r\n/g, '\n'); // DOS to Unix
  4527. text = text.replace(/\r/g, '\n'); // Mac to Unix
  4528. // Stardardize line spaces
  4529. text = text.replace(/\u00A0/g, '&nbsp;');
  4530. if (options.smartIndentationFix) {
  4531. text = rTrimInputText(text);
  4532. }
  4533. // Make sure text begins and ends with a couple of newlines:
  4534. text = '\n\n' + text + '\n\n';
  4535. // detab
  4536. text = showdown.subParser('makehtml.detab')(text, options, globals);
  4537. /**
  4538. * Strip any lines consisting only of spaces and tabs.
  4539. * This makes subsequent regexs easier to write, because we can
  4540. * match consecutive blank lines with /\n+/ instead of something
  4541. * contorted like /[ \t]*\n+/
  4542. */
  4543. text = text.replace(/^[ \t]+$/mg, '');
  4544. //run languageExtensions
  4545. showdown.helper.forEach(langExtensions, function (ext) {
  4546. text = showdown.subParser('makehtml.runExtension')(ext, text, options, globals);
  4547. });
  4548. // run the sub parsers
  4549. text = showdown.subParser('makehtml.metadata')(text, options, globals);
  4550. text = showdown.subParser('makehtml.hashPreCodeTags')(text, options, globals);
  4551. text = showdown.subParser('makehtml.githubCodeBlocks')(text, options, globals);
  4552. text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals);
  4553. text = showdown.subParser('makehtml.hashCodeTags')(text, options, globals);
  4554. text = showdown.subParser('makehtml.stripLinkDefinitions')(text, options, globals);
  4555. text = showdown.subParser('makehtml.blockGamut')(text, options, globals);
  4556. text = showdown.subParser('makehtml.unhashHTMLSpans')(text, options, globals);
  4557. text = showdown.subParser('makehtml.unescapeSpecialChars')(text, options, globals);
  4558. // attacklab: Restore dollar signs
  4559. text = text.replace(/¨D/g, '$$');
  4560. // attacklab: Restore tremas
  4561. text = text.replace(/¨T/g, '¨');
  4562. // render a complete html document instead of a partial if the option is enabled
  4563. text = showdown.subParser('makehtml.completeHTMLDocument')(text, options, globals);
  4564. // Run output modifiers
  4565. showdown.helper.forEach(outputModifiers, function (ext) {
  4566. text = showdown.subParser('makehtml.runExtension')(ext, text, options, globals);
  4567. });
  4568. // update metadata
  4569. metadata = globals.metadata;
  4570. return text;
  4571. };
  4572. /**
  4573. * Converts an HTML string into a markdown string
  4574. * @param src
  4575. * @returns {string}
  4576. */
  4577. this.makeMarkdown = function (src) {
  4578. // replace \r\n with \n
  4579. src = src.replace(/\r\n/g, '\n');
  4580. src = src.replace(/\r/g, '\n'); // old macs
  4581. // due to an edge case, we need to find this: > <
  4582. // to prevent removing of non silent white spaces
  4583. // ex: <em>this is</em> <strong>sparta</strong>
  4584. src = src.replace(/>[ \t]+</, '>¨NBSP;<');
  4585. var doc = showdown.helper.document.createElement('div');
  4586. doc.innerHTML = src;
  4587. var globals = {
  4588. preList: substitutePreCodeTags(doc)
  4589. };
  4590. // remove all newlines and collapse spaces
  4591. clean(doc);
  4592. // some stuff, like accidental reference links must now be escaped
  4593. // TODO
  4594. // doc.innerHTML = doc.innerHTML.replace(/\[[\S\t ]]/);
  4595. var nodes = doc.childNodes,
  4596. mdDoc = '';
  4597. for (var i = 0; i < nodes.length; i++) {
  4598. mdDoc += showdown.subParser('makeMarkdown.node')(nodes[i], globals);
  4599. }
  4600. function clean (node) {
  4601. for (var n = 0; n < node.childNodes.length; ++n) {
  4602. var child = node.childNodes[n];
  4603. if (child.nodeType === 3) {
  4604. if (!/\S/.test(child.nodeValue)) {
  4605. node.removeChild(child);
  4606. --n;
  4607. } else {
  4608. child.nodeValue = child.nodeValue.split('\n').join(' ');
  4609. child.nodeValue = child.nodeValue.replace(/(\s)+/g, '$1');
  4610. }
  4611. } else if (child.nodeType === 1) {
  4612. clean(child);
  4613. }
  4614. }
  4615. }
  4616. // find all pre tags and replace contents with placeholder
  4617. // we need this so that we can remove all indentation from html
  4618. // to ease up parsing
  4619. function substitutePreCodeTags (doc) {
  4620. var pres = doc.querySelectorAll('pre'),
  4621. presPH = [];
  4622. for (var i = 0; i < pres.length; ++i) {
  4623. if (pres[i].childElementCount === 1 && pres[i].firstChild.tagName.toLowerCase() === 'code') {
  4624. var content = pres[i].firstChild.innerHTML.trim(),
  4625. language = pres[i].firstChild.getAttribute('data-language') || '';
  4626. // if data-language attribute is not defined, then we look for class language-*
  4627. if (language === '') {
  4628. var classes = pres[i].firstChild.className.split(' ');
  4629. for (var c = 0; c < classes.length; ++c) {
  4630. var matches = classes[c].match(/^language-(.+)$/);
  4631. if (matches !== null) {
  4632. language = matches[1];
  4633. break;
  4634. }
  4635. }
  4636. }
  4637. // unescape html entities in content
  4638. content = showdown.helper.unescapeHTMLEntities(content);
  4639. presPH.push(content);
  4640. pres[i].outerHTML = '<precode language="' + language + '" precodenum="' + i.toString() + '"></precode>';
  4641. } else {
  4642. presPH.push(pres[i].innerHTML);
  4643. pres[i].innerHTML = '';
  4644. pres[i].setAttribute('prenum', i.toString());
  4645. }
  4646. }
  4647. return presPH;
  4648. }
  4649. return mdDoc;
  4650. };
  4651. /**
  4652. * Set an option of this Converter instance
  4653. * @param {string} key
  4654. * @param {*} value
  4655. */
  4656. this.setOption = function (key, value) {
  4657. options[key] = value;
  4658. };
  4659. /**
  4660. * Get the option of this Converter instance
  4661. * @param {string} key
  4662. * @returns {*}
  4663. */
  4664. this.getOption = function (key) {
  4665. return options[key];
  4666. };
  4667. /**
  4668. * Get the options of this Converter instance
  4669. * @returns {{}}
  4670. */
  4671. this.getOptions = function () {
  4672. return options;
  4673. };
  4674. /**
  4675. * Add extension to THIS converter
  4676. * @param {{}} extension
  4677. * @param {string} [name=null]
  4678. */
  4679. this.addExtension = function (extension, name) {
  4680. name = name || null;
  4681. _parseExtension(extension, name);
  4682. };
  4683. /**
  4684. * Use a global registered extension with THIS converter
  4685. * @param {string} extensionName Name of the previously registered extension
  4686. */
  4687. this.useExtension = function (extensionName) {
  4688. _parseExtension(extensionName);
  4689. };
  4690. /**
  4691. * Set the flavor THIS converter should use
  4692. * @param {string} name
  4693. */
  4694. this.setFlavor = function (name) {
  4695. if (!flavor.hasOwnProperty(name)) {
  4696. throw Error(name + ' flavor was not found');
  4697. }
  4698. var preset = flavor[name];
  4699. setConvFlavor = name;
  4700. for (var option in preset) {
  4701. if (preset.hasOwnProperty(option)) {
  4702. options[option] = preset[option];
  4703. }
  4704. }
  4705. };
  4706. /**
  4707. * Get the currently set flavor of this converter
  4708. * @returns {string}
  4709. */
  4710. this.getFlavor = function () {
  4711. return setConvFlavor;
  4712. };
  4713. /**
  4714. * Remove an extension from THIS converter.
  4715. * Note: This is a costly operation. It's better to initialize a new converter
  4716. * and specify the extensions you wish to use
  4717. * @param {Array} extension
  4718. */
  4719. this.removeExtension = function (extension) {
  4720. if (!showdown.helper.isArray(extension)) {
  4721. extension = [extension];
  4722. }
  4723. for (var a = 0; a < extension.length; ++a) {
  4724. var ext = extension[a];
  4725. for (var i = 0; i < langExtensions.length; ++i) {
  4726. if (langExtensions[i] === ext) {
  4727. langExtensions[i].splice(i, 1);
  4728. }
  4729. }
  4730. for (var ii = 0; ii < outputModifiers.length; ++i) {
  4731. if (outputModifiers[ii] === ext) {
  4732. outputModifiers[ii].splice(i, 1);
  4733. }
  4734. }
  4735. }
  4736. };
  4737. /**
  4738. * Get all extension of THIS converter
  4739. * @returns {{language: Array, output: Array}}
  4740. */
  4741. this.getAllExtensions = function () {
  4742. return {
  4743. language: langExtensions,
  4744. output: outputModifiers
  4745. };
  4746. };
  4747. /**
  4748. * Get the metadata of the previously parsed document
  4749. * @param raw
  4750. * @returns {string|{}}
  4751. */
  4752. this.getMetadata = function (raw) {
  4753. if (raw) {
  4754. return metadata.raw;
  4755. } else {
  4756. return metadata.parsed;
  4757. }
  4758. };
  4759. /**
  4760. * Get the metadata format of the previously parsed document
  4761. * @returns {string}
  4762. */
  4763. this.getMetadataFormat = function () {
  4764. return metadata.format;
  4765. };
  4766. /**
  4767. * Private: set a single key, value metadata pair
  4768. * @param {string} key
  4769. * @param {string} value
  4770. */
  4771. this._setMetadataPair = function (key, value) {
  4772. metadata.parsed[key] = value;
  4773. };
  4774. /**
  4775. * Private: set metadata format
  4776. * @param {string} format
  4777. */
  4778. this._setMetadataFormat = function (format) {
  4779. metadata.format = format;
  4780. };
  4781. /**
  4782. * Private: set metadata raw text
  4783. * @param {string} raw
  4784. */
  4785. this._setMetadataRaw = function (raw) {
  4786. metadata.raw = raw;
  4787. };
  4788. };
  4789. var root = this;
  4790. // AMD Loader
  4791. if (typeof define === 'function' && define.amd) {
  4792. define(function () {
  4793. 'use strict';
  4794. return showdown;
  4795. });
  4796. // CommonJS/nodeJS Loader
  4797. } else if (typeof module !== 'undefined' && module.exports) {
  4798. module.exports = showdown;
  4799. // Regular Browser loader
  4800. } else {
  4801. root.showdown = showdown;
  4802. }
  4803. }).call(this);
  4804. //# sourceMappingURL=showdown.js.map