neovim / tree-sitter-vimdoc

Tree-sitter parser for Vim help files
Apache License 2.0
97 stars 13 forks source link

feat: annotated code blocks #65

Closed clason closed 1 year ago

clason commented 1 year ago
This is a Lua block: >lua
    local foo = 'bar'

This is a Vimscript block: >vim
    au FileType lua setl sw=2

This is a C block: >c
    int *p = get_local_errno(); *p = EINVAL
<
This is a standard block: >
    $ nvim --clean +'q'
<
image

Note that the alternative syntax lua> is much trickier, since the rule for the language marker lua conflicts with normal text rule for the word lua. In either case, the added markers are trivial (and necessary) to add to the legacy syntax file.

Closes #2

clason commented 1 year ago

@justinmk I think this is good to go. The next step is to adapt scripts/gen_help_html.lua to

  1. eat the language node
  2. only show the code node wrapped in a <code class='language-<language>'></code> block

and inject highlight.js to the neovim.io/doc/user pages. But for that the ball is in your corner :)

justinmk commented 1 year ago

I found some cases in the help docs that we should test for:

runtime/bugreport.vim|20 col 20| :  !echo "uname -a" >bugreport.txt
runtime/doc/eval.txt|1051 col 2| >0 / 0  =  0x7fffffff  (like positive infinity)
runtime/doc/eval.txt|1057 col 2| >0 / 0  =  0x7fffffffffffffff  (like positive infinity)
runtime/doc/luaref.txt|460 col 24| while (  step  >0 and  var  <=  limit  )
runtime/doc/usr_02.txt|548 col 7| :help >cont
runtime/doc/usr_10.txt|707 col 17| sort <input.txt >output.txt
clason commented 1 year ago

runtime/bugreport.vim|20 col 20| : !echo "uname -a" >bugreport.txt

Not a help file.

runtime/doc/eval.txt|1051 col 2| >0 / 0 = 0x7fffffff (like positive infinity) runtime/doc/eval.txt|1057 col 2| >0 / 0 = 0x7fffffffffffffff (like positive infinity)

Not at the end of the line, so doesn't match.

runtime/doc/luaref.txt|460 col 24| while ( step >0 and var <= limit ) runtime/doc/usr_02.txt|548 col 7| :help >cont runtime/doc/usr_10.txt|707 col 17| sort output.txt

Inside a codeblock (and not on the end of the line or not [a-z0-9]+), so doesn't match.

justinmk commented 1 year ago

Not at the end of the line, so doesn't match.

worth adding an explicit case to the corpus?

clason commented 1 year ago

Oh, I see what you mean. Yes, I can see about adding a case with whitespace and not at the end of the line; maybe variants of the usr_*.txt examples.

justinmk commented 1 year ago

not a blocker, but this bugs me about >lua :

This is just thinking out loud. Will merge this later this week.

clason commented 1 year ago

Sorry, I tried to make that work; I failed.