@@ -19,18 +19,23 @@ export function parse(content: string): Definition[] {
19
19
content = content . replace ( / \n v i m : [ ^ \n ] * \s * $ / , "" ) ;
20
20
21
21
const definitions : Definition [ ] = [ ] ;
22
+ let last = - 1 ;
22
23
for ( const match of content . matchAll ( / \* ( \w + ?) \( \) \* / g) ) {
23
24
const fn = match [ 1 ] ;
24
25
const i = match . index ?? 0 ;
26
+ if ( i < last ) {
27
+ // It is contained previous block
28
+ continue ;
29
+ }
25
30
const s = content . lastIndexOf ( "\n" , i ) ;
26
31
const ms = regexIndexOf ( content , / \n [ < > \s ] | $ / , i ) ;
27
32
const me = regexIndexOf ( content , / \n [ ^ < > \s ] | $ / , ms ) ;
28
33
const e = content . lastIndexOf ( "\n" , me ) ;
29
34
const block = content
30
35
. substring ( s , e )
31
- . replaceAll ( / \* \S + ?\* / g , "" ) // Remove tags
32
- . replaceAll ( / \s + \n / g , "\n" ) // Remove trailing '\s'
33
- . trim ( ) ;
36
+ . replace ( / \n < ? (?: \s + \ *\S + ?\* ) + \s * $ / , "" ) // Remove next block tag
37
+ . trimEnd ( ) ;
38
+ last = s + block . length ;
34
39
definitions . push ( parseBlock ( fn , block ) ) ;
35
40
}
36
41
return definitions ;
@@ -51,6 +56,11 @@ export function parse(content: string): Definition[] {
51
56
* This function parse content like above and return `Definition`.
52
57
*/
53
58
function parseBlock ( fn : string , body : string ) : Definition {
59
+ // Remove tags
60
+ body = body . replaceAll ( / \* \S + ?\* / g, "" ) ;
61
+ // Remove trailing spaces
62
+ body = body . split ( "\n" ) . map ( ( v ) => v . trimEnd ( ) ) . join ( "\n" ) ;
63
+
54
64
// Remove '\n' in {variant} to make {variant} single line (ex. `searchpairpos`)
55
65
body = body . replaceAll ( new RegExp ( `^(${ fn } \\([^)]*?)\\n\\t*` , "gm" ) , "$1" ) ;
56
66
// Append ')' for an invalid {variant}. (ex. `win_id2tabwin` in Neovim)
0 commit comments