From da62f1f5234856050df1658c87a64be5ab4849ca Mon Sep 17 00:00:00 2001 From: vk Date: Fri, 26 Nov 2021 19:00:08 +0200 Subject: [PATCH 1/2] Replace emarkdown to simple RegEx cases for support Windows --- .github/workflows/ci.yaml | 16 ++++++++++++++++ rebar.config | 2 +- rebar.lock | 5 +---- src/adapter/markdown_adapter.erl | 11 +++++++++-- src/sheldon.app.src | 1 - 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6c83fdc..221b7f1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/rebar.config b/rebar.config index 5b7d5f6..58fc33f 100644 --- a/rebar.config +++ b/rebar.config @@ -21,7 +21,7 @@ %% == Dependencies == -{deps, [{worker_pool, "5.0.0"}, {emarkdown, "0.1.0"}]}. +{deps, [{worker_pool, "5.0.0"}]}. %% == Profiles == diff --git a/rebar.lock b/rebar.lock index 71bda50..10a005f 100644 --- a/rebar.lock +++ b/rebar.lock @@ -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">>}]} ]. diff --git a/src/adapter/markdown_adapter.erl b/src/adapter/markdown_adapter.erl index 5aec58c..c83b1b0 100644 --- a/src/adapter/markdown_adapter.erl +++ b/src/adapter/markdown_adapter.erl @@ -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]). diff --git a/src/sheldon.app.src b/src/sheldon.app.src index 1cbe154..b5a6419 100644 --- a/src/sheldon.app.src +++ b/src/sheldon.app.src @@ -6,7 +6,6 @@ {applications, [ kernel, stdlib, - emarkdown, worker_pool ]}, {modules, []}, From 75d9607ea6c7126a426f085a12782b1d07784590 Mon Sep 17 00:00:00 2001 From: vk Date: Fri, 26 Nov 2021 19:20:04 +0200 Subject: [PATCH 2/2] Add remove '\r' for Windows --- rebar.config | 4 +--- src/sheldon.erl | 3 ++- src/sheldon_dictionary.erl | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/rebar.config b/rebar.config index 58fc33f..1ba37b6 100644 --- a/rebar.config +++ b/rebar.config @@ -56,7 +56,7 @@ {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 == @@ -64,8 +64,6 @@ {cover_export_enabled, true}. -{provider_hooks, [{post, [{ct, {codecov, analyze}}]}]}. - {cover_opts, [verbose]}. %% == EDoc == diff --git a/src/sheldon.erl b/src/sheldon.erl index 0e532ea..b79280a 100644 --- a/src/sheldon.erl +++ b/src/sheldon.erl @@ -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 = diff --git a/src/sheldon_dictionary.erl b/src/sheldon_dictionary.erl index 045ce1b..2c5d629 100644 --- a/src/sheldon_dictionary.erl +++ b/src/sheldon_dictionary.erl @@ -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]). @@ -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). @@ -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}]), @@ -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.