New partialRendering extension
This commit is contained in:
parent
6c9e8317dd
commit
0d6d329e6a
@ -630,7 +630,7 @@
|
||||
<div class="msg-no-publish hide">
|
||||
"<span class="file-title"></span>" is not published yet. <br /> <br />
|
||||
</div>
|
||||
<b>NOTE:</b> You can add locations using "Publish on" sub-menu.
|
||||
<b>NOTE:</b> You can add publications using "Publish on" sub-menu.
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
10
js/core.js
10
js/core.js
@ -224,8 +224,8 @@ define([
|
||||
if(editor !== undefined) {
|
||||
// If the editor is already created
|
||||
editor.undoManager.reinit(initDocumentContent, fileDesc.editorStart, fileDesc.editorEnd, fileDesc.editorScrollTop);
|
||||
editor.refreshPreview();
|
||||
extensionMgr.onFileOpen(fileDesc);
|
||||
editor.refreshPreview();
|
||||
return;
|
||||
}
|
||||
var previewContainerElt = $(".preview-container");
|
||||
@ -256,12 +256,12 @@ define([
|
||||
converter.hooks.chain("preConversion", function(text) {
|
||||
var tmpText = text + "\n\n";
|
||||
var sectionList = [], offset = 0;
|
||||
// Look for titles (exclude gfm blocs)
|
||||
// Look for titles (excluding gfm blocs)
|
||||
tmpText.replace(/^```.*\n[\s\S]*?\n```|(^.+[ \t]*\n=+[ \t]*\n+|^.+[ \t]*\n-+[ \t]*\n+|^\#{1,6}[ \t]*.+?[ \t]*\#*\n+)/gm, function(match, title, matchOffset) {
|
||||
if(title && matchOffset > offset) {
|
||||
if(title) {
|
||||
// We just found a title which means end of the previous section
|
||||
// Exclude last \n of the section
|
||||
sectionList.push(tmpText.substring(offset, matchOffset - 1));
|
||||
sectionList.push(tmpText.substring(offset, matchOffset));
|
||||
offset = matchOffset;
|
||||
}
|
||||
return "";
|
||||
@ -318,7 +318,7 @@ define([
|
||||
else {
|
||||
previewWrapper = function(makePreview) {
|
||||
return function() {
|
||||
window.previewStartTime = new Date().getTime();
|
||||
extensionMgr.previewStartTime = new Date();
|
||||
makePreview();
|
||||
if(documentContent === undefined) {
|
||||
previewContainerElt.scrollTop(fileDesc.previewScrollTop);
|
||||
|
@ -164,7 +164,7 @@ define([
|
||||
html += $(this).html();
|
||||
});
|
||||
onPreviewFinished(utils.trim(html));
|
||||
console.log("Preview time: " + (new Date().getTime() - window.previewStartTime));
|
||||
logger.log("Preview time: " + (new Date() - extensionMgr.previewStartTime));
|
||||
}
|
||||
}
|
||||
// We assume images are loading in the preview
|
||||
|
@ -35,7 +35,7 @@ define([
|
||||
linebreaks: {
|
||||
automatic: true
|
||||
},
|
||||
EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50),
|
||||
EqnChunk: 10,
|
||||
imageFont: null
|
||||
},
|
||||
tex2jax: tex2jax,
|
||||
|
@ -5,23 +5,23 @@ define([
|
||||
"text!html/partialRenderingSettingsBlock.html",
|
||||
], function($, _, Extension, partialRenderingSettingsBlockHTML) {
|
||||
|
||||
var partialRendering = new Extension("partialRendering", "Partial rendering", true);
|
||||
var partialRendering = new Extension("partialRendering", "Partial Rendering", true);
|
||||
partialRendering.settingsBlock = partialRenderingSettingsBlockHTML;
|
||||
|
||||
var converter = undefined;
|
||||
var sectionCounter = 0;
|
||||
var sectionList = [];
|
||||
var linkDefinition = "";
|
||||
var linkDefinition = undefined;
|
||||
var sectionsToRemove = [];
|
||||
var modifiedSections = [];
|
||||
var insertAfterSection = undefined;
|
||||
var fileChanged = true;
|
||||
var fileChanged = false;
|
||||
function updateSectionList(newSectionList, newLinkDefinition) {
|
||||
modifiedSections = [];
|
||||
sectionsToRemove = [];
|
||||
insertAfterSection = undefined;
|
||||
|
||||
// Render everything if file changed or linkDefinition changed
|
||||
// Render everything if file or linkDefinition changed
|
||||
if(fileChanged === true || linkDefinition != newLinkDefinition) {
|
||||
fileChanged = false;
|
||||
linkDefinition = newLinkDefinition;
|
||||
@ -31,7 +31,7 @@ define([
|
||||
return;
|
||||
}
|
||||
|
||||
// Find modified sections starting from left
|
||||
// Find modified sections starting from top
|
||||
var leftIndex = sectionList.length;
|
||||
_.some(sectionList, function(section, index) {
|
||||
if(index >= newSectionList.length || section.text != newSectionList[index].text) {
|
||||
@ -40,7 +40,7 @@ define([
|
||||
}
|
||||
});
|
||||
|
||||
// Find modified sections starting from right
|
||||
// Find modified sections starting from bottom
|
||||
var rightIndex = -sectionList.length;
|
||||
_.some(sectionList.slice().reverse(), function(section, index) {
|
||||
if(index >= newSectionList.length || section.text != newSectionList[newSectionList.length - index - 1].text) {
|
||||
@ -82,7 +82,7 @@ define([
|
||||
return wholeMatch;
|
||||
});
|
||||
|
||||
// And eventually footnotes...
|
||||
// And footnotes eventually
|
||||
if(doFootnotes) {
|
||||
text = text.replace(/^```.*\n[\s\S]*?\n```|\n[ ]{0,3}\[\^(.+?)\]\:[ \t]*\n?([\s\S]*?)\n{1,2}((?=\n[ ]{0,3}\S)|$)/g, function(wholeMatch, footnote) {
|
||||
if(footnote) {
|
||||
@ -120,7 +120,7 @@ define([
|
||||
var insertAfterSectionElt = insertAfterSection === undefined ? wmdPreviewElt : $("#wmd-preview-section-" + insertAfterSection.id);
|
||||
_.each(modifiedSections, function(section) {
|
||||
var sectionElt = $('<div id="wmd-preview-section-' + section.id + '" class="wmd-preview-section preview-content">');
|
||||
_.some(wmdPreviewElt.children(), function(elt, index) {
|
||||
_.some(wmdPreviewElt.contents(), function(elt, index) {
|
||||
elt = $(elt);
|
||||
if(index !== 0 && elt.is(".wmd-title")) {
|
||||
return true;
|
||||
@ -155,7 +155,7 @@ define([
|
||||
// Append the whole footnotes at the end of the document
|
||||
footnoteContainerElt.html($('<div class="footnotes">').append("<hr>").append(footnoteElts));
|
||||
}
|
||||
// Keep only used footnotes in our map
|
||||
// Keep used footnotes only in our map
|
||||
footnoteList = _.pick(footnoteList, usedFootnoteIds);
|
||||
}
|
||||
}
|
||||
@ -174,15 +174,11 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
partialRendering.onPreviewFinished = function() {
|
||||
$('script[type="math/tex; mode=display"]').remove();
|
||||
};
|
||||
|
||||
partialRendering.onReady = function() {
|
||||
$("#preview-contents").append(footnoteContainerElt);
|
||||
$("#wmd-preview").hide();
|
||||
};
|
||||
partialRendering.onFileClose = function() {
|
||||
partialRendering.onFileSelected = function() {
|
||||
fileChanged = true;
|
||||
};
|
||||
partialRendering.onFileOpen = function() {
|
||||
|
@ -31,12 +31,13 @@ define([
|
||||
var textareaElt = $("#md-section-helper");
|
||||
// It has to be the same width as wmd-input
|
||||
textareaElt.width(editorElt.width());
|
||||
// Consider wmd-input top padding (will be used for 1st and last section)
|
||||
// Consider wmd-input top padding (will be used for 1st and last
|
||||
// section)
|
||||
var padding = pxToFloat(editorElt.css('padding-top'));
|
||||
var mdSectionOffset = 0;
|
||||
function addMdSection(sectionText) {
|
||||
var sectionHeight = padding;
|
||||
if(sectionText !== undefined) {
|
||||
if(sectionText.length !== 0) {
|
||||
textareaElt.val(sectionText);
|
||||
sectionHeight += textareaElt.prop('scrollHeight');
|
||||
}
|
||||
@ -50,9 +51,14 @@ define([
|
||||
padding = 0;
|
||||
}
|
||||
_.each(sectionList, function(sectionText, index) {
|
||||
if(index === sectionList.length - 1) {
|
||||
if(index !== sectionList.length - 1) {
|
||||
// Remove the last \n preceding the next title
|
||||
sectionText = sectionText.substring(0, sectionText.length - 1);
|
||||
}
|
||||
else {
|
||||
// Last section
|
||||
// Consider wmd-input bottom padding and exclude \n\n previously added
|
||||
// Consider wmd-input bottom padding and exclude \n\n previously
|
||||
// added
|
||||
padding += pxToFloat(editorElt.css('padding-bottom'));
|
||||
}
|
||||
addMdSection(sectionText);
|
||||
|
@ -114,14 +114,17 @@ define([
|
||||
}
|
||||
|
||||
toc.onEditorConfigure = function(editor) {
|
||||
var tocExp = new RegExp("^" + toc.config.marker + "$", "g")
|
||||
// Run TOC generation when conversion is finished directly on HTML
|
||||
editor.hooks.chain("onPreviewRefresh", function() {
|
||||
var htmlToc = buildToc();
|
||||
$("#preview-contents > .preview-content").each(function() {
|
||||
var html = $(this).html();
|
||||
html = html.replace(new RegExp("<p>" + toc.config.marker + "<\\/p>", "g"), htmlToc);
|
||||
$(this).html(html);
|
||||
// Replace toc paragraphs
|
||||
$("#preview-contents p").each(function() {
|
||||
if(tocExp.test($(this).html())) {
|
||||
$(this).html(htmlToc);
|
||||
}
|
||||
});
|
||||
// Add toc in the TOC button
|
||||
$(".table-of-contents").html(htmlToc);
|
||||
});
|
||||
};
|
||||
|
@ -1,7 +1,5 @@
|
||||
<p>Binds together editor and preview scrollbars.</p>
|
||||
<p>Renders modified sections only.</p>
|
||||
<blockquote class="muted">
|
||||
<b>NOTE:</b> The mapping between Markdown and HTML is based on the
|
||||
position of the title elements (h1 h2 ...) in the page. Therefore if
|
||||
your document does not contain any title the mapping will be linear and
|
||||
consequently less accurate.
|
||||
<b>NOTE:</b> Document sections are based on title elements (h1, h2...). Therefore if
|
||||
your document does not contain any title, performance will not be increased.
|
||||
</blockquote>
|
@ -1,7 +1,7 @@
|
||||
<p>Binds together editor and preview scrollbars.</p>
|
||||
<blockquote class="muted">
|
||||
<b>NOTE:</b> The mapping between Markdown and HTML is based on the
|
||||
position of the title elements (h1 h2 ...) in the page. Therefore if
|
||||
your document does not contain any title the mapping will be linear and
|
||||
position of the title elements (h1, h2...) in the page. Therefore if
|
||||
your document does not contain any title, the mapping will be linear and
|
||||
consequently less accurate.
|
||||
</blockquote>
|
@ -297,7 +297,7 @@ define([
|
||||
|
||||
if(isRealtime) {
|
||||
if(_.size(fileDesc.syncLocations) > 0) {
|
||||
extensionMgr.onError("Realtime collaboration document can't be synchronized with multiple locations");
|
||||
extensionMgr.onError("Real time collaborative document can't be synchronized with multiple locations");
|
||||
return;
|
||||
}
|
||||
// Perform the provider's real time export
|
||||
@ -317,7 +317,7 @@ define([
|
||||
}
|
||||
else {
|
||||
if(_.size(fileDesc.syncLocations) > 0 && _.first(_.values(fileDesc.syncLocations)).isRealtime) {
|
||||
extensionMgr.onError("Realtime collaboration document can't be synchronized with multiple locations");
|
||||
extensionMgr.onError("Real time collaborative document can't be synchronized with multiple locations");
|
||||
return;
|
||||
}
|
||||
// Perform the provider's standard export
|
||||
@ -342,7 +342,7 @@ define([
|
||||
$(".action-sync-manual-" + provider.providerId).click(function(event) {
|
||||
var fileDesc = fileMgr.currentFile;
|
||||
if(_.size(fileDesc.syncLocations) > 0 && _.first(_.values(fileDesc.syncLocations)).isRealtime) {
|
||||
extensionMgr.onError("Realtime collaboration document can't be synchronized with multiple locations");
|
||||
extensionMgr.onError("Real time collaborative document can't be synchronized with multiple locations");
|
||||
return;
|
||||
}
|
||||
provider.exportManual(event, fileDesc.title, fileDesc.content, function(error, syncAttributes) {
|
||||
|
Loading…
Reference in New Issue
Block a user