@@ -76,60 +76,62 @@ export default function Transclude(source = 'string', options = {}) {
7676 let line = 1 ;
7777 let column = 0 ;
7878
79- // eslint-disable-next-line consistent-return
8079 function transclude ( chunk , cb ) {
8180 const self = this ;
8281
83- if ( ! chunk . link ) {
84- self . push ( chunk ) ;
85- return cb ( ) ;
86- }
82+ // eslint-disable-next-line consistent-return
83+ process . nextTick ( ( ) => {
84+ if ( ! chunk . link ) {
85+ self . push ( chunk ) ;
86+ return cb ( ) ;
87+ }
8788
88- const { parents, indent } = chunk ;
89- const sourceLine = chunk . line ;
90- const sourceColumn = chunk . column ;
91- const content = chunk . content ;
92-
93- let out ;
94- try {
95- out = applyReferences ( chunk ) ;
96- } catch ( error ) {
97- self . push ( chunk . link ) ;
98- return cb ( { message : 'Link could not be parsed' , path : source , error, line : sourceLine , column : sourceColumn } ) ;
99- }
89+ const { parents, indent } = chunk ;
90+ const sourceLine = chunk . line ;
91+ const sourceColumn = chunk . column ;
92+ const content = chunk . content ;
93+
94+ let out ;
95+ try {
96+ out = applyReferences ( chunk ) ;
97+ } catch ( error ) {
98+ self . push ( chunk . link ) ;
99+ return cb ( { message : 'Link could not be parsed' , path : source , error, line : sourceLine , column : sourceColumn } ) ;
100+ }
100101
101- const { link, nextReferences } = out ;
102- link . content = content ;
102+ const { link, nextReferences } = out ;
103+ link . content = content ;
103104
104- const { contentStream, resolvedUrl } = resolveToReadableStream ( link , resolvers ) ;
105- if ( _ . includes ( parents , resolvedUrl ) ) {
106- self . push ( link ) ;
107- return cb ( { message : 'Circular dependency detected' , path : resolvedUrl , line : link . line , column : link . column } ) ;
108- }
105+ const { contentStream, resolvedUrl } = resolveToReadableStream ( link , resolvers ) ;
106+ if ( _ . includes ( parents , resolvedUrl ) ) {
107+ self . push ( link ) ;
108+ return cb ( { message : 'Circular dependency detected' , path : resolvedUrl , line : link . line , column : link . column } ) ;
109+ }
109110
110- // Resolved URL will be undefined for quoted strings: :[exmple](link || "fallback" reference:"string")
111- const resolvedSource = resolvedUrl || link . source ;
112- const resolvedParents = resolvedSource ? parents : undefined ;
111+ // Resolved URL will be undefined for quoted strings: :[exmple](link || "fallback" reference:"string")
112+ const resolvedSource = resolvedUrl || link . source ;
113+ const resolvedParents = resolvedSource ? parents : undefined ;
113114
114- const nestedTransclude = new Transclude ( resolvedSource , {
115- transclusionSyntax,
116- inheritedParents : resolvedParents ,
117- inheritedReferences : nextReferences ,
118- inheritedIndent : indent ,
119- resolvers,
120- } ) ;
115+ const nestedTransclude = new Transclude ( resolvedSource , {
116+ transclusionSyntax,
117+ inheritedParents : resolvedParents ,
118+ inheritedReferences : nextReferences ,
119+ inheritedIndent : indent ,
120+ resolvers,
121+ } ) ;
121122
122- nestedTransclude
123- . on ( 'readable' , function inputReadable ( ) {
124- let streamContent ;
125- while ( ( streamContent = this . read ( ) ) !== null ) {
126- self . push ( streamContent ) ;
127- }
128- } )
129- . on ( 'error' , err => cb ( err ) )
130- . on ( 'end' , ( ) => cb ( null , true ) ) ;
131- contentStream . on ( 'error' , err => cb ( err ) ) ;
132- contentStream . pipe ( nestedTransclude ) ;
123+ nestedTransclude
124+ . on ( 'readable' , function inputReadable ( ) {
125+ let streamContent ;
126+ while ( ( streamContent = this . read ( ) ) !== null ) {
127+ self . push ( streamContent ) ;
128+ }
129+ } )
130+ . on ( 'error' , err => cb ( err ) )
131+ . on ( 'end' , ( ) => cb ( null , true ) ) ;
132+ contentStream . on ( 'error' , err => cb ( err ) ) ;
133+ contentStream . pipe ( nestedTransclude ) ;
134+ } ) ;
133135 }
134136
135137 function toToken ( chunk ) {
0 commit comments