@@ -19,18 +19,23 @@ export function parse(content: string): Definition[] {
1919 content = content . replace ( / \n v i m : [ ^ \n ] * \s * $ / , "" ) ;
2020
2121 const definitions : Definition [ ] = [ ] ;
22+ let last = - 1 ;
2223 for ( const match of content . matchAll ( / \* ( \w + ?) \( \) \* / g) ) {
2324 const fn = match [ 1 ] ;
2425 const i = match . index ?? 0 ;
26+ if ( i < last ) {
27+ // It is contained previous block
28+ continue ;
29+ }
2530 const s = content . lastIndexOf ( "\n" , i ) ;
2631 const ms = regexIndexOf ( content , / \n [ < > \s ] | $ / , i ) ;
2732 const me = regexIndexOf ( content , / \n [ ^ < > \s ] | $ / , ms ) ;
2833 const e = content . lastIndexOf ( "\n" , me ) ;
2934 const block = content
3035 . 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 ;
3439 definitions . push ( parseBlock ( fn , block ) ) ;
3540 }
3641 return definitions ;
@@ -51,6 +56,11 @@ export function parse(content: string): Definition[] {
5156 * This function parse content like above and return `Definition`.
5257 */
5358function 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+
5464 // Remove '\n' in {variant} to make {variant} single line (ex. `searchpairpos`)
5565 body = body . replaceAll ( new RegExp ( `^(${ fn } \\([^)]*?)\\n\\t*` , "gm" ) , "$1" ) ;
5666 // Append ')' for an invalid {variant}. (ex. `win_id2tabwin` in Neovim)
0 commit comments