-module(ml9_2_html). -export([exec/2]). -import(lists, [map/2, member/2]). exec(File, Parse) -> B = filename:rootname(File), Parse1 = map(fun(I) -> xform(I, Parse) end, Parse), file:write_file(B ++ ".html", [css(),Parse1]). css() -> ["", "
",Str,""]; C -> color(C, ["
",Str,""]) end; xform(Other, _) -> io:format("ignoring:~p~n",[Other]), []. color(C, X) -> ["
| ", X, " |
",map(fun inline_to_html/1, X)].
inline_to_html({str,S}) -> S;
inline_to_html({italic, S}) -> ["",S,""];
inline_to_html({bold,S}) -> ["",S,""];
inline_to_html({code,S}) -> ["",S,""];
inline_to_html({link,Str}) ->
case member($|, Str) of
true ->
case string:tokens(Str,"|") of
[Href,Text] ->
["",Text,""];
_ ->
["",Str,""]
end;
false ->
Ext = filename:extension(Str),
case member(Ext, [".gif",".jpg",".GIF",".JPG",".png"]) of
true ->
[""];
false ->
["",Str,""]
end
end;
inline_to_html(C) -> ["
",io_lib:format("unknown inline:~p",[C]),
""].