Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more general URI redirect

  • Loading branch information...
commit 8fc6e8721494488919bed8bfe068c6951f0f77bc 1 parent 9036f27
Ulf Wiger authored
View
10 doc/edown_doclet.md
@@ -47,8 +47,8 @@ Main doclet entry point.
-Also see [`//edoc/edoc:layout/2`](http://www.erlang.org/doc/man/edoc/doc/edoc.html#layout-2) for layout-related options, and
-[`//edoc/edoc:get_doc/2`](http://www.erlang.org/doc/man/edoc/doc/edoc.html#get_doc-2) for options related to reading source
+Also see [`//edoc/edoc:layout/2`](http://www.erlang.org/doc/man/edoc.html#layout-2) for layout-related options, and
+[`//edoc/edoc:get_doc/2`](http://www.erlang.org/doc/man/edoc.html#get_doc-2) for options related to reading source
files.
Options:
@@ -81,7 +81,7 @@ functions will also be included. The default value is <code>false</code>.
-<dt><code>{overview, <a href="edoc.html#type-filename">edoc:filename()</a>}</code>
+<dt><code>{overview, <a href="http://www.erlang.org/doc/man/edoc.html#type-filename">//edoc/edoc:filename()</a>}</code>
</dt>
@@ -121,7 +121,7 @@ specified, no stylesheet reference will be generated.
-<dt><code>{stylesheet_file, <a href="edoc.html#type-filename">edoc:filename()</a>}</code>
+<dt><code>{stylesheet_file, <a href="http://www.erlang.org/doc/man/edoc.html#type-filename">//edoc/edoc:filename()</a>}</code>
</dt>
@@ -148,4 +148,4 @@ will be copied to the target directory.
-_Generated by EDoc, Oct 31 2010, 17:32:47._
+_Generated by EDoc, Oct 31 2010, 18:25:18._
View
8 doc/edown_layout.md
@@ -113,15 +113,15 @@ the source file. The default value is <code>true</code>.
-<dd>Specifies an <a href="http://www.erlang.org/doc/man/xmerl/doc/index.html" target="_top"><code>xmerl</code></a> callback module to be
-used for exporting the documentation. See <a href="http://www.erlang.org/doc/man/xmerl/doc/xmerl.html#export_simple_content-2"><code>//xmerl/xmerl:export_simple_content/2</code></a> for details.
+<dd>Specifies an <a href="http://www.erlang.org/doc/man/index.html" target="_top"><code>xmerl</code></a> callback module to be
+used for exporting the documentation. See <a href="http://www.erlang.org/doc/man/xmerl.html#export_simple_content-2"><code>//xmerl/xmerl:export_simple_content/2</code></a> for details.
</dd>
-__See also:__ [//edoc/edoc:layout/2](http://www.erlang.org/doc/man/edoc.html#layout-2), [edown_doclet:layout/2](edown_doclet.md#layout-2).
+__See also:__ [//edoc/edoc:layout/2](http://www.erlang.org/doc/man/edoc.html#layout-2), [edown_doclet:layout/2](edown_doclet.html#layout-2).
<a name="overview-2"></a>
@@ -159,4 +159,4 @@ __See also:__ [//edoc/edoc:layout/2](http://www.erlang.org/doc/man/edoc.html#lay
-_Generated by EDoc, Oct 31 2010, 17:32:47._
+_Generated by EDoc, Oct 31 2010, 18:25:18._
View
28 doc/edown_lib.md
@@ -19,7 +19,7 @@ __Authors:__ Ulf Wiger ([`ulf.wiger@erlang-solutions.com`](mailto:ulf.wiger@erla
-<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#export-1">export/1</a></td><td></td></tr></table>
+<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#export-1">export/1</a></td><td></td></tr><tr><td valign="top"><a href="#get_attrval-2">get_attrval/2</a></td><td></td></tr><tr><td valign="top"><a href="#redirect_uri-1">redirect_uri/1</a></td><td></td></tr></table>
<a name="functions"></a>
@@ -40,5 +40,29 @@ __Authors:__ Ulf Wiger ([`ulf.wiger@erlang-solutions.com`](mailto:ulf.wiger@erla
`export(Data) -> any()`
+<a name="get_attrval-2"></a>
-_Generated by EDoc, Oct 31 2010, 17:32:47._
+
+<h3>get_attrval/2</h3>
+
+
+
+
+
+`get_attrval(Name, XmlElement) -> any()`
+
+
+<a name="redirect_uri-1"></a>
+
+
+<h3>redirect_uri/1</h3>
+
+
+
+
+
+`redirect_uri(XmlElement) -> any()`
+
+
+
+_Generated by EDoc, Oct 31 2010, 18:25:18._
View
2  doc/edown_xmerl.md
@@ -76,4 +76,4 @@ __Authors:__ Ulf Wiger ([`ulf.wiger@erlang-solutions.com`](mailto:ulf.wiger@erla
-_Generated by EDoc, Oct 31 2010, 17:32:47._
+_Generated by EDoc, Oct 31 2010, 18:25:18._
View
4 src/edown_doclet.erl
@@ -68,7 +68,7 @@
%% <dd>If the value is `true', documentation of hidden modules and
%% functions will also be included. The default value is `false'.
%% </dd>
-%% <dt>{@type {overview, edoc:filename()@}}
+%% <dt>{@type {overview, //edoc/edoc:filename()@}}
%% </dt>
%% <dd>Specifies the name of the overview-file. By default, this doclet
%% looks for a file `"overview.edoc"' in the target directory.
@@ -84,7 +84,7 @@
%% default value is `"stylesheet.css"'. If an empty string is
%% specified, no stylesheet reference will be generated.
%% </dd>
-%% <dt>{@type {stylesheet_file, edoc:filename()@}}
+%% <dt>{@type {stylesheet_file, //edoc/edoc:filename()@}}
%% </dt>
%% <dd>Specifies the name of the stylesheet file. By default, this
%% doclet uses the file `"stylesheet.css"' in the `priv'
View
53 src/edown_layout.erl
@@ -526,58 +526,7 @@ sees(Es) ->
end.
see(E=#xmlElement{content = Es}) ->
- case get_attrval(name, E) of
- "" ->
- see(E, Es);
- [_|_] = Str ->
- see(redirect_uri(Str, E), Es)
- end.
-
-redirect_uri("//" ++ _Str, E) ->
- case get_attrval(href, E) of
- "http://" ++ _ = URI ->
- %% abusing the filename API a little - but whatever works...
- case filename:split(URI) of
- [_,"www.erlang.org","doc","man",_,"doc",Mod] ->
- NewURI = "http://www.erlang.org/doc/man/" ++ Mod,
- replace_uri(NewURI, E);
- _Split ->
- E
- end;
- "/" ++ _ = URI ->
- case lists:prefix(otp_root(), URI) of
- true ->
- case lists:reverse(filename:split(URI)) of
- [Mod, "doc", _App | _] ->
- NewURI = "http://www.erlang.org/doc/man/" ++ Mod,
- replace_uri(NewURI, E);
- _ ->
- E
- end;
- false ->
- E
- end
- end;
-redirect_uri(Str, #xmlElement{} = E) ->
- case re:split(Str, ":", [{return,list}]) of
- [_, _] ->
- [_|_] = URI = get_attrval(href, E),
- NewURI = re:replace(URI,".html",".md",[{return,list}]),
- replace_uri(NewURI, E);
- _ ->
- E
- end.
-
-replace_uri(URI, #xmlElement{attributes = As} = E) ->
- #xmlAttribute{} = A = lists:keyfind(href, #xmlAttribute.name, As),
- As1 = lists:keyreplace(href, #xmlAttribute.name, As,
- A#xmlAttribute{value = URI}),
- E#xmlElement{attributes = As1}.
-
-otp_root() ->
- {ok, [[Root]]} = init:get_argument(root),
- Root.
-
+ see(E, Es).
see(E, Es) ->
View
67 src/edown_lib.erl
@@ -23,8 +23,73 @@
-module(edown_lib).
--export([export/1]).
+-export([export/1, redirect_uri/1, get_attrval/2]).
+
+-include_lib("xmerl/include/xmerl.hrl").
export(Data) ->
xmerl:export_simple_content(Data, edown_xmerl).
+
+
+redirect_uri(#xmlElement{} = E) ->
+ redirect_uri(get_attrval(href, E), get_attrval(name, E), E);
+redirect_uri(_E) ->
+ false.
+
+redirect_uri("http://www.erlang.org" ++ _ = URI, _, E) ->
+ %% abusing the filename API a little - but whatever works...
+ case filename:split(URI) of
+ [_,"www.erlang.org","doc","man",_,"doc",Mod] ->
+ NewURI = "http://www.erlang.org/doc/man/" ++ Mod,
+ replace_uri(NewURI, E);
+ _Split ->
+ false
+ end;
+redirect_uri("/" ++ _ = URI, "//" ++ _, E) ->
+ case lists:prefix(otp_root(), URI) of
+ true ->
+ case lists:reverse(filename:split(URI)) of
+ [Mod, "doc", _App | _] ->
+ NewURI = "http://www.erlang.org/doc/man/" ++ Mod,
+ replace_uri(NewURI, E);
+ _ ->
+ false
+ end;
+ false ->
+ false
+ end;
+redirect_uri(_, Name, E) ->
+ case re:split(Name, ":", [{return,list}]) of
+ [_, _] ->
+ [_|_] = URI = get_attrval(href, E),
+ NewURI = re:replace(URI,".html",".md",[{return,list}]),
+ replace_uri(NewURI, E);
+ _ ->
+ false
+ end.
+
+replace_uri(URI, #xmlElement{attributes = As} = E) ->
+ #xmlAttribute{} = A = lists:keyfind(href, #xmlAttribute.name, As),
+ As1 = lists:keyreplace(href, #xmlAttribute.name, As,
+ A#xmlAttribute{value = URI}),
+ E#xmlElement{attributes = As1}.
+
+get_attrval(Name, #xmlElement{attributes = As}) ->
+ case get_attr(Name, As) of
+ [#xmlAttribute{value = V}] ->
+ V;
+ [] -> ""
+ end.
+
+get_attr(Name, [#xmlAttribute{name = Name} = A | As]) ->
+ [A | get_attr(Name, As)];
+get_attr(Name, [_ | As]) ->
+ get_attr(Name, As);
+get_attr(_, []) ->
+ [].
+
+
+otp_root() ->
+ {ok, [[Root]]} = init:get_argument(root),
+ Root.
View
24 src/edown_xmerl.erl
@@ -79,12 +79,24 @@ normalize([]) ->
'#element#'('div', Data, _, _Parents, _E) ->
%% special case - we use 'div' to enforce html encoding
Data;
+'#element#'(a, Data, Attrs, Parents, E) ->
+ case edown_lib:redirect_uri(E) of
+ false ->
+ elem(a, Data, Attrs, Parents, E);
+ #xmlElement{attributes = Attrs1, parents = Parents1,
+ content = Data1} = E1 ->
+ elem(a, Data, Attrs1, Parents1, E1)
+ end;
'#element#'(Tag, Data, Attrs, Parents, E) ->
+ elem(Tag, Data, Attrs, Parents, E).
+
+
+elem(Tag, Data, Attrs, Parents, E) ->
case needs_html(Tag) orelse within_html(Parents) of
true ->
html_elem(Tag, Data, Attrs, Parents, E);
false ->
- elem(Tag, Data, Attrs, Parents, E)
+ md_elem(Tag, Data, Attrs, Parents, E)
end.
html_elem(Tag, Data, Attrs, Parents, E) ->
@@ -98,7 +110,7 @@ html_elem(Tag, Data, Attrs, Parents, E) ->
["\n\n", HTML(), "\n\n"]
end.
-elem(a, Data, Attrs, _Parents, _E) ->
+md_elem(a, Data, Attrs, _Parents, _E) ->
%% io:fwrite("A TAG = ~p~nPs = ~p~n", [Data, _Parents]),
case lists:keyfind(href, #xmlAttribute.name, Attrs) of
#xmlAttribute{value = HRef} ->
@@ -113,15 +125,15 @@ elem(a, Data, Attrs, _Parents, _E) ->
"\n"]
end
end;
-elem(img, _Data, Attrs, _Parents, _E) ->
+md_elem(img, _Data, Attrs, _Parents, _E) ->
#xmlAttribute{value = Src} = lists:keyfind(src,#xmlAttribute.name,Attrs),
#xmlAttribute{value = Alt} = lists:keyfind(alt,#xmlAttribute.name,Attrs),
"![" ++ Alt ++ "](" ++ Src ++ ")";
-elem(li, Data, _Attrs, [{ul,_}|_], _E) ->
+md_elem(li, Data, _Attrs, [{ul,_}|_], _E) ->
"* " ++ Data ++ "\n";
-elem(li, Data, _Attrs, [{ol,_}|_], _E) ->
+md_elem(li, Data, _Attrs, [{ol,_}|_], _E) ->
"1. " ++ Data ++ "\n";
-elem(Tag, Data, Attrs, Parents, E) ->
+md_elem(Tag, Data, Attrs, Parents, E) ->
case Tag of
title ->
%% io:fwrite("TITLE = |~s|~n", [Data]),

0 comments on commit 8fc6e87

Please sign in to comment.
Something went wrong with that request. Please try again.