From b995841de6b336fae80aff2914047d98e527f57b Mon Sep 17 00:00:00 2001 From: Tim Swalling Date: Mon, 6 Mar 2017 09:20:15 +0000 Subject: [PATCH] Add user-configurable `beautify` filter Use the theme's `beautify` configuration as a custom beautification function or options for JS Beautify. --- src/filters.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/filters.js b/src/filters.js index b6e40f9..865dc80 100644 --- a/src/filters.js +++ b/src/filters.js @@ -24,12 +24,21 @@ module.exports = function(theme, env, app){ }); env.engine.addFilter('beautify', function(str) { - return beautifyHTML(str, { - // TODO: move to config - indent_size: 4, - preserve_newlines: true, - max_preserve_newlines: 1 - }); + const defaults = { + indent_size: 4, + preserve_newlines: true, + max_preserve_newlines: 1 + }; + + let beautifyOptions = theme.getOption('beautify') || {}; + + if (typeof beautifyOptions === 'function') { + return beautifyOptions(str); + } + + beautifyOptions = _.merge({}, defaults, beautifyOptions); + + return beautifyHTML(str, beautifyOptions); }); env.engine.addFilter('resourceUrl', function(str) {