UNPKG

showdown

Version:

A Markdown to HTML converter written in Javascript

43 lines (35 loc) 1.37 kB
/** * Strips link definitions from text, stores the URLs and titles in * hash references. * Link defs are in the form: ^[id]: url "optional title" */ showdown.subParser('stripLinkDefinitions', function (text, options, globals) { 'use strict'; 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; // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug text += '~0'; text = text.replace(regex, function (wholeMatch, linkId, url, width, height, blankLines, title) { linkId = linkId.toLowerCase(); globals.gUrls[linkId] = showdown.subParser('encodeAmpsAndAngles')(url); // Link IDs are case-insensitive if (blankLines) { // Oops, found blank lines, so it's not a title. // Put back the parenthetical statement we stole. return blankLines + title; } else { if (title) { globals.gTitles[linkId] = title.replace(/"|'/g, '&quot;'); } if (options.parseImgDimensions && width && height) { globals.gDimensions[linkId] = { width: width, height: height }; } } // Completely remove the definition from the text return ''; }); // attacklab: strip sentinel text = text.replace(/~0/, ''); return text; });