Fix JSON punctuation highlighting inside string values

This commit is contained in:
Graham McIntire 2026-06-04 17:01:36 -05:00
parent 0a4f921fd9
commit 32fca73d3a
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -209,29 +209,29 @@ defmodule AprsmeWeb.ApiDocsLive do
defp sanitize_raw_packet(raw_packet), do: raw_packet
defp highlight_json(text) do
highlighted =
Regex.replace(
~r/(?<!\\)("(?:[^"\\]|\\.)*")(?=\s*:)|(?<!\\)("(?:[^"\\]|\\.)*")|(\btrue\b|\bfalse\b)|(\bnull\b)|(-?\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/,
text,
fn
_, key, "", "", "", "" ->
~s(<span class="json-key">#{key}</span>)
Regex.replace(
~r/(?<!\\)("(?:[^"\\]|\\.)*")(?=\s*:)|(?<!\\)("(?:[^"\\]|\\.)*")|(\btrue\b|\bfalse\b)|(\bnull\b)|(-?\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)|([{}[\]\:,])/,
text,
fn
_, key, "", "", "", "", "" ->
~s(<span class="json-key">#{key}</span>)
_, "", str, "", "", "" ->
~s(<span class="json-string">#{str}</span>)
_, "", str, "", "", "", "" ->
~s(<span class="json-string">#{str}</span>)
_, "", "", bool, "", "" ->
~s(<span class="json-boolean">#{bool}</span>)
_, "", "", bool, "", "", "" ->
~s(<span class="json-boolean">#{bool}</span>)
_, "", "", "", null, "" ->
~s(<span class="json-null">#{null}</span>)
_, "", "", "", null, "", "" ->
~s(<span class="json-null">#{null}</span>)
_, "", "", "", "", num ->
~s(<span class="json-number">#{num}</span>)
end
)
_, "", "", "", "", num, "" ->
~s(<span class="json-number">#{num}</span>)
Regex.replace(~r/[{}[\]\:,]/, highlighted, ~s(<span class="json-punc">\\0</span>))
_, "", "", "", "", "", punc ->
~s(<span class="json-punc">#{punc}</span>)
end
)
end
defp callsign_success_json, do: ~s|{