File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed
packages/theme/src/cli/utilities/theme-environment Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change 2626 * @param tag - The Liquid tag to extract content from.
2727 *
2828 * @returns The tag content, or undefined if not found.
29- *
3029 */
3130export function getLiquidTagContent ( liquid : string , tag : 'javascript' | 'stylesheet' | 'schema' ) : string | undefined {
32- const tagRE = new RegExp ( `{%-?\\s*${ tag } \\s*-?%}([^%]*){%-?\\s*end${ tag } \\s*-?%}` )
33- const match = liquid . match ( tagRE ) ?. [ 1 ]
34- return match
31+ const openTagRE = new RegExp ( `{%-?\\s*${ tag } \\s*-?%}` )
32+ const closeTagRE = new RegExp ( `{%-?\\s*end${ tag } \\s*-?%}` )
33+
34+ const openMatch = openTagRE . exec ( liquid )
35+
36+ if ( ! openMatch ) {
37+ return
38+ }
39+
40+ const startIndex = openMatch . index + openMatch [ 0 ] . length
41+ const closeMatch = closeTagRE . exec ( liquid )
42+
43+ if ( ! closeMatch ) {
44+ return
45+ }
46+
47+ const endIndex = closeMatch . index
48+
49+ if ( startIndex > endIndex ) {
50+ return
51+ }
52+
53+ return liquid . slice ( startIndex , endIndex )
3554}
You can’t perform that action at this time.
0 commit comments