Permalink
Browse files

normalize #text#

  • Loading branch information...
1 parent 659a33f commit c7f546ec301e088088317f65cb209755ab395d33 Ulf Wiger committed Oct 25, 2010
Showing with 120 additions and 96 deletions.
  1. +45 −45 doc/edown_doclet.md
  2. +30 −30 doc/edown_layout.md
  3. +1 −1 doc/edown_lib.md
  4. +1 −1 doc/edown_xmerl.md
  5. +43 −19 src/edown_xmerl.erl
View
@@ -46,108 +46,108 @@ EDoc Doclet module for producing Github-flavored Markdown.
Main doclet entry point.
-
-
+
+
Also see [`edoc:layout/2`](edoc.html#layout-2) for layout-related options, and
- [`edoc:get_doc/2`](edoc.html#get_doc-2) for options related to reading source
+[`edoc:get_doc/2`](edoc.html#get_doc-2) for options related to reading source
files.
-
- Options:
-
-
+
+Options:
+
+
<dt><code>{file_suffix, string()}</code>
- </dt>
+</dt>
+
-
<dd>Specifies the suffix used for output files. The default value is
- <code>".md"</code>.
- </dd>
+<code>".md"</code>.
+</dd>
+
-
<dt><code>{hidden, bool()}</code>
- </dt>
+</dt>
+
-
<dd>If the value is <code>true</code>, documentation of hidden modules and
- functions will also be included. The default value is <code>false</code>.
- </dd>
+functions will also be included. The default value is <code>false</code>.
+</dd>
+
-
<dt><code>{overview, <a href="edoc.html#type-filename">edoc:filename()</a>}</code>
- </dt>
+</dt>
+
-
<dd>Specifies the name of the overview-file. By default, this doclet
- looks for a file <code>"overview.edoc"</code> in the target directory.
- </dd>
+looks for a file <code>"overview.edoc"</code> in the target directory.
+</dd>
+
-
<dt><code>{private, bool()}</code>
- </dt>
+</dt>
+
-
<dd>If the value is <code>true</code>, documentation of private modules and
- functions will also be included. The default value is <code>false</code>.
- </dd>
+functions will also be included. The default value is <code>false</code>.
+</dd>
+
-
<dt><code>{stylesheet, string()}</code>
- </dt>
+</dt>
+
-
<dd>Specifies the URI used for referencing the stylesheet. The
- default value is <code>"stylesheet.css"</code>. If an empty string is
- specified, no stylesheet reference will be generated.
- </dd>
+default value is <code>"stylesheet.css"</code>. If an empty string is
+specified, no stylesheet reference will be generated.
+</dd>
+
-
<dt><code>{stylesheet_file, <a href="edoc.html#type-filename">edoc:filename()</a>}</code>
- </dt>
+</dt>
+
-
<dd>Specifies the name of the stylesheet file. By default, this
- doclet uses the file <code>"stylesheet.css"</code> in the <code>priv</code>
- subdirectory of the EDoc installation directory. The named file
- will be copied to the target directory.
- </dd>
+doclet uses the file <code>"stylesheet.css"</code> in the <code>priv</code>
+subdirectory of the EDoc installation directory. The named file
+will be copied to the target directory.
+</dd>
+
-
<dt><code>{title, string()}</code>
- </dt>
+</dt>
+
-
<dd>Specifies the title of the overview-page.
- </dd>
+</dd>
+
-
-_Generated by EDoc, Oct 25 2010, 17:08:25._
+_Generated by EDoc, Oct 25 2010, 17:44:35._
View
@@ -16,8 +16,8 @@ __Authors:__ Ulf Wiger ([`ulf.wiger@erlang-solutions.com`](mailto:ulf.wiger@erla
<h2><a name="description">Description</a></h2>
Github-flavored Markdown layout module for EDoc.
- Derived from `edoc_layout`, which is part of the Erlang/OTP application EDoc.
- The module is intended to be used together with edoc.
+Derived from `edoc_layout`, which is part of the Erlang/OTP application EDoc.
+The module is intended to be used together with edoc.
<h2><a name="index">Function Index</a></h2>
@@ -60,65 +60,65 @@ Github-flavored Markdown layout module for EDoc.
The layout function.
-
- Options to the standard layout:
-
-
+
+Options to the standard layout:
+
+
<dt><code>{index_columns, integer()}</code>
- </dt>
+</dt>
+
-
<dd>Specifies the number of column pairs used for the function
- index tables. The default value is 1.
- </dd>
+index tables. The default value is 1.
+</dd>
+
-
<dt><code>{stylesheet, string()}</code>
- </dt>
+</dt>
+
-
<dd>Specifies the URI used for referencing the stylesheet. The
- default value is <code>"stylesheet.css"</code>. If an empty string is
- specified, no stylesheet reference will be generated.
- </dd>
+default value is <code>"stylesheet.css"</code>. If an empty string is
+specified, no stylesheet reference will be generated.
+</dd>
+
-
<dt><code>{sort_functions, bool()}</code>
- </dt>
+</dt>
+
-
<dd>If <code>true</code>, the detailed function descriptions are listed by
- name, otherwise they are listed in the order of occurrence in
- the source file. The default value is <code>true</code>.
- </dd>
+name, otherwise they are listed in the order of occurrence in
+the source file. The default value is <code>true</code>.
+</dd>
+
-
<dt><code>{xml_export, Module::atom()}</code>
- </dt>
+</dt>
+
-
<dd>Specifies an <a href="/Users/uwiger/ETC/git/xmerl/doc/index.html" target="_top"><code>xmerl</code></a> callback module to be
- used for exporting the documentation. See <a href="/Users/uwiger/ETC/git/xmerl/doc/xmerl.html#export_simple_content-2"><code>//xmerl/xmerl:export_simple_content/2</code></a> for details.
- </dd>
+used for exporting the documentation. See <a href="/Users/uwiger/ETC/git/xmerl/doc/xmerl.html#export_simple_content-2"><code>//xmerl/xmerl:export_simple_content/2</code></a> for details.
+</dd>
+
+
-
-
__See also:__ [edoc:layout/2](edoc.html#layout-2).
<a name="overview-2"></a>
@@ -158,4 +158,4 @@ __See also:__ [edoc:layout/2](edoc.html#layout-2).
-_Generated by EDoc, Oct 25 2010, 17:08:25._
+_Generated by EDoc, Oct 25 2010, 17:44:35._
View
@@ -43,4 +43,4 @@ Github-flavored Markdown for EDoc - common support functions
-_Generated by EDoc, Oct 25 2010, 17:08:25._
+_Generated by EDoc, Oct 25 2010, 17:44:35._
View
@@ -74,4 +74,4 @@ __Authors:__ Ulf Wiger ([`ulf.wiger@erlang-solutions.com`](mailto:ulf.wiger@erla
-_Generated by EDoc, Oct 25 2010, 17:08:25._
+_Generated by EDoc, Oct 25 2010, 17:44:35._
View
@@ -42,12 +42,21 @@
'#text#'(Text) ->
%% export_text(Text).
- try binary_to_list(list_to_binary(Text))
+ try normalize(binary_to_list(list_to_binary(Text)))
catch
error:_ ->
lists:flatten(io_lib:fwrite("~p", [Text]))
end.
+normalize("\n" ++ [H|T]) when H==$\s;
+ H==$\t ->
+ normalize("\n" ++ T);
+normalize([H|T]) ->
+ [H|normalize(T)];
+normalize([]) ->
+ [].
+
+
%% The '#root#' tag is called when the entire structure has been
@@ -67,14 +76,28 @@
%% for an example. (By default, we always generate the end tag, to make
%% sure that the scope of a markup is not extended by mistake.)
+'#element#'('div', Data, _, _Parents, _E) ->
+ %% special case - we use 'div' to enforce html encoding
+ Data;
'#element#'(Tag, Data, Attrs, Parents, E) ->
- case within_html(Parents) of
+ case needs_html(Tag) orelse within_html(Parents) of
true ->
- xmerl_html:'#element#'(Tag, Data, Attrs, Parents, E);
+ html_elem(Tag, Data, Attrs, Parents, E);
false ->
elem(Tag, Data, Attrs, Parents, E)
end.
+html_elem(Tag, Data, Attrs, Parents, E) ->
+ HTML = fun() ->
+ xmerl_html:'#element#'(Tag, Data, Attrs, Parents, E)
+ end,
+ case within_html(Parents) of
+ true ->
+ HTML();
+ false ->
+ ["\n\n", HTML(), "\n\n"]
+ end.
+
elem(a, Data, Attrs, _Parents, _E) ->
%% io:fwrite("A TAG = ~p~nPs = ~p~n", [Data, _Parents]),
case lists:keyfind(href, #xmlAttribute.name, Attrs) of
@@ -104,19 +127,20 @@ elem(Tag, Data, Attrs, Parents, E) ->
%% io:fwrite("TITLE = |~s|~n", [Data]),
Str = lists:flatten(Data),
Str ++ "\n" ++ [$= || _ <- Str] ++ "\n";
- html -> Data;
- body -> Data;
- ul -> Data;
- ol -> Data;
- p -> "\n" ++ Data;
- b -> "__" ++ no_nl(Data) ++ "__";
- em -> "_" ++ no_nl(Data) ++ "_";
- i -> "_" ++ no_nl(Data) ++ "_";
- tt -> "`" ++ no_nl(Data) ++ "`";
- code -> "`" ++ no_nl(Data) ++ "`";
- dl -> Data;
- dt -> elem(h3, Data, Attrs, Parents, E);
- dd -> elem(p, Data, Attrs, Parents, E);
+ html -> Data;
+ body -> Data;
+ 'div' -> Data;
+ ul -> Data;
+ ol -> Data;
+ p -> "\n\n" ++ Data;
+ b -> "__" ++ no_nl(Data) ++ "__";
+ em -> "_" ++ no_nl(Data) ++ "_";
+ i -> "_" ++ no_nl(Data) ++ "_";
+ tt -> "`" ++ no_nl(Data) ++ "`";
+ code -> "`" ++ no_nl(Data) ++ "`";
+ dl -> Data;
+ dt -> html_elem(h3, Data, Attrs, Parents, E);
+ dd -> html_elem(p, Data, Attrs, Parents, E);
h1 -> "\n\n#" ++ no_nl(Data) ++ "#\n";
h2 -> "\n\n##" ++ no_nl(Data) ++ "##\n";
h3 -> "\n\n###" ++ no_nl(Data) ++ "##\n";
@@ -132,10 +156,10 @@ elem(Tag, Data, Attrs, Parents, E) ->
end.
within_html(Tags) ->
- lists:any(fun needs_html/1, Tags).
+ lists:any(fun({T,_}) -> needs_html(T) end, Tags).
-needs_html({T,_}) ->
- lists:member(T, [table]).
+needs_html(T) ->
+ lists:member(T, [table,'div',h1,h2,h3,h4,dd,dt]).
no_nl(S) ->
string:strip([C || C <- lists:flatten(S),

0 comments on commit c7f546e

Please sign in to comment.