Fix markdown breaking namepaths w/special chars

This commit is contained in:
James Hill 2015-07-06 11:33:03 +12:00
parent 7a0ec07521
commit acc47fdfd1

View File

@ -77,6 +77,20 @@ function escapeCode(source) {
.replace(/'/g, '''); .replace(/'/g, ''');
} }
/**
* Unencode quotes that occur within {@ ... } after the markdown parser has turned them
* into html entities (unfortunately it isn't possible to escape them before parsing)
*
* @param {string} source - The source text to unencode.
* @return {string} The source text with html entity `"` converted back to standard quotes
*/
function unencodeQuotes(source) {
return source.replace(/\{@[^}\r\n]+\}/g, function (wholeMatch) {
return wholeMatch.replace(/"/g, '"');
});
}
/** /**
* Retrieve a function that accepts a single parameter containing Markdown source. The function uses * Retrieve a function that accepts a single parameter containing Markdown source. The function uses
* the specified parser to transform the Markdown source to HTML, then returns the HTML as a string. * the specified parser to transform the Markdown source to HTML, then returns the HTML as a string.
@ -125,7 +139,9 @@ function getParseFunction(parserName, conf) {
result = marked(source, { renderer: markedRenderer }) result = marked(source, { renderer: markedRenderer })
.replace(/\s+$/, '') .replace(/\s+$/, '')
.replace(/'/g, "'"); .replace(/'/g, "'");
result = unescapeUrls(result); result = unescapeUrls(result);
result = unencodeQuotes(result);
return result; return result;
}; };