diff --git a/compiler/Compiler.js b/compiler/Compiler.js index 5971bbf5e..4c346242f 100644 --- a/compiler/Compiler.js +++ b/compiler/Compiler.js @@ -70,13 +70,19 @@ class Compiler { ok(this.parser, '"options.parser" is required'); } - compile(src, filename) { + compile(src, filename, options) { ok(typeof src === 'string', '"src" argument should be a string'); ok(filename, '"filename" argument is required'); ok(typeof filename === 'string', '"filename" argument should be a string'); var context = new CompileContext(src, filename, this.builder); + if (options) { + if (options.preserveWhitespace) { + context.setPreserveWhitespace(true); + } + } + // STAGE 1: Parse the template to produce the initial AST var ast = this.parser.parse(src, context); context.root = ast; diff --git a/compiler/index.js b/compiler/index.js index e142909f2..8fc5fb783 100644 --- a/compiler/index.js +++ b/compiler/index.js @@ -76,14 +76,14 @@ function compileFile(filename, options, callback) { } try { - callback(null, compiler.compile(templateSrc, filename)); + callback(null, compiler.compile(templateSrc, filename, options)); } catch(e) { callback(e); } }); } else { let templateSrc = fs.readFileSync(filename, {encoding: 'utf8'}); - return compiler.compile(templateSrc, filename); + return compiler.compile(templateSrc, filename, options); } } @@ -105,7 +105,7 @@ function compile(src, filename, options, callback) { if (callback) { try { - callback(null, compiler.compile(src, filename)); + callback(null, compiler.compile(src, filename, options)); } catch(e) { callback(e); } diff --git a/runtime/loader.js b/runtime/loader.js index a97098d91..72b658c53 100644 --- a/runtime/loader.js +++ b/runtime/loader.js @@ -44,7 +44,7 @@ function loadSource(templatePath, compiledSrc) { return templateModule.exports; } -function loadFile(templatePath) { +function loadFile(templatePath, options) { templatePath = nodePath.resolve(cwd, templatePath); var targetDir = nodePath.dirname(templatePath); @@ -54,7 +54,7 @@ function loadFile(templatePath) { return require(targetFile); } - var compiledSrc = markoCompiler.compileFile(templatePath); + var compiledSrc = markoCompiler.compileFile(templatePath, options); // console.log('Compiled code for "' + templatePath + '":\n' + compiledSrc); var filename = nodePath.basename(targetFile); @@ -91,10 +91,10 @@ module.exports = function load(templatePath, templateSrc, options) { templateSrc = fs.readFileSync(templatePath, fsReadOptions); } - var compiledSrc = markoCompiler.compile(templateSrc, templatePath); + var compiledSrc = markoCompiler.compile(templateSrc, templatePath, options); return loadSource(templatePath, compiledSrc); } else { - return loadFile(templatePath); + return loadFile(templatePath, options); } }; diff --git a/taglibs/core/marko-taglib.json b/taglibs/core/marko-taglib.json index c2cc69f36..c6c6faaa8 100644 --- a/taglibs/core/marko-taglib.json +++ b/taglibs/core/marko-taglib.json @@ -39,6 +39,9 @@ "ignore": true } }, + "