diff --git a/index.js b/index.js index 374391c..c7db41f 100644 --- a/index.js +++ b/index.js @@ -37,12 +37,11 @@ function parseLocals({options, node}, optionLocals, attributeLocals) { try { const locals = merge({...optionLocals}, {...attrLocals}, JSON.parse(attributeLocals)); - - return expressions({locals}); + return expressions({...options.expressions, locals}); } catch { const locals = merge({...optionLocals}, {...attrLocals}); - return expressions({locals}); + return expressions({...options.expressions, locals}); } } @@ -135,6 +134,7 @@ module.exports = (options = {}) => { options.attribute = options.attribute || 'href'; options.root = path.resolve(options.root || './'); options.attributeAsLocals = options.attributeAsLocals || false; + options.expressions = options.expressions || {}; return function (tree) { if (options.initial) { diff --git a/readme.md b/readme.md index f5eb991..bcf7d9d 100644 --- a/readme.md +++ b/readme.md @@ -74,7 +74,7 @@ Root path for modules lookup. Type: `array | function`\ Default: `[]` -PostHTML plugins to apply for every parsed module. +PostHTML plugins to apply for every parsed module. If a function provided, it will be called with module's file path. @@ -127,10 +127,18 @@ All attributes on `` will be added to [locals](#locals) Type: `object`\ Default: `{}` -Options for the PostHTML parser. +Options for the PostHTML parser. By default, [`posthtml-parser`](https://github.com/posthtml/posthtml-parser) is used. +### `expressions` + +Type: `object`\ +Default: `{}` + +Options to forward to [posthtml-expressions](https://github.com/posthtml/posthtml-expressions), like custom delimiters for example. Available options can be found [here](https://github.com/posthtml/posthtml-expressions#options). + + ## Component options ### `locals` diff --git a/test/locals.expressions.spec.html b/test/locals.expressions.spec.html new file mode 100644 index 0000000..e5fa89c --- /dev/null +++ b/test/locals.expressions.spec.html @@ -0,0 +1 @@ +
%[ foo ]%{{ ignored }}
diff --git a/test/test.js b/test/test.js index 0176c62..ebd14d8 100644 --- a/test/test.js +++ b/test/test.js @@ -195,3 +195,12 @@ test('Must parse attribute as locals', async t => { t.is(html, expected); }); + +test('Must use posthtml-expressions options', async t => { + const actual = ``; + const expected = `
bar{{ ignored }}
`; + + const html = await posthtml().use(plugin({expressions: {delimiters: ['%[', ']%']}})).process(actual).then(result => clean(result.html)); + + t.is(html, expected); +});