Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule Example do
- def parse(elements, acc \\ [])
- def parse([], acc), do: Enum.reverse(acc)
- def parse([{"table", attrs, nested} | rest], acc) do
- parse(rest, [{"v-table", attrs, parse(nested)} | acc])
- end
- def parse([{"thead", _attrs, nested} | rest], acc) do
- parse(rest, parse(nested) ++ acc)
- end
- def parse([{"tbody", _attrs, nested} | rest], acc) do
- parse(rest, parse(nested) ++ acc)
- end
- def parse([{"tr", _attrs, nested} | rest], acc) do
- parse(rest, [parse(nested) | acc])
- end
- def parse([{"th", _attrs, [content]} | rest], acc) do
- parse(rest, [content | acc])
- end
- def parse([{"td", _attrs, [content]} | rest], acc) do
- parse(rest, [content | acc])
- end
- def test do
- decodedHTML = [{"table", [{"class", "table table-striped"}],
- [
- {"thead", [],
- [
- {"tr", [],
- [
- {"th", [{"scope", "col"}], ["#"]},
- {"th", [{"scope", "col"}], ["First"]},
- {"th", [{"scope", "col"}], ["Last"]},
- {"th", [{"scope", "col"}], ["Handle"]}
- ]}
- ]},
- {"tbody", [],
- [
- {"tr", [],
- [
- {"th", [{"scope", "row"}], ["1"]},
- {"td", [], ["Mark"]},
- {"td", [], ["Otto"]},
- {"td", [], ["@mdo"]}
- ]},
- {"tr", [],
- [
- {"th", [{"scope", "row"}], ["2"]},
- {"td", [], ["Jacob"]},
- {"td", [], ["Thornton"]},
- {"td", [], ["@fat"]}
- ]},
- {"tr", [],
- [
- {"th", [{"scope", "row"}], ["3"]},
- {"td", [], ["Larry"]},
- {"td", [], ["the Bird"]},
- {"td", [], ["@twitter"]}
- ]}
- ]}
- ]}]
- IO.inspect parse(decodedHTML)
- end
- end
- Example.test
Add Comment
Please, Sign In to add comment