docb_html_util.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 537 行 · 第 1/2 页
ERL
537 行
".html"), NewPath end end, case Frag1 of "" -> attribute_cdata_to_html(Path1); _ -> attribute_cdata_to_html(Path1) ++ "#" ++ attribute_cdata_to_html(Frag1) end.make_anchor_href_short(Path, Frag, RefType) -> ShortFrag = make_funcdef_short(Frag, RefType), make_anchor_href(Path, ShortFrag).make_anchor_name_short(FuncName0, RefType) -> FuncName1 = make_funcdef_short(FuncName0, RefType), attribute_cdata_to_html(FuncName1).make_funcdef_short(FuncDef0, RefType) -> FuncDef1 = docb_util:trim(FuncDef0), Any0 = case lists:member(RefType, [cref, erlref]) of true -> case catch docb_util:fknidx(FuncDef1, "/") of {'EXIT', _} -> false; Any1 -> Any1 end; false -> false end, case Any0 of false -> case string:tokens(FuncDef1, " ") of [Any2| _] -> Any2; _ -> FuncDef1 end; _ -> Any0 end.%%--Include tags--------------------------------------------------------%% Only used in report DTDerl_include(File, Tag) -> case docb_main:include_file(File, Tag) of {ok, Cs} -> {drop, "\n<PRE>\n" ++ text_to_html(Cs) ++ "\n</PRE>\n"}; error -> {drop, ""} end.code_include(File, Tag) -> case docb_main:include(File, Tag, Tag) of {ok, Cs} -> {drop, "\n<PRE>\n" ++ text_to_html(Cs) ++ "\n</PRE>\n"}; error -> {drop, ""} end.erl_eval(Expr) -> Cs = docb_main:eval_str(Expr), {drop, "\n<PRE>\n" ++ text_to_html(Cs) ++ "\n</PRE>\n"}.%% Only replaces certain characters. Spaces and new lines etc are kept.%% Used for plain text (e.g. inclusions of code).text_to_html([$>| Cs]) -> [$&, $#, $6, $2, $;| text_to_html(Cs)];text_to_html([$<| Cs]) -> [$&, $#, $6, $0, $;| text_to_html(Cs)];text_to_html([$&| Cs]) -> [$&, $#, $3, $8, $;| text_to_html(Cs)];text_to_html([$\"| Cs]) -> [$&, $#, $3, $4, $;| text_to_html(Cs)];text_to_html([C| Cs]) -> [C| text_to_html(Cs)];text_to_html([]) -> [].%%--Number sections-----------------------------------------------------number({Tag, Attrs, More}, none, File) -> {Tag, Attrs, do_number(More, [1], File)};number({Tag, Attrs, More}, Prefix, File) -> {Tag, Attrs, do_number(More, [list_to_integer(Prefix)], File)}.do_number([], _, _) -> [];do_number([{header, Attrs, More}| Rest], NN, File) -> [{header, Attrs, More}| do_number(Rest, NN, File)];do_number([{section, Attrs, More}| Rest], [N| NN], File) -> [{section, Attrs, do_number(More, [1, N| NN], File)}| do_number(Rest, [N+1| NN], File)];do_number([{title, _, [{pcdata, _, Title}]}| More], [N| NN], File) -> Format = make_format(length(NN)), Number = lists:flatten(io_lib:format(Format, lists:reverse(NN))), [{marker, [{"ID", "CDATA", Number}], []}, {title, [{"NUMBER", "CDATA", Number}, {"FILE", "CDATA", File}], [{pcdata, [], Title}]}| do_number(More, [N| NN], File)];do_number([{pcdata, Attrs, More}| Rest], NN, File) -> [{pcdata, Attrs, More}| do_number(Rest, NN, File)];do_number([{Tag, Attrs, More}| Rest], NN, File) -> [{Tag, Attrs, do_number(More, NN, File)}|do_number(Rest, NN, File)].make_format(1) -> "~w";make_format(N) -> "~w." ++ make_format(N-1).count_sections([section| Rest]) -> 1 + count_sections(Rest);count_sections([_| Rest]) -> count_sections(Rest);count_sections([]) -> 0.%%--Make a ToC----------------------------------------------------------format_toc(Toc) -> lists:map(fun({Number, Title}) -> [Number, " <A HREF = \"#", Number, "\">", Title, "</A><BR>\n"] end, Toc).%%--Convert HTML ISO Latin 1 characters to ordinary characters----------%% To be used for sorting. Cs must be flat.html_latin1_sort_order(Cs) -> hlso(Cs).hlso([]) -> [];hlso([$&, $#, C2, C1, C0, $;| Cs]) when $0 =< C2, C2 =< $9, $0 =< C1, C1 =< $9, $0 =< C0, C0 =< $9 -> C = ((C2-$0)*10 + (C1-$0))*10 + C0-$0, hlso0(C, Cs);hlso([$&, $#, C1, C0, $;| Cs]) when $0 =< C1, C1 =< $9, $0 =< C0, C0 =< $9 -> C = (C1-$0)*10 + C0-$0, hlso0(C, Cs);hlso([C| Cs]) -> [C| hlso(Cs)].hlso0(C, Cs) when 0 =< C, C =< 159 -> [C| hlso(Cs)];hlso0(160, Cs) -> %% no-break space hlso(Cs); % Remove it.hlso0(161, Cs) -> %% inverted exclamation mark [$? |hlso(Cs)];hlso0(162, Cs) -> %% cent sign [$$|hlso(Cs)];hlso0(163, Cs) -> %% pound sterling sign [$$|hlso(Cs)];hlso0(164, Cs) -> %% general currency sign [$$|hlso(Cs)];hlso0(165, Cs) -> %% yen sign [$$|hlso(Cs)];hlso0(166, Cs) -> %% broken (vertical) bar [$| |hlso(Cs)];hlso0(167, Cs) -> %% section sign [$$|hlso(Cs)];hlso0(168, Cs) -> %% umlaut (dieresis) [$: |hlso(Cs)];hlso0(169, Cs) -> %% copyright sign [$c |hlso(Cs)];hlso0(170, Cs) -> %% ordinal indicator, feminine [$f |hlso(Cs)];hlso0(171, Cs) -> %% angle quotation mark, left [$" |hlso(Cs)];hlso0(172, Cs) -> %% not sign [$- |hlso(Cs)];hlso0(173, Cs) -> %% soft hyphen [$- |hlso(Cs)];hlso0(174, Cs) -> %% registered sign [$r |hlso(Cs)];hlso0(175, Cs) -> %% macron [$- |hlso(Cs)];hlso0(176, Cs) -> %% degree sign [$d |hlso(Cs)];hlso0(177, Cs) -> %% plus-or-minus sign [$+ |hlso(Cs)];hlso0(178, Cs) -> %% superscript two [$2 |hlso(Cs)];hlso0(179, Cs) -> %% superscript three [$3 |hlso(Cs)];hlso0(180, Cs) -> %% acute accent [$' |hlso(Cs)];hlso0(181, Cs) -> %% micro sign [$' |hlso(Cs)];hlso0(182, Cs) -> %% pilcrow (paragraph sign) [$$|hlso(Cs)];hlso0(183, Cs) -> %% middle dot [$. |hlso(Cs)];hlso0(184, Cs) -> %% cedilla [$c |hlso(Cs)];hlso0(185, Cs) -> %% superscript one [$1 |hlso(Cs)];hlso0(186, Cs) -> %% ordinal indicator, masculine [$m |hlso(Cs)];hlso0(187, Cs) -> %% angle quotation mark, right [$" |hlso(Cs)];hlso0(188, Cs) -> %% fraction one-quarter [$4 |hlso(Cs)];hlso0(189, Cs) -> %% fraction one-half [$2 |hlso(Cs)];hlso0(190, Cs) -> %% fraction three-quarters [$3 |hlso(Cs)];hlso0(191, Cs) -> %% inverted question mark [$? |hlso(Cs)];hlso0(C, Cs) when 192 =< C, C =< 198 -> %% capital A [$A |hlso(Cs)];hlso0(199, Cs) -> %% capital C, cedilla [$C |hlso(Cs)];hlso0(C, Cs) when 200 =< C, C =< 203 -> %% capital E [$E |hlso(Cs)];hlso0(C, Cs) when 204 =< C, C =< 207 -> %% capital I [$I |hlso(Cs)];hlso0(208, Cs) -> %% capital Eth, Icelandic [$D |hlso(Cs)];hlso0(209, Cs) -> %% capital N, tilde [$N |hlso(Cs)];hlso0(C, Cs) when 210 =< C, C =< 214 -> %% capital O [$O |hlso(Cs)];hlso0(215, Cs) -> %% multiply sign [$x |hlso(Cs)];hlso0(216, Cs) -> %% capital O, slash [$O |hlso(Cs)];hlso0(C, Cs) when 217 =< C, C =< 220 -> %% capital U [$U |hlso(Cs)];hlso0(221, Cs) -> %% capital Y, acute accent [$Y |hlso(Cs)];hlso0(222, Cs) -> %% capital THORN, Icelandic [$T |hlso(Cs)];hlso0(223, Cs) -> %% small sharp s, German (sz [$s |hlso(Cs)];hlso0(C, Cs) when 224 =< C, C =< 230-> %% small a [$a |hlso(Cs)];hlso0(231, Cs) -> %% small c, cedilla [$c |hlso(Cs)];hlso0(C, Cs) when 232 =< C, C =< 235 -> %% small e [$e |hlso(Cs)];hlso0(C, Cs) when 236 =< C, C =< 239 -> %% small i [$i |hlso(Cs)];hlso0(240, Cs) -> %% small eth, Icelandic [$d |hlso(Cs)];hlso0(241, Cs) -> %% small n, tilde [$n |hlso(Cs)];hlso0(C, Cs) when 242 =< C, C =< 246 -> %% small o [$o |hlso(Cs)];hlso0(247, Cs) -> %% divide sign [$/ |hlso(Cs)];hlso0(248, Cs) -> %% small o, slash [$o |hlso(Cs)];hlso0(C, Cs) when 249 =< C, C =< 252 -> %% small u [$u |hlso(Cs)];hlso0(253, Cs) -> %% small y, acute accent [$y |hlso(Cs)];hlso0(254, Cs) -> %% small thorn, Icelandic [$t |hlso(Cs)];hlso0(255, Cs) -> %% small y, dieresis or umlaut [$y |hlso(Cs)].
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?