Skip to content

Commit 5e64962

Browse files
committed
Decode GitHub README as UTF-8 to fix mojibake
1 parent 94699db commit 5e64962

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/loaders/github-readme.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ export function githubReadmeLoader(): LiveLoader<ReadmeData, EntryFilter, Collec
153153

154154
const readmeData = await readmeResponse.json();
155155

156-
// Decode base64 content
157-
const readmeMarkdown = atob(readmeData.content);
156+
// Decode base64 content, reinterpreting the raw bytes as UTF-8 so
157+
// multibyte characters (em dashes, smart quotes, etc.) render correctly
158+
const bytes = Uint8Array.from(atob(readmeData.content), (c) => c.charCodeAt(0));
159+
const readmeMarkdown = new TextDecoder("utf-8").decode(bytes);
158160

159161
// Strip the first H1 heading
160162
const markdownWithoutH1 = stripFirstH1(readmeMarkdown);

0 commit comments

Comments
 (0)