aboutsummaryrefslogtreecommitdiff
path: root/core/encoding/entity/entity.odin
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2026-01-19 18:17:13 +0000
committergingerBill <gingerBill@users.noreply.github.com>2026-01-19 18:17:13 +0000
commitfddc73286999df7f0e04f00ea36d404687a82ec4 (patch)
tree9ca7068efa65229c93b7498d90b37b8c9dbbb217 /core/encoding/entity/entity.odin
parent27ac0ebc371883ebedc2c24b8f1154621af71a4d (diff)
Escape non-breaking space (0xa0) to `&nbsp;`
Diffstat (limited to 'core/encoding/entity/entity.odin')
-rw-r--r--core/encoding/entity/entity.odin5
1 files changed, 4 insertions, 1 deletions
diff --git a/core/encoding/entity/entity.odin b/core/encoding/entity/entity.odin
index 95a404a81..89155b3a7 100644
--- a/core/encoding/entity/entity.odin
+++ b/core/encoding/entity/entity.odin
@@ -263,7 +263,7 @@ xml_decode_entity :: proc(entity: string) -> (decoded: [2]rune, rune_count: int,
// escape_html escapes special characters like '&' to become '&amp;'.
-// It escapes only 5 different characters: & ' < > and ".
+// It escapes only 6 different characters: & ' < > " and non-breaking space.
@(require_results)
escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_location) -> (output: string, was_allocation: bool) {
/*
@@ -272,6 +272,7 @@ escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_lo
< -> &lt;
> -> &gt;
" -> &#34; // &#34; is shorter than &quot;
+ 0x6a -> &nbsp;
*/
b := transmute([]byte)s
@@ -285,6 +286,7 @@ escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_lo
case '<': extra_bytes_needed += 3
case '>': extra_bytes_needed += 3
case '"': extra_bytes_needed += 4
+ case 0xa0: extra_bytes_needed += 5
}
}
@@ -307,6 +309,7 @@ escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_lo
case '<': x = "&lt;"
case '>': x = "&gt;"
case '"': x = "&#34;"
+ case 0xa0: x = "&nbsp;"
}
if x != "" {
copy(t[w:], x)