Skip to content

Commit cb1e00d

Browse files
committed
Add support of exporting raw html
1 parent 4d24476 commit cb1e00d

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

public/js/extra.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,7 @@ function postProcess(code) {
430430
return result;
431431
}
432432

433-
//extract markdown body to html and compile to template
434-
function exportToHTML(view) {
435-
var title = renderTitle(ui.area.markdown);
436-
var filename = renderFilename(ui.area.markdown) + '.html';
433+
function generateCleanHTML(view) {
437434
var src = view.clone();
438435
var eles = src.find('*');
439436
//remove syncscroll parts
@@ -469,6 +466,25 @@ function exportToHTML(view) {
469466
$(value).html(iframe);
470467
}
471468
});
469+
return src;
470+
}
471+
472+
function exportToRawHTML(view) {
473+
var filename = renderFilename(ui.area.markdown) + '.html';
474+
var src = generateCleanHTML(view);
475+
$(src).find('a.anchor').remove();
476+
var html = src[0].outerHTML;
477+
var blob = new Blob([html], {
478+
type: "text/html;charset=utf-8"
479+
});
480+
saveAs(blob, filename);
481+
}
482+
483+
//extract markdown body to html and compile to template
484+
function exportToHTML(view) {
485+
var title = renderTitle(ui.area.markdown);
486+
var filename = renderFilename(ui.area.markdown) + '.html';
487+
var src = generateCleanHTML(view);
472488
//generate toc
473489
var toc = $('#toc').clone();
474490
toc.find('*').removeClass('active');

public/js/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ var ui = {
505505
publish: $(".ui-publish"),
506506
download: {
507507
markdown: $(".ui-download-markdown"),
508-
html: $(".ui-download-html")
508+
html: $(".ui-download-html"),
509+
rawhtml: $(".ui-download-raw-html")
509510
},
510511
export: {
511512
dropbox: $(".ui-save-dropbox"),
@@ -1174,6 +1175,12 @@ ui.toolbar.download.html.click(function (e) {
11741175
e.stopPropagation();
11751176
exportToHTML(ui.area.markdown);
11761177
});
1178+
// raw html
1179+
ui.toolbar.download.rawhtml.click(function (e) {
1180+
e.preventDefault();
1181+
e.stopPropagation();
1182+
exportToRawHTML(ui.area.markdown);
1183+
});
11771184
//export to dropbox
11781185
ui.toolbar.export.dropbox.click(function () {
11791186
var filename = renderFilename(ui.area.markdown) + '.md';

public/views/header.ejs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
</li>
6969
<li role="presentation"><a role="menuitem" class="ui-download-html" tabindex="-1" href="#" target="_self"><i class="fa fa-file-code-o fa-fw"></i> HTML</a>
7070
</li>
71+
<li role="presentation"><a role="menuitem" class="ui-download-raw-html" tabindex="-1" href="#" target="_self"><i class="fa fa-file-code-o fa-fw"></i> Raw HTML</a>
72+
</li>
7173
<li class="divider"></li>
7274
<li role="presentation"><a role="menuitem" class="ui-help" href="#" data-toggle="modal" data-target=".help-modal"><i class="fa fa-question-circle fa-fw"></i> Help</a>
7375
</li>
@@ -163,6 +165,8 @@
163165
</li>
164166
<li role="presentation"><a role="menuitem" class="ui-download-html" tabindex="-1" href="#" target="_self"><i class="fa fa-file-code-o fa-fw"></i> HTML</a>
165167
</li>
168+
<li role="presentation"><a role="menuitem" class="ui-download-raw-html" tabindex="-1" href="#" target="_self"><i class="fa fa-file-code-o fa-fw"></i> Raw HTML</a>
169+
</li>
166170
</ul>
167171
</li>
168172
</ul>

0 commit comments

Comments
 (0)