apiblueprint.vim
apiblueprint.vim copied to clipboard
Syntax highlight the body block from a request and response section
Syntax highlight the body block from a request and response section. This should take the content-type in brackets and infer the type to a syntax. (application/json = javascript).
Example:
+ Request (application/json)
+ Headers
Key: Value
+ Response 201 (application/json)
{ "email": "[email protected]", "name": "Kyle Fuller", "token": "527d11fe429f3426cb8dbeba183a0d80" }
+ Request (application/json)
{ "email": "[email protected]", "name": "Kyle Fuller" }
+ Response 201 (application/json)
{ "email": "[email protected]", "name": "Kyle Fuller", "token": "527d11fe429f3426cb8dbeba183a0d80" }
+ Request (application/json)
+ Headers
Key: Value
+ Body
{ "email": "[email protected]", "name": "Kyle Fuller" }
@Keithbsmiley: Hey Keith, I have no idea how to implement the above in a vim syntax (my knowledge is very limited). Is it possible?
Would you be able to give me some pointers on where to begin? Just brief such as which vim command i'll need to use so I can read up. (There is example content here).
Thanks!
Here are my unabridged thoughts on this:
- If the answer to that question is yes, you could create individual syntax files that dealt with the different options individually. Since you can scan any number of lines to figure out the correct filetype (seen here)
- Otherwise you could attempt to wrap syntax highlighting by option. So what I'm thinking there is you could start a block like:
syntax region start="(application/json)" end="something" transparent nextgroup=javascriptSomething
Or possibly for that last guess you might want to use contains=javascriptSomething
All of this seems like a horrible pain in the ass. The best option here really would be the best.
Awesome, thanks for the tips. I'll go over and see if I can get this working. :+1:. Thank you so much!
The answer was no, different content-types could be found in the same file. So it needs to actually parse the content-type and figure out the syntax, then apply that syntax.
And the content may be directly under the request/response, or it may be wrapped further down in a Body block. That looks good, I'll have a play around. Seems the regex isn't true regex for matching.
That's too bad. Another thing. Checkout the syntax file built in for HTML. ftp://ftp.vim.org/pub/vim/runtime/syntax/html.vim
Search for:
syn include @htmlJavaScript syntax/javascript.vim
Looks like that's how they nest javascript correctly. So instead of that you'd do that with the ruby syntax file! You can view that locally with :e $VIMRUNTIME/syntax/html.vim
Here's another option: https://github.com/pangloss/vim-javascript/blob/a1165dca3e0cdc8754ca77ddd99510b1f093c04b/syntax/javascript.vim#L153-L179
This plugin just make sure the container contains all possible HTML and CSS elements. Not the most elegant option.
Another crazy amazing implementation: https://github.com/tpope/vim-markdown/blob/master/syntax/markdown.vim at https://github.com/tpope/vim-markdown/blob/master/syntax/markdown.vim#L18-L28 and https://github.com/tpope/vim-markdown/blob/master/syntax/markdown.vim#L91-L96
It produces these commands:

So it declares them as those include groups @markdownHighlight<lang> then it highlights blocks based on those include groups with the contains= based on the name of the language. Pretty genius stuff. Tim Pope never ceases to amaze.
Thanks for all your great links here @Keithbsmiley. Haven't found the time to sort this out but hopefully really soon. :+1:.