You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Markdown blocks have trouble rendering unicode emoji #749
When using unicode emoji in a markdown block, the output appears to be getting trimmed. I tried to see if this was an issue with goldmark, but I don't think it is. I see that there is goldmark-emoji for :joy:-style emojis, but it didn't look like d2 was using this.
Issue appears to be for all layout engines.
Open to working on this if provided some guidance (would be my foray into the codebase).
Resources
D2 test file
Single emoji: |md
🐵
|
Single emoji with text at beginning: |md
This is a monkey emoji: 🐵
|
Single emoji with text at end: |md
🐵 That was a monkey emoji.
|
Single emoji with text around: |md
This is a monkey emoji: 🐵 It's pretty cool.
|
Multiple emojis: |md
🐵🐵🐵🐵
|
Multiple emojis with text at beginning: |md
These are monkey emojis: 🐵🐵🐵🐵
|
Multiple emojis with text at end: |md
🐵🐵🐵🐵 Those were monkey emojis.
|
Multiple emojis with text around: |md
These are monkey emojis: 🐵🐵🐵🐵 They are pretty cool.
|
If you can reproduce this with labels, then it's not a markdown problem. But that might not be ascertainable, since we pad labels, so it won't have that noticeable cutoff.
I suspect the emoji unicode gets measured incorrectly. I'm not really sure what the correct measurement should be, whether it's constant or some unit size of the font-size.
Good luck and please let me know if you get stuck, happy to dig into it more with you!
ohh that makes sense. I don't think the shim is necessary though, better to overflow into the padding a bit imo.
My fear is just that even if we measure this "right", if it's not part of the font we use, and users on different machines will just fallback to their OS's emoji font, which will over/underflow anyway. I don't think there's an option other than having the TTF support a large corpus of emojis
Activity
bo-ku-ra commentedon Feb 3, 2023
is the following relevant?
#517
#513
alixander commentedon Feb 5, 2023
@jameschensmith if you're open to looking into this, I would look here to start: https://github.com/terrastruct/d2/blob/8fa00ca4c3ec9e5ff55f6d2c74be983a3132247f/lib/textmeasure/markdown.go#L88
For Markdown to work, D2 has to manually measure everything and match it with CSS. For example, H1 tags have x padding, y line height, z margin. https://github.com/terrastruct/d2/blob/8fa00ca4c3ec9e5ff55f6d2c74be983a3132247f/lib/textmeasure/markdown.go#L33
The way fonts work, we measure each glyph: https://github.com/terrastruct/d2/blob/8fa00ca4c3ec9e5ff55f6d2c74be983a3132247f/lib/textmeasure/textmeasure.go#L172
If you can reproduce this with labels, then it's not a markdown problem. But that might not be ascertainable, since we pad labels, so it won't have that noticeable cutoff.
I suspect the emoji unicode gets measured incorrectly. I'm not really sure what the correct measurement should be, whether it's constant or some unit size of the font-size.
Good luck and please let me know if you get stuck, happy to dig into it more with you!
alixander commentedon Feb 5, 2023
oh interesting. maybe the font we use, Source Sans Pro, actually just has a subset of emojis supported.
adobe-fonts/source-sans#85
Maybe we need to package an emoji font like https://github.com/samuelngs/apple-emoji-linux, detect if the user used any emojis, and then inject that font into their SVG if so.
https://github.com/terrastruct/d2/blob/0da4e150cd01c8ec4c3b6d25487d11bf5d4ea2a7/d2renderers/d2svg/d2svg.go#L1062
alixander commentedon Feb 5, 2023
hah, wow interesting, til about emojis
alixander commentedon Feb 6, 2023
ohh that makes sense. I don't think the shim is necessary though, better to overflow into the padding a bit imo.
My fear is just that even if we measure this "right", if it's not part of the font we use, and users on different machines will just fallback to their OS's emoji font, which will over/underflow anyway. I don't think there's an option other than having the TTF support a large corpus of emojis
alixander commentedon Feb 6, 2023
Might have to implement this #638 first. Emoji packs might be huge to embed just for a 🙈
bo-ku-ra commentedon Feb 6, 2023
fyi. https://github.com/rivo/uniseg
alixander commentedon Feb 7, 2023
@bo-ku-ra oh wow, good find. this looks incredibly relevant
bo-ku-ra commentedon Feb 7, 2023
japanese uses double-byte characters.
so there seems to be a lot of information about it on japanese websites.