Fixed section delimiter conflict with html blocks

This commit is contained in:
benweet 2013-11-20 01:01:48 +00:00
parent 7880a5c87d
commit 7c0e6f74e7

View File

@ -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<div class="se-section-delimiter"></div>\n\n' + sectionText + '\n'
});
addSection(offset, matchOffset);
offset = matchOffset;
});
// Last section
var sectionText = tmpText.substring(offset, text.length);
sectionList.push({
text: sectionText,
textWithDelimiter: '\n<div class="se-section-delimiter"></div>\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(/<p>~~~SectionDelimiter~~~<\/p>/g, '<div class="se-section-delimiter"></div>');
});
};
return markdownSectionParser;