Skip to content

Commit

Permalink
Merge pull request #79 from inaka/delete_emarkdown
Browse files Browse the repository at this point in the history
Delete emarkdown
  • Loading branch information
ferigis authored Nov 26, 2021
2 parents 0003280 + 75d9607 commit 89df879
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

windows:
name: "Windows"
runs-on: windows-latest
strategy:
matrix:
otp: [23.3, 24.1]
rebar: [3.17.0]
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
rebar3-version: ${{matrix.rebar}}
- name: Tests
run: rebar3 test
6 changes: 2 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

%% == Dependencies ==

{deps, [{worker_pool, "5.0.0"}, {emarkdown, "0.1.0"}]}.
{deps, [{worker_pool, "5.0.0"}]}.

%% == Profiles ==

Expand Down Expand Up @@ -56,16 +56,14 @@
{rebar3_lint, "~> 1.0.1"},
{rebar3_hank, "~> 1.2.2"},
{coveralls, "~> 2.2.0"},
{rebar3_codecov, "0.2.0"}]}.
{rebar3_codecov, "~> 0.2.0"}]}.

%% == Cover ==

{cover_enabled, true}.

{cover_export_enabled, true}.

{provider_hooks, [{post, [{ct, {codecov, analyze}}]}]}.

{cover_opts, [verbose]}.

%% == EDoc ==
Expand Down
5 changes: 1 addition & 4 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{"1.2.0",
[{<<"emarkdown">>,{pkg,<<"emarkdown">>,<<"0.1.0">>},0},
{<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"5.0.0">>},0}]}.
[{<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"5.0.0">>},0}]}.
[
{pkg_hash,[
{<<"emarkdown">>, <<"F1310FB8EE1A488CB2E16AA4E13CB34A7B68B310222CC47BB817B52242D7337C">>},
{<<"worker_pool">>, <<"B4B867BDF7E4D6451ED82C47BD72E53C24C04518C0AB821FDC6D28BA0F8EEDE2">>}]},
{pkg_hash_ext,[
{<<"emarkdown">>, <<"260E4170C0FAD7532B5651486C1FF4291E3069CF6D862393106CF3E2B2F3EFCE">>},
{<<"worker_pool">>, <<"1F9EBE0650BD4B2C4BD34A5BF59D29DEA37BF80C6C22AB4BE2BD02C6BA264BB6">>}]}
].
11 changes: 9 additions & 2 deletions src/adapter/markdown_adapter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@

-spec adapt(binary()) -> iodata().
adapt(Line) ->
Line1 = emarkdown:to_html(Line),
html_adapter:adapt(Line1).
%% Prepare links
L0 = binary:replace(Line,
[<<"`">>, <<"[">>, <<"]">>, <<"(">>, <<")">>],
<<" ">>,
[global]),
%% Delete links in line
L1 = re:replace(L0, "(http\S*?)(\.*?\s)", " ", [global, {return, binary}]),
%% Delete other symbols
binary:replace(L1, [<<"`">>, <<"<">>, <<">">>, <<"*">>, <<"#">>], <<>>, [global]).
1 change: 0 additions & 1 deletion src/sheldon.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
{applications, [
kernel,
stdlib,
emarkdown,
worker_pool
]},
{modules, []},
Expand Down
3 changes: 2 additions & 1 deletion src/sheldon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ check(Text, Config) ->

-spec do_check(iodata(), sheldon_config:config()) -> sheldon_result:result().
do_check(Text, #{ignore_blocks := IgnoreBlocks} = Config) ->
Lines = string:split(Text, "\n", all),
Lines0 = sheldon_dictionary:trim_for_windows(Text),
Lines = string:split(Lines0, "\n", all),

% Create lines in format {lineNumber, Line}
Lines2 =
Expand Down
19 changes: 16 additions & 3 deletions src/sheldon_dictionary.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
-behaviour(gen_server).

%% API
-export([start_link/1, member/2, dictionary_name/1, get_bazinga/1, candidates/2]).
-export([start_link/1, member/2, dictionary_name/1, get_bazinga/1, candidates/2,
trim_for_windows/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3]).
Expand Down Expand Up @@ -116,7 +117,8 @@ learn_language(Lang) ->
set_bazingas(Lang) ->
BazingaSource = [code:priv_dir(sheldon), "/lang/", atom_to_list(Lang), "/bazinga.txt"],
BazingaName = bazinga_name(Lang),
{ok, SourceBin} = file:read_file(BazingaSource),
{ok, SourceBin0} = file:read_file(BazingaSource),
SourceBin = trim_for_windows(SourceBin0),
Words = re:split(SourceBin, "\n"),
persistent_term:put(BazingaName, Words).

Expand All @@ -129,7 +131,8 @@ bazinga_name(Lang) ->

-spec fill_cashe(atom(), term()) -> ok.
fill_cashe(Name, Source) ->
SourceBin = generate_dictionary(Source),
SourceBin0 = generate_dictionary(Source),
SourceBin = trim_for_windows(SourceBin0),
Words = re:split(SourceBin, "\n"), % one word per line
Name = ets:new(Name, [named_table, bag, {read_concurrency, true}]),

Expand Down Expand Up @@ -184,3 +187,13 @@ concat_dictionaries(Source, AdditionalDictionaries) ->
end,
SourceBin,
AdditionalDictionaries).

-spec trim_for_windows(binary()) -> binary().
trim_for_windows(Text) ->
%% Fow Windows remove '\r'
case os:type() of
{win32, _} ->
binary:replace(Text, [<<"\r">>], <<>>, [global]);
_ ->
Text
end.

0 comments on commit 89df879

Please sign in to comment.