fix highlighting

pull/1739/head
Ayrat Badykov 6 years ago
parent 5f637791fd
commit 025dc3ed6d
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex
  2. 18
      apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex

@ -21,7 +21,7 @@
</button> </button>
</div> </div>
<div class="tile tile-muted"> <div class="tile tile-muted">
<pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= highlight_decompiled_code(contract.decompiled_source_code) %></code></pre> <pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= raw(highlight_decompiled_code(contract.decompiled_source_code)) %></code></pre>
</div> </div>
</section> </section>
</div> </div>

@ -2,13 +2,13 @@ defmodule BlockScoutWeb.AddressDecompiledContractView do
use BlockScoutWeb, :view use BlockScoutWeb, :view
@colors %{ @colors %{
"\033[95m" => "235, 97, 247", "\e[95m" => "235, 97, 247",
"\033[91m" => "236, 89, 58", "\e[91m" => "236, 89, 58",
"\033[38;5;8m" => "111, 110, 111", "\e[38;5;8m" => "111, 110, 111",
"\033[32m" => "107, 194, 76", "\e[32m" => "107, 194, 76",
"\033[93m" => "239, 236, 84", "\e[93m" => "239, 236, 84",
"\033[92m" => "119, 232, 81", "\e[92m" => "119, 232, 81",
"\033[94m" => "184, 90, 190" "\e[94m" => "184, 90, 190"
} }
def highlight_decompiled_code(code) do def highlight_decompiled_code(code) do
@ -16,8 +16,8 @@ defmodule BlockScoutWeb.AddressDecompiledContractView do
|> Enum.reduce(code, fn {symbol, rgb}, acc -> |> Enum.reduce(code, fn {symbol, rgb}, acc ->
String.replace(acc, symbol, "<span style=\"color:rgb(#{rgb})\">") String.replace(acc, symbol, "<span style=\"color:rgb(#{rgb})\">")
end) end)
|> String.replace("\033[1m", "<span style=\"font-weight:bold\">") |> String.replace("\e[1m", "<span style=\"font-weight:bold\">")
|> String.replace("»", "&raquo;") |> String.replace("»", "&raquo;")
|> String.replace("\033[0m", "</span>") |> String.replace("\e[0m", "</span>")
end end
end end

Loading…
Cancel
Save