From 8e0709dfb013e91abe2226d986c9739a49bd8015 Mon Sep 17 00:00:00 2001 From: Cosmin Popovici Date: Thu, 16 Mar 2023 15:04:43 +0200 Subject: [PATCH] feat: posthtml parser options --- readme.md | 1 + src/index.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 10f7080..c960999 100644 --- a/readme.md +++ b/readme.md @@ -116,6 +116,7 @@ You can run `npm run build` to compile them. | **propsContext** | `props` | String value used as object name inside the script to process process before passed to the component. | | **propsAttribute** | `props` | String value for props attribute to define props as JSON. | | **propsSlot** | `props` | String value used to retrieve the props passed to slot via `$slots.slotName.props`. | +| **parserOptions** | `{recognizeSelfClosing: true}` | Object to configure `posthtml-parser`. By default, it enables support for self-closing component tags. | | **expressions** | `{}` | Object to configure `posthtml-expressions`. You can pre-set locals or customize the delimiters for example. | | **plugins** | `[]` | PostHTML plugins to apply for every parsed components. | | **matcher** | `[{tag: options.tagPrefix}]` | Array of object used to match the tags. | diff --git a/src/index.js b/src/index.js index c258a93..9bbf32b 100644 --- a/src/index.js +++ b/src/index.js @@ -50,6 +50,7 @@ module.exports = (options = {}) => tree => { options.propsContext = options.propsContext || 'props'; options.propsAttribute = options.propsAttribute || 'props'; options.propsSlot = options.propsSlot || 'props'; + options.parserOptions = options.parserOptions || {recognizeSelfClosing: true}; options.expressions = options.expressions || {}; options.plugins = options.plugins || []; options.attrsParserRules = options.attrsParserRules || {}; @@ -180,7 +181,7 @@ function processTree(options) { log(`${++processCounter}) Processing "${currentNode.tag}" from "${componentPath}"`, 'processTree'); - let nextNode = parser(readFileSync(componentPath, 'utf8')); + let nextNode = parser(readFileSync(componentPath, 'utf8'), options.parserOptions); // Set filled slots setFilledSlots(currentNode, filledSlots, options);