diff --git a/css/default.css b/css/default.css
index bf47a172..465d6dc8 100644
--- a/css/default.css
+++ b/css/default.css
@@ -2,7 +2,7 @@
@page {
margin: 25mm 25mm 25mm 25mm;
}
- #wmd-preview {
+ #preview-contents {
padding: 0px;
margin: 0px;
}
@@ -16,7 +16,7 @@ body {
tab-size: 4;
}
-#wmd-preview {
+#preview-contents {
padding: 19px;
margin-bottom: 50px;
}
@@ -46,7 +46,7 @@ div,span,a,ul,li,textarea,input,button {
text-shadow: none !important;
}
-.btn,.navbar-inner,#wmd-preview,.add-on {
+.btn,.navbar-inner,.add-on {
border: none !important;
}
@@ -720,7 +720,7 @@ table tbody+tbody {
border-top: 2px solid #dddddd;
}
-#wmd-preview blockquote {
+#preview-contents blockquote {
border-color: #ddd;
border-color: rgba(0, 0, 0, 0.15);
}
@@ -796,7 +796,7 @@ input[type="file"] {
background-color: rgba(215, 215, 215, 0.75) !important;
}
-.viewer #wmd-preview {
+.viewer #preview-contents {
max-width: 1024px;
margin: 50px auto;
}
diff --git a/js/core.js b/js/core.js
index 567bb60a..3080e63c 100644
--- a/js/core.js
+++ b/js/core.js
@@ -181,7 +181,7 @@ define([
extensionMgr.onLayoutConfigure(layoutGlobalConfig);
if(settings.layoutOrientation == "horizontal") {
$(".ui-layout-south").remove();
- $(".preview-container").html('
');
+ $(".preview-container").html('');
layout = $('body').layout($.extend(layoutGlobalConfig, {
east__resizable: true,
east__size: .5,
@@ -190,7 +190,7 @@ define([
}
else if(settings.layoutOrientation == "vertical") {
$(".ui-layout-east").remove();
- $(".preview-container").html('');
+ $(".preview-container").html('');
layout = $('body').layout($.extend(layoutGlobalConfig, {
south__resizable: true,
south__size: .5,
@@ -299,6 +299,7 @@ define([
else {
previewWrapper = function(makePreview) {
return function() {
+ window.previewStartTime = new Date().getTime();
makePreview();
if(documentContent === undefined) {
previewContainerElt.scrollTop(fileDesc.previewScrollTop);
diff --git a/js/extensionMgr.js b/js/extensionMgr.js
index 4a7717aa..2c8f52e5 100644
--- a/js/extensionMgr.js
+++ b/js/extensionMgr.js
@@ -158,11 +158,16 @@ define([
var counter = 0;
function tryFinished() {
if(++counter === nbAsyncPreviewCallback) {
- onPreviewFinished();
+ var html = "";
+ $("#preview-contents > .preview-content").each(function() {
+ html += $(this).html();
+ });
+ onPreviewFinished(html);
+ console.log("Preview time: " + (new Date().getTime() - window.previewStartTime));
}
}
// We assume images are loading in the preview
- $("#wmd-preview").waitForImages(tryFinished);
+ $("#preview-contents").waitForImages(tryFinished);
_.each(onAsyncPreviewCallbackList, function(asyncPreviewCallback) {
asyncPreviewCallback(tryFinished);
});
diff --git a/js/extensions/buttonHtmlCode.js b/js/extensions/buttonHtmlCode.js
index f0e2e44f..7828fdb4 100644
--- a/js/extensions/buttonHtmlCode.js
+++ b/js/extensions/buttonHtmlCode.js
@@ -30,12 +30,12 @@ define([
selectedFileDesc = fileDesc;
};
- buttonHtmlCode.onPreviewFinished = function() {
+ buttonHtmlCode.onPreviewFinished = function(html) {
try {
var htmlCode = _.template(buttonHtmlCode.config.template, {
documentTitle: selectedFileDesc.title,
documentMarkdown: selectedFileDesc.content,
- documentHTML: $("#wmd-preview").html()
+ documentHTML: html
});
$("#input-html-code").val(htmlCode);
}
diff --git a/js/extensions/buttonStat.js b/js/extensions/buttonStat.js
index 88c718c2..5c4d5f2e 100644
--- a/js/extensions/buttonStat.js
+++ b/js/extensions/buttonStat.js
@@ -45,7 +45,7 @@ define([
};
buttonStat.onPreviewFinished = function() {
- var text = $("#wmd-preview").clone().find("script").remove().end().text();
+ var text = $("#preview-contents").clone().find("script").remove().end().text();
$("#span-stat-value1").text((text.match(new RegExp(buttonStat.config.value1, "g")) || []).length);
$("#span-stat-value2").text((text.match(new RegExp(buttonStat.config.value2, "g")) || []).length);
$("#span-stat-value3").text((text.match(new RegExp(buttonStat.config.value3, "g")) || []).length);
diff --git a/js/extensions/documentSelector.js b/js/extensions/documentSelector.js
index aa4e21d1..4c1b12a6 100644
--- a/js/extensions/documentSelector.js
+++ b/js/extensions/documentSelector.js
@@ -17,7 +17,7 @@ define([
};
documentSelector.onLoadSettings = function() {
- utils.setInputValue("#select-document-selector-orderby", documentSelector.config.sortBy);
+ utils.setInputValue("#select-document-selector-orderby", documentSelector.config.orderBy);
utils.setInputValue("#input-document-selector-shortcut-previous", documentSelector.config.shortcutPrevious);
utils.setInputValue("#input-document-selector-shortcut-next", documentSelector.config.shortcutNext);
};
diff --git a/js/extensions/mathJax.js b/js/extensions/mathJax.js
index 7f8a3534..7d9d4675 100644
--- a/js/extensions/mathJax.js
+++ b/js/extensions/mathJax.js
@@ -61,6 +61,7 @@ define([
});
};
+ var converter = undefined;
var ready = false; // true after initial typeset is complete
var pending = false; // true when MathJax has been requested
var preview = null; // the preview container
@@ -209,7 +210,7 @@ define([
function RestartMJ() {
pending = false;
HUB.cancelTypeset = false; // won't need to do this in the future
- HUB.Queue([ "Typeset", HUB, preview ]);
+ HUB.Queue([ "Typeset", HUB, converter.eltList || preview ]);
HUB.Queue(afterRefreshCallback);
}
@@ -236,9 +237,9 @@ define([
mathJax.onEditorConfigure = function(editorObject) {
preview = document.getElementById("wmd-preview");
- var converterObject = editorObject.getConverter();
- converterObject.hooks.chain("preConversion", removeMath);
- converterObject.hooks.chain("postConversion", replaceMath);
+ converter = editorObject.getConverter();
+ converter.hooks.chain("preConversion", removeMath);
+ converter.hooks.chain("postConversion", replaceMath);
};
mathJax.onAsyncPreview = function(callback) {
afterRefreshCallback = callback;
diff --git a/js/extensions/partialRendering.js b/js/extensions/partialRendering.js
index d203a006..c9809d92 100644
--- a/js/extensions/partialRendering.js
+++ b/js/extensions/partialRendering.js
@@ -9,8 +9,46 @@ define([
partialRendering.settingsBlock = partialRenderingSettingsBlockHTML;
var converter = undefined;
- var sectionList = [];
- var convertedSectionsList = [];
+ var sectionIdGenerator = 0;
+ var sectionList = [
+ {
+ text: ""
+ }
+ ];
+ var sectionsToRemove = undefined;
+ function updateSectionList(newSectionList) {
+
+ // Find modified sections starting from left
+ var leftIndex = sectionList.length;
+ _.some(sectionList, function(section, index) {
+ if(index >= newSectionList.length || section.text != newSectionList[index].text) {
+ leftIndex = index;
+ return true;
+ }
+ });
+
+ // Find modified sections starting from right
+ var rightIndex = -sectionList.length;
+ _.some(sectionList.slice().reverse(), function(section, index) {
+ if(index >= newSectionList.length || section.text != newSectionList[newSectionList.length - index - 1].text) {
+ rightIndex = -index;
+ return true;
+ }
+ });
+
+ if(leftIndex === sectionList.length && rightIndex === -leftIndex) {
+ // No modification detected...
+ return;
+ }
+
+ // Create an array composed of left unmodified, modified, right
+ // unmodified sections
+ var leftSections = sectionList.slice(0, leftIndex);
+ var modifiedSections = newSectionList.slice(leftIndex, newSectionList.length + rightIndex);
+ var rightSections = sectionList.slice(sectionList.length + rightIndex, sectionList.length);
+ sectionsToRemove = sectionList.slice(leftIndex, sectionList.length + rightIndex);
+ sectionList = leftSections.concat(modifiedSections).concat(rightSections);
+ }
var hasFootnotes = false;
function extractSections(text) {
@@ -43,44 +81,78 @@ define([
if(title) {
// We just found a title which means end of the previous section
if(matchOffset > offset) {
- newSectionList.push(text.substring(offset, matchOffset) + "\n" + linkDefinition);
+ newSectionList.push({
+ id: ++sectionIdGenerator,
+ text: text.substring(offset, matchOffset) + "\n" + linkDefinition
+ });
offset = matchOffset;
}
}
return "";
});
// Last section
- newSectionList.push(text.substring(offset, text.length) + linkDefinition);
+ newSectionList.push({
+ id: ++sectionIdGenerator,
+ text: text.substring(offset, text.length) + linkDefinition
+ });
- sectionList = newSectionList;
+ updateSectionList(newSectionList);
}
var isRendering = false;
+ var footnoteContainer = $('');
+ var footnoteContainerFirstChild = $('
').appendTo(footnoteContainer);
function renderSections() {
- // Renders sections
+ converter.eltList = [];
+ // Remove outdated sections
+ _.each(sectionsToRemove, function(section) {
+ $("#wmd-preview-section-" + section.id).remove();
+ footnoteContainer.find("#footnotes-section-" + section.id).remove();
+ });
+ var footnoteContainerElt = $("#wmd-preview-section-footnotes");
+ footnoteContainerElt.empty();
+
+ // Renders modified sections
isRendering = true;
- convertedSectionsList = _.map(sectionList, converter.makeHtml);
+ var previousSectionElt = $("#wmd-preview");
+ var previousFootnoteElt = footnoteContainerFirstChild;
+ _.each(sectionList, function(section) {
+ if(section.isConverted === true) {
+ previousSectionElt = $("#wmd-preview-section-" + section.id);
+ footnoteContainer.find("#footnotes-section-" + section.id).each(function() {
+ previousFootnoteElt = $(this);
+ });
+ return;
+ }
+ var sectionHtml = converter.makeHtml(section.text);
+ var sectionElt = $('
').html(sectionHtml);
+ sectionElt.find("div.footnotes").each(function() {
+ var footnoteElt = $(this).attr("id", "footnotes-section-" + section.id);
+ previousFootnoteElt.after(footnoteElt);
+ previousFootnoteElt = footnoteElt;
+ });
+ previousSectionElt.after(sectionElt);
+ previousSectionElt = sectionElt;
+ converter.eltList.push(sectionElt[0]);
+ section.isConverted = true;
+ });
isRendering = false;
- $("#wmd-preview").html(convertedSectionsList.join(""));
-
- // Move footnotes in the footer...
+ // Rewrite footnotes in the footer
if(hasFootnotes === true) {
// Recreate a footnote list
var footnoteElts = $("
");
- $("#wmd-preview > div.footnotes > ol > li").each(function(index) {
+ footnoteContainer.find("div.footnotes > ol > li").each(function(index) {
hasFootnotes = true;
var elt = $(this);
- footnoteElts.append(elt);
+ footnoteElts.append(elt.clone());
// Restore footnotes numbers
var refId = "#fnref\\:" + elt.attr("id").substring(3);
$(refId).text(index + 1);
});
// Append the whole footnotes at the end of the document
- $("#wmd-preview > div.footnotes").remove();
- $("#wmd-preview").append($('