Skip to content

Commit

Permalink
Merge pull request #27 from vkatsuba/assume-unicode-in-regex-inputs
Browse files Browse the repository at this point in the history
Assume Unicode in the documentation
  • Loading branch information
dumbbell authored Apr 6, 2023
2 parents 59bed39 + 997ecff commit 4807157
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
otp: [23, 24, 25]
rebar: [3.18.0]
otp: [24, 25]
rebar: [3.20.0]
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ _build
log
rebar3.crashdump
_checkouts/
doc
/doc/
22 changes: 12 additions & 10 deletions src/rebar3_edoc_extensions_wrapper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ patch_html(Dir, Html) ->
"<body +bgcolor=\"[^\"]*\">",
"<body class=\"" ?BODY_CLASSES "\">\n"
?SYNTAX_HIGHLIGHTING_JS,
[{return, list}]),
[{return, list}, unicode]),
Html3 = re:replace(
Html2,
"<pre>(.*)</pre>",
"<pre><code>\\1</code></pre>",
[{return, list}, ungreedy, dotall, global]),
[{return, list}, unicode, ungreedy, dotall, global]),
Html4 = re:replace(
Html3,
"<pre><code> +(" ?LANG_REGEX ")(?:\n)(.*)</code></pre>",
"<pre><code class=\"language-\\1\">\\2</code></pre>",
[{return, list}, ungreedy, dotall, global]),
[{return, list}, unicode, ungreedy, dotall, global]),
Html4.

-spec add_head_addon(Dir, Html) -> Html when
Expand All @@ -97,7 +97,7 @@ add_head_addon(Dir, Html) ->
Html,
"</head>",
[Addon, "</head>"],
[{return, list}]);
[{return, list}, unicode]);
_ ->
Html
end.
Expand All @@ -112,7 +112,7 @@ add_toc(App, Html, Dir) ->
Html,
"(<h2 class=\"indextitle\">Modules</h2>)",
Toc ++ "\\1",
[{return, list}])
[{return, list}, unicode])
end.

-spec generate_toc([binary() | list()], term()) -> [binary() | list()] | undefined.
Expand All @@ -121,19 +121,21 @@ generate_toc(Dir, App) ->
undefined ->
undefined;
Overview ->
Lines = re:split(Overview, "\\n", [{return, list}]),
Lines = re:split(Overview, "\\n", [{return, list}, unicode]),
Titles = [Line ||
Line <- Lines,
match =:= re:run(Line, "^=+.*=+$", [{capture, none}])],
match =:= re:run(Line, "^=+.*=+$",
[{capture, none}, unicode])],
generate_toc1(Titles, 0, [], App)
end.

-spec generate_toc1([binary() | list()], integer(), list(), term()) -> [binary() | list()].
generate_toc1([Title | Rest], CurrentLevel, Result, App) ->
ReOpts = [{capture, all_but_first, list}],
ReOpts = [{capture, all_but_first, list}, unicode],
{match, [Equals, Title1]} = re:run(Title, "^(=+) *(.*)", ReOpts),
Title2 = re:replace(Title1, " *=+$", "", [{return, list}]),
Anchor = "#" ++ re:replace(Title2, " ", "_", [{return, list}, global]),
Title2 = re:replace(Title1, " *=+$", "", [{return, list}, unicode]),
Anchor = "#" ++ re:replace(
Title2, " ", "_", [{return, list}, unicode, global]),
Link = "<a href=\"overview-summary.html" ++ Anchor ++ "\"" ++
"target=\"overviewFrame\">" ++ Title2 ++ "</a>",
Level = length(Equals) - 1,
Expand Down
9 changes: 7 additions & 2 deletions test/rebar3_edoc_extensions_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,19 @@ test_app(_Config) ->
ok = file:set_cwd("../../../../test"),
State = init_test_app(),
{Res, _} = edoc(State),
{ok, Bin} = file:read_file("test_app/doc/test.html"),
?assertEqual(ok, Res),

{ok, Bin} = file:read_file("test_app/doc/test.html"),
?assertEqual(true, filelib:is_file("test_app/doc/edoc-extensions.css")),
?assertEqual(true, filelib:is_file("test_app/doc/prism.js")),
?assertEqual(true, filelib:is_file("test_app/doc/prism.css")),
?assertEqual(true, filelib:is_file("test_app/doc/github-markdown.css")),
?assertEqual(true, nomatch /= re:run(Bin, "language-erlang")),
?assertEqual(true, nomatch /= re:run(Bin, "edoc-extensions.css")).
?assertEqual(true, nomatch /= re:run(Bin, "edoc-extensions.css")),

{ok, Overview} = file:read_file("test_app/doc/overview-summary.html"),
?assertEqual(true, nomatch /= re:run(Overview, "Added to head element")),
?assertEqual(true, nomatch /= re:run(Overview, "Some Unicode")).

-spec command(list()) -> ok | no_return().
command(_Config) ->
Expand Down
3 changes: 3 additions & 0 deletions test/test_app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/doc/
!/doc/overview.edoc
!/doc/_head.html
2 changes: 2 additions & 0 deletions test/test_app/doc/_head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- Added to head element -->
<link/>
10 changes: 10 additions & 0 deletions test/test_app/doc/overview.edoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@doc Test app for `rebar3_edoc_extensions'

== Some Unicode characters ==

Here are some Unicode characters for the test — which should succeed.

<ul>
<li>Ç</li>
<li>É</li>
</ul>

0 comments on commit 4807157

Please sign in to comment.