Added template variable documentHTMLWithComments. Fixes #310

This commit is contained in:
benweet 2014-02-09 13:16:08 +00:00
parent f9322ffee7
commit 5a79f568fa
5 changed files with 23 additions and 16 deletions

View File

@ -234,8 +234,9 @@ define([
html += elt.innerHTML;
});
html = html.replace(/^<div class="se-section-delimiter"><\/div>\n\n/gm, '');
html = html.replace(/ <span class="comment label label-danger">.*<\/span> /g, '');
onPreviewFinished(utils.trim(html));
var htmlWithComments = utils.trim(html);
var htmlWithoutComments = htmlWithComments.replace(/ <span class="comment label label-danger">.*?<\/span> /g, '');
onPreviewFinished(htmlWithComments, htmlWithoutComments);
});
};
callback(function() {

View File

@ -36,13 +36,14 @@ define([
};
var textareaElt;
buttonHtmlCode.onPreviewFinished = function(html) {
buttonHtmlCode.onPreviewFinished = function(htmlWithComments, htmlWithoutComments) {
try {
var htmlCode = _.template(buttonHtmlCode.config.template, {
documentTitle: selectedFileDesc.title,
documentMarkdown: selectedFileDesc.content,
strippedDocumentMarkdown: selectedFileDesc.content.substring(selectedFileDesc.frontMatter ? selectedFileDesc.frontMatter._frontMatter.length : 0),
documentHTML: html,
documentHTML: htmlWithoutComments,
documentHTMLWithComments: htmlWithComments,
frontMatter: selectedFileDesc.frontMatter,
publishAttributes: undefined,
});

View File

@ -9,6 +9,8 @@ Available variables:
<b>strippedDocumentMarkdown</b>: document without front matter</li>
<li>
<b>documentHTML</b>: document in HTML format</li>
<li>
<b>documentHTMLWithComments</b>: HTML format with comments</li>
<li>
<b>frontMatter</b>: YAML front matter object (undefined if not present)</li>
<li>

View File

@ -67,7 +67,8 @@ define([
documentTitle: fileDesc.title,
documentMarkdown: fileDesc.content,
strippedDocumentMarkdown: fileDesc.content.substring(fileDesc.frontMatter ? fileDesc.frontMatter._frontMatter.length : 0),
documentHTML: html,
documentHTML: html.withoutComments,
documentHTMLWithComments: html.withComments,
frontMatter: fileDesc.frontMatter,
publishAttributes: publishAttributes
});
@ -90,7 +91,7 @@ define([
return fileDesc.content;
}
else if(publishAttributes.format == "html") {
return html;
return html.withoutComments;
}
else {
return publisher.applyTemplate(fileDesc, publishAttributes, html);
@ -134,9 +135,12 @@ define([
}
// Get the html from the onPreviewFinished callback
var previewHtml;
eventMgr.addListener("onPreviewFinished", function(html) {
previewHtml = html;
var currentHTML;
eventMgr.addListener("onPreviewFinished", function(htmlWithComments, htmlWithoutComments) {
currentHTML = {
withComments: htmlWithComments,
withoutComments: htmlWithoutComments
};
});
// Listen to offline status changes
@ -155,7 +159,7 @@ define([
publishRunning = true;
eventMgr.onPublishRunning(true);
publishFileDesc = fileMgr.currentFile;
publishHTML = previewHtml;
publishHTML = currentHTML;
publishAttributesList = _.values(publishFileDesc.publishLocations);
publishLocation(function(errorFlag) {
publishRunning = false;
@ -224,8 +228,7 @@ define([
// Perform provider's publishing
var fileDesc = fileMgr.currentFile;
var html = previewHtml;
var content = getPublishContent(fileDesc, publishAttributes, html);
var content = getPublishContent(fileDesc, publishAttributes, currentHTML);
var title = (fileDesc.frontMatter && fileDesc.frontMatter.title) || fileDesc.title;
provider.publish(publishAttributes, fileDesc.frontMatter, title, content, function(error) {
if(error === undefined) {
@ -311,18 +314,18 @@ define([
});
$(".action-download-html").click(function() {
var title = fileMgr.currentFile.title;
utils.saveAs(previewHtml, title + ".html");
utils.saveAs(currentHTML.withoutComments, title + ".html");
});
$(".action-download-template").click(function() {
var fileDesc = fileMgr.currentFile;
var content = publisher.applyTemplate(fileDesc, undefined, previewHtml);
var content = publisher.applyTemplate(fileDesc, undefined, currentHTML);
utils.saveAs(content, fileDesc.title + (settings.template.indexOf("documentHTML") === -1 ? ".md" : ".html"));
});
$(".action-download-pdf").click(function() {
var fileDesc = fileMgr.currentFile;
var content = publisher.applyTemplate(fileDesc, {
customTmpl: settings.pdfTemplate
}, previewHtml);
}, currentHTML);
var task = new AsyncTask();
var pdf;
task.onRun(function() {

View File

@ -115,7 +115,7 @@
@modal-footer-border-color: @secondary-border-color-light;
@modal-content-separator-color: @secondary-border-color-lighter;
@modal-backdrop-bg: desaturate(@tertiary, 90%);
@tooltip-max-width: 240px;
@tooltip-max-width: 250px;
@close-color: @secondary-color-darkest;
@popover-bg: @secondary-bg;
@popover-border-color: @secondary-border-color;