forked from inaka/sheldon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
438 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ log/ | |
*_plt | ||
.DS_Store | ||
doc/ | ||
_elixir_build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
[]. | ||
[{<<"bunt">>,{elixir,"bunt","0.2.0"},2}, | ||
{<<"credo">>,{elixir,"credo","0.7.2"},1}, | ||
{<<"dialyxir">>,{elixir,"dialyxir","0.5.0"},1}, | ||
{<<"earmark">>,{elixir,"earmark","1.2.0"},0}]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
%%% @doc HTML Adapter. *Note* This is not the final version of html_adapter, currently it only | ||
%%% escapes tags and replace some special html characters. | ||
%%% | ||
%%% Copyright 2017 Inaka <[email protected]> | ||
%%% | ||
%%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%%% you may not use this file except in compliance with the License. | ||
%%% You may obtain a copy of the License at | ||
%%% | ||
%%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%%% | ||
%%% Unless required by applicable law or agreed to in writing, software | ||
%%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%%% See the License for the specific language governing permissions and | ||
%%% limitations under the License. | ||
%%% @end | ||
%%% @copyright Inaka <[email protected]> | ||
%%% | ||
-module(html_adapter). | ||
-author("Felipe Ripoll <[email protected]>"). | ||
|
||
%% API | ||
-export([adapt/1]). | ||
|
||
%%%=================================================================== | ||
%%% API | ||
%%%=================================================================== | ||
|
||
-spec adapt(binary()) -> iodata(). | ||
adapt(Line) -> | ||
Line1 = escape_tags(Line), | ||
replace_chars(Line1). | ||
|
||
%%%=================================================================== | ||
%%% Internal Functions | ||
%%%=================================================================== | ||
|
||
-spec replace_chars(binary()) -> iodata(). | ||
replace_chars(Line) -> | ||
Chars = chars_to_replace(), | ||
replace_chars(Line, Chars). | ||
|
||
-spec replace_chars(iodata(), [{string(), string()}]) -> iodata(). | ||
replace_chars(Line, []) -> | ||
Line; | ||
replace_chars(Line, [{Pattern, ReplaceBy} | Rest]) -> | ||
Result = re:replace(Line, Pattern, ReplaceBy), | ||
Result2 = replace(Result, Line, {Pattern, ReplaceBy}), | ||
replace_chars(Result2, Rest). | ||
|
||
-spec escape_tags(iodata()) -> iodata(). | ||
escape_tags(Line) -> | ||
Pattern = "<[^>]*>", | ||
ReplaceBy = "", | ||
Result = re:replace(Line, Pattern, ReplaceBy), | ||
replace(Result, Line, {Pattern, ReplaceBy}). | ||
|
||
-spec replace(iodata(), iodata(), {string(), string()}) -> iodata(). | ||
replace(Line, Line, _) -> | ||
Line; | ||
replace([Line, []], _, _) -> | ||
Line; | ||
replace(Line, _PreviousLine, {Pattern, ReplaceBy}) -> | ||
Result = re:replace(Line, Pattern, ReplaceBy), | ||
replace(Result, Line, {Pattern, ReplaceBy}). | ||
|
||
-spec chars_to_replace() -> [{string(), string()}]. | ||
chars_to_replace() -> | ||
[ {""", "\""} | ||
, {"&", "&"} | ||
, {"<", "<"} | ||
]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
%%% @doc Markdown Adapter. | ||
%%% | ||
%%% Copyright 2017 Inaka <[email protected]> | ||
%%% | ||
%%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%%% you may not use this file except in compliance with the License. | ||
%%% You may obtain a copy of the License at | ||
%%% | ||
%%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%%% | ||
%%% Unless required by applicable law or agreed to in writing, software | ||
%%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%%% See the License for the specific language governing permissions and | ||
%%% limitations under the License. | ||
%%% @end | ||
%%% @copyright Inaka <[email protected]> | ||
%%% | ||
-module(markdown_adapter). | ||
-author("Felipe Ripoll <[email protected]>"). | ||
|
||
%% API | ||
-export([adapt/1]). | ||
|
||
%%%=================================================================== | ||
%%% API | ||
%%%=================================================================== | ||
|
||
-spec adapt(binary()) -> iodata(). | ||
adapt(Line) -> | ||
{ok, Line1, _} = 'Elixir.Earmark':as_html(Line), | ||
% Earmark replace ' by ’ and ‘ which causes a bitstring, so we replace it by ' again | ||
Line2 = binary:replace(Line1, [<<226, 128, 152>>, <<226, 128, 153>>], <<39>>, [global]), | ||
% replace “ and ” by " | ||
Line3 = binary:replace(Line2, [<<226, 128, 156>>, <<226, 128, 157>>], <<34>>, [global]), | ||
html_adapter:adapt(Line3). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.