showdown.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019
  1. ;/*! showdown 17-06-2015 */
  2. (function(){
  3. /**
  4. * Created by Tivie on 06-01-2015.
  5. */
  6. // Private properties
  7. var showdown = {},
  8. parsers = {},
  9. extensions = {},
  10. defaultOptions = {
  11. omitExtraWLInCodeBlocks: false,
  12. prefixHeaderId: false,
  13. noHeaderId: false,
  14. headerLevelStart: 1,
  15. parseImgDimensions: false
  16. },
  17. globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P
  18. /**
  19. * helper namespace
  20. * @type {{}}
  21. */
  22. showdown.helper = {};
  23. /**
  24. * TODO LEGACY SUPPORT CODE
  25. * @type {{}}
  26. */
  27. showdown.extensions = {};
  28. /**
  29. * Set a global option
  30. * @static
  31. * @param {string} key
  32. * @param {*} value
  33. * @returns {showdown}
  34. */
  35. showdown.setOption = function (key, value) {
  36. 'use strict';
  37. globalOptions[key] = value;
  38. return this;
  39. };
  40. /**
  41. * Get a global option
  42. * @static
  43. * @param {string} key
  44. * @returns {*}
  45. */
  46. showdown.getOption = function (key) {
  47. 'use strict';
  48. return globalOptions[key];
  49. };
  50. /**
  51. * Get the global options
  52. * @static
  53. * @returns {{}}
  54. */
  55. showdown.getOptions = function () {
  56. 'use strict';
  57. return globalOptions;
  58. };
  59. /**
  60. * Reset global options to the default values
  61. * @static
  62. */
  63. showdown.resetOptions = function () {
  64. 'use strict';
  65. globalOptions = JSON.parse(JSON.stringify(defaultOptions));
  66. };
  67. /**
  68. * Get the default options
  69. * @static
  70. * @returns {{}}
  71. */
  72. showdown.getDefaultOptions = function () {
  73. 'use strict';
  74. return defaultOptions;
  75. };
  76. /**
  77. * Get or set a subParser
  78. *
  79. * subParser(name) - Get a registered subParser
  80. * subParser(name, func) - Register a subParser
  81. * @static
  82. * @param {string} name
  83. * @param {function} [func]
  84. * @returns {*}
  85. */
  86. showdown.subParser = function (name, func) {
  87. 'use strict';
  88. if (showdown.helper.isString(name)) {
  89. if (typeof func !== 'undefined') {
  90. parsers[name] = func;
  91. } else {
  92. if (parsers.hasOwnProperty(name)) {
  93. return parsers[name];
  94. } else {
  95. throw Error('SubParser named ' + name + ' not registered!');
  96. }
  97. }
  98. }
  99. };
  100. /**
  101. * Gets or registers an extension
  102. * @static
  103. * @param {string} name
  104. * @param {object|function=} ext
  105. * @returns {*}
  106. */
  107. showdown.extension = function (name, ext) {
  108. 'use strict';
  109. if (!showdown.helper.isString(name)) {
  110. throw Error('Extension \'name\' must be a string');
  111. }
  112. name = showdown.helper.stdExtName(name);
  113. // Getter
  114. if (showdown.helper.isUndefined(ext)) {
  115. if (!extensions.hasOwnProperty(name)) {
  116. throw Error('Extension named ' + name + ' is not registered!');
  117. }
  118. return extensions[name];
  119. // Setter
  120. } else {
  121. // Expand extension if it's wrapped in a function
  122. if (typeof ext === 'function') {
  123. ext = ext();
  124. }
  125. // Ensure extension is an array
  126. if (!showdown.helper.isArray(ext)) {
  127. ext = [ext];
  128. }
  129. var validExtension = validate(ext, name);
  130. if (validExtension.valid) {
  131. extensions[name] = ext;
  132. } else {
  133. throw Error(validExtension.error);
  134. }
  135. }
  136. };
  137. /**
  138. * Gets all extensions registered
  139. * @returns {{}}
  140. */
  141. showdown.getAllExtensions = function () {
  142. 'use strict';
  143. return extensions;
  144. };
  145. /**
  146. * Remove an extension
  147. * @param {string} name
  148. */
  149. showdown.removeExtension = function (name) {
  150. 'use strict';
  151. delete extensions[name];
  152. };
  153. /**
  154. * Removes all extensions
  155. */
  156. showdown.resetExtensions = function () {
  157. 'use strict';
  158. extensions = {};
  159. };
  160. /**
  161. * Validate extension
  162. * @param {array} extension
  163. * @param {string} name
  164. * @returns {{valid: boolean, error: string}}
  165. */
  166. function validate(extension, name) {
  167. 'use strict';
  168. var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension',
  169. ret = {
  170. valid: true,
  171. error: ''
  172. };
  173. if (!showdown.helper.isArray(extension)) {
  174. extension = [extension];
  175. }
  176. for (var i = 0; i < extension.length; ++i) {
  177. var baseMsg = errMsg + 'sub-extension ' + i + ': ',
  178. ext = extension[i];
  179. if (typeof ext !== 'object') {
  180. ret.valid = false;
  181. ret.error = baseMsg + 'must be an object, but ' + typeof ext + ' given';
  182. return ret;
  183. }
  184. if (!showdown.helper.isString(ext.type)) {
  185. ret.valid = false;
  186. ret.error = baseMsg + 'property "type" must be a string, but ' + typeof ext.type + ' given';
  187. return ret;
  188. }
  189. var type = ext.type = ext.type.toLowerCase();
  190. // normalize extension type
  191. if (type === 'language') {
  192. type = ext.type = 'lang';
  193. }
  194. if (type === 'html') {
  195. type = ext.type = 'output';
  196. }
  197. if (type !== 'lang' && type !== 'output') {
  198. ret.valid = false;
  199. ret.error = baseMsg + 'type ' + type + ' is not recognized. Valid values: "lang" or "output"';
  200. return ret;
  201. }
  202. if (ext.filter) {
  203. if (typeof ext.filter !== 'function') {
  204. ret.valid = false;
  205. ret.error = baseMsg + '"filter" must be a function, but ' + typeof ext.filter + ' given';
  206. return ret;
  207. }
  208. } else if (ext.regex) {
  209. if (showdown.helper.isString(ext.regex)) {
  210. ext.regex = new RegExp(ext.regex, 'g');
  211. }
  212. if (!ext.regex instanceof RegExp) {
  213. ret.valid = false;
  214. ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' +
  215. typeof ext.regex + ' given';
  216. return ret;
  217. }
  218. if (showdown.helper.isUndefined(ext.replace)) {
  219. ret.valid = false;
  220. ret.error = baseMsg + '"regex" extensions must implement a replace string or function';
  221. return ret;
  222. }
  223. } else {
  224. ret.valid = false;
  225. ret.error = baseMsg + 'extensions must define either a "regex" property or a "filter" method';
  226. return ret;
  227. }
  228. if (showdown.helper.isUndefined(ext.filter) && showdown.helper.isUndefined(ext.regex)) {
  229. ret.valid = false;
  230. ret.error = baseMsg + 'output extensions must define a filter property';
  231. return ret;
  232. }
  233. }
  234. return ret;
  235. }
  236. /**
  237. * Validate extension
  238. * @param {object} ext
  239. * @returns {boolean}
  240. */
  241. showdown.validateExtension = function (ext) {
  242. 'use strict';
  243. var validateExtension = validate(ext, null);
  244. if (!validateExtension.valid) {
  245. console.warn(validateExtension.error);
  246. return false;
  247. }
  248. return true;
  249. };
  250. /**
  251. * showdownjs helper functions
  252. */
  253. if (!showdown.hasOwnProperty('helper')) {
  254. showdown.helper = {};
  255. }
  256. /**
  257. * Check if var is string
  258. * @static
  259. * @param {string} a
  260. * @returns {boolean}
  261. */
  262. showdown.helper.isString = function isString(a) {
  263. 'use strict';
  264. return (typeof a === 'string' || a instanceof String);
  265. };
  266. /**
  267. * ForEach helper function
  268. * @static
  269. * @param {*} obj
  270. * @param {function} callback
  271. */
  272. showdown.helper.forEach = function forEach(obj, callback) {
  273. 'use strict';
  274. if (typeof obj.forEach === 'function') {
  275. obj.forEach(callback);
  276. } else {
  277. for (var i = 0; i < obj.length; i++) {
  278. callback(obj[i], i, obj);
  279. }
  280. }
  281. };
  282. /**
  283. * isArray helper function
  284. * @static
  285. * @param {*} a
  286. * @returns {boolean}
  287. */
  288. showdown.helper.isArray = function isArray(a) {
  289. 'use strict';
  290. return a.constructor === Array;
  291. };
  292. /**
  293. * Check if value is undefined
  294. * @static
  295. * @param {*} value The value to check.
  296. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  297. */
  298. showdown.helper.isUndefined = function isUndefined(value) {
  299. 'use strict';
  300. return typeof value === 'undefined';
  301. };
  302. /**
  303. * Standardidize extension name
  304. * @static
  305. * @param {string} s extension name
  306. * @returns {string}
  307. */
  308. showdown.helper.stdExtName = function (s) {
  309. 'use strict';
  310. return s.replace(/[_-]||\s/g, '').toLowerCase();
  311. };
  312. function escapeCharactersCallback(wholeMatch, m1) {
  313. 'use strict';
  314. var charCodeToEscape = m1.charCodeAt(0);
  315. return '~E' + charCodeToEscape + 'E';
  316. }
  317. /**
  318. * Callback used to escape characters when passing through String.replace
  319. * @static
  320. * @param {string} wholeMatch
  321. * @param {string} m1
  322. * @returns {string}
  323. */
  324. showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
  325. /**
  326. * Escape characters in a string
  327. * @static
  328. * @param {string} text
  329. * @param {string} charsToEscape
  330. * @param {boolean} afterBackslash
  331. * @returns {XML|string|void|*}
  332. */
  333. showdown.helper.escapeCharacters = function escapeCharacters(text, charsToEscape, afterBackslash) {
  334. 'use strict';
  335. // First we have to escape the escape characters so that
  336. // we can build a character class out of them
  337. var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
  338. if (afterBackslash) {
  339. regexString = '\\\\' + regexString;
  340. }
  341. var regex = new RegExp(regexString, 'g');
  342. text = text.replace(regex, escapeCharactersCallback);
  343. return text;
  344. };
  345. /**
  346. * POLYFILLS
  347. */
  348. if (showdown.helper.isUndefined(console)) {
  349. console = {
  350. warn: function (msg) {
  351. 'use strict';
  352. alert(msg);
  353. },
  354. log: function (msg) {
  355. 'use strict';
  356. alert(msg);
  357. }
  358. };
  359. }
  360. /**
  361. * Created by Estevao on 31-05-2015.
  362. */
  363. /**
  364. * Showdown Converter class
  365. * @class
  366. * @param {object} [converterOptions]
  367. * @returns {
  368. * {makeHtml: Function},
  369. * {setOption: Function},
  370. * {getOption: Function},
  371. * {getOptions: Function}
  372. * }
  373. */
  374. showdown.Converter = function (converterOptions) {
  375. 'use strict';
  376. var
  377. /**
  378. * Options used by this converter
  379. * @private
  380. * @type {{}}
  381. */
  382. options = {
  383. omitExtraWLInCodeBlocks: false,
  384. prefixHeaderId: false,
  385. noHeaderId: false
  386. },
  387. /**
  388. * Language extensions used by this converter
  389. * @private
  390. * @type {Array}
  391. */
  392. langExtensions = [],
  393. /**
  394. * Output modifiers extensions used by this converter
  395. * @private
  396. * @type {Array}
  397. */
  398. outputModifiers = [],
  399. /**
  400. * The parser Order
  401. * @private
  402. * @type {string[]}
  403. */
  404. parserOrder = [
  405. 'githubCodeBlocks',
  406. 'hashHTMLBlocks',
  407. 'stripLinkDefinitions',
  408. 'blockGamut',
  409. 'unescapeSpecialChars'
  410. ];
  411. _constructor();
  412. /**
  413. * Converter constructor
  414. * @private
  415. */
  416. function _constructor() {
  417. converterOptions = converterOptions || {};
  418. for (var gOpt in globalOptions) {
  419. if (globalOptions.hasOwnProperty(gOpt)) {
  420. options[gOpt] = globalOptions[gOpt];
  421. }
  422. }
  423. // Merge options
  424. if (typeof converterOptions === 'object') {
  425. for (var opt in converterOptions) {
  426. if (converterOptions.hasOwnProperty(opt)) {
  427. options[opt] = converterOptions[opt];
  428. }
  429. }
  430. } else {
  431. throw Error('Converter expects the passed parameter to be an object, but ' + typeof converterOptions +
  432. ' was passed instead.');
  433. }
  434. if (options.extensions) {
  435. showdown.helper.forEach(options.extensions, _parseExtension);
  436. }
  437. }
  438. /**
  439. * Parse extension
  440. * @param {*} ext
  441. * @private
  442. */
  443. function _parseExtension(ext) {
  444. // If it's a string, the extension was previously loaded
  445. if (showdown.helper.isString(ext)) {
  446. ext = showdown.helper.stdExtName(ext);
  447. // LEGACY_SUPPORT CODE
  448. if (showdown.extensions[ext]) {
  449. console.warn('DEPRECATION WARNING: ' + ext + ' is an old extension that uses a deprecated loading method.' +
  450. 'Please inform the developer that the extension should be updated!');
  451. legacyExtensionLoading(showdown.extensions[ext], ext);
  452. return;
  453. // END LEGACY SUPPORT CODE
  454. } else if (!showdown.helper.isUndefined(extensions[ext])) {
  455. ext = extensions[ext];
  456. } else {
  457. throw Error('Extension "' + ext + '" could not be loaded. It was either not found or is not a valid extension.');
  458. }
  459. }
  460. if (typeof ext === 'function') {
  461. ext = ext();
  462. }
  463. if (!showdown.helper.isArray(ext)) {
  464. ext = [ext];
  465. }
  466. if (!showdown.validateExtension(ext)) {
  467. return;
  468. }
  469. for (var i = 0; i < ext.length; ++i) {
  470. switch (ext[i].type) {
  471. case 'lang':
  472. langExtensions.push(ext[i]);
  473. break;
  474. case 'output':
  475. outputModifiers.push(ext[i]);
  476. break;
  477. default:
  478. // should never reach here
  479. throw Error('Extension loader error: Type unrecognized!!!');
  480. }
  481. }
  482. }
  483. /**
  484. * LEGACY_SUPPORT
  485. * @param {*} ext
  486. * @param {string} name
  487. */
  488. function legacyExtensionLoading(ext, name) {
  489. if (typeof ext === 'function') {
  490. ext = ext(new showdown.Converter());
  491. }
  492. if (!showdown.helper.isArray(ext)) {
  493. ext = [ext];
  494. }
  495. var valid = validate(ext, name);
  496. if (!valid.valid) {
  497. throw Error(valid.error);
  498. }
  499. for (var i = 0; i < ext.length; ++i) {
  500. switch (ext[i].type) {
  501. case 'lang':
  502. langExtensions.push(ext[i]);
  503. break;
  504. case 'output':
  505. outputModifiers.push(ext[i]);
  506. break;
  507. default:// should never reach here
  508. throw Error('Extension loader error: Type unrecognized!!!');
  509. }
  510. }
  511. }
  512. /**
  513. * Converts a markdown string into HTML
  514. * @param {string} text
  515. * @returns {*}
  516. */
  517. this.makeHtml = function (text) {
  518. //check if text is not falsy
  519. if (!text) {
  520. return text;
  521. }
  522. var globals = {
  523. gHtmlBlocks: [],
  524. gUrls: {},
  525. gTitles: {},
  526. gDimensions: {},
  527. gListLevel: 0,
  528. hashLinkCounts: {},
  529. langExtensions: langExtensions,
  530. outputModifiers: outputModifiers,
  531. converter: this
  532. };
  533. // attacklab: Replace ~ with ~T
  534. // This lets us use tilde as an escape char to avoid md5 hashes
  535. // The choice of character is arbitrary; anything that isn't
  536. // magic in Markdown will work.
  537. text = text.replace(/~/g, '~T');
  538. // attacklab: Replace $ with ~D
  539. // RegExp interprets $ as a special character
  540. // when it's in a replacement string
  541. text = text.replace(/\$/g, '~D');
  542. // Standardize line endings
  543. text = text.replace(/\r\n/g, '\n'); // DOS to Unix
  544. text = text.replace(/\r/g, '\n'); // Mac to Unix
  545. // Make sure text begins and ends with a couple of newlines:
  546. text = '\n\n' + text + '\n\n';
  547. // detab
  548. text = showdown.subParser('detab')(text, options, globals);
  549. // stripBlankLines
  550. text = showdown.subParser('stripBlankLines')(text, options, globals);
  551. //run languageExtensions
  552. showdown.helper.forEach(langExtensions, function (ext) {
  553. text = showdown.subParser('runExtension')(ext, text, options, globals);
  554. });
  555. // Run all registered parsers
  556. for (var i = 0; i < parserOrder.length; ++i) {
  557. var name = parserOrder[i];
  558. text = parsers[name](text, options, globals);
  559. }
  560. // attacklab: Restore dollar signs
  561. text = text.replace(/~D/g, '$$');
  562. // attacklab: Restore tildes
  563. text = text.replace(/~T/g, '~');
  564. // Run output modifiers
  565. showdown.helper.forEach(outputModifiers, function (ext) {
  566. text = showdown.subParser('runExtension')(ext, text, options, globals);
  567. });
  568. return text;
  569. };
  570. /**
  571. * Set an option of this Converter instance
  572. * @param {string} key
  573. * @param {*} value
  574. */
  575. this.setOption = function (key, value) {
  576. options[key] = value;
  577. };
  578. /**
  579. * Get the option of this Converter instance
  580. * @param {string} key
  581. * @returns {*}
  582. */
  583. this.getOption = function (key) {
  584. return options[key];
  585. };
  586. /**
  587. * Get the options of this Converter instance
  588. * @returns {{}}
  589. */
  590. this.getOptions = function () {
  591. return options;
  592. };
  593. /**
  594. * Add extension to THIS converter
  595. * @param {{}} extension
  596. */
  597. this.addExtension = function (extension) {
  598. _parseExtension(extension);
  599. };
  600. /**
  601. * Use a global registered extension with THIS converter
  602. * @param {string} extensionName Name of the previously registered extension
  603. */
  604. this.useExtension = function (extensionName) {
  605. _parseExtension(extensionName);
  606. };
  607. /**
  608. * Remove an extension from THIS converter.
  609. * Note: This is a costly operation. It's better to initialize a new converter
  610. * and specify the extensions you wish to use
  611. * @param {Array} extension
  612. */
  613. this.removeExtension = function (extension) {
  614. if (!showdown.helper.isArray(extension)) {
  615. extension = [extension];
  616. }
  617. for (var a = 0; a < extension.length; ++a) {
  618. var ext = extension[a];
  619. for (var i = 0; i < langExtensions.length; ++i) {
  620. if (langExtensions[i] === ext) {
  621. langExtensions[i].splice(i, 1);
  622. }
  623. }
  624. for (var ii = 0; ii < outputModifiers.length; ++i) {
  625. if (outputModifiers[ii] === ext) {
  626. outputModifiers[ii].splice(i, 1);
  627. }
  628. }
  629. }
  630. };
  631. /**
  632. * Get all extension of THIS converter
  633. * @returns {{language: Array, output: Array}}
  634. */
  635. this.getAllExtensions = function () {
  636. return {
  637. language: langExtensions,
  638. output: outputModifiers
  639. };
  640. };
  641. };
  642. /**
  643. * Turn Markdown link shortcuts into XHTML <a> tags.
  644. */
  645. showdown.subParser('anchors', function (text, config, globals) {
  646. 'use strict';
  647. var writeAnchorTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) {
  648. if (showdown.helper.isUndefined(m7)) {
  649. m7 = '';
  650. }
  651. wholeMatch = m1;
  652. var linkText = m2,
  653. linkId = m3.toLowerCase(),
  654. url = m4,
  655. title = m7;
  656. if (!url) {
  657. if (!linkId) {
  658. // lower-case and turn embedded newlines into spaces
  659. linkId = linkText.toLowerCase().replace(/ ?\n/g, ' ');
  660. }
  661. url = '#' + linkId;
  662. if (!showdown.helper.isUndefined(globals.gUrls[linkId])) {
  663. url = globals.gUrls[linkId];
  664. if (!showdown.helper.isUndefined(globals.gTitles[linkId])) {
  665. title = globals.gTitles[linkId];
  666. }
  667. } else {
  668. if (wholeMatch.search(/\(\s*\)$/m) > -1) {
  669. // Special case for explicit empty url
  670. url = '';
  671. } else {
  672. return wholeMatch;
  673. }
  674. }
  675. }
  676. url = showdown.helper.escapeCharacters(url, '*_', false);
  677. var result = '<a href="' + url + '"';
  678. if (title !== '' && title !== null) {
  679. title = title.replace(/"/g, '&quot;');
  680. title = showdown.helper.escapeCharacters(title, '*_', false);
  681. result += ' title="' + title + '"';
  682. }
  683. result += '>' + linkText + '</a>';
  684. return result;
  685. };
  686. // First, handle reference-style links: [link text] [id]
  687. /*
  688. text = text.replace(/
  689. ( // wrap whole match in $1
  690. \[
  691. (
  692. (?:
  693. \[[^\]]*\] // allow brackets nested one level
  694. |
  695. [^\[] // or anything else
  696. )*
  697. )
  698. \]
  699. [ ]? // one optional space
  700. (?:\n[ ]*)? // one optional newline followed by spaces
  701. \[
  702. (.*?) // id = $3
  703. \]
  704. )()()()() // pad remaining backreferences
  705. /g,_DoAnchors_callback);
  706. */
  707. text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, writeAnchorTag);
  708. //
  709. // Next, inline-style links: [link text](url "optional title")
  710. //
  711. /*
  712. text = text.replace(/
  713. ( // wrap whole match in $1
  714. \[
  715. (
  716. (?:
  717. \[[^\]]*\] // allow brackets nested one level
  718. |
  719. [^\[\]] // or anything else
  720. )
  721. )
  722. \]
  723. \( // literal paren
  724. [ \t]*
  725. () // no id, so leave $3 empty
  726. <?(.*?)>? // href = $4
  727. [ \t]*
  728. ( // $5
  729. (['"]) // quote char = $6
  730. (.*?) // Title = $7
  731. \6 // matching quote
  732. [ \t]* // ignore any spaces/tabs between closing quote and )
  733. )? // title is optional
  734. \)
  735. )
  736. /g,writeAnchorTag);
  737. */
  738. text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
  739. writeAnchorTag);
  740. //
  741. // Last, handle reference-style shortcuts: [link text]
  742. // These must come last in case you've also got [link test][1]
  743. // or [link test](/foo)
  744. //
  745. /*
  746. text = text.replace(/
  747. ( // wrap whole match in $1
  748. \[
  749. ([^\[\]]+) // link text = $2; can't contain '[' or ']'
  750. \]
  751. )()()()()() // pad rest of backreferences
  752. /g, writeAnchorTag);
  753. */
  754. text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
  755. return text;
  756. });
  757. showdown.subParser('autoLinks', function (text) {
  758. 'use strict';
  759. text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi, '<a href=\"$1\">$1</a>');
  760. // Email addresses: <address@domain.foo>
  761. /*
  762. text = text.replace(/
  763. <
  764. (?:mailto:)?
  765. (
  766. [-.\w]+
  767. \@
  768. [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
  769. )
  770. >
  771. /gi);
  772. */
  773. var pattern = /<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
  774. text = text.replace(pattern, function (wholeMatch, m1) {
  775. var unescapedStr = showdown.subParser('unescapeSpecialChars')(m1);
  776. return showdown.subParser('encodeEmailAddress')(unescapedStr);
  777. });
  778. return text;
  779. });
  780. /**
  781. * These are all the transformations that form block-level
  782. * tags like paragraphs, headers, and list items.
  783. */
  784. showdown.subParser('blockGamut', function (text, options, globals) {
  785. 'use strict';
  786. text = showdown.subParser('headers')(text, options, globals);
  787. // Do Horizontal Rules:
  788. var key = showdown.subParser('hashBlock')('<hr />', options, globals);
  789. text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm, key);
  790. text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm, key);
  791. text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm, key);
  792. text = showdown.subParser('lists')(text, options, globals);
  793. text = showdown.subParser('codeBlocks')(text, options, globals);
  794. text = showdown.subParser('blockQuotes')(text, options, globals);
  795. // We already ran _HashHTMLBlocks() before, in Markdown(), but that
  796. // was to escape raw HTML in the original Markdown source. This time,
  797. // we're escaping the markup we've just created, so that we don't wrap
  798. // <p> tags around block-level tags.
  799. text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
  800. text = showdown.subParser('paragraphs')(text, options, globals);
  801. return text;
  802. });
  803. showdown.subParser('blockQuotes', function (text, options, globals) {
  804. 'use strict';
  805. /*
  806. text = text.replace(/
  807. ( // Wrap whole match in $1
  808. (
  809. ^[ \t]*>[ \t]? // '>' at the start of a line
  810. .+\n // rest of the first line
  811. (.+\n)* // subsequent consecutive lines
  812. \n* // blanks
  813. )+
  814. )
  815. /gm, function(){...});
  816. */
  817. text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) {
  818. var bq = m1;
  819. // attacklab: hack around Konqueror 3.5.4 bug:
  820. // "----------bug".replace(/^-/g,"") == "bug"
  821. bq = bq.replace(/^[ \t]*>[ \t]?/gm, '~0'); // trim one level of quoting
  822. // attacklab: clean up hack
  823. bq = bq.replace(/~0/g, '');
  824. bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines
  825. bq = showdown.subParser('blockGamut')(bq, options, globals); // recurse
  826. bq = bq.replace(/(^|\n)/g, '$1 ');
  827. // These leading spaces screw with <pre> content, so we need to fix that:
  828. bq = bq.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm, function (wholeMatch, m1) {
  829. var pre = m1;
  830. // attacklab: hack around Konqueror 3.5.4 bug:
  831. pre = pre.replace(/^ /mg, '~0');
  832. pre = pre.replace(/~0/g, '');
  833. return pre;
  834. });
  835. return showdown.subParser('hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals);
  836. });
  837. return text;
  838. });
  839. /**
  840. * Process Markdown `<pre><code>` blocks.
  841. */
  842. showdown.subParser('codeBlocks', function (text, options, globals) {
  843. 'use strict';
  844. /*
  845. text = text.replace(text,
  846. /(?:\n\n|^)
  847. ( // $1 = the code block -- one or more lines, starting with a space/tab
  848. (?:
  849. (?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
  850. .*\n+
  851. )+
  852. )
  853. (\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
  854. /g,function(){...});
  855. */
  856. // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
  857. text += '~0';
  858. var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g;
  859. text = text.replace(pattern, function (wholeMatch, m1, m2) {
  860. var codeblock = m1,
  861. nextChar = m2,
  862. end = '\n';
  863. codeblock = showdown.subParser('outdent')(codeblock);
  864. codeblock = showdown.subParser('encodeCode')(codeblock);
  865. codeblock = showdown.subParser('detab')(codeblock);
  866. codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
  867. codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
  868. if (options.omitExtraWLInCodeBlocks) {
  869. end = '';
  870. }
  871. codeblock = '<pre><code>' + codeblock + end + '</code></pre>';
  872. return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
  873. });
  874. // attacklab: strip sentinel
  875. text = text.replace(/~0/, '');
  876. return text;
  877. });
  878. /**
  879. *
  880. * * Backtick quotes are used for <code></code> spans.
  881. *
  882. * * You can use multiple backticks as the delimiters if you want to
  883. * include literal backticks in the code span. So, this input:
  884. *
  885. * Just type ``foo `bar` baz`` at the prompt.
  886. *
  887. * Will translate to:
  888. *
  889. * <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
  890. *
  891. * There's no arbitrary limit to the number of backticks you
  892. * can use as delimters. If you need three consecutive backticks
  893. * in your code, use four for delimiters, etc.
  894. *
  895. * * You can use spaces to get literal backticks at the edges:
  896. *
  897. * ... type `` `bar` `` ...
  898. *
  899. * Turns to:
  900. *
  901. * ... type <code>`bar`</code> ...
  902. */
  903. showdown.subParser('codeSpans', function (text) {
  904. 'use strict';
  905. /*
  906. text = text.replace(/
  907. (^|[^\\]) // Character before opening ` can't be a backslash
  908. (`+) // $2 = Opening run of `
  909. ( // $3 = The code block
  910. [^\r]*?
  911. [^`] // attacklab: work around lack of lookbehind
  912. )
  913. \2 // Matching closer
  914. (?!`)
  915. /gm, function(){...});
  916. */
  917. text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm, function (wholeMatch, m1, m2, m3) {
  918. var c = m3;
  919. c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
  920. c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
  921. c = showdown.subParser('encodeCode')(c);
  922. return m1 + '<code>' + c + '</code>';
  923. });
  924. return text;
  925. });
  926. /**
  927. * Convert all tabs to spaces
  928. */
  929. showdown.subParser('detab', function (text) {
  930. 'use strict';
  931. // expand first n-1 tabs
  932. text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
  933. // replace the nth with two sentinels
  934. text = text.replace(/\t/g, '~A~B');
  935. // use the sentinel to anchor our regex so it doesn't explode
  936. text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1) {
  937. var leadingText = m1,
  938. numSpaces = 4 - leadingText.length % 4; // g_tab_width
  939. // there *must* be a better way to do this:
  940. for (var i = 0; i < numSpaces; i++) {
  941. leadingText += ' ';
  942. }
  943. return leadingText;
  944. });
  945. // clean up sentinels
  946. text = text.replace(/~A/g, ' '); // g_tab_width
  947. text = text.replace(/~B/g, '');
  948. return text;
  949. });
  950. /**
  951. * Smart processing for ampersands and angle brackets that need to be encoded.
  952. */
  953. showdown.subParser('encodeAmpsAndAngles', function (text) {
  954. 'use strict';
  955. // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
  956. // http://bumppo.net/projects/amputator/
  957. text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&amp;');
  958. // Encode naked <'s
  959. text = text.replace(/<(?![a-z\/?\$!])/gi, '&lt;');
  960. return text;
  961. });
  962. /**
  963. * Returns the string, with after processing the following backslash escape sequences.
  964. *
  965. * attacklab: The polite way to do this is with the new escapeCharacters() function:
  966. *
  967. * text = escapeCharacters(text,"\\",true);
  968. * text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
  969. *
  970. * ...but we're sidestepping its use of the (slow) RegExp constructor
  971. * as an optimization for Firefox. This function gets called a LOT.
  972. */
  973. showdown.subParser('encodeBackslashEscapes', function (text) {
  974. 'use strict';
  975. text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
  976. text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, showdown.helper.escapeCharactersCallback);
  977. return text;
  978. });
  979. /**
  980. * Encode/escape certain characters inside Markdown code runs.
  981. * The point is that in code, these characters are literals,
  982. * and lose their special Markdown meanings.
  983. */
  984. showdown.subParser('encodeCode', function (text) {
  985. 'use strict';
  986. // Encode all ampersands; HTML entities are not
  987. // entities within a Markdown code span.
  988. text = text.replace(/&/g, '&amp;');
  989. // Do the angle bracket song and dance:
  990. text = text.replace(/</g, '&lt;');
  991. text = text.replace(/>/g, '&gt;');
  992. // Now, escape characters that are magic in Markdown:
  993. text = showdown.helper.escapeCharacters(text, '*_{}[]\\', false);
  994. // jj the line above breaks this:
  995. //---
  996. //* Item
  997. // 1. Subitem
  998. // special char: *
  999. // ---
  1000. return text;
  1001. });
  1002. /**
  1003. * Input: an email address, e.g. "foo@example.com"
  1004. *
  1005. * Output: the email address as a mailto link, with each character
  1006. * of the address encoded as either a decimal or hex entity, in
  1007. * the hopes of foiling most address harvesting spam bots. E.g.:
  1008. *
  1009. * <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
  1010. * x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
  1011. * &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
  1012. *
  1013. * Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
  1014. * mailing list: <http://tinyurl.com/yu7ue>
  1015. *
  1016. */
  1017. showdown.subParser('encodeEmailAddress', function (addr) {
  1018. 'use strict';
  1019. var encode = [
  1020. function (ch) {
  1021. return '&#' + ch.charCodeAt(0) + ';';
  1022. },
  1023. function (ch) {
  1024. return '&#x' + ch.charCodeAt(0).toString(16) + ';';
  1025. },
  1026. function (ch) {
  1027. return ch;
  1028. }
  1029. ];
  1030. addr = 'mailto:' + addr;
  1031. addr = addr.replace(/./g, function (ch) {
  1032. if (ch === '@') {
  1033. // this *must* be encoded. I insist.
  1034. ch = encode[Math.floor(Math.random() * 2)](ch);
  1035. } else if (ch !== ':') {
  1036. // leave ':' alone (to spot mailto: later)
  1037. var r = Math.random();
  1038. // roughly 10% raw, 45% hex, 45% dec
  1039. ch = (
  1040. r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch)
  1041. );
  1042. }
  1043. return ch;
  1044. });
  1045. addr = '<a href="' + addr + '">' + addr + '</a>';
  1046. addr = addr.replace(/">.+:/g, '">'); // strip the mailto: from the visible part
  1047. return addr;
  1048. });
  1049. /**
  1050. * Within tags -- meaning between < and > -- encode [\ ` * _] so they
  1051. * don't conflict with their use in Markdown for code, italics and strong.
  1052. */
  1053. showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
  1054. 'use strict';
  1055. // Build a regex to find HTML tags and comments. See Friedl's
  1056. // "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
  1057. var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
  1058. text = text.replace(regex, function (wholeMatch) {
  1059. var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g, '$1`');
  1060. tag = showdown.helper.escapeCharacters(tag, '\\`*_', false);
  1061. return tag;
  1062. });
  1063. return text;
  1064. });
  1065. /**
  1066. * Handle github codeblocks prior to running HashHTML so that
  1067. * HTML contained within the codeblock gets escaped properly
  1068. * Example:
  1069. * ```ruby
  1070. * def hello_world(x)
  1071. * puts "Hello, #{x}"
  1072. * end
  1073. * ```
  1074. */
  1075. showdown.subParser('githubCodeBlocks', function (text, options, globals) {
  1076. 'use strict';
  1077. text += '~0';
  1078. text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) {
  1079. var language = m1,
  1080. codeblock = m2,
  1081. end = '\n';
  1082. if (options.omitExtraWLInCodeBlocks) {
  1083. end = '';
  1084. }
  1085. codeblock = showdown.subParser('encodeCode')(codeblock);
  1086. codeblock = showdown.subParser('detab')(codeblock);
  1087. codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
  1088. codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
  1089. codeblock = '<pre><code' + (language ? ' class="' + language + '"' : '') + '>' + codeblock + end + '</code></pre>';
  1090. return showdown.subParser('hashBlock')(codeblock, options, globals);
  1091. });
  1092. // attacklab: strip sentinel
  1093. text = text.replace(/~0/, '');
  1094. return text;
  1095. });
  1096. showdown.subParser('hashBlock', function (text, options, globals) {
  1097. 'use strict';
  1098. text = text.replace(/(^\n+|\n+$)/g, '');
  1099. return '\n\n~K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
  1100. });
  1101. showdown.subParser('hashElement', function (text, options, globals) {
  1102. 'use strict';
  1103. return function (wholeMatch, m1) {
  1104. var blockText = m1;
  1105. // Undo double lines
  1106. blockText = blockText.replace(/\n\n/g, '\n');
  1107. blockText = blockText.replace(/^\n/, '');
  1108. // strip trailing blank lines
  1109. blockText = blockText.replace(/\n+$/g, '');
  1110. // Replace the element text with a marker ("~KxK" where x is its key)
  1111. blockText = '\n\n~K' + (globals.gHtmlBlocks.push(blockText) - 1) + 'K\n\n';
  1112. return blockText;
  1113. };
  1114. });
  1115. showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
  1116. 'use strict';
  1117. // attacklab: Double up blank lines to reduce lookaround
  1118. text = text.replace(/\n/g, '\n\n');
  1119. // Hashify HTML blocks:
  1120. // We only want to do this for block-level HTML tags, such as headers,
  1121. // lists, and tables. That's because we still want to wrap <p>s around
  1122. // "paragraphs" that are wrapped in non-block-level tags, such as anchors,
  1123. // phrase emphasis, and spans. The list of tags we're looking for is
  1124. // hard-coded:
  1125. //var block_tags_a =
  1126. // 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del|style|section|header|footer|nav|article|aside';
  1127. // var block_tags_b =
  1128. // 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|style|section|header|footer|nav|article|aside';
  1129. // First, look for nested blocks, e.g.:
  1130. // <div>
  1131. // <div>
  1132. // tags for inner block must be indented.
  1133. // </div>
  1134. // </div>
  1135. //
  1136. // The outermost tags must start at the left margin for this to match, and
  1137. // the inner nested divs must be indented.
  1138. // We need to do this before the next, more liberal match, because the next
  1139. // match will start at the first `<div>` and stop at the first `</div>`.
  1140. // attacklab: This regex can be expensive when it fails.
  1141. /*
  1142. var text = text.replace(/
  1143. ( // save in $1
  1144. ^ // start of line (with /m)
  1145. <($block_tags_a) // start tag = $2
  1146. \b // word break
  1147. // attacklab: hack around khtml/pcre bug...
  1148. [^\r]*?\n // any number of lines, minimally matching
  1149. </\2> // the matching end tag
  1150. [ \t]* // trailing spaces/tabs
  1151. (?=\n+) // followed by a newline
  1152. ) // attacklab: there are sentinel newlines at end of document
  1153. /gm,function(){...}};
  1154. */
  1155. text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm,
  1156. showdown.subParser('hashElement')(text, options, globals));
  1157. //
  1158. // Now match more liberally, simply from `\n<tag>` to `</tag>\n`
  1159. //
  1160. /*
  1161. var text = text.replace(/
  1162. ( // save in $1
  1163. ^ // start of line (with /m)
  1164. <($block_tags_b) // start tag = $2
  1165. \b // word break
  1166. // attacklab: hack around khtml/pcre bug...
  1167. [^\r]*? // any number of lines, minimally matching
  1168. </\2> // the matching end tag
  1169. [ \t]* // trailing spaces/tabs
  1170. (?=\n+) // followed by a newline
  1171. ) // attacklab: there are sentinel newlines at end of document
  1172. /gm,function(){...}};
  1173. */
  1174. text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|style|section|header|footer|nav|article|aside|address|audio|canvas|figure|hgroup|output|video)\b[^\r]*?<\/\2>[ \t]*(?=\n+)\n)/gm,
  1175. showdown.subParser('hashElement')(text, options, globals));
  1176. // Special case just for <hr />. It was easier to make a special case than
  1177. // to make the other regex more complicated.
  1178. /*
  1179. text = text.replace(/
  1180. ( // save in $1
  1181. \n\n // Starting after a blank line
  1182. [ ]{0,3}
  1183. (<(hr) // start tag = $2
  1184. \b // word break
  1185. ([^<>])*? //
  1186. \/?>) // the matching end tag
  1187. [ \t]*
  1188. (?=\n{2,}) // followed by a blank line
  1189. )
  1190. /g,showdown.subParser('hashElement')(text, options, globals));
  1191. */
  1192. text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
  1193. showdown.subParser('hashElement')(text, options, globals));
  1194. // Special case for standalone HTML comments:
  1195. /*
  1196. text = text.replace(/
  1197. ( // save in $1
  1198. \n\n // Starting after a blank line
  1199. [ ]{0,3} // attacklab: g_tab_width - 1
  1200. <!
  1201. (--[^\r]*?--\s*)+
  1202. >
  1203. [ \t]*
  1204. (?=\n{2,}) // followed by a blank line
  1205. )
  1206. /g,showdown.subParser('hashElement')(text, options, globals));
  1207. */
  1208. text = text.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g,
  1209. showdown.subParser('hashElement')(text, options, globals));
  1210. // PHP and ASP-style processor instructions (<?...?> and <%...%>)
  1211. /*
  1212. text = text.replace(/
  1213. (?:
  1214. \n\n // Starting after a blank line
  1215. )
  1216. ( // save in $1
  1217. [ ]{0,3} // attacklab: g_tab_width - 1
  1218. (?:
  1219. <([?%]) // $2
  1220. [^\r]*?
  1221. \2>
  1222. )
  1223. [ \t]*
  1224. (?=\n{2,}) // followed by a blank line
  1225. )
  1226. /g,showdown.subParser('hashElement')(text, options, globals));
  1227. */
  1228. text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
  1229. showdown.subParser('hashElement')(text, options, globals));
  1230. // attacklab: Undo double lines (see comment at top of this function)
  1231. text = text.replace(/\n\n/g, '\n');
  1232. return text;
  1233. });
  1234. showdown.subParser('headers', function (text, options, globals) {
  1235. 'use strict';
  1236. var prefixHeader = options.prefixHeaderId;
  1237. // Set text-style headers:
  1238. // Header 1
  1239. // ========
  1240. //
  1241. // Header 2
  1242. // --------
  1243. //
  1244. text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm, function (wholeMatch, m1) {
  1245. var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
  1246. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
  1247. hLevel = parseInt(options.headerLevelStart),
  1248. hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
  1249. return showdown.subParser('hashBlock')(hashBlock, options, globals);
  1250. });
  1251. text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm, function (matchFound, m1) {
  1252. var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
  1253. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
  1254. hLevel = parseInt(options.headerLevelStart) + 1,
  1255. hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
  1256. return showdown.subParser('hashBlock')(hashBlock, options, globals);
  1257. });
  1258. // atx-style headers:
  1259. // # Header 1
  1260. // ## Header 2
  1261. // ## Header 2 with closing hashes ##
  1262. // ...
  1263. // ###### Header 6
  1264. //
  1265. /*
  1266. text = text.replace(/
  1267. ^(\#{1,6}) // $1 = string of #'s
  1268. [ \t]*
  1269. (.+?) // $2 = Header text
  1270. [ \t]*
  1271. \#* // optional closing #'s (not counted)
  1272. \n+
  1273. /gm, function() {...});
  1274. */
  1275. text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) {
  1276. var span = showdown.subParser('spanGamut')(m2, options, globals),
  1277. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
  1278. hLevel = parseInt(options.headerLevelStart) - 1 + m1.length,
  1279. header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
  1280. return showdown.subParser('hashBlock')(header, options, globals);
  1281. });
  1282. function headerId(m) {
  1283. var title, escapedId = m.replace(/[^\w]/g, '').toLowerCase();
  1284. if (globals.hashLinkCounts[escapedId]) {
  1285. title = escapedId + '-' + (globals.hashLinkCounts[escapedId]++);
  1286. } else {
  1287. title = escapedId;
  1288. globals.hashLinkCounts[escapedId] = 1;
  1289. }
  1290. // Prefix id to prevent causing inadvertent pre-existing style matches.
  1291. if (prefixHeader === true) {
  1292. prefixHeader = 'section';
  1293. }
  1294. if (showdown.helper.isString(prefixHeader)) {
  1295. return prefixHeader + title;
  1296. }
  1297. return title;
  1298. }
  1299. return text;
  1300. });
  1301. /**
  1302. * Turn Markdown image shortcuts into <img> tags.
  1303. */
  1304. showdown.subParser('images', function (text, options, globals) {
  1305. 'use strict';
  1306. var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
  1307. referenceRegExp = /!\[(.*?)][ ]?(?:\n[ ]*)?\[(.*?)]()()()()()/g;
  1308. function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
  1309. var gUrls = globals.gUrls,
  1310. gTitles = globals.gTitles,
  1311. gDims = globals.gDimensions;
  1312. linkId = linkId.toLowerCase();
  1313. if (!title) {
  1314. title = '';
  1315. }
  1316. if (url === '' || url === null) {
  1317. if (linkId === '' || linkId === null) {
  1318. // lower-case and turn embedded newlines into spaces
  1319. linkId = altText.toLowerCase().replace(/ ?\n/g, ' ');
  1320. }
  1321. url = '#' + linkId;
  1322. if (!showdown.helper.isUndefined(gUrls[linkId])) {
  1323. url = gUrls[linkId];
  1324. if (!showdown.helper.isUndefined(gTitles[linkId])) {
  1325. title = gTitles[linkId];
  1326. }
  1327. if (!showdown.helper.isUndefined(gDims[linkId])) {
  1328. width = gDims[linkId].width;
  1329. height = gDims[linkId].height;
  1330. }
  1331. } else {
  1332. return wholeMatch;
  1333. }
  1334. }
  1335. altText = altText.replace(/"/g, '&quot;');
  1336. url = showdown.helper.escapeCharacters(url, '*_', false);
  1337. var result = '<img src="' + url + '" alt="' + altText + '"';
  1338. if (title) {
  1339. title = title.replace(/"/g, '&quot;');
  1340. title = showdown.helper.escapeCharacters(title, '*_', false);
  1341. result += ' title="' + title + '"';
  1342. }
  1343. if (width && height) {
  1344. width = (width === '*') ? 'auto' : width;
  1345. height = (height === '*') ? 'auto' : height;
  1346. result += ' width="' + width + '"';
  1347. result += ' height="' + height + '"';
  1348. }
  1349. result += ' />';
  1350. return result;
  1351. }
  1352. // First, handle reference-style labeled images: ![alt text][id]
  1353. text = text.replace(referenceRegExp, writeImageTag);
  1354. // Next, handle inline images: ![alt text](url =<width>x<height> "optional title")
  1355. text = text.replace(inlineRegExp, writeImageTag);
  1356. return text;
  1357. });
  1358. showdown.subParser('italicsAndBold', function (text) {
  1359. 'use strict';
  1360. // <strong> must go first:
  1361. text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, '<strong>$2</strong>');
  1362. text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
  1363. return text;
  1364. });
  1365. /**
  1366. * Form HTML ordered (numbered) and unordered (bulleted) lists.
  1367. */
  1368. showdown.subParser('lists', function (text, options, globals) {
  1369. 'use strict';
  1370. var spl = '~1';
  1371. /**
  1372. * Process the contents of a single ordered or unordered list, splitting it
  1373. * into individual list items.
  1374. * @param {string} listStr
  1375. * @returns {string}
  1376. */
  1377. function processListItems (listStr) {
  1378. // The $g_list_level global keeps track of when we're inside a list.
  1379. // Each time we enter a list, we increment it; when we leave a list,
  1380. // we decrement. If it's zero, we're not in a list anymore.
  1381. //
  1382. // We do this because when we're not inside a list, we want to treat
  1383. // something like this:
  1384. //
  1385. // I recommend upgrading to version
  1386. // 8. Oops, now this line is treated
  1387. // as a sub-list.
  1388. //
  1389. // As a single paragraph, despite the fact that the second line starts
  1390. // with a digit-period-space sequence.
  1391. //
  1392. // Whereas when we're inside a list (or sub-list), that line will be
  1393. // treated as the start of a sub-list. What a kludge, huh? This is
  1394. // an aspect of Markdown's syntax that's hard to parse perfectly
  1395. // without resorting to mind-reading. Perhaps the solution is to
  1396. // change the syntax rules such that sub-lists must start with a
  1397. // starting cardinal number; e.g. "1." or "a.".
  1398. globals.gListLevel++;
  1399. // trim trailing blank lines:
  1400. listStr = listStr.replace(/\n{2,}$/, '\n');
  1401. // attacklab: add sentinel to emulate \z
  1402. listStr += '~0';
  1403. /*
  1404. list_str = list_str.replace(/
  1405. (\n)? // leading line = $1
  1406. (^[ \t]*) // leading whitespace = $2
  1407. ([*+-]|\d+[.]) [ \t]+ // list marker = $3
  1408. ([^\r]+? // list item text = $4
  1409. (\n{1,2}))
  1410. (?= \n* (~0 | \2 ([*+-]|\d+[.]) [ \t]+))
  1411. /gm, function(){...});
  1412. */
  1413. var rgx = /(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm;
  1414. listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4) {
  1415. var item = showdown.subParser('outdent')(m4, options, globals);
  1416. //m1 - LeadingLine
  1417. if (m1 || (item.search(/\n{2,}/) > -1)) {
  1418. item = showdown.subParser('blockGamut')(item, options, globals);
  1419. } else {
  1420. // Recursion for sub-lists:
  1421. item = showdown.subParser('lists')(item, options, globals);
  1422. item = item.replace(/\n$/, ''); // chomp(item)
  1423. item = showdown.subParser('spanGamut')(item, options, globals);
  1424. }
  1425. // this is a "hack" to differentiate between ordered and unordered lists
  1426. // related to issue #142
  1427. var tp = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
  1428. return spl + tp + '<li>' + item + '</li>\n';
  1429. });
  1430. // attacklab: strip sentinel
  1431. listStr = listStr.replace(/~0/g, '');
  1432. globals.gListLevel--;
  1433. return listStr;
  1434. }
  1435. /**
  1436. * Slit consecutive ol/ul lists (related to issue 142)
  1437. * @param {Array} results
  1438. * @param {string} listType
  1439. * @returns {string|*}
  1440. */
  1441. function splitConsecutiveLists (results, listType) {
  1442. var cthulhu = /(<p[^>]+?>|<p>|<\/p>)/img,
  1443. holder = [[]],
  1444. res = '',
  1445. y = 0;
  1446. // Initialize first sublist
  1447. holder[0].type = listType;
  1448. for (var i = 0; i < results.length; ++i) {
  1449. var txt = results[i].slice(2),
  1450. nListType = results[i].slice(0, 2);
  1451. if (listType !== nListType) {
  1452. y++;
  1453. holder[y] = [];
  1454. holder[y].type = nListType;
  1455. listType = nListType;
  1456. }
  1457. holder[y].push(txt);
  1458. }
  1459. for (i = 0; i < holder.length; ++i) {
  1460. res += '<' + holder[i].type + '>\n';
  1461. for (var ii = 0; ii < holder[i].length; ++ii) {
  1462. if (holder[i].length > 1 && ii === holder[i].length - 1 && !cthulhu.test(holder[i][ii - 1])) {
  1463. //holder[i][ii] = holder[i][ii].replace(cthulhu, '');
  1464. }
  1465. res += holder[i][ii];
  1466. }
  1467. res += '</' + holder[i].type + '>\n';
  1468. }
  1469. return res;
  1470. }
  1471. // attacklab: add sentinel to hack around khtml/safari bug:
  1472. // http://bugs.webkit.org/show_bug.cgi?id=11231
  1473. text += '~0';
  1474. // Re-usable pattern to match any entire ul or ol list:
  1475. /*
  1476. var whole_list = /
  1477. ( // $1 = whole list
  1478. ( // $2
  1479. [ ]{0,3} // attacklab: g_tab_width - 1
  1480. ([*+-]|\d+[.]) // $3 = first list item marker
  1481. [ \t]+
  1482. )
  1483. [^\r]+?
  1484. ( // $4
  1485. ~0 // sentinel for workaround; should be $
  1486. |
  1487. \n{2,}
  1488. (?=\S)
  1489. (?! // Negative lookahead for another list item marker
  1490. [ \t]*
  1491. (?:[*+-]|\d+[.])[ \t]+
  1492. )
  1493. )
  1494. )/g
  1495. */
  1496. var wholeList = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
  1497. if (globals.gListLevel) {
  1498. text = text.replace(wholeList, function (wholeMatch, m1, m2) {
  1499. var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol',
  1500. result = processListItems(m1);
  1501. // Turn double returns into triple returns, so that we can make a
  1502. // paragraph for the last item in a list, if necessary:
  1503. //list = list.replace(/\n{2,}/g, '\n\n\n');
  1504. //result = processListItems(list);
  1505. // Trim any trailing whitespace, to put the closing `</$list_type>`
  1506. // up on the preceding line, to get it past the current stupid
  1507. // HTML block parser. This is a hack to work around the terrible
  1508. // hack that is the HTML block parser.
  1509. result = result.replace(/\s+$/, '');
  1510. var splRes = result.split(spl);
  1511. splRes.shift();
  1512. result = splitConsecutiveLists(splRes, listType);
  1513. return result;
  1514. });
  1515. } else {
  1516. wholeList = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;
  1517. //wholeList = /(\n\n|^\n?)( {0,3}([*+-]|\d+\.)[ \t]+[\s\S]+?)(?=(~0)|(\n\n(?!\t| {2,}| {0,3}([*+-]|\d+\.)[ \t])))/g;
  1518. text = text.replace(wholeList, function (wholeMatch, m1, m2, m3) {
  1519. // Turn double returns into triple returns, so that we can make a
  1520. // paragraph for the last item in a list, if necessary:
  1521. var list = m2.replace(/\n{2,}/g, '\n\n\n'),
  1522. //var list = (m2.slice(-2) !== '~0') ? m2 + '\n' : m2, //add a newline after the list
  1523. listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol',
  1524. result = processListItems(list),
  1525. splRes = result.split(spl);
  1526. splRes.shift();
  1527. return m1 + splitConsecutiveLists(splRes, listType) + '\n';
  1528. });
  1529. }
  1530. // attacklab: strip sentinel
  1531. text = text.replace(/~0/, '');
  1532. return text;
  1533. });
  1534. /**
  1535. * Remove one level of line-leading tabs or spaces
  1536. */
  1537. showdown.subParser('outdent', function (text) {
  1538. 'use strict';
  1539. // attacklab: hack around Konqueror 3.5.4 bug:
  1540. // "----------bug".replace(/^-/g,"") == "bug"
  1541. text = text.replace(/^(\t|[ ]{1,4})/gm, '~0'); // attacklab: g_tab_width
  1542. // attacklab: clean up hack
  1543. text = text.replace(/~0/g, '');
  1544. return text;
  1545. });
  1546. /**
  1547. *
  1548. */
  1549. showdown.subParser('paragraphs', function (text, options, globals) {
  1550. 'use strict';
  1551. // Strip leading and trailing lines:
  1552. text = text.replace(/^\n+/g, '');
  1553. text = text.replace(/\n+$/g, '');
  1554. var grafs = text.split(/\n{2,}/g),
  1555. grafsOut = [],
  1556. end = grafs.length; // Wrap <p> tags
  1557. for (var i = 0; i < end; i++) {
  1558. var str = grafs[i];
  1559. // if this is an HTML marker, copy it
  1560. if (str.search(/~K(\d+)K/g) >= 0) {
  1561. grafsOut.push(str);
  1562. } else if (str.search(/\S/) >= 0) {
  1563. str = showdown.subParser('spanGamut')(str, options, globals);
  1564. str = str.replace(/^([ \t]*)/g, '<p>');
  1565. str += '</p>';
  1566. grafsOut.push(str);
  1567. }
  1568. }
  1569. /** Unhashify HTML blocks */
  1570. end = grafsOut.length;
  1571. for (i = 0; i < end; i++) {
  1572. // if this is a marker for an html block...
  1573. while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
  1574. var blockText = globals.gHtmlBlocks[RegExp.$1];
  1575. blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
  1576. grafsOut[i] = grafsOut[i].replace(/~K\d+K/, blockText);
  1577. }
  1578. }
  1579. return grafsOut.join('\n\n');
  1580. });
  1581. /**
  1582. * Run extension
  1583. */
  1584. showdown.subParser('runExtension', function (ext, text, options, globals) {
  1585. 'use strict';
  1586. if (ext.filter) {
  1587. text = ext.filter(text, globals.converter, options);
  1588. } else if (ext.regex) {
  1589. // TODO remove this when old extension loading mechanism is deprecated
  1590. var re = ext.regex;
  1591. if (!re instanceof RegExp) {
  1592. re = new RegExp(re, 'g');
  1593. }
  1594. text = text.replace(re, ext.replace);
  1595. }
  1596. return text;
  1597. });
  1598. /**
  1599. * These are all the transformations that occur *within* block-level
  1600. * tags like paragraphs, headers, and list items.
  1601. */
  1602. showdown.subParser('spanGamut', function (text, options, globals) {
  1603. 'use strict';
  1604. text = showdown.subParser('codeSpans')(text, options, globals);
  1605. text = showdown.subParser('escapeSpecialCharsWithinTagAttributes')(text, options, globals);
  1606. text = showdown.subParser('encodeBackslashEscapes')(text, options, globals);
  1607. // Process anchor and image tags. Images must come first,
  1608. // because ![foo][f] looks like an anchor.
  1609. text = showdown.subParser('images')(text, options, globals);
  1610. text = showdown.subParser('anchors')(text, options, globals);
  1611. // Make links out of things like `<http://example.com/>`
  1612. // Must come after _DoAnchors(), because you can use < and >
  1613. // delimiters in inline links like [this](<url>).
  1614. text = showdown.subParser('autoLinks')(text, options, globals);
  1615. text = showdown.subParser('encodeAmpsAndAngles')(text, options, globals);
  1616. text = showdown.subParser('italicsAndBold')(text, options, globals);
  1617. // Do hard breaks:
  1618. text = text.replace(/ +\n/g, ' <br />\n');
  1619. return text;
  1620. });
  1621. /**
  1622. * Strip any lines consisting only of spaces and tabs.
  1623. * This makes subsequent regexs easier to write, because we can
  1624. * match consecutive blank lines with /\n+/ instead of something
  1625. * contorted like /[ \t]*\n+/
  1626. */
  1627. showdown.subParser('stripBlankLines', function (text) {
  1628. 'use strict';
  1629. return text.replace(/^[ \t]+$/mg, '');
  1630. });
  1631. /**
  1632. * Strips link definitions from text, stores the URLs and titles in
  1633. * hash references.
  1634. * Link defs are in the form: ^[id]: url "optional title"
  1635. *
  1636. * ^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1
  1637. * [ \t]*
  1638. * \n? // maybe *one* newline
  1639. * [ \t]*
  1640. * <?(\S+?)>? // url = $2
  1641. * [ \t]*
  1642. * \n? // maybe one newline
  1643. * [ \t]*
  1644. * (?:
  1645. * (\n*) // any lines skipped = $3 attacklab: lookbehind removed
  1646. * ["(]
  1647. * (.+?) // title = $4
  1648. * [")]
  1649. * [ \t]*
  1650. * )? // title is optional
  1651. * (?:\n+|$)
  1652. * /gm,
  1653. * function(){...});
  1654. *
  1655. */
  1656. showdown.subParser('stripLinkDefinitions', function (text, options, globals) {
  1657. 'use strict';
  1658. 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;
  1659. // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
  1660. text += '~0';
  1661. text = text.replace(regex, function (wholeMatch, linkId, url, width, height, blankLines, title) {
  1662. linkId = linkId.toLowerCase();
  1663. globals.gUrls[linkId] = showdown.subParser('encodeAmpsAndAngles')(url); // Link IDs are case-insensitive
  1664. if (blankLines) {
  1665. // Oops, found blank lines, so it's not a title.
  1666. // Put back the parenthetical statement we stole.
  1667. return blankLines + title;
  1668. } else {
  1669. if (title) {
  1670. globals.gTitles[linkId] = title.replace(/"|'/g, '&quot;');
  1671. }
  1672. if (options.parseImgDimensions && width && height) {
  1673. globals.gDimensions[linkId] = {
  1674. width: width,
  1675. height: height
  1676. };
  1677. }
  1678. }
  1679. // Completely remove the definition from the text
  1680. return '';
  1681. });
  1682. // attacklab: strip sentinel
  1683. text = text.replace(/~0/, '');
  1684. return text;
  1685. });
  1686. /**
  1687. * Swap back in all the special characters we've hidden.
  1688. */
  1689. showdown.subParser('unescapeSpecialChars', function (text) {
  1690. 'use strict';
  1691. text = text.replace(/~E(\d+)E/g, function (wholeMatch, m1) {
  1692. var charCodeToReplace = parseInt(m1);
  1693. return String.fromCharCode(charCodeToReplace);
  1694. });
  1695. return text;
  1696. });
  1697. var root = this;
  1698. // CommonJS/nodeJS Loader
  1699. if (typeof module !== 'undefined' && module.exports) {
  1700. module.exports = showdown;
  1701. // AMD Loader
  1702. } else if (typeof define === 'function' && define.amd) {
  1703. define('showdown', function () {
  1704. 'use strict';
  1705. return showdown;
  1706. });
  1707. // Regular Browser loader
  1708. } else {
  1709. root.showdown = showdown;
  1710. }
  1711. }).call(this);
  1712. //# sourceMappingURL=showdown.js.map