Why does fancy text turn into boxes after I paste it?
Copy A and π into your browser console. They look like the same letter in different weights. JavaScript sees two different characters: for (const ch of ['A', 'π']) { console.log(ch, ch.codePointAt(0).toString(16).to
Copy A and π into your browser console. They look like the same letter in different weights. JavaScript sees two different characters:
for (const ch of ['A', 'π']) {
console.log(ch, ch.codePointAt(0).toString(16).toUpperCase());
}
// A 41
// π 1D400
U+1D400 is Mathematical Bold Capital A. A copy-and-paste text tool can swap A for π, and the replacement goes onto the clipboard as plain text. The font that made it look good in the preview stays behind.
The replacement is the easy part
Hereβs a small version of the mapping. It handles ASCII letters and leaves everything else alone:
function toMathBold(text) {
return Array.from(text, ch => {
const code = ch.codePointAt(0);
if (code >= 0x41 && code <= 0x5A) {
return String.fromCodePoint(0x1D400 + code - 0x41);
}
if (code >= 0x61 && code <= 0x7A) {
return String.fromCodePoint(0x1D41A + code - 0x61);
}
return ch;
}).join('');
}
console.log(toMathBold('Alex, cafΓ©! π'));
// ππ₯ππ±, πππΓ©! π
The Γ© stays as it was because it falls outside those two ranges. PasteCharm uses the same idea of passing unmapped characters through. Some styles need explicit exceptions too. For example, the italic mapping uses β for lowercase h, so walking a range wonβt work for every style.
The box shows up at the other end
The receiving app has to find a glyph to draw U+1D400. Its font stack can differ from your browserβs, even on the same device. If the rendering system canβt draw a character, it may show a missing-glyph box. If the app refuses to save the text, check the rules for that input field separately. Unicode FAQ on unsupported characters
A browser preview tells you how the text looks here. For a quick check, paste the same string into the actual profile field and view the saved profile. If youβre debugging someone elseβs report, ask which app and device showed the box, and which character was affected.
Style less of the string
In the PasteCharm bio builder, the first line is the display name. The converter styles that line and leaves the lines underneath alone. So a name can have a decorative accent while the sentence that tells people who you are stays in ordinary text. If the styled name shows up as boxes or sounds strange in a screen reader, the original spelling is an easy fallback.
For text that stays on a page you control, Iβd use CSS to bold normal letters. Iβd reserve these substitutions for cases where someone explicitly wants to copy the characters themselves.
This article was drafted with AI using PasteCharmβs implementation as a reference.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.