@@ -87,8 +87,32 @@ Default config:
8787---
8888]]
8989
90+ --- Converts markdown "```" codeblock to vimdoc format.
91+ local function codeblock_to_vimdoc (doc )
92+ local function make_fn (before , extra )
93+ return function (lang , code )
94+ if not code then
95+ code = lang
96+ lang = ' '
97+ end
98+ -- Indent code by 2 spaces.
99+ return before .. ' >' .. lang .. extra .. code :gsub (' [^\n ]+' , ' %0' )
100+ end
101+ end
102+
103+ doc = doc
104+ -- "```lang" following a nonblank line.
105+ :gsub (' [^%s]\n ```(%w+)\n (.-)\n ```' , make_fn (' ' , ' \n ' ))
106+ -- "```lang" following a blank line.
107+ :gsub (' \n ```(%w+)\n (.-)\n ```' , make_fn (' ' , ' \n ' ))
108+ -- "```" (no language)
109+ :gsub (' \n ```\n (..-)\n ```' , make_fn (' ' , ' \n ' ))
110+
111+ return doc
112+ end
113+
90114--- Gets docstring by looking for "@brief" in a Lua code docstring.
91- local function extract_brief (text )
115+ local function extract_brief (text , is_markdown )
92116 local doc = text :match (' %-%-+ *%@brief.-(\n %-%-.*)' )
93117 if not doc then
94118 return ' '
@@ -99,12 +123,18 @@ local function extract_brief(text)
99123 doc = doc :gsub (' \n %-%-+' , ' \n ' )
100124 -- Remove leading whitespace (shared indent).
101125 doc = vim .trim (vim .text .indent (0 , doc ))
126+
127+ -- Convert codeblocks for vimdoc.
128+ if not is_markdown then
129+ doc = codeblock_to_vimdoc (doc )
130+ end
131+
102132 return doc
103133end
104134
105135local function make_lsp_section (config_sections , config_name , config_file , is_markdown )
106136 local config = require (' lsp.' .. config_name )
107- local docstring = extract_brief (readfile (config_file ))
137+ local docstring = extract_brief (readfile (config_file ), is_markdown )
108138 local params = {
109139 config_name = config_name ,
110140 preamble = docstring ,
@@ -186,8 +216,7 @@ local function make_lsp_sections(is_markdown)
186216 -- vim.env.HOME = '/home/user'
187217 -- vim.env.XDG_CACHE_HOME = '/home/user/.cache'
188218 local old_fn = vim .fn
189- local new_fn = {}
190- vim .fn = setmetatable (new_fn , {
219+ vim .fn = setmetatable ({}, {
191220 __index = function (_t , key )
192221 if key == ' getpid' then
193222 return function ()
0 commit comments