Allow for multiple xpath matches at the top level.
Showing
1 changed file
with
4 additions
and
4 deletions
... | @@ -18,10 +18,10 @@ export const getDocFromProps = async (props, options) => { | ... | @@ -18,10 +18,10 @@ export const getDocFromProps = async (props, options) => { |
18 | return parseHtml(html, { ...options, adjuster }) | 18 | return parseHtml(html, { ...options, adjuster }) |
19 | } | 19 | } |
20 | 20 | ||
21 | export const getNodeFromProps = async (props, options) => { | 21 | export const getNodesFromProps = async (props, options) => { |
22 | const doc = await getDocFromProps(props, options) | 22 | const doc = await getDocFromProps(props, options) |
23 | const { xpath } = props | 23 | const { xpath } = props |
24 | return xpath ? findNode(doc, xpath) : doc | 24 | return xpath ? findNode(doc, xpath, { single: false }) : [ doc ] |
25 | } | 25 | } |
26 | 26 | ||
27 | export const createAdjuster = (adjustments = {}) => { | 27 | export const createAdjuster = (adjustments = {}) => { |
... | @@ -39,8 +39,8 @@ export const createAdjuster = (adjustments = {}) => { | ... | @@ -39,8 +39,8 @@ export const createAdjuster = (adjustments = {}) => { |
39 | 39 | ||
40 | const { props } = Astro | 40 | const { props } = Astro |
41 | const { debug, replacers, slotHandler } = props | 41 | const { debug, replacers, slotHandler } = props |
42 | const node = await getNodeFromProps(props) | 42 | const nodes = await getNodesFromProps(props) |
43 | 43 | ||
44 | const nextDebug = debug ? debug - 1 : 0 | 44 | const nextDebug = debug ? debug - 1 : 0 |
45 | --- | 45 | --- |
46 | <Match node={node} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} adjuster={adjuster}/> | 46 | {nodes.map(node => <Match node={node} debug={nextDebug} replacers={replacers} slotHandler={slotHandler}/>)} | ... | ... |
-
Please register or sign in to post a comment