Skip to content
Open
Changes from all 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
22 changes: 19 additions & 3 deletions h5tk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,39 @@ function fmt_traverse_aux_attr(tree)
end
end

-- sort element attributes, in order to achieve identical
-- output with same input values
local function sort_attr(tree)
local t = {}
for k, _ in pairs(tree) do
if type(k) == "string" then
t[#t+1] = k
end
end
table.sort(t)
return t
end

-- queries all values with string keys and
-- folds the together to one single string
-- using fmt_traverse_aux_attr
function fmt_traverse_attr(tree)
local attr = buffer_get()

for k, v in pairs(tree) do
-- ensure alphabetical attribute order
local keys = sort_attr(tree)
for _, k in ipairs(keys) do
local v = tree[k]
if type(k) == "string" then
buffer_add(attr, " " .. k .. "=\"")
buffer_add(attr, fmt_traverse_aux_attr(v))
buffer_add(attr, "\"")
end
end

return buffer_tostring(attr)
end


function fmt_traverse_data(source)
local tree = tree_get()

Expand Down