@@ -60,6 +60,18 @@ function interpretEscapes(str) {
6060 return str . replace ( / \\ n / g, '\n' ) . replace ( / \\ t / g, '\t' )
6161}
6262
63+ /**
64+ * JSON.stringify replacer that handles RegExp objects
65+ * @param {string } key
66+ * @param {any } value
67+ */
68+ function jsonReplacer ( key , value ) {
69+ if ( value instanceof RegExp ) {
70+ return value . toString ( )
71+ }
72+ return value
73+ }
74+
6375/**
6476 * Check if string looks like markdown content vs a file path
6577 * @param {string } str
@@ -103,6 +115,7 @@ Options:
103115 --output Output directory
104116 --open Opening comment keyword (default: docs)
105117 --close Closing comment keyword (default: /docs)
118+ --json Output full result as JSON
106119 --pretty Render output with ANSI styling
107120 --dry Dry run - show what would be changed
108121 --debug Show debug output
@@ -130,7 +143,12 @@ Stdin/stdout mode:
130143 }
131144
132145 // Check if first positional arg is markdown content (before stdin check)
133- const firstArg = options . _ && options . _ [ 0 ]
146+ // Handle case where mri assigns content to a flag (e.g., --json '# content')
147+ let firstArg = options . _ && options . _ [ 0 ]
148+ const outputJson = options . json === true || ( typeof options . json === 'string' && isMarkdownContent ( options . json ) )
149+ if ( typeof options . json === 'string' && isMarkdownContent ( options . json ) ) {
150+ firstArg = options . json
151+ }
134152 const openKeyword = options . open || 'docs'
135153 const closeKeyword = options . close || ( options . open && options . open !== 'docs' ? `/${ options . open } ` : '/docs' )
136154 if ( firstArg && isMarkdownContent ( firstArg ) ) {
@@ -143,14 +161,12 @@ Stdin/stdout mode:
143161 transforms : defaultTransforms ,
144162 dryRun : true ,
145163 } )
146- // TODO future pretty option
147- // if (options.pretty) {
148- // console.log(await renderMarkdown(result.updatedContents))
149- // } else {
150- // console.log()
151- // console.log(result.updatedContents)
152- // }
153- console . log ( result . updatedContents )
164+ console . log ( 'result' , result )
165+ if ( outputJson ) {
166+ console . log ( JSON . stringify ( result , jsonReplacer , 2 ) )
167+ } else {
168+ console . log ( result . updatedContents )
169+ }
154170 return
155171 }
156172
@@ -168,14 +184,11 @@ Stdin/stdout mode:
168184 transforms : defaultTransforms ,
169185 dryRun : true , // Don't write files
170186 } )
171- // TODO future pretty option
172- // if (options.pretty) {
173- // console.log(await renderMarkdown(result.updatedContents))
174- // } else {
175- // console.log()
176- // console.log(result.updatedContents)
177- // }
178- console . log ( result . updatedContents )
187+ if ( outputJson ) {
188+ console . log ( JSON . stringify ( result , jsonReplacer , 2 ) )
189+ } else {
190+ console . log ( result . updatedContents )
191+ }
179192 return
180193 }
181194 }
0 commit comments