Skip to content

Commit

Permalink
check encoding of source file, not doc target
Browse files Browse the repository at this point in the history
  • Loading branch information
uwiger committed Feb 21, 2014
1 parent 98d8b02 commit 4cb4ad6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/edown_doclet.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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}
Expand All @@ -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).

Expand Down

0 comments on commit 4cb4ad6

Please sign in to comment.