showdown.js 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541
  1. ;/*! showdown 30-12-2016 */
  2. (function(){
  3. /**
  4. * Created by Tivie on 13-07-2015.
  5. */
  6. function getDefaultOpts(simple) {
  7. 'use strict';
  8. var defaultOptions = {
  9. omitExtraWLInCodeBlocks: {
  10. defaultValue: false,
  11. describe: 'Omit the default extra whiteline added to code blocks',
  12. type: 'boolean'
  13. },
  14. noHeaderId: {
  15. defaultValue: false,
  16. describe: 'Turn on/off generated header id',
  17. type: 'boolean'
  18. },
  19. prefixHeaderId: {
  20. defaultValue: false,
  21. describe: 'Specify a prefix to generated header ids',
  22. type: 'string'
  23. },
  24. ghCompatibleHeaderId: {
  25. defaultValue: false,
  26. describe: 'Generate header ids compatible with github style (spaces are replaced with dashes, &~$!@#*()=:/,;?+%\\\'. chars are removed)',
  27. type: 'string'
  28. },
  29. headerLevelStart: {
  30. defaultValue: false,
  31. describe: 'The header blocks level start',
  32. type: 'integer'
  33. },
  34. parseImgDimensions: {
  35. defaultValue: false,
  36. describe: 'Turn on/off image dimension parsing',
  37. type: 'boolean'
  38. },
  39. simplifiedAutoLink: {
  40. defaultValue: false,
  41. describe: 'Turn on/off GFM autolink style',
  42. type: 'boolean'
  43. },
  44. excludeTrailingPunctuationFromURLs: {
  45. defaultValue: false,
  46. describe: 'Excludes trailing punctuation from links generated with autoLinking',
  47. type: 'boolean'
  48. },
  49. literalMidWordUnderscores: {
  50. defaultValue: false,
  51. describe: 'Parse midword underscores as literal underscores',
  52. type: 'boolean'
  53. },
  54. strikethrough: {
  55. defaultValue: false,
  56. describe: 'Turn on/off strikethrough support',
  57. type: 'boolean'
  58. },
  59. tables: {
  60. defaultValue: false,
  61. describe: 'Turn on/off tables support',
  62. type: 'boolean'
  63. },
  64. tablesHeaderId: {
  65. defaultValue: false,
  66. describe: 'Add an id to table headers',
  67. type: 'boolean'
  68. },
  69. ghCodeBlocks: {
  70. defaultValue: true,
  71. describe: 'Turn on/off GFM fenced code blocks support',
  72. type: 'boolean'
  73. },
  74. tasklists: {
  75. defaultValue: false,
  76. describe: 'Turn on/off GFM tasklist support',
  77. type: 'boolean'
  78. },
  79. smoothLivePreview: {
  80. defaultValue: false,
  81. describe: 'Prevents weird effects in live previews due to incomplete input',
  82. type: 'boolean'
  83. },
  84. smartIndentationFix: {
  85. defaultValue: false,
  86. description: 'Tries to smartly fix indentation in es6 strings',
  87. type: 'boolean'
  88. },
  89. disableForced4SpacesIndentedSublists: {
  90. defaultValue: false,
  91. description: 'Disables the requirement of indenting nested sublists by 4 spaces',
  92. type: 'boolean'
  93. },
  94. simpleLineBreaks: {
  95. defaultValue: false,
  96. description: 'Parses simple line breaks as <br> (GFM Style)',
  97. type: 'boolean'
  98. },
  99. requireSpaceBeforeHeadingText: {
  100. defaultValue: false,
  101. description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
  102. type: 'boolean'
  103. }
  104. };
  105. if (simple === false) {
  106. return JSON.parse(JSON.stringify(defaultOptions));
  107. }
  108. var ret = {};
  109. for (var opt in defaultOptions) {
  110. if (defaultOptions.hasOwnProperty(opt)) {
  111. ret[opt] = defaultOptions[opt].defaultValue;
  112. }
  113. }
  114. return ret;
  115. }
  116. function allOptionsOn() {
  117. 'use strict';
  118. var options = getDefaultOpts(true),
  119. ret = {};
  120. for (var opt in options) {
  121. if (options.hasOwnProperty(opt)) {
  122. ret[opt] = true;
  123. }
  124. }
  125. return ret;
  126. }
  127. /**
  128. * Created by Tivie on 06-01-2015.
  129. */
  130. // Private properties
  131. var showdown = {},
  132. parsers = {},
  133. extensions = {},
  134. globalOptions = getDefaultOpts(true),
  135. flavor = {
  136. github: {
  137. omitExtraWLInCodeBlocks: true,
  138. prefixHeaderId: 'user-content-',
  139. simplifiedAutoLink: true,
  140. excludeTrailingPunctuationFromURLs: true,
  141. literalMidWordUnderscores: true,
  142. strikethrough: true,
  143. tables: true,
  144. tablesHeaderId: true,
  145. ghCodeBlocks: true,
  146. tasklists: true,
  147. disableForced4SpacesIndentedSublists: true,
  148. simpleLineBreaks: true,
  149. requireSpaceBeforeHeadingText: true,
  150. ghCompatibleHeaderId: true
  151. },
  152. vanilla: getDefaultOpts(true),
  153. allOn: allOptionsOn()
  154. };
  155. /**
  156. * helper namespace
  157. * @type {{}}
  158. */
  159. showdown.helper = {};
  160. /**
  161. * TODO LEGACY SUPPORT CODE
  162. * @type {{}}
  163. */
  164. showdown.extensions = {};
  165. /**
  166. * Set a global option
  167. * @static
  168. * @param {string} key
  169. * @param {*} value
  170. * @returns {showdown}
  171. */
  172. showdown.setOption = function (key, value) {
  173. 'use strict';
  174. globalOptions[key] = value;
  175. return this;
  176. };
  177. /**
  178. * Get a global option
  179. * @static
  180. * @param {string} key
  181. * @returns {*}
  182. */
  183. showdown.getOption = function (key) {
  184. 'use strict';
  185. return globalOptions[key];
  186. };
  187. /**
  188. * Get the global options
  189. * @static
  190. * @returns {{}}
  191. */
  192. showdown.getOptions = function () {
  193. 'use strict';
  194. return globalOptions;
  195. };
  196. /**
  197. * Reset global options to the default values
  198. * @static
  199. */
  200. showdown.resetOptions = function () {
  201. 'use strict';
  202. globalOptions = getDefaultOpts(true);
  203. };
  204. /**
  205. * Set the flavor showdown should use as default
  206. * @param {string} name
  207. */
  208. showdown.setFlavor = function (name) {
  209. 'use strict';
  210. if (flavor.hasOwnProperty(name)) {
  211. var preset = flavor[name];
  212. for (var option in preset) {
  213. if (preset.hasOwnProperty(option)) {
  214. globalOptions[option] = preset[option];
  215. }
  216. }
  217. }
  218. };
  219. /**
  220. * Get the default options
  221. * @static
  222. * @param {boolean} [simple=true]
  223. * @returns {{}}
  224. */
  225. showdown.getDefaultOptions = function (simple) {
  226. 'use strict';
  227. return getDefaultOpts(simple);
  228. };
  229. /**
  230. * Get or set a subParser
  231. *
  232. * subParser(name) - Get a registered subParser
  233. * subParser(name, func) - Register a subParser
  234. * @static
  235. * @param {string} name
  236. * @param {function} [func]
  237. * @returns {*}
  238. */
  239. showdown.subParser = function (name, func) {
  240. 'use strict';
  241. if (showdown.helper.isString(name)) {
  242. if (typeof func !== 'undefined') {
  243. parsers[name] = func;
  244. } else {
  245. if (parsers.hasOwnProperty(name)) {
  246. return parsers[name];
  247. } else {
  248. throw Error('SubParser named ' + name + ' not registered!');
  249. }
  250. }
  251. }
  252. };
  253. /**
  254. * Gets or registers an extension
  255. * @static
  256. * @param {string} name
  257. * @param {object|function=} ext
  258. * @returns {*}
  259. */
  260. showdown.extension = function (name, ext) {
  261. 'use strict';
  262. if (!showdown.helper.isString(name)) {
  263. throw Error('Extension \'name\' must be a string');
  264. }
  265. name = showdown.helper.stdExtName(name);
  266. // Getter
  267. if (showdown.helper.isUndefined(ext)) {
  268. if (!extensions.hasOwnProperty(name)) {
  269. throw Error('Extension named ' + name + ' is not registered!');
  270. }
  271. return extensions[name];
  272. // Setter
  273. } else {
  274. // Expand extension if it's wrapped in a function
  275. if (typeof ext === 'function') {
  276. ext = ext();
  277. }
  278. // Ensure extension is an array
  279. if (!showdown.helper.isArray(ext)) {
  280. ext = [ext];
  281. }
  282. var validExtension = validate(ext, name);
  283. if (validExtension.valid) {
  284. extensions[name] = ext;
  285. } else {
  286. throw Error(validExtension.error);
  287. }
  288. }
  289. };
  290. /**
  291. * Gets all extensions registered
  292. * @returns {{}}
  293. */
  294. showdown.getAllExtensions = function () {
  295. 'use strict';
  296. return extensions;
  297. };
  298. /**
  299. * Remove an extension
  300. * @param {string} name
  301. */
  302. showdown.removeExtension = function (name) {
  303. 'use strict';
  304. delete extensions[name];
  305. };
  306. /**
  307. * Removes all extensions
  308. */
  309. showdown.resetExtensions = function () {
  310. 'use strict';
  311. extensions = {};
  312. };
  313. /**
  314. * Validate extension
  315. * @param {array} extension
  316. * @param {string} name
  317. * @returns {{valid: boolean, error: string}}
  318. */
  319. function validate(extension, name) {
  320. 'use strict';
  321. var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension',
  322. ret = {
  323. valid: true,
  324. error: ''
  325. };
  326. if (!showdown.helper.isArray(extension)) {
  327. extension = [extension];
  328. }
  329. for (var i = 0; i < extension.length; ++i) {
  330. var baseMsg = errMsg + ' sub-extension ' + i + ': ',
  331. ext = extension[i];
  332. if (typeof ext !== 'object') {
  333. ret.valid = false;
  334. ret.error = baseMsg + 'must be an object, but ' + typeof ext + ' given';
  335. return ret;
  336. }
  337. if (!showdown.helper.isString(ext.type)) {
  338. ret.valid = false;
  339. ret.error = baseMsg + 'property "type" must be a string, but ' + typeof ext.type + ' given';
  340. return ret;
  341. }
  342. var type = ext.type = ext.type.toLowerCase();
  343. // normalize extension type
  344. if (type === 'language') {
  345. type = ext.type = 'lang';
  346. }
  347. if (type === 'html') {
  348. type = ext.type = 'output';
  349. }
  350. if (type !== 'lang' && type !== 'output' && type !== 'listener') {
  351. ret.valid = false;
  352. ret.error = baseMsg + 'type ' + type + ' is not recognized. Valid values: "lang/language", "output/html" or "listener"';
  353. return ret;
  354. }
  355. if (type === 'listener') {
  356. if (showdown.helper.isUndefined(ext.listeners)) {
  357. ret.valid = false;
  358. ret.error = baseMsg + '. Extensions of type "listener" must have a property called "listeners"';
  359. return ret;
  360. }
  361. } else {
  362. if (showdown.helper.isUndefined(ext.filter) && showdown.helper.isUndefined(ext.regex)) {
  363. ret.valid = false;
  364. ret.error = baseMsg + type + ' extensions must define either a "regex" property or a "filter" method';
  365. return ret;
  366. }
  367. }
  368. if (ext.listeners) {
  369. if (typeof ext.listeners !== 'object') {
  370. ret.valid = false;
  371. ret.error = baseMsg + '"listeners" property must be an object but ' + typeof ext.listeners + ' given';
  372. return ret;
  373. }
  374. for (var ln in ext.listeners) {
  375. if (ext.listeners.hasOwnProperty(ln)) {
  376. if (typeof ext.listeners[ln] !== 'function') {
  377. ret.valid = false;
  378. ret.error = baseMsg + '"listeners" property must be an hash of [event name]: [callback]. listeners.' + ln +
  379. ' must be a function but ' + typeof ext.listeners[ln] + ' given';
  380. return ret;
  381. }
  382. }
  383. }
  384. }
  385. if (ext.filter) {
  386. if (typeof ext.filter !== 'function') {
  387. ret.valid = false;
  388. ret.error = baseMsg + '"filter" must be a function, but ' + typeof ext.filter + ' given';
  389. return ret;
  390. }
  391. } else if (ext.regex) {
  392. if (showdown.helper.isString(ext.regex)) {
  393. ext.regex = new RegExp(ext.regex, 'g');
  394. }
  395. if (!ext.regex instanceof RegExp) {
  396. ret.valid = false;
  397. ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' + typeof ext.regex + ' given';
  398. return ret;
  399. }
  400. if (showdown.helper.isUndefined(ext.replace)) {
  401. ret.valid = false;
  402. ret.error = baseMsg + '"regex" extensions must implement a replace string or function';
  403. return ret;
  404. }
  405. }
  406. }
  407. return ret;
  408. }
  409. /**
  410. * Validate extension
  411. * @param {object} ext
  412. * @returns {boolean}
  413. */
  414. showdown.validateExtension = function (ext) {
  415. 'use strict';
  416. var validateExtension = validate(ext, null);
  417. if (!validateExtension.valid) {
  418. console.warn(validateExtension.error);
  419. return false;
  420. }
  421. return true;
  422. };
  423. /**
  424. * showdownjs helper functions
  425. */
  426. if (!showdown.hasOwnProperty('helper')) {
  427. showdown.helper = {};
  428. }
  429. /**
  430. * Check if var is string
  431. * @static
  432. * @param {string} a
  433. * @returns {boolean}
  434. */
  435. showdown.helper.isString = function isString(a) {
  436. 'use strict';
  437. return (typeof a === 'string' || a instanceof String);
  438. };
  439. /**
  440. * Check if var is a function
  441. * @static
  442. * @param {string} a
  443. * @returns {boolean}
  444. */
  445. showdown.helper.isFunction = function isFunction(a) {
  446. 'use strict';
  447. var getType = {};
  448. return a && getType.toString.call(a) === '[object Function]';
  449. };
  450. /**
  451. * ForEach helper function
  452. * @static
  453. * @param {*} obj
  454. * @param {function} callback
  455. */
  456. showdown.helper.forEach = function forEach(obj, callback) {
  457. 'use strict';
  458. if (typeof obj.forEach === 'function') {
  459. obj.forEach(callback);
  460. } else {
  461. for (var i = 0; i < obj.length; i++) {
  462. callback(obj[i], i, obj);
  463. }
  464. }
  465. };
  466. /**
  467. * isArray helper function
  468. * @static
  469. * @param {*} a
  470. * @returns {boolean}
  471. */
  472. showdown.helper.isArray = function isArray(a) {
  473. 'use strict';
  474. return a.constructor === Array;
  475. };
  476. /**
  477. * Check if value is undefined
  478. * @static
  479. * @param {*} value The value to check.
  480. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  481. */
  482. showdown.helper.isUndefined = function isUndefined(value) {
  483. 'use strict';
  484. return typeof value === 'undefined';
  485. };
  486. /**
  487. * Standardidize extension name
  488. * @static
  489. * @param {string} s extension name
  490. * @returns {string}
  491. */
  492. showdown.helper.stdExtName = function (s) {
  493. 'use strict';
  494. return s.replace(/[_-]||\s/g, '').toLowerCase();
  495. };
  496. function escapeCharactersCallback(wholeMatch, m1) {
  497. 'use strict';
  498. var charCodeToEscape = m1.charCodeAt(0);
  499. return '~E' + charCodeToEscape + 'E';
  500. }
  501. /**
  502. * Callback used to escape characters when passing through String.replace
  503. * @static
  504. * @param {string} wholeMatch
  505. * @param {string} m1
  506. * @returns {string}
  507. */
  508. showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
  509. /**
  510. * Escape characters in a string
  511. * @static
  512. * @param {string} text
  513. * @param {string} charsToEscape
  514. * @param {boolean} afterBackslash
  515. * @returns {XML|string|void|*}
  516. */
  517. showdown.helper.escapeCharacters = function escapeCharacters(text, charsToEscape, afterBackslash) {
  518. 'use strict';
  519. // First we have to escape the escape characters so that
  520. // we can build a character class out of them
  521. var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
  522. if (afterBackslash) {
  523. regexString = '\\\\' + regexString;
  524. }
  525. var regex = new RegExp(regexString, 'g');
  526. text = text.replace(regex, escapeCharactersCallback);
  527. return text;
  528. };
  529. var rgxFindMatchPos = function (str, left, right, flags) {
  530. 'use strict';
  531. var f = flags || '',
  532. g = f.indexOf('g') > -1,
  533. x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
  534. l = new RegExp(left, f.replace(/g/g, '')),
  535. pos = [],
  536. t, s, m, start, end;
  537. do {
  538. t = 0;
  539. while ((m = x.exec(str))) {
  540. if (l.test(m[0])) {
  541. if (!(t++)) {
  542. s = x.lastIndex;
  543. start = s - m[0].length;
  544. }
  545. } else if (t) {
  546. if (!--t) {
  547. end = m.index + m[0].length;
  548. var obj = {
  549. left: {start: start, end: s},
  550. match: {start: s, end: m.index},
  551. right: {start: m.index, end: end},
  552. wholeMatch: {start: start, end: end}
  553. };
  554. pos.push(obj);
  555. if (!g) {
  556. return pos;
  557. }
  558. }
  559. }
  560. }
  561. } while (t && (x.lastIndex = s));
  562. return pos;
  563. };
  564. /**
  565. * matchRecursiveRegExp
  566. *
  567. * (c) 2007 Steven Levithan <stevenlevithan.com>
  568. * MIT License
  569. *
  570. * Accepts a string to search, a left and right format delimiter
  571. * as regex patterns, and optional regex flags. Returns an array
  572. * of matches, allowing nested instances of left/right delimiters.
  573. * Use the "g" flag to return all matches, otherwise only the
  574. * first is returned. Be careful to ensure that the left and
  575. * right format delimiters produce mutually exclusive matches.
  576. * Backreferences are not supported within the right delimiter
  577. * due to how it is internally combined with the left delimiter.
  578. * When matching strings whose format delimiters are unbalanced
  579. * to the left or right, the output is intentionally as a
  580. * conventional regex library with recursion support would
  581. * produce, e.g. "<<x>" and "<x>>" both produce ["x"] when using
  582. * "<" and ">" as the delimiters (both strings contain a single,
  583. * balanced instance of "<x>").
  584. *
  585. * examples:
  586. * matchRecursiveRegExp("test", "\\(", "\\)")
  587. * returns: []
  588. * matchRecursiveRegExp("<t<<e>><s>>t<>", "<", ">", "g")
  589. * returns: ["t<<e>><s>", ""]
  590. * matchRecursiveRegExp("<div id=\"x\">test</div>", "<div\\b[^>]*>", "</div>", "gi")
  591. * returns: ["test"]
  592. */
  593. showdown.helper.matchRecursiveRegExp = function (str, left, right, flags) {
  594. 'use strict';
  595. var matchPos = rgxFindMatchPos (str, left, right, flags),
  596. results = [];
  597. for (var i = 0; i < matchPos.length; ++i) {
  598. results.push([
  599. str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
  600. str.slice(matchPos[i].match.start, matchPos[i].match.end),
  601. str.slice(matchPos[i].left.start, matchPos[i].left.end),
  602. str.slice(matchPos[i].right.start, matchPos[i].right.end)
  603. ]);
  604. }
  605. return results;
  606. };
  607. /**
  608. *
  609. * @param {string} str
  610. * @param {string|function} replacement
  611. * @param {string} left
  612. * @param {string} right
  613. * @param {string} flags
  614. * @returns {string}
  615. */
  616. showdown.helper.replaceRecursiveRegExp = function (str, replacement, left, right, flags) {
  617. 'use strict';
  618. if (!showdown.helper.isFunction(replacement)) {
  619. var repStr = replacement;
  620. replacement = function () {
  621. return repStr;
  622. };
  623. }
  624. var matchPos = rgxFindMatchPos(str, left, right, flags),
  625. finalStr = str,
  626. lng = matchPos.length;
  627. if (lng > 0) {
  628. var bits = [];
  629. if (matchPos[0].wholeMatch.start !== 0) {
  630. bits.push(str.slice(0, matchPos[0].wholeMatch.start));
  631. }
  632. for (var i = 0; i < lng; ++i) {
  633. bits.push(
  634. replacement(
  635. str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
  636. str.slice(matchPos[i].match.start, matchPos[i].match.end),
  637. str.slice(matchPos[i].left.start, matchPos[i].left.end),
  638. str.slice(matchPos[i].right.start, matchPos[i].right.end)
  639. )
  640. );
  641. if (i < lng - 1) {
  642. bits.push(str.slice(matchPos[i].wholeMatch.end, matchPos[i + 1].wholeMatch.start));
  643. }
  644. }
  645. if (matchPos[lng - 1].wholeMatch.end < str.length) {
  646. bits.push(str.slice(matchPos[lng - 1].wholeMatch.end));
  647. }
  648. finalStr = bits.join('');
  649. }
  650. return finalStr;
  651. };
  652. /**
  653. * POLYFILLS
  654. */
  655. if (showdown.helper.isUndefined(console)) {
  656. console = {
  657. warn: function (msg) {
  658. 'use strict';
  659. alert(msg);
  660. },
  661. log: function (msg) {
  662. 'use strict';
  663. alert(msg);
  664. },
  665. error: function (msg) {
  666. 'use strict';
  667. throw msg;
  668. }
  669. };
  670. }
  671. /**
  672. * Created by Estevao on 31-05-2015.
  673. */
  674. /**
  675. * Showdown Converter class
  676. * @class
  677. * @param {object} [converterOptions]
  678. * @returns {Converter}
  679. */
  680. showdown.Converter = function (converterOptions) {
  681. 'use strict';
  682. var
  683. /**
  684. * Options used by this converter
  685. * @private
  686. * @type {{}}
  687. */
  688. options = {},
  689. /**
  690. * Language extensions used by this converter
  691. * @private
  692. * @type {Array}
  693. */
  694. langExtensions = [],
  695. /**
  696. * Output modifiers extensions used by this converter
  697. * @private
  698. * @type {Array}
  699. */
  700. outputModifiers = [],
  701. /**
  702. * Event listeners
  703. * @private
  704. * @type {{}}
  705. */
  706. listeners = {};
  707. _constructor();
  708. /**
  709. * Converter constructor
  710. * @private
  711. */
  712. function _constructor() {
  713. converterOptions = converterOptions || {};
  714. for (var gOpt in globalOptions) {
  715. if (globalOptions.hasOwnProperty(gOpt)) {
  716. options[gOpt] = globalOptions[gOpt];
  717. }
  718. }
  719. // Merge options
  720. if (typeof converterOptions === 'object') {
  721. for (var opt in converterOptions) {
  722. if (converterOptions.hasOwnProperty(opt)) {
  723. options[opt] = converterOptions[opt];
  724. }
  725. }
  726. } else {
  727. throw Error('Converter expects the passed parameter to be an object, but ' + typeof converterOptions +
  728. ' was passed instead.');
  729. }
  730. if (options.extensions) {
  731. showdown.helper.forEach(options.extensions, _parseExtension);
  732. }
  733. }
  734. /**
  735. * Parse extension
  736. * @param {*} ext
  737. * @param {string} [name='']
  738. * @private
  739. */
  740. function _parseExtension(ext, name) {
  741. name = name || null;
  742. // If it's a string, the extension was previously loaded
  743. if (showdown.helper.isString(ext)) {
  744. ext = showdown.helper.stdExtName(ext);
  745. name = ext;
  746. // LEGACY_SUPPORT CODE
  747. if (showdown.extensions[ext]) {
  748. console.warn('DEPRECATION WARNING: ' + ext + ' is an old extension that uses a deprecated loading method.' +
  749. 'Please inform the developer that the extension should be updated!');
  750. legacyExtensionLoading(showdown.extensions[ext], ext);
  751. return;
  752. // END LEGACY SUPPORT CODE
  753. } else if (!showdown.helper.isUndefined(extensions[ext])) {
  754. ext = extensions[ext];
  755. } else {
  756. throw Error('Extension "' + ext + '" could not be loaded. It was either not found or is not a valid extension.');
  757. }
  758. }
  759. if (typeof ext === 'function') {
  760. ext = ext();
  761. }
  762. if (!showdown.helper.isArray(ext)) {
  763. ext = [ext];
  764. }
  765. var validExt = validate(ext, name);
  766. if (!validExt.valid) {
  767. throw Error(validExt.error);
  768. }
  769. for (var i = 0; i < ext.length; ++i) {
  770. switch (ext[i].type) {
  771. case 'lang':
  772. langExtensions.push(ext[i]);
  773. break;
  774. case 'output':
  775. outputModifiers.push(ext[i]);
  776. break;
  777. }
  778. if (ext[i].hasOwnProperty('listeners')) {
  779. for (var ln in ext[i].listeners) {
  780. if (ext[i].listeners.hasOwnProperty(ln)) {
  781. listen(ln, ext[i].listeners[ln]);
  782. }
  783. }
  784. }
  785. }
  786. }
  787. /**
  788. * LEGACY_SUPPORT
  789. * @param {*} ext
  790. * @param {string} name
  791. */
  792. function legacyExtensionLoading(ext, name) {
  793. if (typeof ext === 'function') {
  794. ext = ext(new showdown.Converter());
  795. }
  796. if (!showdown.helper.isArray(ext)) {
  797. ext = [ext];
  798. }
  799. var valid = validate(ext, name);
  800. if (!valid.valid) {
  801. throw Error(valid.error);
  802. }
  803. for (var i = 0; i < ext.length; ++i) {
  804. switch (ext[i].type) {
  805. case 'lang':
  806. langExtensions.push(ext[i]);
  807. break;
  808. case 'output':
  809. outputModifiers.push(ext[i]);
  810. break;
  811. default:// should never reach here
  812. throw Error('Extension loader error: Type unrecognized!!!');
  813. }
  814. }
  815. }
  816. /**
  817. * Listen to an event
  818. * @param {string} name
  819. * @param {function} callback
  820. */
  821. function listen(name, callback) {
  822. if (!showdown.helper.isString(name)) {
  823. throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given');
  824. }
  825. if (typeof callback !== 'function') {
  826. throw Error('Invalid argument in converter.listen() method: callback must be a function, but ' + typeof callback + ' given');
  827. }
  828. if (!listeners.hasOwnProperty(name)) {
  829. listeners[name] = [];
  830. }
  831. listeners[name].push(callback);
  832. }
  833. function rTrimInputText(text) {
  834. var rsp = text.match(/^\s*/)[0].length,
  835. rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
  836. return text.replace(rgx, '');
  837. }
  838. /**
  839. * Dispatch an event
  840. * @private
  841. * @param {string} evtName Event name
  842. * @param {string} text Text
  843. * @param {{}} options Converter Options
  844. * @param {{}} globals
  845. * @returns {string}
  846. */
  847. this._dispatch = function dispatch (evtName, text, options, globals) {
  848. if (listeners.hasOwnProperty(evtName)) {
  849. for (var ei = 0; ei < listeners[evtName].length; ++ei) {
  850. var nText = listeners[evtName][ei](evtName, text, this, options, globals);
  851. if (nText && typeof nText !== 'undefined') {
  852. text = nText;
  853. }
  854. }
  855. }
  856. return text;
  857. };
  858. /**
  859. * Listen to an event
  860. * @param {string} name
  861. * @param {function} callback
  862. * @returns {showdown.Converter}
  863. */
  864. this.listen = function (name, callback) {
  865. listen(name, callback);
  866. return this;
  867. };
  868. /**
  869. * Converts a markdown string into HTML
  870. * @param {string} text
  871. * @returns {*}
  872. */
  873. this.makeHtml = function (text) {
  874. //check if text is not falsy
  875. if (!text) {
  876. return text;
  877. }
  878. var globals = {
  879. gHtmlBlocks: [],
  880. gHtmlMdBlocks: [],
  881. gHtmlSpans: [],
  882. gUrls: {},
  883. gTitles: {},
  884. gDimensions: {},
  885. gListLevel: 0,
  886. hashLinkCounts: {},
  887. langExtensions: langExtensions,
  888. outputModifiers: outputModifiers,
  889. converter: this,
  890. ghCodeBlocks: []
  891. };
  892. // attacklab: Replace ~ with ~T
  893. // This lets us use tilde as an escape char to avoid md5 hashes
  894. // The choice of character is arbitrary; anything that isn't
  895. // magic in Markdown will work.
  896. text = text.replace(/~/g, '~T');
  897. // attacklab: Replace $ with ~D
  898. // RegExp interprets $ as a special character
  899. // when it's in a replacement string
  900. text = text.replace(/\$/g, '~D');
  901. // Standardize line endings
  902. text = text.replace(/\r\n/g, '\n'); // DOS to Unix
  903. text = text.replace(/\r/g, '\n'); // Mac to Unix
  904. // Stardardize line spaces (nbsp causes trouble in older browsers and some regex flavors)
  905. text = text.replace(/\u00A0/g, ' ');
  906. if (options.smartIndentationFix) {
  907. text = rTrimInputText(text);
  908. }
  909. // Make sure text begins and ends with a couple of newlines:
  910. text = '\n\n' + text + '\n\n';
  911. // detab
  912. text = showdown.subParser('detab')(text, options, globals);
  913. // stripBlankLines
  914. text = showdown.subParser('stripBlankLines')(text, options, globals);
  915. //run languageExtensions
  916. showdown.helper.forEach(langExtensions, function (ext) {
  917. text = showdown.subParser('runExtension')(ext, text, options, globals);
  918. });
  919. // run the sub parsers
  920. text = showdown.subParser('hashPreCodeTags')(text, options, globals);
  921. text = showdown.subParser('githubCodeBlocks')(text, options, globals);
  922. text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
  923. text = showdown.subParser('hashHTMLSpans')(text, options, globals);
  924. text = showdown.subParser('stripLinkDefinitions')(text, options, globals);
  925. text = showdown.subParser('blockGamut')(text, options, globals);
  926. text = showdown.subParser('unhashHTMLSpans')(text, options, globals);
  927. text = showdown.subParser('unescapeSpecialChars')(text, options, globals);
  928. // attacklab: Restore dollar signs
  929. text = text.replace(/~D/g, '$$');
  930. // attacklab: Restore tildes
  931. text = text.replace(/~T/g, '~');
  932. // Run output modifiers
  933. showdown.helper.forEach(outputModifiers, function (ext) {
  934. text = showdown.subParser('runExtension')(ext, text, options, globals);
  935. });
  936. return text;
  937. };
  938. /**
  939. * Set an option of this Converter instance
  940. * @param {string} key
  941. * @param {*} value
  942. */
  943. this.setOption = function (key, value) {
  944. options[key] = value;
  945. };
  946. /**
  947. * Get the option of this Converter instance
  948. * @param {string} key
  949. * @returns {*}
  950. */
  951. this.getOption = function (key) {
  952. return options[key];
  953. };
  954. /**
  955. * Get the options of this Converter instance
  956. * @returns {{}}
  957. */
  958. this.getOptions = function () {
  959. return options;
  960. };
  961. /**
  962. * Add extension to THIS converter
  963. * @param {{}} extension
  964. * @param {string} [name=null]
  965. */
  966. this.addExtension = function (extension, name) {
  967. name = name || null;
  968. _parseExtension(extension, name);
  969. };
  970. /**
  971. * Use a global registered extension with THIS converter
  972. * @param {string} extensionName Name of the previously registered extension
  973. */
  974. this.useExtension = function (extensionName) {
  975. _parseExtension(extensionName);
  976. };
  977. /**
  978. * Set the flavor THIS converter should use
  979. * @param {string} name
  980. */
  981. this.setFlavor = function (name) {
  982. if (flavor.hasOwnProperty(name)) {
  983. var preset = flavor[name];
  984. for (var option in preset) {
  985. if (preset.hasOwnProperty(option)) {
  986. options[option] = preset[option];
  987. }
  988. }
  989. }
  990. };
  991. /**
  992. * Remove an extension from THIS converter.
  993. * Note: This is a costly operation. It's better to initialize a new converter
  994. * and specify the extensions you wish to use
  995. * @param {Array} extension
  996. */
  997. this.removeExtension = function (extension) {
  998. if (!showdown.helper.isArray(extension)) {
  999. extension = [extension];
  1000. }
  1001. for (var a = 0; a < extension.length; ++a) {
  1002. var ext = extension[a];
  1003. for (var i = 0; i < langExtensions.length; ++i) {
  1004. if (langExtensions[i] === ext) {
  1005. langExtensions[i].splice(i, 1);
  1006. }
  1007. }
  1008. for (var ii = 0; ii < outputModifiers.length; ++i) {
  1009. if (outputModifiers[ii] === ext) {
  1010. outputModifiers[ii].splice(i, 1);
  1011. }
  1012. }
  1013. }
  1014. };
  1015. /**
  1016. * Get all extension of THIS converter
  1017. * @returns {{language: Array, output: Array}}
  1018. */
  1019. this.getAllExtensions = function () {
  1020. return {
  1021. language: langExtensions,
  1022. output: outputModifiers
  1023. };
  1024. };
  1025. };
  1026. /**
  1027. * Turn Markdown link shortcuts into XHTML <a> tags.
  1028. */
  1029. showdown.subParser('anchors', function (text, options, globals) {
  1030. 'use strict';
  1031. text = globals.converter._dispatch('anchors.before', text, options, globals);
  1032. var writeAnchorTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) {
  1033. if (showdown.helper.isUndefined(m7)) {
  1034. m7 = '';
  1035. }
  1036. wholeMatch = m1;
  1037. var linkText = m2,
  1038. linkId = m3.toLowerCase(),
  1039. url = m4,
  1040. title = m7;
  1041. if (!url) {
  1042. if (!linkId) {
  1043. // lower-case and turn embedded newlines into spaces
  1044. linkId = linkText.toLowerCase().replace(/ ?\n/g, ' ');
  1045. }
  1046. url = '#' + linkId;
  1047. if (!showdown.helper.isUndefined(globals.gUrls[linkId])) {
  1048. url = globals.gUrls[linkId];
  1049. if (!showdown.helper.isUndefined(globals.gTitles[linkId])) {
  1050. title = globals.gTitles[linkId];
  1051. }
  1052. } else {
  1053. if (wholeMatch.search(/\(\s*\)$/m) > -1) {
  1054. // Special case for explicit empty url
  1055. url = '';
  1056. } else {
  1057. return wholeMatch;
  1058. }
  1059. }
  1060. }
  1061. url = showdown.helper.escapeCharacters(url, '*_', false);
  1062. var result = '<a href="' + url + '"';
  1063. if (title !== '' && title !== null) {
  1064. title = title.replace(/"/g, '&quot;');
  1065. title = showdown.helper.escapeCharacters(title, '*_', false);
  1066. result += ' title="' + title + '"';
  1067. }
  1068. result += '>' + linkText + '</a>';
  1069. return result;
  1070. };
  1071. // First, handle reference-style links: [link text] [id]
  1072. text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)][ ]?(?:\n[ ]*)?\[(.*?)])()()()()/g, writeAnchorTag);
  1073. // Next, inline-style links: [link text](url "optional title")
  1074. text = text.replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
  1075. writeAnchorTag);
  1076. // Last, handle reference-style shortcuts: [link text]
  1077. // These must come last in case you've also got [link test][1]
  1078. // or [link test](/foo)
  1079. text = text.replace(/(\[([^\[\]]+)])()()()()()/g, writeAnchorTag);
  1080. text = globals.converter._dispatch('anchors.after', text, options, globals);
  1081. return text;
  1082. });
  1083. showdown.subParser('autoLinks', function (text, options, globals) {
  1084. 'use strict';
  1085. text = globals.converter._dispatch('autoLinks.before', text, options, globals);
  1086. var simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)()(?=\s|$)(?!["<>])/gi,
  1087. simpleURLRegex2 = /\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+?)([.!?()]?)(?=\s|$)(?!["<>])/gi,
  1088. delimUrlRegex = /<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,
  1089. simpleMailRegex = /(?:^|\s)([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|\s)/gi,
  1090. delimMailRegex = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
  1091. text = text.replace(delimUrlRegex, replaceLink);
  1092. text = text.replace(delimMailRegex, replaceMail);
  1093. // simpleURLRegex = /\b(((https?|ftp|dict):\/\/|www\.)[-.+~:?#@!$&'()*,;=[\]\w]+)\b/gi,
  1094. // Email addresses: <address@domain.foo>
  1095. if (options.simplifiedAutoLink) {
  1096. if (options.excludeTrailingPunctuationFromURLs) {
  1097. text = text.replace(simpleURLRegex2, replaceLink);
  1098. } else {
  1099. text = text.replace(simpleURLRegex, replaceLink);
  1100. }
  1101. text = text.replace(simpleMailRegex, replaceMail);
  1102. }
  1103. function replaceLink(wm, link, m2, m3, trailingPunctuation) {
  1104. var lnkTxt = link,
  1105. append = '';
  1106. if (/^www\./i.test(link)) {
  1107. link = link.replace(/^www\./i, 'http://www.');
  1108. }
  1109. if (options.excludeTrailingPunctuationFromURLs && trailingPunctuation) {
  1110. append = trailingPunctuation;
  1111. }
  1112. return '<a href="' + link + '">' + lnkTxt + '</a>' + append;
  1113. }
  1114. function replaceMail(wholeMatch, mail) {
  1115. var unescapedStr = showdown.subParser('unescapeSpecialChars')(mail);
  1116. return showdown.subParser('encodeEmailAddress')(unescapedStr);
  1117. }
  1118. text = globals.converter._dispatch('autoLinks.after', text, options, globals);
  1119. return text;
  1120. });
  1121. /**
  1122. * These are all the transformations that form block-level
  1123. * tags like paragraphs, headers, and list items.
  1124. */
  1125. showdown.subParser('blockGamut', function (text, options, globals) {
  1126. 'use strict';
  1127. text = globals.converter._dispatch('blockGamut.before', text, options, globals);
  1128. // we parse blockquotes first so that we can have headings and hrs
  1129. // inside blockquotes
  1130. text = showdown.subParser('blockQuotes')(text, options, globals);
  1131. text = showdown.subParser('headers')(text, options, globals);
  1132. // Do Horizontal Rules:
  1133. var key = showdown.subParser('hashBlock')('<hr />', options, globals);
  1134. text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
  1135. text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
  1136. text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
  1137. text = showdown.subParser('lists')(text, options, globals);
  1138. text = showdown.subParser('codeBlocks')(text, options, globals);
  1139. text = showdown.subParser('tables')(text, options, globals);
  1140. // We already ran _HashHTMLBlocks() before, in Markdown(), but that
  1141. // was to escape raw HTML in the original Markdown source. This time,
  1142. // we're escaping the markup we've just created, so that we don't wrap
  1143. // <p> tags around block-level tags.
  1144. text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
  1145. text = showdown.subParser('paragraphs')(text, options, globals);
  1146. text = globals.converter._dispatch('blockGamut.after', text, options, globals);
  1147. return text;
  1148. });
  1149. showdown.subParser('blockQuotes', function (text, options, globals) {
  1150. 'use strict';
  1151. text = globals.converter._dispatch('blockQuotes.before', text, options, globals);
  1152. text = text.replace(/((^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) {
  1153. var bq = m1;
  1154. // attacklab: hack around Konqueror 3.5.4 bug:
  1155. // "----------bug".replace(/^-/g,"") == "bug"
  1156. bq = bq.replace(/^[ \t]*>[ \t]?/gm, '~0'); // trim one level of quoting
  1157. // attacklab: clean up hack
  1158. bq = bq.replace(/~0/g, '');
  1159. bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines
  1160. bq = showdown.subParser('githubCodeBlocks')(bq, options, globals);
  1161. bq = showdown.subParser('blockGamut')(bq, options, globals); // recurse
  1162. bq = bq.replace(/(^|\n)/g, '$1 ');
  1163. // These leading spaces screw with <pre> content, so we need to fix that:
  1164. bq = bq.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm, function (wholeMatch, m1) {
  1165. var pre = m1;
  1166. // attacklab: hack around Konqueror 3.5.4 bug:
  1167. pre = pre.replace(/^ /mg, '~0');
  1168. pre = pre.replace(/~0/g, '');
  1169. return pre;
  1170. });
  1171. return showdown.subParser('hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals);
  1172. });
  1173. text = globals.converter._dispatch('blockQuotes.after', text, options, globals);
  1174. return text;
  1175. });
  1176. /**
  1177. * Process Markdown `<pre><code>` blocks.
  1178. */
  1179. showdown.subParser('codeBlocks', function (text, options, globals) {
  1180. 'use strict';
  1181. text = globals.converter._dispatch('codeBlocks.before', text, options, globals);
  1182. // sentinel workarounds for lack of \A and \Z, safari\khtml bug
  1183. text += '~0';
  1184. var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g;
  1185. text = text.replace(pattern, function (wholeMatch, m1, m2) {
  1186. var codeblock = m1,
  1187. nextChar = m2,
  1188. end = '\n';
  1189. codeblock = showdown.subParser('outdent')(codeblock);
  1190. codeblock = showdown.subParser('encodeCode')(codeblock);
  1191. codeblock = showdown.subParser('detab')(codeblock);
  1192. codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
  1193. codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
  1194. if (options.omitExtraWLInCodeBlocks) {
  1195. end = '';
  1196. }
  1197. codeblock = '<pre><code>' + codeblock + end + '</code></pre>';
  1198. return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
  1199. });
  1200. // strip sentinel
  1201. text = text.replace(/~0/, '');
  1202. text = globals.converter._dispatch('codeBlocks.after', text, options, globals);
  1203. return text;
  1204. });
  1205. /**
  1206. *
  1207. * * Backtick quotes are used for <code></code> spans.
  1208. *
  1209. * * You can use multiple backticks as the delimiters if you want to
  1210. * include literal backticks in the code span. So, this input:
  1211. *
  1212. * Just type ``foo `bar` baz`` at the prompt.
  1213. *
  1214. * Will translate to:
  1215. *
  1216. * <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
  1217. *
  1218. * There's no arbitrary limit to the number of backticks you
  1219. * can use as delimters. If you need three consecutive backticks
  1220. * in your code, use four for delimiters, etc.
  1221. *
  1222. * * You can use spaces to get literal backticks at the edges:
  1223. *
  1224. * ... type `` `bar` `` ...
  1225. *
  1226. * Turns to:
  1227. *
  1228. * ... type <code>`bar`</code> ...
  1229. */
  1230. showdown.subParser('codeSpans', function (text, options, globals) {
  1231. 'use strict';
  1232. text = globals.converter._dispatch('codeSpans.before', text, options, globals);
  1233. /*
  1234. text = text.replace(/
  1235. (^|[^\\]) // Character before opening ` can't be a backslash
  1236. (`+) // $2 = Opening run of `
  1237. ( // $3 = The code block
  1238. [^\r]*?
  1239. [^`] // attacklab: work around lack of lookbehind
  1240. )
  1241. \2 // Matching closer
  1242. (?!`)
  1243. /gm, function(){...});
  1244. */
  1245. if (typeof(text) === 'undefined') {
  1246. text = '';
  1247. }
  1248. text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
  1249. function (wholeMatch, m1, m2, m3) {
  1250. var c = m3;
  1251. c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
  1252. c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
  1253. c = showdown.subParser('encodeCode')(c);
  1254. return m1 + '<code>' + c + '</code>';
  1255. }
  1256. );
  1257. text = globals.converter._dispatch('codeSpans.after', text, options, globals);
  1258. return text;
  1259. });
  1260. /**
  1261. * Convert all tabs to spaces
  1262. */
  1263. showdown.subParser('detab', function (text) {
  1264. 'use strict';
  1265. // expand first n-1 tabs
  1266. text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
  1267. // replace the nth with two sentinels
  1268. text = text.replace(/\t/g, '~A~B');
  1269. // use the sentinel to anchor our regex so it doesn't explode
  1270. text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1) {
  1271. var leadingText = m1,
  1272. numSpaces = 4 - leadingText.length % 4; // g_tab_width
  1273. // there *must* be a better way to do this:
  1274. for (var i = 0; i < numSpaces; i++) {
  1275. leadingText += ' ';
  1276. }
  1277. return leadingText;
  1278. });
  1279. // clean up sentinels
  1280. text = text.replace(/~A/g, ' '); // g_tab_width
  1281. text = text.replace(/~B/g, '');
  1282. return text;
  1283. });
  1284. /**
  1285. * Smart processing for ampersands and angle brackets that need to be encoded.
  1286. */
  1287. showdown.subParser('encodeAmpsAndAngles', function (text) {
  1288. 'use strict';
  1289. // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
  1290. // http://bumppo.net/projects/amputator/
  1291. text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&amp;');
  1292. // Encode naked <'s
  1293. text = text.replace(/<(?![a-z\/?\$!])/gi, '&lt;');
  1294. return text;
  1295. });
  1296. /**
  1297. * Returns the string, with after processing the following backslash escape sequences.
  1298. *
  1299. * attacklab: The polite way to do this is with the new escapeCharacters() function:
  1300. *
  1301. * text = escapeCharacters(text,"\\",true);
  1302. * text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
  1303. *
  1304. * ...but we're sidestepping its use of the (slow) RegExp constructor
  1305. * as an optimization for Firefox. This function gets called a LOT.
  1306. */
  1307. showdown.subParser('encodeBackslashEscapes', function (text) {
  1308. 'use strict';
  1309. text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
  1310. text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, showdown.helper.escapeCharactersCallback);
  1311. return text;
  1312. });
  1313. /**
  1314. * Encode/escape certain characters inside Markdown code runs.
  1315. * The point is that in code, these characters are literals,
  1316. * and lose their special Markdown meanings.
  1317. */
  1318. showdown.subParser('encodeCode', function (text) {
  1319. 'use strict';
  1320. // Encode all ampersands; HTML entities are not
  1321. // entities within a Markdown code span.
  1322. text = text.replace(/&/g, '&amp;');
  1323. // Do the angle bracket song and dance:
  1324. text = text.replace(/</g, '&lt;');
  1325. text = text.replace(/>/g, '&gt;');
  1326. // Now, escape characters that are magic in Markdown:
  1327. text = showdown.helper.escapeCharacters(text, '*_{}[]\\', false);
  1328. // jj the line above breaks this:
  1329. //---
  1330. //* Item
  1331. // 1. Subitem
  1332. // special char: *
  1333. // ---
  1334. return text;
  1335. });
  1336. /**
  1337. * Input: an email address, e.g. "foo@example.com"
  1338. *
  1339. * Output: the email address as a mailto link, with each character
  1340. * of the address encoded as either a decimal or hex entity, in
  1341. * the hopes of foiling most address harvesting spam bots. E.g.:
  1342. *
  1343. * <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
  1344. * x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
  1345. * &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
  1346. *
  1347. * Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
  1348. * mailing list: <http://tinyurl.com/yu7ue>
  1349. *
  1350. */
  1351. showdown.subParser('encodeEmailAddress', function (addr) {
  1352. 'use strict';
  1353. var encode = [
  1354. function (ch) {
  1355. return '&#' + ch.charCodeAt(0) + ';';
  1356. },
  1357. function (ch) {
  1358. return '&#x' + ch.charCodeAt(0).toString(16) + ';';
  1359. },
  1360. function (ch) {
  1361. return ch;
  1362. }
  1363. ];
  1364. addr = 'mailto:' + addr;
  1365. addr = addr.replace(/./g, function (ch) {
  1366. if (ch === '@') {
  1367. // this *must* be encoded. I insist.
  1368. ch = encode[Math.floor(Math.random() * 2)](ch);
  1369. } else if (ch !== ':') {
  1370. // leave ':' alone (to spot mailto: later)
  1371. var r = Math.random();
  1372. // roughly 10% raw, 45% hex, 45% dec
  1373. ch = (
  1374. r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch)
  1375. );
  1376. }
  1377. return ch;
  1378. });
  1379. addr = '<a href="' + addr + '">' + addr + '</a>';
  1380. addr = addr.replace(/">.+:/g, '">'); // strip the mailto: from the visible part
  1381. return addr;
  1382. });
  1383. /**
  1384. * Within tags -- meaning between < and > -- encode [\ ` * _] so they
  1385. * don't conflict with their use in Markdown for code, italics and strong.
  1386. */
  1387. showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
  1388. 'use strict';
  1389. // Build a regex to find HTML tags and comments. See Friedl's
  1390. // "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
  1391. var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
  1392. text = text.replace(regex, function (wholeMatch) {
  1393. var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g, '$1`');
  1394. tag = showdown.helper.escapeCharacters(tag, '\\`*_', false);
  1395. return tag;
  1396. });
  1397. return text;
  1398. });
  1399. /**
  1400. * Handle github codeblocks prior to running HashHTML so that
  1401. * HTML contained within the codeblock gets escaped properly
  1402. * Example:
  1403. * ```ruby
  1404. * def hello_world(x)
  1405. * puts "Hello, #{x}"
  1406. * end
  1407. * ```
  1408. */
  1409. showdown.subParser('githubCodeBlocks', function (text, options, globals) {
  1410. 'use strict';
  1411. // early exit if option is not enabled
  1412. if (!options.ghCodeBlocks) {
  1413. return text;
  1414. }
  1415. text = globals.converter._dispatch('githubCodeBlocks.before', text, options, globals);
  1416. text += '~0';
  1417. text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, language, codeblock) {
  1418. var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
  1419. // First parse the github code block
  1420. codeblock = showdown.subParser('encodeCode')(codeblock);
  1421. codeblock = showdown.subParser('detab')(codeblock);
  1422. codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
  1423. codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
  1424. codeblock = '<pre><code' + (language ? ' class="' + language + ' language-' + language + '"' : '') + '>' + codeblock + end + '</code></pre>';
  1425. codeblock = showdown.subParser('hashBlock')(codeblock, options, globals);
  1426. // Since GHCodeblocks can be false positives, we need to
  1427. // store the primitive text and the parsed text in a global var,
  1428. // and then return a token
  1429. return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
  1430. });
  1431. // attacklab: strip sentinel
  1432. text = text.replace(/~0/, '');
  1433. return globals.converter._dispatch('githubCodeBlocks.after', text, options, globals);
  1434. });
  1435. showdown.subParser('hashBlock', function (text, options, globals) {
  1436. 'use strict';
  1437. text = text.replace(/(^\n+|\n+$)/g, '');
  1438. return '\n\n~K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
  1439. });
  1440. showdown.subParser('hashElement', function (text, options, globals) {
  1441. 'use strict';
  1442. return function (wholeMatch, m1) {
  1443. var blockText = m1;
  1444. // Undo double lines
  1445. blockText = blockText.replace(/\n\n/g, '\n');
  1446. blockText = blockText.replace(/^\n/, '');
  1447. // strip trailing blank lines
  1448. blockText = blockText.replace(/\n+$/g, '');
  1449. // Replace the element text with a marker ("~KxK" where x is its key)
  1450. blockText = '\n\n~K' + (globals.gHtmlBlocks.push(blockText) - 1) + 'K\n\n';
  1451. return blockText;
  1452. };
  1453. });
  1454. showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
  1455. 'use strict';
  1456. var blockTags = [
  1457. 'pre',
  1458. 'div',
  1459. 'h1',
  1460. 'h2',
  1461. 'h3',
  1462. 'h4',
  1463. 'h5',
  1464. 'h6',
  1465. 'blockquote',
  1466. 'table',
  1467. 'dl',
  1468. 'ol',
  1469. 'ul',
  1470. 'script',
  1471. 'noscript',
  1472. 'form',
  1473. 'fieldset',
  1474. 'iframe',
  1475. 'math',
  1476. 'style',
  1477. 'section',
  1478. 'header',
  1479. 'footer',
  1480. 'nav',
  1481. 'article',
  1482. 'aside',
  1483. 'address',
  1484. 'audio',
  1485. 'canvas',
  1486. 'figure',
  1487. 'hgroup',
  1488. 'output',
  1489. 'video',
  1490. 'p'
  1491. ],
  1492. repFunc = function (wholeMatch, match, left, right) {
  1493. var txt = wholeMatch;
  1494. // check if this html element is marked as markdown
  1495. // if so, it's contents should be parsed as markdown
  1496. if (left.search(/\bmarkdown\b/) !== -1) {
  1497. txt = left + globals.converter.makeHtml(match) + right;
  1498. }
  1499. return '\n\n~K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
  1500. };
  1501. for (var i = 0; i < blockTags.length; ++i) {
  1502. text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<' + blockTags[i] + '\\b[^>]*>', '</' + blockTags[i] + '>', 'gim');
  1503. }
  1504. // HR SPECIAL CASE
  1505. text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
  1506. showdown.subParser('hashElement')(text, options, globals));
  1507. // Special case for standalone HTML comments
  1508. text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
  1509. return '\n\n~K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
  1510. }, '^ {0,3}<!--', '-->', 'gm');
  1511. // PHP and ASP-style processor instructions (<?...?> and <%...%>)
  1512. text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
  1513. showdown.subParser('hashElement')(text, options, globals));
  1514. return text;
  1515. });
  1516. /**
  1517. * Hash span elements that should not be parsed as markdown
  1518. */
  1519. showdown.subParser('hashHTMLSpans', function (text, config, globals) {
  1520. 'use strict';
  1521. var matches = showdown.helper.matchRecursiveRegExp(text, '<code\\b[^>]*>', '</code>', 'gi');
  1522. for (var i = 0; i < matches.length; ++i) {
  1523. text = text.replace(matches[i][0], '~C' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'C');
  1524. }
  1525. return text;
  1526. });
  1527. /**
  1528. * Unhash HTML spans
  1529. */
  1530. showdown.subParser('unhashHTMLSpans', function (text, config, globals) {
  1531. 'use strict';
  1532. for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
  1533. text = text.replace('~C' + i + 'C', globals.gHtmlSpans[i]);
  1534. }
  1535. return text;
  1536. });
  1537. /**
  1538. * Hash span elements that should not be parsed as markdown
  1539. */
  1540. showdown.subParser('hashPreCodeTags', function (text, config, globals) {
  1541. 'use strict';
  1542. var repFunc = function (wholeMatch, match, left, right) {
  1543. // encode html entities
  1544. var codeblock = left + showdown.subParser('encodeCode')(match) + right;
  1545. return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
  1546. };
  1547. text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<pre\\b[^>]*>\\s*<code\\b[^>]*>', '^ {0,3}</code>\\s*</pre>', 'gim');
  1548. return text;
  1549. });
  1550. showdown.subParser('headers', function (text, options, globals) {
  1551. 'use strict';
  1552. text = globals.converter._dispatch('headers.before', text, options, globals);
  1553. var prefixHeader = options.prefixHeaderId,
  1554. headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
  1555. ghHeaderId = options.ghCompatibleHeaderId,
  1556. // Set text-style headers:
  1557. // Header 1
  1558. // ========
  1559. //
  1560. // Header 2
  1561. // --------
  1562. //
  1563. setextRegexH1 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n={2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n=+[ \t]*\n+/gm,
  1564. setextRegexH2 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n-+[ \t]*\n+/gm;
  1565. text = text.replace(setextRegexH1, function (wholeMatch, m1) {
  1566. var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
  1567. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
  1568. hLevel = headerLevelStart,
  1569. hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
  1570. return showdown.subParser('hashBlock')(hashBlock, options, globals);
  1571. });
  1572. text = text.replace(setextRegexH2, function (matchFound, m1) {
  1573. var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
  1574. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
  1575. hLevel = headerLevelStart + 1,
  1576. hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
  1577. return showdown.subParser('hashBlock')(hashBlock, options, globals);
  1578. });
  1579. // atx-style headers:
  1580. // # Header 1
  1581. // ## Header 2
  1582. // ## Header 2 with closing hashes ##
  1583. // ...
  1584. // ###### Header 6
  1585. //
  1586. var atxStyle = (options.requireSpaceBeforeHeadingText) ? /^(#{1,6})[ \t]+(.+?)[ \t]*#*\n+/gm : /^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm;
  1587. text = text.replace(atxStyle, function (wholeMatch, m1, m2) {
  1588. var span = showdown.subParser('spanGamut')(m2, options, globals),
  1589. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
  1590. hLevel = headerLevelStart - 1 + m1.length,
  1591. header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
  1592. return showdown.subParser('hashBlock')(header, options, globals);
  1593. });
  1594. function headerId(m) {
  1595. var title, escapedId;
  1596. if (ghHeaderId) {
  1597. escapedId = m
  1598. .replace(/ /g, '-')
  1599. //replace previously escaped chars (&, ~ and $)
  1600. .replace(/&amp;/g, '')
  1601. .replace(/~T/g, '')
  1602. .replace(/~D/g, '')
  1603. //replace rest of the chars (&~$ are repeated as they might have been escaped)
  1604. .replace(/[&~$!@#*()=:/,;?+'.%\\]/g, '')
  1605. .toLowerCase();
  1606. } else {
  1607. escapedId = m.replace(/[^\w]/g, '').toLowerCase();
  1608. }
  1609. if (globals.hashLinkCounts[escapedId]) {
  1610. title = escapedId + '-' + (globals.hashLinkCounts[escapedId]++);
  1611. } else {
  1612. title = escapedId;
  1613. globals.hashLinkCounts[escapedId] = 1;
  1614. }
  1615. // Prefix id to prevent causing inadvertent pre-existing style matches.
  1616. if (prefixHeader === true) {
  1617. prefixHeader = 'section';
  1618. }
  1619. if (showdown.helper.isString(prefixHeader)) {
  1620. return prefixHeader + title;
  1621. }
  1622. return title;
  1623. }
  1624. text = globals.converter._dispatch('headers.after', text, options, globals);
  1625. return text;
  1626. });
  1627. /**
  1628. * Turn Markdown image shortcuts into <img> tags.
  1629. */
  1630. showdown.subParser('images', function (text, options, globals) {
  1631. 'use strict';
  1632. text = globals.converter._dispatch('images.before', text, options, globals);
  1633. var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
  1634. referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g;
  1635. function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
  1636. var gUrls = globals.gUrls,
  1637. gTitles = globals.gTitles,
  1638. gDims = globals.gDimensions;
  1639. linkId = linkId.toLowerCase();
  1640. if (!title) {
  1641. title = '';
  1642. }
  1643. if (url === '' || url === null) {
  1644. if (linkId === '' || linkId === null) {
  1645. // lower-case and turn embedded newlines into spaces
  1646. linkId = altText.toLowerCase().replace(/ ?\n/g, ' ');
  1647. }
  1648. url = '#' + linkId;
  1649. if (!showdown.helper.isUndefined(gUrls[linkId])) {
  1650. url = gUrls[linkId];
  1651. if (!showdown.helper.isUndefined(gTitles[linkId])) {
  1652. title = gTitles[linkId];
  1653. }
  1654. if (!showdown.helper.isUndefined(gDims[linkId])) {
  1655. width = gDims[linkId].width;
  1656. height = gDims[linkId].height;
  1657. }
  1658. } else {
  1659. return wholeMatch;
  1660. }
  1661. }
  1662. altText = altText.replace(/"/g, '&quot;');
  1663. altText = showdown.helper.escapeCharacters(altText, '*_', false);
  1664. url = showdown.helper.escapeCharacters(url, '*_', false);
  1665. var result = '<img src="' + url + '" alt="' + altText + '"';
  1666. if (title) {
  1667. title = title.replace(/"/g, '&quot;');
  1668. title = showdown.helper.escapeCharacters(title, '*_', false);
  1669. result += ' title="' + title + '"';
  1670. }
  1671. if (width && height) {
  1672. width = (width === '*') ? 'auto' : width;
  1673. height = (height === '*') ? 'auto' : height;
  1674. result += ' width="' + width + '"';
  1675. result += ' height="' + height + '"';
  1676. }
  1677. result += ' />';
  1678. return result;
  1679. }
  1680. // First, handle reference-style labeled images: ![alt text][id]
  1681. text = text.replace(referenceRegExp, writeImageTag);
  1682. // Next, handle inline images: ![alt text](url =<width>x<height> "optional title")
  1683. text = text.replace(inlineRegExp, writeImageTag);
  1684. text = globals.converter._dispatch('images.after', text, options, globals);
  1685. return text;
  1686. });
  1687. showdown.subParser('italicsAndBold', function (text, options, globals) {
  1688. 'use strict';
  1689. text = globals.converter._dispatch('italicsAndBold.before', text, options, globals);
  1690. if (options.literalMidWordUnderscores) {
  1691. //underscores
  1692. // Since we are consuming a \s character, we need to add it
  1693. text = text.replace(/(^|\s|>|\b)__(?=\S)([\s\S]+?)__(?=\b|<|\s|$)/gm, '$1<strong>$2</strong>');
  1694. text = text.replace(/(^|\s|>|\b)_(?=\S)([\s\S]+?)_(?=\b|<|\s|$)/gm, '$1<em>$2</em>');
  1695. //asterisks
  1696. text = text.replace(/(\*\*)(?=\S)([^\r]*?\S[*]*)\1/g, '<strong>$2</strong>');
  1697. text = text.replace(/(\*)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
  1698. } else {
  1699. // <strong> must go first:
  1700. text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, '<strong>$2</strong>');
  1701. text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
  1702. }
  1703. text = globals.converter._dispatch('italicsAndBold.after', text, options, globals);
  1704. return text;
  1705. });
  1706. /**
  1707. * Form HTML ordered (numbered) and unordered (bulleted) lists.
  1708. */
  1709. showdown.subParser('lists', function (text, options, globals) {
  1710. 'use strict';
  1711. text = globals.converter._dispatch('lists.before', text, options, globals);
  1712. /**
  1713. * Process the contents of a single ordered or unordered list, splitting it
  1714. * into individual list items.
  1715. * @param {string} listStr
  1716. * @param {boolean} trimTrailing
  1717. * @returns {string}
  1718. */
  1719. function processListItems (listStr, trimTrailing) {
  1720. // The $g_list_level global keeps track of when we're inside a list.
  1721. // Each time we enter a list, we increment it; when we leave a list,
  1722. // we decrement. If it's zero, we're not in a list anymore.
  1723. //
  1724. // We do this because when we're not inside a list, we want to treat
  1725. // something like this:
  1726. //
  1727. // I recommend upgrading to version
  1728. // 8. Oops, now this line is treated
  1729. // as a sub-list.
  1730. //
  1731. // As a single paragraph, despite the fact that the second line starts
  1732. // with a digit-period-space sequence.
  1733. //
  1734. // Whereas when we're inside a list (or sub-list), that line will be
  1735. // treated as the start of a sub-list. What a kludge, huh? This is
  1736. // an aspect of Markdown's syntax that's hard to parse perfectly
  1737. // without resorting to mind-reading. Perhaps the solution is to
  1738. // change the syntax rules such that sub-lists must start with a
  1739. // starting cardinal number; e.g. "1." or "a.".
  1740. globals.gListLevel++;
  1741. // trim trailing blank lines:
  1742. listStr = listStr.replace(/\n{2,}$/, '\n');
  1743. // attacklab: add sentinel to emulate \z
  1744. listStr += '~0';
  1745. var rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0| {0,3}([*+-]|\d+[.])[ \t]+))/gm,
  1746. isParagraphed = (/\n[ \t]*\n(?!~0)/.test(listStr));
  1747. // Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation,
  1748. // which is a syntax breaking change
  1749. // activating this option reverts to old behavior
  1750. if (options.disableForced4SpacesIndentedSublists) {
  1751. rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm;
  1752. }
  1753. listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) {
  1754. checked = (checked && checked.trim() !== '');
  1755. var item = showdown.subParser('outdent')(m4, options, globals),
  1756. bulletStyle = '';
  1757. // Support for github tasklists
  1758. if (taskbtn && options.tasklists) {
  1759. bulletStyle = ' class="task-list-item" style="list-style-type: none;"';
  1760. item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () {
  1761. var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"';
  1762. if (checked) {
  1763. otp += ' checked';
  1764. }
  1765. otp += '>';
  1766. return otp;
  1767. });
  1768. }
  1769. // ISSUE #312
  1770. // This input: - - - a
  1771. // causes trouble to the parser, since it interprets it as:
  1772. // <ul><li><li><li>a</li></li></li></ul>
  1773. // instead of:
  1774. // <ul><li>- - a</li></ul>
  1775. // So, to prevent it, we will put a marker (~A)in the beginning of the line
  1776. // Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser
  1777. item = item.replace(/^([-*+]|\d\.)[ \t]+[\S\n ]*/g, function (wm2) {
  1778. return '~A' + wm2;
  1779. });
  1780. // m1 - Leading line or
  1781. // Has a double return (multi paragraph) or
  1782. // Has sublist
  1783. if (m1 || (item.search(/\n{2,}/) > -1)) {
  1784. item = showdown.subParser('githubCodeBlocks')(item, options, globals);
  1785. item = showdown.subParser('blockGamut')(item, options, globals);
  1786. } else {
  1787. // Recursion for sub-lists:
  1788. item = showdown.subParser('lists')(item, options, globals);
  1789. item = item.replace(/\n$/, ''); // chomp(item)
  1790. item = showdown.subParser('hashHTMLBlocks')(item, options, globals);
  1791. item = item.replace(/\n\n+/g, '\n\n');
  1792. if (isParagraphed) {
  1793. item = showdown.subParser('paragraphs')(item, options, globals);
  1794. } else {
  1795. item = showdown.subParser('spanGamut')(item, options, globals);
  1796. }
  1797. }
  1798. // now we need to remove the marker (~A)
  1799. item = item.replace('~A', '');
  1800. // we can finally wrap the line in list item tags
  1801. item = '<li' + bulletStyle + '>' + item + '</li>\n';
  1802. return item;
  1803. });
  1804. // attacklab: strip sentinel
  1805. listStr = listStr.replace(/~0/g, '');
  1806. globals.gListLevel--;
  1807. if (trimTrailing) {
  1808. listStr = listStr.replace(/\s+$/, '');
  1809. }
  1810. return listStr;
  1811. }
  1812. /**
  1813. * Check and parse consecutive lists (better fix for issue #142)
  1814. * @param {string} list
  1815. * @param {string} listType
  1816. * @param {boolean} trimTrailing
  1817. * @returns {string}
  1818. */
  1819. function parseConsecutiveLists(list, listType, trimTrailing) {
  1820. // check if we caught 2 or more consecutive lists by mistake
  1821. // we use the counterRgx, meaning if listType is UL we look for OL and vice versa
  1822. var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
  1823. ulRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?[*+-][ \t]/gm : /^ {0,3}[*+-][ \t]/gm,
  1824. counterRxg = (listType === 'ul') ? olRgx : ulRgx,
  1825. result = '';
  1826. if (list.search(counterRxg) !== -1) {
  1827. (function parseCL(txt) {
  1828. var pos = txt.search(counterRxg);
  1829. if (pos !== -1) {
  1830. // slice
  1831. result += '\n<' + listType + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
  1832. // invert counterType and listType
  1833. listType = (listType === 'ul') ? 'ol' : 'ul';
  1834. counterRxg = (listType === 'ul') ? olRgx : ulRgx;
  1835. //recurse
  1836. parseCL(txt.slice(pos));
  1837. } else {
  1838. result += '\n<' + listType + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
  1839. }
  1840. })(list);
  1841. } else {
  1842. result = '\n<' + listType + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
  1843. }
  1844. return result;
  1845. }
  1846. // add sentinel to hack around khtml/safari bug:
  1847. // http://bugs.webkit.org/show_bug.cgi?id=11231
  1848. text += '~0';
  1849. if (globals.gListLevel) {
  1850. text = text.replace(/^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,
  1851. function (wholeMatch, list, m2) {
  1852. var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
  1853. return parseConsecutiveLists(list, listType, true);
  1854. }
  1855. );
  1856. } else {
  1857. text = text.replace(/(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,
  1858. function (wholeMatch, m1, list, m3) {
  1859. var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
  1860. return parseConsecutiveLists(list, listType, false);
  1861. }
  1862. );
  1863. }
  1864. // strip sentinel
  1865. text = text.replace(/~0/, '');
  1866. text = globals.converter._dispatch('lists.after', text, options, globals);
  1867. return text;
  1868. });
  1869. /**
  1870. * Remove one level of line-leading tabs or spaces
  1871. */
  1872. showdown.subParser('outdent', function (text) {
  1873. 'use strict';
  1874. // attacklab: hack around Konqueror 3.5.4 bug:
  1875. // "----------bug".replace(/^-/g,"") == "bug"
  1876. text = text.replace(/^(\t|[ ]{1,4})/gm, '~0'); // attacklab: g_tab_width
  1877. // attacklab: clean up hack
  1878. text = text.replace(/~0/g, '');
  1879. return text;
  1880. });
  1881. /**
  1882. *
  1883. */
  1884. showdown.subParser('paragraphs', function (text, options, globals) {
  1885. 'use strict';
  1886. text = globals.converter._dispatch('paragraphs.before', text, options, globals);
  1887. // Strip leading and trailing lines:
  1888. text = text.replace(/^\n+/g, '');
  1889. text = text.replace(/\n+$/g, '');
  1890. var grafs = text.split(/\n{2,}/g),
  1891. grafsOut = [],
  1892. end = grafs.length; // Wrap <p> tags
  1893. for (var i = 0; i < end; i++) {
  1894. var str = grafs[i];
  1895. // if this is an HTML marker, copy it
  1896. if (str.search(/~(K|G)(\d+)\1/g) >= 0) {
  1897. grafsOut.push(str);
  1898. } else {
  1899. str = showdown.subParser('spanGamut')(str, options, globals);
  1900. str = str.replace(/^([ \t]*)/g, '<p>');
  1901. str += '</p>';
  1902. grafsOut.push(str);
  1903. }
  1904. }
  1905. /** Unhashify HTML blocks */
  1906. end = grafsOut.length;
  1907. for (i = 0; i < end; i++) {
  1908. var blockText = '',
  1909. grafsOutIt = grafsOut[i],
  1910. codeFlag = false;
  1911. // if this is a marker for an html block...
  1912. while (grafsOutIt.search(/~(K|G)(\d+)\1/) >= 0) {
  1913. var delim = RegExp.$1,
  1914. num = RegExp.$2;
  1915. if (delim === 'K') {
  1916. blockText = globals.gHtmlBlocks[num];
  1917. } else {
  1918. // we need to check if ghBlock is a false positive
  1919. if (codeFlag) {
  1920. // use encoded version of all text
  1921. blockText = showdown.subParser('encodeCode')(globals.ghCodeBlocks[num].text);
  1922. } else {
  1923. blockText = globals.ghCodeBlocks[num].codeblock;
  1924. }
  1925. }
  1926. blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
  1927. grafsOutIt = grafsOutIt.replace(/(\n\n)?~(K|G)\d+\2(\n\n)?/, blockText);
  1928. // Check if grafsOutIt is a pre->code
  1929. if (/^<pre\b[^>]*>\s*<code\b[^>]*>/.test(grafsOutIt)) {
  1930. codeFlag = true;
  1931. }
  1932. }
  1933. grafsOut[i] = grafsOutIt;
  1934. }
  1935. text = grafsOut.join('\n');
  1936. // Strip leading and trailing lines:
  1937. text = text.replace(/^\n+/g, '');
  1938. text = text.replace(/\n+$/g, '');
  1939. return globals.converter._dispatch('paragraphs.after', text, options, globals);
  1940. });
  1941. /**
  1942. * Run extension
  1943. */
  1944. showdown.subParser('runExtension', function (ext, text, options, globals) {
  1945. 'use strict';
  1946. if (ext.filter) {
  1947. text = ext.filter(text, globals.converter, options);
  1948. } else if (ext.regex) {
  1949. // TODO remove this when old extension loading mechanism is deprecated
  1950. var re = ext.regex;
  1951. if (!re instanceof RegExp) {
  1952. re = new RegExp(re, 'g');
  1953. }
  1954. text = text.replace(re, ext.replace);
  1955. }
  1956. return text;
  1957. });
  1958. /**
  1959. * These are all the transformations that occur *within* block-level
  1960. * tags like paragraphs, headers, and list items.
  1961. */
  1962. showdown.subParser('spanGamut', function (text, options, globals) {
  1963. 'use strict';
  1964. text = globals.converter._dispatch('spanGamut.before', text, options, globals);
  1965. text = showdown.subParser('codeSpans')(text, options, globals);
  1966. text = showdown.subParser('escapeSpecialCharsWithinTagAttributes')(text, options, globals);
  1967. text = showdown.subParser('encodeBackslashEscapes')(text, options, globals);
  1968. // Process anchor and image tags. Images must come first,
  1969. // because ![foo][f] looks like an anchor.
  1970. text = showdown.subParser('images')(text, options, globals);
  1971. text = showdown.subParser('anchors')(text, options, globals);
  1972. // Make links out of things like `<http://example.com/>`
  1973. // Must come after _DoAnchors(), because you can use < and >
  1974. // delimiters in inline links like [this](<url>).
  1975. text = showdown.subParser('autoLinks')(text, options, globals);
  1976. text = showdown.subParser('encodeAmpsAndAngles')(text, options, globals);
  1977. text = showdown.subParser('italicsAndBold')(text, options, globals);
  1978. text = showdown.subParser('strikethrough')(text, options, globals);
  1979. // Do hard breaks
  1980. if (options.simpleLineBreaks) {
  1981. // GFM style hard breaks
  1982. text = text.replace(/\b\n\b/g, '<br />\n');
  1983. } else {
  1984. // Vanilla hard breaks
  1985. text = text.replace(/\b +\n\b/g, '<br />\n');
  1986. }
  1987. text = globals.converter._dispatch('spanGamut.after', text, options, globals);
  1988. return text;
  1989. });
  1990. showdown.subParser('strikethrough', function (text, options, globals) {
  1991. 'use strict';
  1992. if (options.strikethrough) {
  1993. text = globals.converter._dispatch('strikethrough.before', text, options, globals);
  1994. text = text.replace(/(?:~T){2}([\s\S]+?)(?:~T){2}/g, '<del>$1</del>');
  1995. text = globals.converter._dispatch('strikethrough.after', text, options, globals);
  1996. }
  1997. return text;
  1998. });
  1999. /**
  2000. * Strip any lines consisting only of spaces and tabs.
  2001. * This makes subsequent regexs easier to write, because we can
  2002. * match consecutive blank lines with /\n+/ instead of something
  2003. * contorted like /[ \t]*\n+/
  2004. */
  2005. showdown.subParser('stripBlankLines', function (text) {
  2006. 'use strict';
  2007. return text.replace(/^[ \t]+$/mg, '');
  2008. });
  2009. /**
  2010. * Strips link definitions from text, stores the URLs and titles in
  2011. * hash references.
  2012. * Link defs are in the form: ^[id]: url "optional title"
  2013. */
  2014. showdown.subParser('stripLinkDefinitions', function (text, options, globals) {
  2015. 'use strict';
  2016. 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;
  2017. // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
  2018. text += '~0';
  2019. text = text.replace(regex, function (wholeMatch, linkId, url, width, height, blankLines, title) {
  2020. linkId = linkId.toLowerCase();
  2021. globals.gUrls[linkId] = showdown.subParser('encodeAmpsAndAngles')(url); // Link IDs are case-insensitive
  2022. if (blankLines) {
  2023. // Oops, found blank lines, so it's not a title.
  2024. // Put back the parenthetical statement we stole.
  2025. return blankLines + title;
  2026. } else {
  2027. if (title) {
  2028. globals.gTitles[linkId] = title.replace(/"|'/g, '&quot;');
  2029. }
  2030. if (options.parseImgDimensions && width && height) {
  2031. globals.gDimensions[linkId] = {
  2032. width: width,
  2033. height: height
  2034. };
  2035. }
  2036. }
  2037. // Completely remove the definition from the text
  2038. return '';
  2039. });
  2040. // attacklab: strip sentinel
  2041. text = text.replace(/~0/, '');
  2042. return text;
  2043. });
  2044. showdown.subParser('tables', function (text, options, globals) {
  2045. 'use strict';
  2046. if (!options.tables) {
  2047. return text;
  2048. }
  2049. var tableRgx = /^ {0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|~0)/gm;
  2050. function parseStyles(sLine) {
  2051. if (/^:[ \t]*--*$/.test(sLine)) {
  2052. return ' style="text-align:left;"';
  2053. } else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) {
  2054. return ' style="text-align:right;"';
  2055. } else if (/^:[ \t]*--*[ \t]*:$/.test(sLine)) {
  2056. return ' style="text-align:center;"';
  2057. } else {
  2058. return '';
  2059. }
  2060. }
  2061. function parseHeaders(header, style) {
  2062. var id = '';
  2063. header = header.trim();
  2064. if (options.tableHeaderId) {
  2065. id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
  2066. }
  2067. header = showdown.subParser('spanGamut')(header, options, globals);
  2068. return '<th' + id + style + '>' + header + '</th>\n';
  2069. }
  2070. function parseCells(cell, style) {
  2071. var subText = showdown.subParser('spanGamut')(cell, options, globals);
  2072. return '<td' + style + '>' + subText + '</td>\n';
  2073. }
  2074. function buildTable(headers, cells) {
  2075. var tb = '<table>\n<thead>\n<tr>\n',
  2076. tblLgn = headers.length;
  2077. for (var i = 0; i < tblLgn; ++i) {
  2078. tb += headers[i];
  2079. }
  2080. tb += '</tr>\n</thead>\n<tbody>\n';
  2081. for (i = 0; i < cells.length; ++i) {
  2082. tb += '<tr>\n';
  2083. for (var ii = 0; ii < tblLgn; ++ii) {
  2084. tb += cells[i][ii];
  2085. }
  2086. tb += '</tr>\n';
  2087. }
  2088. tb += '</tbody>\n</table>\n';
  2089. return tb;
  2090. }
  2091. text = globals.converter._dispatch('tables.before', text, options, globals);
  2092. text = text.replace(tableRgx, function (rawTable) {
  2093. var i, tableLines = rawTable.split('\n');
  2094. // strip wrong first and last column if wrapped tables are used
  2095. for (i = 0; i < tableLines.length; ++i) {
  2096. if (/^ {0,3}\|/.test(tableLines[i])) {
  2097. tableLines[i] = tableLines[i].replace(/^ {0,3}\|/, '');
  2098. }
  2099. if (/\|[ \t]*$/.test(tableLines[i])) {
  2100. tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
  2101. }
  2102. }
  2103. var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}),
  2104. rawStyles = tableLines[1].split('|').map(function (s) { return s.trim();}),
  2105. rawCells = [],
  2106. headers = [],
  2107. styles = [],
  2108. cells = [];
  2109. tableLines.shift();
  2110. tableLines.shift();
  2111. for (i = 0; i < tableLines.length; ++i) {
  2112. if (tableLines[i].trim() === '') {
  2113. continue;
  2114. }
  2115. rawCells.push(
  2116. tableLines[i]
  2117. .split('|')
  2118. .map(function (s) {
  2119. return s.trim();
  2120. })
  2121. );
  2122. }
  2123. if (rawHeaders.length < rawStyles.length) {
  2124. return rawTable;
  2125. }
  2126. for (i = 0; i < rawStyles.length; ++i) {
  2127. styles.push(parseStyles(rawStyles[i]));
  2128. }
  2129. for (i = 0; i < rawHeaders.length; ++i) {
  2130. if (showdown.helper.isUndefined(styles[i])) {
  2131. styles[i] = '';
  2132. }
  2133. headers.push(parseHeaders(rawHeaders[i], styles[i]));
  2134. }
  2135. for (i = 0; i < rawCells.length; ++i) {
  2136. var row = [];
  2137. for (var ii = 0; ii < headers.length; ++ii) {
  2138. if (showdown.helper.isUndefined(rawCells[i][ii])) {
  2139. }
  2140. row.push(parseCells(rawCells[i][ii], styles[ii]));
  2141. }
  2142. cells.push(row);
  2143. }
  2144. return buildTable(headers, cells);
  2145. });
  2146. text = globals.converter._dispatch('tables.after', text, options, globals);
  2147. return text;
  2148. });
  2149. /**
  2150. * Swap back in all the special characters we've hidden.
  2151. */
  2152. showdown.subParser('unescapeSpecialChars', function (text) {
  2153. 'use strict';
  2154. text = text.replace(/~E(\d+)E/g, function (wholeMatch, m1) {
  2155. var charCodeToReplace = parseInt(m1);
  2156. return String.fromCharCode(charCodeToReplace);
  2157. });
  2158. return text;
  2159. });
  2160. var root = this;
  2161. // CommonJS/nodeJS Loader
  2162. if (typeof module !== 'undefined' && module.exports) {
  2163. module.exports = showdown;
  2164. // AMD Loader
  2165. } else if (typeof define === 'function' && define.amd) {
  2166. define(function () {
  2167. 'use strict';
  2168. return showdown;
  2169. });
  2170. // Regular Browser loader
  2171. } else {
  2172. root.showdown = showdown;
  2173. }
  2174. }).call(this);
  2175. //# sourceMappingURL=showdown.js.map