|
357 | 357 | vimdoc.tag = function (buffer, _, text, range) |
358 | 358 | local after = vim.api.nvim_buf_get_text(buffer, range.row_start, range.col_end, range.row_start, -1, {})[1] or ""; |
359 | 359 |
|
| 360 | + if string.match(text[1], "%*hl%-.+%*") then |
| 361 | + local next_line = vim.api.nvim_buf_get_lines(buffer, range.row_start + 1, range.row_start + 2, false)[1]; |
| 362 | + local spaces, hl = string.match(next_line or "", "^(%s*)([a-zA-Z0-9_.@-]+)") |
| 363 | + |
| 364 | + if hl then |
| 365 | + vimdoc.internal_hl(buffer, _, { hl }, { |
| 366 | + row_start = range.row_start + 1, |
| 367 | + row_end = range.row_start + 1, |
| 368 | + |
| 369 | + col_start = #spaces, |
| 370 | + col_end = #spaces + vim.fn.strcharlen(hl); |
| 371 | + }); |
| 372 | + end |
| 373 | + end |
| 374 | + |
360 | 375 | vimdoc.insert({ |
361 | 376 | class = "vimdoc_tag", |
362 | 377 |
|
@@ -386,16 +401,30 @@ vimdoc.taglink = function (buffer, _, text, range) |
386 | 401 | }); |
387 | 402 | end |
388 | 403 |
|
| 404 | +--- Word processor for `default` help files. |
| 405 | +---@param text string[] |
| 406 | +---@param range helpview.parsed.range |
| 407 | +vimdoc.internal_hl = function (buffer, _, text, range) |
| 408 | + local after = vim.api.nvim_buf_get_text(buffer, range.row_start, range.col_end, range.row_start, -1, {})[1] or ""; |
| 409 | + |
| 410 | + vimdoc.insert({ |
| 411 | + class = "vimdoc_hl", |
| 412 | + |
| 413 | + group_name = text[1], |
| 414 | + after = after:match("^ +"), |
| 415 | + |
| 416 | + text = text, |
| 417 | + range = range |
| 418 | + }); |
| 419 | +end |
| 420 | + |
389 | 421 | --- Word processor. |
390 | 422 | ---@param text string[] |
391 | 423 | ---@param range helpview.parsed.range |
392 | 424 | vimdoc.hl = function (buffer, _, text, range) |
393 | 425 | if not vim.g.__helpview_hl_group_map then |
394 | | - -- Do not show highlight groups if we don't |
395 | | - -- have the highlight group map. |
396 | 426 | return; |
397 | 427 | elseif not text[1] or not vim.g.__helpview_hl_group_map[text[1]] then |
398 | | - -- Highlight group doesn't exist. |
399 | 428 | return; |
400 | 429 | end |
401 | 430 |
|
@@ -479,6 +508,16 @@ vimdoc.parse = function (buffer, TSTree, from, to) |
479 | 508 |
|
480 | 509 | if not capture_name:match("^vimdoc%.") then |
481 | 510 | goto continue |
| 511 | + elseif capture_name == "vimdoc.hl" then |
| 512 | + local runtime = vim.pesc( |
| 513 | + vim.fn.expand("$VIMRUNTIME") |
| 514 | + ); |
| 515 | + local bufname = vim.api.nvim_buf_get_name(buffer); |
| 516 | + |
| 517 | + if string.match(bufname, "^" .. runtime) then |
| 518 | + -- Use `vimdoc.default_hl()` for the builtin help files. |
| 519 | + goto continue; |
| 520 | + end |
482 | 521 | end |
483 | 522 |
|
484 | 523 | ---@type string? |
|
0 commit comments