showdown.js 54 KB

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