Skip to content

Commit

Permalink
Merge pull request #79 from cloudfour/fix-pre_html_output
Browse files Browse the repository at this point in the history
Fix: <pre> HTML output
  • Loading branch information
erikjung committed Apr 21, 2016
2 parents c442741 + 4c3a1aa commit ef8de38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import parsers from './parse/parsers';

const defaults = {
beautifier: {
indent_size: 2,
indent_char: ' ',
indent_size: 2,
indent_with_tabs: false,
wrap_attributes: 'auto',
wrap_attributes_indent_size: 1,
wrap_line_length: 60,
unformatted:
`a abbr acronym address b bdo big cite code col del dfn dt em font
h1 h2 h3 h4 h5 h6 i img ins kbd mark pre q s samp small span
Expand Down
9 changes: 7 additions & 2 deletions src/helpers/pattern.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {html as beautify} from 'js-beautify';
import DrizzleError from '../utils/error';
import { deepPattern } from '../utils/object';
import { patternContext } from '../utils/context';
Expand Down Expand Up @@ -54,8 +55,12 @@ function registerPatternHelpers (options) {
*/
Handlebars.registerHelper('patternSource', (id, rootContext, opts) => {
const renderedTemplate = renderPatternPartial(
id, rootContext.drizzle, Handlebars);
return Handlebars.Utils.escapeExpression(renderedTemplate);
id,
rootContext.drizzle,
Handlebars
);
const sourceMarkup = beautify(renderedTemplate, options.beautifier);
return Handlebars.Utils.escapeExpression(sourceMarkup);
});
return Handlebars;
}
Expand Down
9 changes: 8 additions & 1 deletion src/utils/render.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Options for Handlebars.compile()
*/
const compileOptions = {
preventIndent: true
};

function applyTemplate (template, context, options) {
if (typeof template !== 'function') {
template = compileTemplate(template, options);
Expand All @@ -6,7 +13,7 @@ function applyTemplate (template, context, options) {
}

function compileTemplate (template, options) {
return options.handlebars.compile(template);
return options.handlebars.compile(template, compileOptions);
}

export { applyTemplate,
Expand Down

0 comments on commit ef8de38

Please sign in to comment.