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;