Fix JSON punctuation highlighting inside string values
This commit is contained in:
parent
0a4f921fd9
commit
32fca73d3a
1 changed files with 18 additions and 18 deletions
|
|
@ -209,29 +209,29 @@ defmodule AprsmeWeb.ApiDocsLive do
|
||||||
defp sanitize_raw_packet(raw_packet), do: raw_packet
|
defp sanitize_raw_packet(raw_packet), do: raw_packet
|
||||||
|
|
||||||
defp highlight_json(text) do
|
defp highlight_json(text) do
|
||||||
highlighted =
|
Regex.replace(
|
||||||
Regex.replace(
|
~r/(?<!\\)("(?:[^"\\]|\\.)*")(?=\s*:)|(?<!\\)("(?:[^"\\]|\\.)*")|(\btrue\b|\bfalse\b)|(\bnull\b)|(-?\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)|([{}[\]\:,])/,
|
||||||
~r/(?<!\\)("(?:[^"\\]|\\.)*")(?=\s*:)|(?<!\\)("(?:[^"\\]|\\.)*")|(\btrue\b|\bfalse\b)|(\bnull\b)|(-?\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/,
|
text,
|
||||||
text,
|
fn
|
||||||
fn
|
_, key, "", "", "", "", "" ->
|
||||||
_, key, "", "", "", "" ->
|
~s(<span class="json-key">#{key}</span>)
|
||||||
~s(<span class="json-key">#{key}</span>)
|
|
||||||
|
|
||||||
_, "", str, "", "", "" ->
|
_, "", str, "", "", "", "" ->
|
||||||
~s(<span class="json-string">#{str}</span>)
|
~s(<span class="json-string">#{str}</span>)
|
||||||
|
|
||||||
_, "", "", bool, "", "" ->
|
_, "", "", bool, "", "", "" ->
|
||||||
~s(<span class="json-boolean">#{bool}</span>)
|
~s(<span class="json-boolean">#{bool}</span>)
|
||||||
|
|
||||||
_, "", "", "", null, "" ->
|
_, "", "", "", null, "", "" ->
|
||||||
~s(<span class="json-null">#{null}</span>)
|
~s(<span class="json-null">#{null}</span>)
|
||||||
|
|
||||||
_, "", "", "", "", num ->
|
_, "", "", "", "", num, "" ->
|
||||||
~s(<span class="json-number">#{num}</span>)
|
~s(<span class="json-number">#{num}</span>)
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
Regex.replace(~r/[{}[\]\:,]/, highlighted, ~s(<span class="json-punc">\\0</span>))
|
_, "", "", "", "", "", punc ->
|
||||||
|
~s(<span class="json-punc">#{punc}</span>)
|
||||||
|
end
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp callsign_success_json, do: ~s|{
|
defp callsign_success_json, do: ~s|{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue