From 7c0e6f74e7425fbd3a03e3c6fcfdd2033891f153 Mon Sep 17 00:00:00 2001 From: benweet Date: Wed, 20 Nov 2013 01:01:48 +0000 Subject: [PATCH] Fixed section delimiter conflict with html blocks --- .../res/extensions/markdownSectionParser.js | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/public/res/extensions/markdownSectionParser.js b/public/res/extensions/markdownSectionParser.js index 16f71eed..750c2619 100644 --- a/public/res/extensions/markdownSectionParser.js +++ b/public/res/extensions/markdownSectionParser.js @@ -35,28 +35,32 @@ define([ converter.hooks.chain("preConversion", function(text) { eventMgr.previewStartTime = new Date(); var tmpText = text + "\n\n"; + function addSection(startOffset, endOffset) { + var sectionText = tmpText.substring(offset, endOffset); + sectionList.push({ + text: sectionText, + textWithDelimiter: '\n~~~SectionDelimiter~~~\n\n' + sectionText + '\n' + }); + } var sectionList = [], offset = 0; // Look for delimiters tmpText.replace(regexp, function(match, matchOffset) { // Create a new section with the text preceding the delimiter - var sectionText = tmpText.substring(offset, matchOffset); - sectionList.push({ - text: sectionText, - textWithDelimiter: '\n
\n\n' + sectionText + '\n' - }); + addSection(offset, matchOffset); offset = matchOffset; }); // Last section - var sectionText = tmpText.substring(offset, text.length); - sectionList.push({ - text: sectionText, - textWithDelimiter: '\n
\n\n' + sectionText + '\n' - }); + addSection(offset, text.length); eventMgr.onSectionsCreated(sectionList); return _.reduce(sectionList, function(result, section) { return result + section.textWithDelimiter; }, ''); }); + + converter.hooks.chain("postConversion", function(text) { + // Convert delimiters into hidden elements + return text.replace(/

~~~SectionDelimiter~~~<\/p>/g, '

'); + }); }; return markdownSectionParser;