Skip to content
This repository has been archived by the owner on Aug 1, 2020. It is now read-only.

Commit

Permalink
Add user-configurable beautify filter
Browse files Browse the repository at this point in the history
Use the theme's `beautify` configuration as a custom beautification
function or options for JS Beautify.
  • Loading branch information
timswalling committed Mar 6, 2017
1 parent 069bae9 commit b995841
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b995841

Please sign in to comment.