showdown.js 54 KB

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