JsonRemedy.Layer3.HtmlHandlers (JsonRemedy v0.1.11)
View SourceHandles detection and quoting of unquoted HTML content in JSON values.
This module detects HTML-like content that appears unquoted after colons in JSON and wraps it in quotes with proper escaping.
Summary
Functions
Extract HTML content starting from position until we hit a JSON structural delimiter. Returns {html_content, chars_consumed, bytes_consumed}.
Check if the current position starts with HTML content. Returns true if it looks like HTML (starts with < followed by tag name or !DOCTYPE).
Process HTML content for IO list version. Returns {html_iolist, chars_consumed, bytes_consumed, repairs}.
Process HTML content for regular string version. Returns {html_string, chars_consumed, bytes_consumed, repairs}.
Process HTML content by wrapping it in quotes and escaping internal quotes and special characters. Returns {quoted_html, repairs}.
Functions
@spec extract_html_content(String.t(), non_neg_integer()) :: {String.t(), non_neg_integer(), non_neg_integer()}
Extract HTML content starting from position until we hit a JSON structural delimiter. Returns {html_content, chars_consumed, bytes_consumed}.
Strategy: Track HTML tag depth. Only stop at JSON delimiters when:
- We're at HTML tag depth 0 (all tags closed)
- We're at JSON depth 0 (no nested JSON-like braces)
- We're not inside an HTML tag marker (between < and >)
@spec is_html_start?(String.t(), non_neg_integer()) :: boolean()
Check if the current position starts with HTML content. Returns true if it looks like HTML (starts with < followed by tag name or !DOCTYPE).
@spec process_html_iolist(String.t(), map()) :: {iodata(), non_neg_integer(), non_neg_integer(), list()}
Process HTML content for IO list version. Returns {html_iolist, chars_consumed, bytes_consumed, repairs}.
@spec process_html_string(String.t(), map()) :: {String.t(), non_neg_integer(), non_neg_integer(), list()}
Process HTML content for regular string version. Returns {html_string, chars_consumed, bytes_consumed, repairs}.
@spec quote_html_content(String.t(), non_neg_integer()) :: {String.t(), list()}
Process HTML content by wrapping it in quotes and escaping internal quotes and special characters. Returns {quoted_html, repairs}.