fix: set view blob charset=utf-8 to avoid non-ASCII mojibake - #10
Open
wang1212 wants to merge 1 commit into
Open
fix: set view blob charset=utf-8 to avoid non-ASCII mojibake#10wang1212 wants to merge 1 commit into
wang1212 wants to merge 1 commit into
Conversation
viewAsMarkdown opens page content in a new tab via Blob([content], { type: "text/plain" }).
Without an explicit charset, the browser falls back to ISO-8859-1 for text/plain,
so UTF-8 byte streams are decoded as latin1 and non-ASCII text (e.g. CJK) renders as
mojibake. Declare charset=utf-8 so the blob is decoded correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When users click the View as Markdown action, the page opens in a new tab with non-ASCII text (e.g. CJK content) rendered as mojibake.
Root cause
viewAsMarkdown()opens the page content in a new tab via:Blobencodes the JS string as UTF-8 bytes, buttype: "text/plain"does not declare a charset. Per the HTTP/text/*default, the browser falls back to ISO-8859-1 (latin1) when decoding the resulting blob URL, so UTF-8 byte streams are decoded as single-byte latin1 characters — that's the mojibake.Fix
Declare
charset=utf-8on the blob type:The content is already UTF-8 (it's produced by the existing markdown extraction from the page DOM and from any generated per-page
.mdfiles), so declaring the charset only fixes decoding and changes nothing else.Impact
viewaction only.copyand the AI-tool actions are unaffected (clipboard write and link construction already handle UTF-8 correctly).Tested on
i18n.defaultLocale: zh-Hans, Chinese documentation pages.应用安全etc.应用安全correctly./cc maintainers — happy to adjust if you prefer a different approach (e.g. serve via a generated
.mdroute whengenerateMarkdownRoutesis enabled).