@@ -15,13 +15,16 @@ import { Counter, regexIndexOf } from "./utils.ts";
1515 * ```
1616 */
1717export function parse ( content : string ) : Definition [ ] {
18+ // Remove modeline
19+ content = content . replace ( / \n v i m : [ ^ \n ] * \s * $ / , "" ) ;
20+
1821 const definitions : Definition [ ] = [ ] ;
1922 for ( const match of content . matchAll ( / \* ( \w + ?) \( \) \* / g) ) {
2023 const fn = match [ 1 ] ;
21- const i = match . index || 0 ;
24+ const i = match . index ?? 0 ;
2225 const s = content . lastIndexOf ( "\n" , i ) ;
23- const ms = regexIndexOf ( content , / \n [ < > \s ] / , i ) ;
24- const me = regexIndexOf ( content , / \n [ ^ < > \s ] / , ms ) ;
26+ const ms = regexIndexOf ( content , / \n [ < > \s ] | $ / , i ) ;
27+ const me = regexIndexOf ( content , / \n [ ^ < > \s ] | $ / , ms ) ;
2528 const e = content . lastIndexOf ( "\n" , me ) ;
2629 const block = content
2730 . substring ( s , e )
@@ -49,11 +52,11 @@ export function parse(content: string): Definition[] {
4952 */
5053function parseBlock ( fn : string , body : string ) : Definition {
5154 // Remove '\n' in {variant} to make {variant} single line (ex. `searchpairpos`)
52- body = body . replaceAll ( new RegExp ( `^\ (${ fn } \\([^\ )]*?\)\n\ t*` , "g " ) , "$1" ) ;
55+ body = body . replaceAll ( new RegExp ( `^(${ fn } \\([^)]*?)\\n\\ t*` , "gm " ) , "$1" ) ;
5356 // Append ')' for an invalid {variant}. (ex. `win_id2tabwin` in Neovim)
54- body = body . replaceAll ( new RegExp ( `^\ (${ fn } \\([^\ )]*?\)\ t+` , "g " ) , "$1)\t" ) ;
57+ body = body . replaceAll ( new RegExp ( `^(${ fn } \\([^)]*?)\\ t+` , "gm " ) , "$1)\t" ) ;
5558 // Insert '\n' between {variant} and {document} (ex. `argidx`)
56- body = body . replaceAll ( new RegExp ( `^\ (${ fn } \\(.*?\\)\)\ t` , "g " ) , "$1\n\t\t" ) ;
59+ body = body . replaceAll ( new RegExp ( `^(${ fn } \\(.*?\\))\\ t` , "gm " ) , "$1\n\t\t" ) ;
5760
5861 // Remove leading '>' or trailing '<' which is used to define code block in help
5962 body = body . replaceAll ( / \n < | > \n / g, "\n" ) ;
0 commit comments