diff --git a/apps/block_scout_web/assets/css/_code.scss b/apps/block_scout_web/assets/css/_code.scss index f6e2c8afc6..e466993e55 100644 --- a/apps/block_scout_web/assets/css/_code.scss +++ b/apps/block_scout_web/assets/css/_code.scss @@ -6,6 +6,22 @@ pre { white-space: pre-wrap; } +.pre-decompiled code { + white-space: pre-wrap; + counter-increment: line; +} + +.pre-decompiled code::before { + content: counter(line); + display: inline-block; + width: 2.5em; /* Fixed width */ + border-right: 1px solid #ddd; + padding: 0 .5em; + margin-right: .5em; + color: #888; + -webkit-user-select: none; +} + .pre-scrollable-shorty { max-height: $pre-scrollable-max-height / 7; } diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex index 141fd544bb..d2412d62c1 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex @@ -21,7 +21,7 @@
-
<%= raw(highlight_decompiled_code(contract.decompiled_source_code)) %>
+
<%= raw(highlight_decompiled_code(contract.decompiled_source_code)) %>
diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex index a679e2e141..82c5dd91fd 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex @@ -25,5 +25,15 @@ defmodule BlockScoutWeb.AddressDecompiledContractView do |> String.replace("\e[1m", "") |> String.replace("ยป", "»") |> String.replace("\e[0m", "") + |> add_line_numbers() + end + + defp add_line_numbers(code) do + code + |> String.split("\n") + |> Enum.reduce("", fn line, acc -> + acc <> "#{line}\n" + end) + |> IO.inspect() end end