From 5f043ca46d20eb88240c753ae7f7c7429f4ee275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Soares=20dos=20Santos?= Date: Tue, 14 Jul 2015 20:49:04 +0100 Subject: [PATCH] fix(subParsers/codeSpans): Fix issue with code html tags not being correctly escaped --- src/subParsers/codeSpans.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/subParsers/codeSpans.js b/src/subParsers/codeSpans.js index 639ffa8..e0d0522 100644 --- a/src/subParsers/codeSpans.js +++ b/src/subParsers/codeSpans.js @@ -26,6 +26,14 @@ showdown.subParser('codeSpans', function (text) { 'use strict'; + //special case -> literal html code tag + text = text.replace(/(<]*?>)([^]*?)<\/code>/g, function (wholeMatch, tag, c) { + c = c.replace(/^([ \t]*)/g, ''); // leading whitespace + c = c.replace(/[ \t]*$/g, ''); // trailing whitespace + c = showdown.subParser('encodeCode')(c); + return tag + c + ''; + }); + /* text = text.replace(/ (^|[^\\]) // Character before opening ` can't be a backslash @@ -38,15 +46,14 @@ showdown.subParser('codeSpans', function (text) { (?!`) /gm, function(){...}); */ - - text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm, function (wholeMatch, m1, m2, m3) { - var c = m3; - c = c.replace(/^([ \t]*)/g, ''); // leading whitespace - c = c.replace(/[ \t]*$/g, ''); // trailing whitespace - c = showdown.subParser('encodeCode')(c); - return m1 + '' + c + ''; + text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm, + function (wholeMatch, m1, m2, m3) { + var c = m3; + c = c.replace(/^([ \t]*)/g, ''); // leading whitespace + c = c.replace(/[ \t]*$/g, ''); // trailing whitespace + c = showdown.subParser('encodeCode')(c); + return m1 + '' + c + ''; }); return text; - });