Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add xml type for response formatting and highlight #181

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 install prettier in your system, e.g: npm install -g prettier
jellydn marked this conversation as resolved.
Show resolved Hide resolved
'-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
Loading