Created
January 11, 2018 02:38
-
-
Save elixirplayground/e2f0daa90c5c29d9873d3e583b498b75 to your computer and use it in GitHub Desktop.
elixirplayground.com code share
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Example do | |
def parse([]), do: [] | |
def parse([{"table", attrs, nested} | rest]) do | |
[{"v-table", attrs, parse(nested)} | parse(rest)] | |
end | |
def parse([{"thead", _attrs, nested} | rest]) do | |
[[parse(nested)] | parse(rest)] | |
end | |
def parse([{"tr", _attrs, nested} | rest]) do | |
[[parse(nested)] | parse(rest)] | |
end | |
def parse([{"th", _attrs, nested} | rest]) do | |
[[parse(nested)] | parse(rest)] | |
end | |
def parse([{"td", _attrs, content} | rest]) do | |
[content | parse(rest)] | |
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"]} | |
]} | |
]} | |
]} | |
parse(decodedHTML) | |
end | |
end | |
Example.test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment