From 7f00144160c8e0202cfe7368830bdd472bc73505 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Mon, 3 Dec 2012 12:36:49 +0100 Subject: [erl_docgen] Update due to introduction of Unicode --- lib/erl_docgen/priv/bin/xml_from_edoc.escript | 8 +++++--- lib/erl_docgen/src/docgen_edoc_xml_cb.erl | 18 +++++++++++++++--- lib/erl_docgen/src/docgen_xmerl_xml_cb.erl | 9 +++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/erl_docgen/priv/bin/xml_from_edoc.escript b/lib/erl_docgen/priv/bin/xml_from_edoc.escript index 2cb81be1be..65a580dca2 100755 --- a/lib/erl_docgen/priv/bin/xml_from_edoc.escript +++ b/lib/erl_docgen/priv/bin/xml_from_edoc.escript @@ -2,7 +2,7 @@ %% -*- erlang -*- %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2011. All Rights Reserved. +%% Copyright Ericsson AB 2010-2012. All Rights Reserved. %% %% 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 @@ -100,10 +100,12 @@ module(File, Args) -> users_guide(File, Args) -> case filelib:is_regular(File) of true -> + Enc = epp:read_encoding(File, [{in_comment_only, false}]), + Encoding = [{encoding, Enc} || Enc =/= none], Opts = [{def, Args#args.def}, {app_default, "OTPROOT"}, {file_suffix, Args#args.suffix}, - {layout, Args#args.layout}], + {layout, Args#args.layout}] ++ Encoding, Env = edoc_lib:get_doc_env(Opts), @@ -115,7 +117,7 @@ users_guide(File, Args) -> Text = edoc_lib:run_layout(F, Opts), OutFile = "chapter" ++ Args#args.suffix, - edoc_lib:write_file(Text, ".", OutFile); + edoc_lib:write_file(Text, ".", OutFile, '', Encoding); false -> io:format("~s: not a regular file\n", [File]), usage() diff --git a/lib/erl_docgen/src/docgen_edoc_xml_cb.erl b/lib/erl_docgen/src/docgen_edoc_xml_cb.erl index cbaa93a15d..ec7c3ef8e5 100644 --- a/lib/erl_docgen/src/docgen_edoc_xml_cb.erl +++ b/lib/erl_docgen/src/docgen_edoc_xml_cb.erl @@ -39,12 +39,14 @@ module(Element, Opts) -> SortP = proplists:get_value(sort_functions, Opts, true), XML = layout_module(Element, SortP), - xmerl:export_simple([XML], docgen_xmerl_xml_cb, []). + RootAttributes = root_attributes(Element, Opts), + xmerl:export_simple([XML], docgen_xmerl_xml_cb, RootAttributes). %% CHAPTER -overview(Element, _Opts) -> +overview(Element, Opts) -> XML = layout_chapter(Element), - xmerl:export_simple([XML], docgen_xmerl_xml_cb, []). + RootAttributes = root_attributes(Element, Opts), + xmerl:export_simple([XML], docgen_xmerl_xml_cb, RootAttributes). %%--Internal functions-------------------------------------------------- @@ -99,6 +101,16 @@ layout_module(#xmlElement{name = module, content = Es}=E, SortP) -> ?NL,Authors] }. +root_attributes(Element, Opts) -> + Encoding = case get_attrval(encoding, Element) of + "" -> + DefaultEncoding = epp:default_encoding(), + proplists:get_value(encoding, Opts, DefaultEncoding); + Enc -> + Enc + end, + [#xmlAttribute{name=encoding, value=Encoding}]. + layout_chapter(#xmlElement{name=overview, content=Es}) -> Title = get_text(title, Es), Header = {header, [ diff --git a/lib/erl_docgen/src/docgen_xmerl_xml_cb.erl b/lib/erl_docgen/src/docgen_xmerl_xml_cb.erl index 884932ed12..253019ffd6 100644 --- a/lib/erl_docgen/src/docgen_xmerl_xml_cb.erl +++ b/lib/erl_docgen/src/docgen_xmerl_xml_cb.erl @@ -35,9 +35,14 @@ '#xml-inheritance#'() -> [xmerl_xml]. -'#root#'(Data, _Attrs, [], _E) -> +'#root#'(Data, Attrs, [], _E) -> + Encoding = + case [E || #xmlAttribute{name = encoding, value = E} <- Attrs] of + [E] -> E; + _ -> atom_to_list(epp:default_encoding()) + end, ["<",DTD,">"] = hd(hd(Data)), - ["\n", + ["\n", "\n", Data]. -- cgit v1.2.3