diff --git a/CHANGELOG.md b/CHANGELOG.md index 309ef8f3..9b9feaac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * adds scroll position reset on location change (issue [#279](https://github.com/lrsjng/h5ai/issues/279)) * adds option to hide unreadable files * adds option where to place folders (top, inplace, bottom) +* adds markdown support for custom header and footer files * fixes QR code URI origin (issue [#287](https://github.com/lrsjng/h5ai/issues/287)) * improves preview GUI * adds Google UA support diff --git a/src/_h5ai/client/css/inc/content.less b/src/_h5ai/client/css/inc/content.less index ddda9b97..75abee3a 100644 --- a/src/_h5ai/client/css/inc/content.less +++ b/src/_h5ai/client/css/inc/content.less @@ -17,6 +17,10 @@ color: #555; } } + + pre, code { + font-family: @font-family-mono; + } } #content-header { diff --git a/src/_h5ai/client/js/inc/core/resource.js b/src/_h5ai/client/js/inc/core/resource.js index 8e864534..384aeae7 100644 --- a/src/_h5ai/client/js/inc/core/resource.js +++ b/src/_h5ai/client/js/inc/core/resource.js @@ -4,6 +4,7 @@ modulejs.define('core/resource', ['_', 'config', 'core/settings'], function (_, var imagesHref = settings.appHref + 'client/images/', fallbackHref = settings.appHref + 'client/images/fallback/', themesHref = settings.appHref + 'client/themes/', + scriptsHref = settings.appHref + 'client/js/', fallbacks = ['file', 'folder', 'folder-page', 'folder-parent', 'ar', 'aud', 'bin', 'img', 'txt', 'vid'], image = function (id) { @@ -29,10 +30,39 @@ modulejs.define('core/resource', ['_', 'config', 'core/settings'], function (_, } return fallbackHref + 'file.svg'; + }, + + loadScript = function (url, globalId, callback) { + + if (window[globalId]) { + callback(window[globalId]); + } else { + $.ajax({ + url: url, + dataType: 'script', + complete: function () { + + callback(window[globalId]); + } + }); + } + }, + + loadSyntaxhighlighter = function (callback) { + + loadScript(scriptsHref + 'syntaxhighlighter.js', 'SyntaxHighlighter', callback); + }, + + loadMarkdown = function (callback) { + + loadScript(scriptsHref + 'markdown.js', 'markdown', callback); }; + return { image: image, - icon: icon + icon: icon, + loadSyntaxhighlighter: loadSyntaxhighlighter, + loadMarkdown: loadMarkdown }; }); diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 613165e5..7d116740 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -1,5 +1,5 @@ -modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/event'], function (_, $, allsettings, server, event) { +modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/event', 'core/resource'], function (_, $, allsettings, server, event, resource) { var settings = _.extend({ enabled: false @@ -10,16 +10,38 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/e server.request({action: 'get', custom: true, customHref: item.absHref}, function (response) { var h, f; + if (response) { + if (response.custom.header) { - $('#content-header').html(response.custom.header).stop().slideDown(200); + if (response.custom.header_type === 'md') { + resource.loadMarkdown(function (md) { + + if (md) { + $('#content-header').html(md.toHTML(response.custom.header)).stop().slideDown(200); + } + }); + } else { + $('#content-header').html(response.custom.header).stop().slideDown(200); + } h = true; } + if (response.custom.footer) { - $('#content-footer').html(response.custom.footer).stop().slideDown(200); + if (response.custom.footer_type === 'md') { + resource.loadMarkdown(function (md) { + + if (md) { + $('#content-footer').html(md.toHTML(response.custom.footer)).stop().slideDown(200); + } + }); + } else { + $('#content-footer').html(response.custom.footer).stop().slideDown(200); + } f = true; } } + if (!h) { $('#content-header').stop().slideUp(200); } diff --git a/src/_h5ai/client/js/inc/ext/preview-txt.js b/src/_h5ai/client/js/inc/ext/preview-txt.js index ee857a27..c001b7a2 100644 --- a/src/_h5ai/client/js/inc/ext/preview-txt.js +++ b/src/_h5ai/client/js/inc/ext/preview-txt.js @@ -1,5 +1,5 @@ -modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'ext/preview'], function (_, $, allsettings, event, preview) { +modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'core/resource', 'ext/preview'], function (_, $, allsettings, event, resource, preview) { var settings = _.extend({ enabled: false, @@ -46,30 +46,6 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'ex return $(brush.getHtml(content)).find('.line'); }, - loadScript = function (url, globalId, callback) { - - if (window[globalId]) { - callback(window[globalId]); - } else { - $.ajax({ - url: url, - dataType: 'script', - complete: function () { - - callback(window[globalId]); - } - }); - } - }, - loadSyntaxhighlighter = function (callback) { - - loadScript(allsettings.appHref + 'client/js/syntaxhighlighter.js', 'SyntaxHighlighter', callback); - }, - loadMarkdown = function (callback) { - - loadScript(allsettings.appHref + 'client/js/markdown.js', 'markdown', callback); - }, - preloadText = function (absHref, callback) { $.ajax({ @@ -132,7 +108,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'ex $text = $(templateMarkdown).text(textContent); - loadMarkdown(function (md) { + resource.loadMarkdown(function (md) { if (md) { $text.html(md.toHTML(textContent)); @@ -142,7 +118,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'ex $text = $(templateText).text(textContent); - loadSyntaxhighlighter(function (sh) { + resource.loadSyntaxhighlighter(function (sh) { if (sh) { var $table = $('