Support for HTML request bodies
bennypowers opened this issue · 2 comments
bennypowers commented
Using release 2.0.1, I got:
POST http://localhost:3333
Content-Type: text/html
Accept: text/html
<rh-card>
<h2 slot="header">SSR</h2>
</rh-card>
Error 09:09:57 AM notify.error [rest.nvim] ERROR: The tree-sitter node at the range [0:0 - 5:28] has a syntax error and cannot be parsed
Error 09:09:57 AM msg_show.lua_error Rest run Error executing Lua callback: .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:143: attempt to index local 'document_node' (a nil value)
stack traceback:
.../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:143: in function 'traverse_variables'
.../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:434: in function 'parse'
...al/share/nvim/lazy/rest.nvim/lua/rest-nvim/functions.lua:61: in function 'exec'
...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:44: in function 'impl'
...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:182: in function <...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:165>
More generally, rest.nvim may parse the mimetype in the Content-Type header and parse the request body using the associated ts parser
Originally posted by @bennypowers in #242 (comment)
boltlessengineer commented
Closing due to tree-sitter-http v3 release.
This is now possible in rest.nvim v3
bennypowers commented
Thanks. I added this query in ~/.config/nvim/after/queries/http/injections.scm
to get HTML highlighting, since i suppose i don't have the xml highlighter installed
; extends
(document
(section
(request
(header
(header_entity) @_header
(value) @_value)
(#eq? @_value "text/html")
(#match? @_header "^[cC][oO][nN][tT][eE][nN][tT]-[tT][yY][pP][eE]$")
(xml_body) @injection.content
(#set! injection.language "html"))))