%% ``The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved via the world wide web at http://www.erlang.org/. %% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See %% the License for the specific language governing rights and limitations %% under the License. %% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB. %% Portions created by Ericsson are Copyright 1999-2000, Ericsson %% Utvecklings AB. All Rights Reserved.'' %% %% $Id$ %% -module(docb_html). -export([rule/2, rule/3]). rule([p, item, list|_], {_, _, _}) -> {"", "
\n"}; rule([p, item, taglist|_], {_, _, _}) -> {"", "
\n"}; rule([p|_], _) -> {"\n

", "\n

"}; rule([pre|_], _) -> {"\n
\n", "\n
\n"}; rule([input|_], _) -> {"", ""}; rule([quote|_], _) -> {"\n
\n", "\n
\n"}; rule([i|_], _) -> {"", ""}; rule([b|_], _) -> {"", ""}; rule([c|_], _) -> {"", ""}; rule([em|_], _) -> {"", ""}; rule([sub|_], _) -> {"", ""}; rule([sup|_], _) -> {"", ""}; rule([termdef|_], _) -> {drop, ""}; rule([citedef|_], _) -> {drop, ""}; rule([br|_], _) -> {"
\n", ""}; rule([digression|_], _) -> {"\n" " \n" " \n" " \n" " \n" "
\n" " \n", " \n" "
\n"}; rule([list, item, list|_], {_, ["ORDERED"], _}) -> {"\n
    \n", "\n
\n"}; rule([list, item, taglist|_], {_, ["ORDERED"], _}) -> {"\n
    \n", "\n
\n"}; rule([list|_], {_, ["ORDERED"], _}) -> {"\n
    \n", "\n
\n"}; rule([list, item, list|_], {_, ["BULLETED"], _}) -> {"\n\n"}; rule([list, item, taglist|_], {_, ["BULLETED"], _}) -> {"\n\n"}; rule([list|_], {_, ["BULLETED"], _}) -> {"\n\n"}; rule([taglist, item, taglist|_], _) -> {"\n
\n", "\n
\n"}; rule([taglist, item, list|_], _) -> {"\n
\n", "\n
\n"}; rule([taglist|_], _) -> {"\n
\n", "\n
\n"}; rule([tag|_], _) -> {"\n
\n", "\n
\n"}; rule([item, list|_], _) -> {"\n
  • \n", "\n
  • \n\n"}; rule([item, taglist|_], _) -> {"\n
    \n", "\n
    \n"}; rule([image|_], {_, [File], _}) -> File2 = case filename:extension(File) of [] -> File ++ ".gif"; _ -> File end, {["\n
    \n", "\"",
    \n"], "\n
    \n"}; rule([icaption|_], _) -> {"", "\n"}; rule([url|_], {_, [HREF], _}) -> URI = docb_html_util:make_uri(HREF), {io_lib:format("", [URI]), ""}; rule([marker|_], {_, [ID], _}) -> %% remove all chars before first # including the # {ok, NewID, _} = regexp:sub(ID, "^[^#]*#", ""), %% replace "/" with "-" because "/" xhtml does not %% allow "/" in the name attribute of element %% so we have to do the same as for marker i.e %% Function/Arity is translated to an anchor in xhtml %% like this : NewID2 = [case X of $/ -> $-;_->X end||X <- NewID], {drop, [""]}; rule([table|_], {_, ["", ""], Ts}) -> {newargs, "\n
    \n" "\n", reorder_table(Ts), "\n
    \n" "
    \n"}; rule([table|_], {_, [Width, ""], Ts}) -> {newargs, ["\n
    \n" "\n"], reorder_table(Ts), "\n
    \n" "
    \n"}; %% The clauses above are for the report DTD. This one is for the other %% DTDs. rule([table|_], {_, ["LEFT"], Ts}) -> {newargs, "\n" "\n", reorder_table(Ts), "\n
    \n"}; rule([table|_], {_, _, Ts}) -> {newargs, "\n
    \n" "\n", reorder_table(Ts), "\n
    \n" "
    \n"}; rule([row|_], _) -> {" \n", "\n \n"}; rule([cell|_], {_, ["", ""], _}) -> {" \n", "\n \n"}; rule([cell|_], {_, [Align, ""], _}) -> {[" \n"], "\n \n"}; rule([cell|_], {_, ["", VAlign], _}) -> {[" \n"], "\n \n"}; rule([cell|_], {_, [Align, VAlign], _}) -> {[" \n"], "\n \n"}; rule([tcaption|_], _) -> {" ", "\n"}; rule([codeinclude|_], {_, [File, Tag, _Type], _}) -> %% Type can be "ERL", "C" or "NONE" {ok,Data} = docb_html_util:code_include(File, Tag), {drop, ["\n
    \n", Data,
    	     "\n
    \n"]}; rule([erleval|_], {_, [Expr], _}) -> docb_html_util:erl_eval(Expr); rule([pcdata, pre|_], {_, _, Data}) -> %% Do not remove leading spaces. {drop, docb_html_util:pcdata_to_html(Data, false)}; rule([pcdata|_], {_, _, Data}) -> {drop, docb_html_util:pcdata_to_html(Data)}. rule([seealso|_], {_, [Marker], _}, Opts) -> Href = case docb_util:html_snippet(seealso, Marker, Opts) of "" -> %% DocBuilder default behavior: %% Marker is of format "Path#Fragment", both optional. %% Translated to case string:chr(Marker, $#) of 0 -> % No Fragment Marker++".html"; 1 -> % No Path %% replace "/" with "-" because "/" xhtml does not %% allow "/" in the name attribute of element %% so we have to do the same as for marker i.e %% Function/Arity is translated to an anchor in xhtml %% like this : [case X of $/ -> $-;_->X end||X <- Marker]; _ -> Marker1 = [case X of $/ -> $-;_->X end||X <- Marker], case string:tokens(Marker1, "#") of [Path] -> % # at end, remove it Path++".html"; [Path | Frag0] -> Path++".html#"++ docb_util:join(Frag0, "#") end end; Href0 -> %% User defined behavior, use result as-is Href0 end, {{[""], ""}, Opts}; rule([warning|_], _, Opts) -> docb_html_util:copy_pics("warning.gif", "warning.gif", Opts), {{"\n
    \n" "
    Warning
    \n" "
    \n", "\n
    " "\n
    \n"}, Opts}; rule([note|_], _, Opts) -> docb_html_util:copy_pics("note.gif", "note.gif", Opts), {{"\n
    \n" "
    Note
    \n" "
    ", "\n
    " "\n
    \n"}, Opts}; rule([path|_], {_, [UNIX, Windows], [{pcdata, _, Text}]}, Opts) -> UnixPart = docb_util:an_option({ptype,"unix"}, Opts) and (UNIX/=""), WinPart = docb_util:an_option({ptype,"windows"}, Opts) and (Windows/=""), if UnixPart, WinPart -> {{drop, [docb_html_util:pcdata_to_html(Text), " (UNIX: ", docb_html_util:attribute_cdata_to_html(UNIX), ", ", "Windows: ", docb_html_util:attribute_cdata_to_html(Windows), ")"]}, Opts}; UnixPart -> {{drop, [docb_html_util:pcdata_to_html(Text), " (UNIX: ", docb_html_util:attribute_cdata_to_html(UNIX), ")"]}, Opts}; WinPart -> {{drop, [docb_html_util:pcdata_to_html(Text), " (Windows: ", docb_html_util:attribute_cdata_to_html(Windows), ")"]}, Opts}; true -> {{drop, docb_html_util:pcdata_to_html(Text)}, Opts} end; rule([term|_], {_, [ID], _}, Opts) -> case docb_util:an_option(dict, Opts) of false -> case docb_util:lookup_option({defs, term}, Opts) of false -> {{drop, ["", ID, " "]}, Opts}; TermList -> case lists:keyfind(ID, 1, TermList) of false -> {{drop, ["", ID, " "]}, Opts}; {ID, Name, _Description, _Resp} -> {{drop, ["", Name, " "]}, Opts}; {ID, Name, _Description} -> {{drop, [ "", Name, " "]}, Opts} end end; true -> case docb_util:lookup_option({defs, term}, Opts) of false -> {{drop, ["", ID, " "]}, Opts}; TermList -> PartApplication = docb_util:lookup_option(part_application, Opts), case lists:keyfind(ID, 1, TermList) of false -> {{drop, ["", ID, " "]}, Opts}; {ID, Name, _Description, _Resp} -> {{drop, ["", Name, " "]}, Opts}; {ID, Name, _Description} -> {{drop, ["", Name, " "]}, Opts} end end end; rule([cite|_], {_, [ID], _}, Opts) -> case docb_util:an_option(dict, Opts) of false -> case docb_util:lookup_option({defs, cite}, Opts) of false -> {{drop, ["", ID, " "]}, Opts}; CiteList -> case lists:keyfind(ID, 1, CiteList) of false -> {{drop, ["", ID, " "]}, Opts}; {ID, Name, _Description, _Resp} -> {{drop, ["", Name, " "]}, Opts}; {ID, Name, _Description} -> {{drop, ["", Name, " "]}, Opts} end end; true -> case docb_util:lookup_option({defs, cite}, Opts) of false -> {{drop, ["", ID, " "]}, Opts}; CiteList -> PartApp = docb_util:lookup_option(part_application, Opts), case lists:keyfind(ID, 1, CiteList) of false -> {{drop, ["", ID, " "]}, Opts}; {ID, Name, _Description, _Resp} -> {{drop, ["", Name, " "]}, Opts}; {ID, Name, _Description} -> {{drop, ["", Name, " "]}, Opts} end end end; rule([code|_], {_, [Type], [{pcdata, _, Code}]}, Opts) -> case lists:member(Type, ["ERL","C","NONE"]) of true -> {{drop, ["\n
    \n", docb_html_util:element_cdata_to_html(Code),
    		     "\n
    \n"]}, Opts}; false -> exit({error,"unknown type of "}) end. reorder_table(TableContent) -> reorder_table(TableContent, [], []). reorder_table([], Caption, NewTableContent) -> Caption ++ lists:reverse(NewTableContent); reorder_table([{tcaption,_,_} = Caption | TableContent], _, NewTableContent) -> reorder_table(TableContent, [Caption], NewTableContent); reorder_table([Row | TableContent], Caption, NewTableContent) -> reorder_table(TableContent, Caption, [Row | NewTableContent]).