123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /**
- * Strips link definitions from text, stores the URLs and titles in
- * hash references.
- * Link defs are in the form: ^[id]: url "optional title"
- *
- * ^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1
- * [ \t]*
- * \n? // maybe *one* newline
- * [ \t]*
- * <?(\S+?)>? // url = $2
- * [ \t]*
- * \n? // maybe one newline
- * [ \t]*
- * (?:
- * (\n*) // any lines skipped = $3 attacklab: lookbehind removed
- * ["(]
- * (.+?) // title = $4
- * [")]
- * [ \t]*
- * )? // title is optional
- * (?:\n+|$)
- * /gm,
- * function(){...});
- *
- */
- showdown.subParser('stripLinkDefinitions', function (text, options, globals) {
- 'use strict';
- var regex = /^[ ]{0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \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, m1, m2, m3, m4) {
- m1 = m1.toLowerCase();
- globals.gUrls[m1] = showdown.subParser('encodeAmpsAndAngles')(m2); // Link IDs are case-insensitive
- if (m3) {
- // Oops, found blank lines, so it's not a title.
- // Put back the parenthetical statement we stole.
- return m3 + m4;
- } else if (m4) {
- globals.gTitles[m1] = m4.replace(/"/g, '"');
- }
- // Completely remove the definition from the text
- return '';
- });
- // attacklab: strip sentinel
- text = text.replace(/~0/, '');
- return text;
- });
|