/** * Turn Markdown image shortcuts into tags. */ showdown.subParser('images', function (text, options, globals) { 'use strict'; var writeImageTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) { wholeMatch = m1; var altText = m2, linkId = m3.toLowerCase(), url = m4, title = m7, gUrls = globals.gUrls, gTitles = globals.gTitles; if (!title) { title = ''; } if (url === '' || url === null) { if (linkId === '' || linkId === null) { // lower-case and turn embedded newlines into spaces linkId = altText.toLowerCase().replace(/ ?\n/g, ' '); } url = '#' + linkId; if (typeof gUrls[linkId] !== 'undefined') { url = gUrls[linkId]; if (typeof gTitles[linkId] !== 'undefined') { title = gTitles[linkId]; } } else { return wholeMatch; } } altText = altText.replace(/"/g, '"'); url = showdown.helper.escapeCharacters(url, '*_', false); var result = '' + altText + '? // src url = $4 [ \t]* ( // $5 (['"]) // quote char = $6 (.*?) // title = $7 \6 // matching quote [ \t]* )? // title is optional \) ) /g,writeImageTag); */ text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, writeImageTag); return text; });