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