Skip to content

Commit 5f82df7

Browse files
committed
Added support of export to HTML, and changed the navbar menu for consistency
1 parent 60414fe commit 5f82df7

6 files changed

Lines changed: 253 additions & 12 deletions

File tree

public/css/compress.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cleancss -o html.min.css github-extract.css markdown.css extra.css site.css

public/css/html.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/extra.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,70 @@ function postProcess(code) {
212212
result.find('a:not([target])').attr('target', '_blank');
213213
return result;
214214
}
215+
216+
//extract markdown body to html and compile to template
217+
function exportToHTML(view) {
218+
var title = renderTitle(ui.area.markdown);
219+
var filename = renderFilename(ui.area.markdown) + '.html';
220+
var src = view.clone();
221+
var eles = src.find('*');
222+
//remove syncscroll parts
223+
eles.removeClass('part');
224+
src.find('*[class=""]').removeAttr('class');
225+
eles.removeAttr('data-startline data-endline');
226+
eles.find("a[href^='#'][smoothhashscroll]").removeAttr('smoothhashscroll');
227+
//remove gist content
228+
src.find("code[data-gist-id]").children().remove();
229+
//disable todo list
230+
src.find("input.task-list-item-checkbox").attr('disabled', '');
231+
//replace emoji image path
232+
src.find("img.emoji").each(function (key, value) {
233+
var name = $(value).attr('alt');
234+
name = name.substr(1);
235+
name = name.slice(0, name.length - 1);
236+
$(value).attr('src', 'https://www.tortue.me/emoji/' + name + '.png');
237+
});
238+
//replace video to iframe
239+
src.find("div[videoid]").each(function (key, value) {
240+
var id = $(value).attr('videoid');
241+
var style = $(value).attr('style');
242+
var url = null;
243+
if ($(value).hasClass('youtube')) {
244+
url = 'https://www.youtube.com/embed/';
245+
} else if ($(value).hasClass('vimeo')) {
246+
url = 'https://player.vimeo.com/video/';
215247
}
248+
if (url) {
249+
var iframe = $('<iframe frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>');
250+
iframe.attr('src', url + id);
251+
iframe.attr('style', style);
252+
$(value).html(iframe);
216253
}
254+
});
255+
//generate toc
256+
var toc = $('#toc').clone();
257+
toc.find('*').removeClass('active');
258+
var tocAffix = $('#toc-affix').clone();
259+
tocAffix.find('*').removeClass('active');
260+
//generate html via template
261+
$.get('/css/html.min.css', function (css) {
262+
$.get('/views/html.hbs', function (data) {
263+
var template = Handlebars.compile(data);
264+
var context = {
265+
title: title,
266+
css: css,
267+
html: src[0].outerHTML,
268+
toc: toc.html(),
269+
'toc-affix': tocAffix.html()
270+
};
271+
var html = template(context);
272+
// console.log(html);
273+
var blob = new Blob([html], {
274+
type: "text/html;charset=utf-8"
275+
});
276+
saveAs(blob, filename);
277+
});
278+
});
217279
}
218280

219281
//jQuery sortByDepth

public/js/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,10 @@ var ui = {
285285
new: $(".ui-new"),
286286
publish: $(".ui-publish"),
287287
download: {
288-
markdown: $(".ui-download-markdown")
288+
markdown: $(".ui-download-markdown"),
289+
html: $(".ui-download-html")
289290
},
290-
save: {
291+
export: {
291292
dropbox: $(".ui-save-dropbox")
292293
},
293294
import: {
@@ -801,8 +802,12 @@ ui.toolbar.download.markdown.click(function () {
801802
});
802803
saveAs(blob, filename);
803804
});
804-
//save to dropbox
805-
ui.toolbar.save.dropbox.click(function () {
805+
//html
806+
ui.toolbar.download.html.click(function () {
807+
exportToHTML(ui.area.markdown);
808+
});
809+
//export to dropbox
810+
ui.toolbar.export.dropbox.click(function () {
806811
var filename = renderFilename(ui.area.markdown) + '.md';
807812
var options = {
808813
files: [

0 commit comments

Comments
 (0)