Skip to content

Commit 7e6b8b2

Browse files
MrFlounderclaude
andcommitted
fix(md): decode UTF-8 correctly when rendering markdown in browser
atob() returns a Latin-1 binary string, so multi-byte UTF-8 characters (like em dashes) were rendered as mojibake (e.g. â€" instead of —). Use TextDecoder to properly convert the base64-decoded bytes to UTF-8. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8734bf6 commit 7e6b8b2

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/crabcode

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9139,7 +9139,7 @@ cmd_md() {
91399139
filename=$(basename "$file")
91409140
local tmp_html="/tmp/crab-md-${filename%.*}-$$.html"
91419141

9142-
# Base64-encode markdown content (atob handles line wraps fine)
9142+
# Base64-encode markdown content; decoded via atob + TextDecoder for UTF-8 support
91439143
local md_b64
91449144
md_b64=$(base64 < "$file")
91459145

@@ -9204,7 +9204,10 @@ MDCSS
92049204
},
92059205
gfm:true
92069206
});
9207-
var src=atob('${md_b64}');
9207+
var bin=atob('${md_b64}');
9208+
var bytes=new Uint8Array(bin.length);
9209+
for(var i=0;i<bin.length;i++)bytes[i]=bin.charCodeAt(i);
9210+
var src=new TextDecoder('utf-8').decode(bytes);
92089211
document.querySelector('.markdown-body').innerHTML=marked.parse(src);
92099212
document.querySelectorAll('pre code').forEach(function(b){hljs.highlightElement(b);});
92109213
MDSCRIPT

0 commit comments

Comments
 (0)