add line numbers

pull/1739/head
Ayrat Badykov 6 years ago
parent abc6750f76
commit 1a5c023704
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 16
      apps/block_scout_web/assets/css/_code.scss
  2. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex
  3. 10
      apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex

@ -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;
}

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

@ -25,5 +25,15 @@ defmodule BlockScoutWeb.AddressDecompiledContractView do
|> String.replace("\e[1m", "<span style=\"font-weight:bold\">")
|> String.replace("»", "&raquo;")
|> String.replace("\e[0m", "</span>")
|> add_line_numbers()
end
defp add_line_numbers(code) do
code
|> String.split("\n")
|> Enum.reduce("", fn line, acc ->
acc <> "<code>#{line}</code>\n"
end)
|> IO.inspect()
end
end

Loading…
Cancel
Save