25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6825 lines
283KB

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