@@ -15,13 +15,16 @@ import { Counter, regexIndexOf } from "./utils.ts";
15
15
* ```
16
16
*/
17
17
export function parse ( content : string ) : Definition [ ] {
18
+ // Remove modeline
19
+ content = content . replace ( / \n v i m : [ ^ \n ] * \s * $ / , "" ) ;
20
+
18
21
const definitions : Definition [ ] = [ ] ;
19
22
for ( const match of content . matchAll ( / \* ( \w + ?) \( \) \* / g) ) {
20
23
const fn = match [ 1 ] ;
21
- const i = match . index || 0 ;
24
+ const i = match . index ?? 0 ;
22
25
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 ) ;
25
28
const e = content . lastIndexOf ( "\n" , me ) ;
26
29
const block = content
27
30
. substring ( s , e )
@@ -49,11 +52,11 @@ export function parse(content: string): Definition[] {
49
52
*/
50
53
function parseBlock ( fn : string , body : string ) : Definition {
51
54
// 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" ) ;
53
56
// 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" ) ;
55
58
// 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" ) ;
57
60
58
61
// Remove leading '>' or trailing '<' which is used to define code block in help
59
62
body = body . replaceAll ( / \n < | > \n / g, "\n" ) ;
0 commit comments