From 4cb4ad67382590d92228ea6c56225376bd9f5685 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Fri, 21 Feb 2014 14:48:27 +0100 Subject: [PATCH] check encoding of source file, not doc target --- src/edown_doclet.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/edown_doclet.erl b/src/edown_doclet.erl index 632939e..9bc63c8 100644 --- a/src/edown_doclet.erl +++ b/src/edown_doclet.erl @@ -298,6 +298,7 @@ sources(Sources, Dir, Modules, Env, Options) -> source({M, P, Name, Path}, Dir, Suffix, Env, Set, Private, Hidden, Error, Options) -> File = filename:join(Path, Name), + Enc = guess_encoding(File), case catch {ok, edoc:get_doc(File, Env, Options)} of {ok, {Module, Doc}} -> check_name(Module, M, P, File), @@ -306,7 +307,7 @@ source({M, P, Name, Path}, Dir, Suffix, Env, Set, Private, Hidden, true -> Text = edoc:layout(Doc, Options), Name1 = packages_last(M) ++ Suffix, - write_file(Text, Dir, Name1, Name, P), + write_file(Text, Dir, Name1, Name, P, Enc), {sets:add_element(Module, Set), Error}; false -> {Set, Error} @@ -316,6 +317,15 @@ source({M, P, Name, Path}, Dir, Suffix, Env, Set, Private, Hidden, {Set, true} end. +guess_encoding(File) -> + try epp:read_encoding(File) of + none -> latin1; + Enc -> Enc + catch + _:_ -> + latin1 + end. + write_file(Text, Dir, F) -> write_file(Text, Dir, F, F, '', auto).