@@ -69,30 +69,6 @@ export const convertRawTypstAstStringToObject = (rawTypstAstString: string) => {
69
69
return parsed . ast as TypstAstNode ;
70
70
} ;
71
71
72
- /**
73
- * Convert a Typst AST node type to a textlint AST node type.
74
- * @param typstAstNodeType The Typst AST node type.
75
- * @returns The textlint AST node type.
76
- **/
77
- export const convertTypstAstNodeTypeToTextlintNodeType = (
78
- typstAstNodeType : string ,
79
- ) : string => {
80
- const nodeTypeMap = new Map < RegExp , string > ( [
81
- [ / ^ M a r k e d : : H e a d i n g $ / , ASTNodeTypes . Header ] ,
82
- [ / ^ M a r k e d : : T e x t / , ASTNodeTypes . Str ] ,
83
- [ / ^ M a r k e d : : P a r b r e a k / , ASTNodeTypes . Break ] ,
84
- [ / ^ E s c a p e : : L i n e b r e a k / , ASTNodeTypes . Break ] ,
85
- ] ) ;
86
-
87
- for ( const [ pattern , nodeType ] of nodeTypeMap ) {
88
- if ( pattern . test ( typstAstNodeType ) ) {
89
- return nodeType ;
90
- }
91
- }
92
-
93
- return typstAstNodeType ;
94
- } ;
95
-
96
72
interface TypstAstNode {
97
73
s : string ;
98
74
c ?: TypstAstNode [ ] ;
@@ -296,13 +272,22 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
296
272
297
273
const endOffset = currentOffset + nodeLength ;
298
274
299
- node . type = convertTypstAstNodeTypeToTextlintNodeType (
300
- extractNodeType ( node . s ) ,
301
- ) ;
302
275
node . raw = extractRawSourceByLocation ( typstSource , location ) ;
303
276
node . range = [ startOffset , endOffset ] ;
304
277
node . loc = location ;
305
-
278
+ node . type = extractNodeType ( node . s ) ;
279
+ if ( / ^ M a r k e d : : H e a d i n g $ / . test ( node . type ) ) {
280
+ node . type = ASTNodeTypes . Header ;
281
+ }
282
+ if ( / ^ M a r k e d : : T e x t / . test ( node . type ) ) {
283
+ node . type = ASTNodeTypes . Str ;
284
+ }
285
+ if ( / ^ M a r k e d : : P a r b r e a k / . test ( node . type ) ) {
286
+ node . type = ASTNodeTypes . Break ;
287
+ }
288
+ if ( / ^ E s c a p e : : L i n e b r e a k / . test ( node . type ) ) {
289
+ node . type = ASTNodeTypes . Break ;
290
+ }
306
291
if ( node . type === "Marked::Raw" ) {
307
292
if ( node . loc . start . line === node . loc . end . line ) {
308
293
// If Code
0 commit comments