1
1
import { Parent , Root , RootContent } from 'mdast'
2
2
import { remark } from 'remark'
3
- import remarkStringify from 'remark-stringify'
4
- import { Options } from 'remark-stringify'
3
+ import remarkStringify , { Options } from 'remark-stringify'
5
4
6
5
const REMARK_STRINGIFY_OPTIONS : Options = {
7
6
bullet : '*' ,
@@ -13,12 +12,11 @@ const REMARK_STRINGIFY_OPTIONS: Options = {
13
12
placeholder : ( node : PlaceholderNode ) => {
14
13
return node . value
15
14
}
16
- } as any
15
+ } as any
17
16
}
18
17
19
18
function createRemarkProcessor ( ) {
20
- return remark ( )
21
- . use ( remarkStringify , REMARK_STRINGIFY_OPTIONS )
19
+ return remark ( ) . use ( remarkStringify , REMARK_STRINGIFY_OPTIONS )
22
20
}
23
21
24
22
/**
@@ -31,7 +29,6 @@ export function customAstToString(ast: Root): string {
31
29
return processor . stringify ( ast ) . trim ( )
32
30
}
33
31
34
-
35
32
/**
36
33
* Process code blocks with labels and convert them to placeholders
37
34
*/
@@ -71,12 +68,16 @@ export function processCodeBlocksWithLabel(ast: Root): RootContent[] {
71
68
switch ( metas [ 'label' ] ) {
72
69
case 'changes' :
73
70
finalCommandText = 'contextCommand:changes'
74
- placeholderNode = createPlaceholderNode ( `[[contextCommand:${ finalCommandText } ]]` ) as unknown as RootContent
71
+ placeholderNode = createPlaceholderNode (
72
+ `[[contextCommand:${ finalCommandText } ]]`
73
+ ) as unknown as RootContent
75
74
break
76
75
case 'file' :
77
76
if ( metas [ 'object' ] ) {
78
77
try {
79
- placeholderNode = createPlaceholderNode ( `[[file:${ metas [ 'object' ] } ]]` ) as unknown as RootContent
78
+ placeholderNode = createPlaceholderNode (
79
+ `[[file:${ metas [ 'object' ] } ]]`
80
+ ) as unknown as RootContent
80
81
if ( ! placeholderNode ) {
81
82
shouldProcessNode = false
82
83
newChildren . push ( node )
@@ -90,7 +91,9 @@ export function processCodeBlocksWithLabel(ast: Root): RootContent[] {
90
91
case 'symbol' :
91
92
if ( metas [ 'object' ] ) {
92
93
try {
93
- placeholderNode = createPlaceholderNode ( `[[symbol:${ metas [ 'object' ] } ]]` ) as unknown as RootContent
94
+ placeholderNode = createPlaceholderNode (
95
+ `[[symbol:${ metas [ 'object' ] } ]]`
96
+ ) as unknown as RootContent
94
97
if ( ! placeholderNode ) {
95
98
shouldProcessNode = false
96
99
newChildren . push ( node )
@@ -201,20 +204,16 @@ export function formatObjectToMarkdownBlock(
201
204
} as RootContent
202
205
]
203
206
}
204
-
207
+
205
208
const processor = createRemarkProcessor ( )
206
-
209
+
207
210
const res = '\n' + processor . stringify ( codeNode ) . trim ( ) + '\n'
208
- return res ;
211
+ return res
209
212
} catch ( error ) {
210
213
return `\n*Error formatting ${ label } *\n`
211
214
}
212
215
}
213
216
214
-
215
-
216
-
217
-
218
217
export interface PlaceholderNode extends Node {
219
218
type : 'placeholder'
220
219
value : string
@@ -223,6 +222,6 @@ export interface PlaceholderNode extends Node {
223
222
export function createPlaceholderNode ( value : string ) : PlaceholderNode {
224
223
return {
225
224
type : 'placeholder' ,
226
- value : value ,
225
+ value : value
227
226
} as PlaceholderNode
228
227
}
0 commit comments