-- Push dedented lines of markup onto output and return true;
-- otherwise return false because:
-- * props include a multiline string
-- * text has more than one adjacent line
-- * markup does not close

function dedentMarkup(input: Array<string>, output: Array<string>): boolean
	local line = input[#output + 1]

	if not dedentStartTag(input, output) then
		return false
	end

	if string.find(input[#output], "/>") then
		return true
	end

	local isText = false
	local stack: Array<number> = {}
	table.insert(stack, getIndentationLength(line))

	while #stack > 0 and #output < #input do
		line = input[#output + 1]

		if isFirstLineOfTag(line) then
			if string.find(line, "</") then
				table.insert(output, dedentLine(line))
				table.remove(stack)
			else
				if not dedentStartTag(input, output) then
					return false
				end

				if not string.find(input[#output], "/>") then
					table.insert(stack, getIndentationLength(line))
				end
			end
			isText = false
		else
			if isText then
				return false -- because text has more than one adjacent line
			end

			local getIndentationLengthOfTag = stack[#stack]
			table.insert(output, line:sub(getIndentationLengthOfTag + 3))
			isText = true
		end
	end

	return #stack == 0
end
