Skip to content

Commit

Permalink
feat: add xml type for response formatting and highlight (#181)
Browse files Browse the repository at this point in the history
* feat: add xml type for response formatting and highlight

* feat: add xml type for response formatting and highlight

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(doc): necessary installed dependency for example xml command fixed

---------

Co-authored-by: Javier Ugarte <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent 2b2bff7 commit f9edcfb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 6 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Add the following configuration to your Neovim setup with [lazy.nvim](https://gi
'--parser',
'html',
},
xml = {
'tidy', -- Make sure you have installed tidy in your system, e.g: brew install tidy-html5
'-xml',
'-i',
'-q',
},
},
},
keys = {
Expand Down Expand Up @@ -251,6 +257,12 @@ local default_config = {
'--parser',
'html',
},
xml = {
'tidy', -- Uses tidy to format XML responses
'-xml',
'-i',
'-q',
},
},
}
```
Expand All @@ -269,6 +281,12 @@ require('hurl').setup({
'--parser',
'html',
},
xml = {
'tidy', -- Customize the XML formatter command
'-xml',
'-i',
'-q',
},
},
})
```
Expand Down
18 changes: 18 additions & 0 deletions doc/hurl.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ Add the following configuration to your Neovim setup with lazy.nvim
'--parser',
'html',
},
xml = {
'tidy', -- Make sure you have installed tidy in your system, e.g: brew install tidy-html5
'-xml',
'-i',
'-q',
},
},
},
keys = {
Expand Down Expand Up @@ -326,6 +332,12 @@ CONFIGURATION *hurl.nvim-configuration*
'--parser',
'html',
},
xml = {
'tidy', -- Uses tidy to format XML responses
'-xml',
'-i',
'-q',
},
},
}
<
Expand All @@ -344,6 +356,12 @@ To apply these configurations, include them in your Neovim setup like this:
'--parser',
'html',
},
xml = {
'tidy', -- Customize the XML formatter command
'-xml',
'-i',
'-q',
},
},
})
<
Expand Down
6 changes: 5 additions & 1 deletion lua/hurl/history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ M.show = function(response)
if utils.is_html_response(content_type) then
container.show(response, 'html')
else
container.show(response, 'text')
if utils.is_xml_response(content_type) then
container.show(response, 'xml')
else
container.show(response, 'text')
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lua/hurl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ local default_config = {
'--parser',
'html',
},
xml = {
'tidy',
'-xml',
'-i',
'-q',
},
},
}
--- Global configuration for entire plugin, easy to access from anywhere
Expand Down
6 changes: 5 additions & 1 deletion lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ local function execute_hurl_cmd(opts, callback)
if utils.is_html_response(content_type) then
container.show(response, 'html')
else
container.show(response, 'text')
if utils.is_xml_response(content_type) then
container.show(response, 'xml')
else
container.show(response, 'text')
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lua/hurl/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local layout = Layout(
---@param data table
--- - body string
--- - headers table
---@param type 'json' | 'html' | 'text'
---@param type 'json' | 'html' | 'xml' | 'text'
M.show = function(data, type)
layout:mount()

Expand Down
2 changes: 1 addition & 1 deletion lua/hurl/split.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local M = {}
---@param data table
--- - body string
--- - headers table
---@param type 'json' | 'html' | 'text'
---@param type 'json' | 'html' | 'xml' | 'text'
M.show = function(data, type)
-- mount/open the component
split:mount()
Expand Down
13 changes: 11 additions & 2 deletions lua/hurl/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ end

--- Format the body of the request
---@param body string
---@param type 'json' | 'html' | 'text'
---@param type 'json' | 'html' | 'xml' | 'text'
---@return string[] | nil
util.format = function(body, type)
local formatters = _HURL_GLOBAL_CONFIG.formatters
or { json = { 'jq' }, html = { 'prettier', '--parser', 'html' } }
or {
json = { 'jq' },
html = { 'prettier', '--parser', 'html' },
xml = { 'tidy', '-xml', '-i', '-q' },
}

-- If no formatter is defined, return the body
if not formatters[type] then
Expand Down Expand Up @@ -170,6 +174,11 @@ util.is_html_response = function(content_type)
return string.find(content_type, 'text/html') ~= nil
end

util.is_xml_response = function(content_type)
return string.find(content_type, 'text/xml') ~= nil
or string.find(content_type, 'application/xml') ~= nil
end

--- Check if nvim is running in nightly or stable version
---@return boolean
util.is_nightly = function()
Expand Down

0 comments on commit f9edcfb

Please sign in to comment.