File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,16 +17,27 @@ module.exports = (options = {}) => {
1717
1818 tree . match ( { tag : 'include' } , node => {
1919 let src = node . attrs . src || false ;
20- let locals = node . attrs . locals || ( node . content ? node . content . join ( ) . replace ( / ' \n ' / g, '' ) : false ) ;
2120 let content ;
2221 let subtree ;
2322 let source ;
23+ let locals ;
24+
25+ const localsString = node . attrs . locals || ( node . content ? node . content . join ( ) . replace ( / \n / g, '' ) : '' ) ;
26+ const tryToParseLocals = localsString . trim ( ) && localsString . trim ( ) . startsWith ( '{' ) ;
27+
28+ if ( tryToParseLocals ) {
29+ try {
30+ locals = JSON . parse ( localsString ) ;
31+ } catch {
32+ locals = false ;
33+ }
34+ }
2435
2536 if ( src ) {
2637 src = path . resolve ( options . root , src ) ;
2738 source = fs . readFileSync ( src , options . encoding ) ;
28- if ( locals && locals . includes ( ':' ) ) {
29- locals = JSON . parse ( locals ) ;
39+
40+ if ( locals ) {
3041 const result = posthtml ( )
3142 . use ( expressions ( { locals} ) )
3243 . process ( source , { sync : true } ) ;
You can’t perform that action at this time.
0 commit comments