advanced-tables-obsidian icon indicating copy to clipboard operation
advanced-tables-obsidian copied to clipboard

Emoji break the column alignment

Open spencercook opened this issue 4 years ago • 14 comments

NOT A HUGE ISSUE but... Emoji break the column alignment in edit mode. In preview the tables look perfect.

To Reproduce

  1. Insert an emoji in any column
  2. Hit tab or enter
  3. Observe the misaligned columns

Desktop:

  • OS: Mac OS
  • Obsidian Version: 0.10.3
  • Advanced Tables Version: 1.4.11

spencercook avatar Dec 30 '20 15:12 spencercook

Can you please provide a screenshot?

This might be similar to #33.

tgrosinger avatar Dec 30 '20 15:12 tgrosinger

image

It seems the rendering issue is theme independent. I am using the Minimal theme and it's settings plugin but after disabling it and restoring the default theme the issue remained. I tried specifying Inconsolata at the monospace font in the advanced tables plugin as suggested but that didn't work either.

Thanks for checking this out!

spencercook avatar Dec 30 '20 16:12 spencercook

Hmm, I this one is getting outside my understanding of unicode. I'm not sure if it has to do with the emoji containing multiple code points or if it is because of varying widths of the emoji themselves.

tgrosinger avatar Dec 30 '20 16:12 tgrosinger

Same issue occurs when using Japanese characters, without emojis.

For example:

| Name    | Name2   |
| ------- | ------- |
| testing | Column2 |
| 漢字    | Column2 |
| テスト  | Column2 |

A few monospace fonts (Consolas, Courier, Roboto Mono) do not seem to fix the issue. I don't think this could be perfectly aligned, but could be better aligned with space adjustments. How, I am not sure.

krausekai avatar Mar 24 '21 19:03 krausekai

Yep, here's another example:

image

Here's a really good blog post that discusses emoji length issues and how to address them. It won't be perfect, but a step in the right direction.

https://blog.jonnew.com/posts/poo-dot-length-equals-two

zephraph avatar Jun 01 '21 18:06 zephraph

Same issue occurs when using Chinese characters

2045ga avatar Jul 21 '21 10:07 2045ga

@krausekai

Same issue occurs when using Japanese characters, without emojis.

For example:

| Name    | Name2   |
| ------- | ------- |
| testing | Column2 |
| 漢字    | Column2 |
| テスト  | Column2 |

A few monospace fonts (Consolas, Courier, Roboto Mono) do not seem to fix the issue. I don't think this could be perfectly aligned, but could be better aligned with space adjustments. How, I am not sure.

I'm not sure how did you change monospace fonts, I got similar problem but I solved it.

han

If you just edit .markdown-source-view in snippet, then you didn't change table's font. You can try to set monospace global wide or specific your table's font:

.cm-s-obsidian .HyperMD-table-row {
  font-family: 'your font';
}

Similar for @zephraph, the biggest problem is font. Try some different fonts (Source Code Pro + Noto Color Emoji). Still not perfect, but better: emo

Sicalxy avatar Aug 29 '21 20:08 Sicalxy

Same here.

Screenshot 2022-11-27 at 19 21 12

Any thoughts on a fix?

robertandrews avatar Nov 27 '22 19:11 robertandrews

I think we could likely use string-length to fix this.

zephraph avatar Nov 27 '22 20:11 zephraph

After digging into this a bit more I think the issue is in @tgrosinger/md-advanced-tables, not this repo. My suspicion is that you'd need to update https://github.com/tgrosinger/md-advanced-tables/blob/37dd2c5a81faa3eb35d99683e11f3addac4017bd/src/table-cell.ts to use something like string-length (mentioned above) instead of calling .length. Essentially .length is going to lie to you if you're using it to measure position.

zephraph avatar Nov 27 '22 20:11 zephraph

After digging into this a bit more I think the issue is in @tgrosinger/md-advanced-tables, not this repo. My suspicion is that you'd need to update https://github.com/tgrosinger/md-advanced-tables/blob/37dd2c5a81faa3eb35d99683e11f3addac4017bd/src/table-cell.ts to use something like string-length (mentioned above) instead of calling .length. Essentially .length is going to lie to you if you're using it to measure position.

Good work, that's encouraging. Crossing fingers for a fix. Don't think it's in my wheelhouse.

robertandrews avatar Nov 28 '22 22:11 robertandrews

Thank you very much @zephraph for digging into this. Unfortunately, I think it's a little more nuanced, which is why I haven't quite figured out how to solve it.

The md-advanced-tables library actually does put some work into determining the width of a character. Take a look here.

But emoji are particularly tricky. For example:

Emoji

Or this might show it even better:

Emoji-2

It's not 1 or 2 characters wide, it's like 2.2 characters wide. You can't align that using normal spaces... Currently md-advanced-tables is smart enough to call 👍 two characters wide, but it can't do 2.2 spaces of padding.

I'm definitely open to suggestions if anyone knows how to solve this one!

tgrosinger avatar Dec 02 '22 02:12 tgrosinger

And that's not even taking into consideration that some monospace fonts might render emoji differently. Or are emoji even in fonts? Are emoji different widths on different operating systems? I have no idea 🤷‍♂️

tgrosinger avatar Dec 02 '22 02:12 tgrosinger

Not an expert, but it seems that in JavaScript, the Intl.Segmenter allows you to split strings by grapheme clusters, which are what people think of as actual "characters"[^1]. The above-linked library https://github.com/sindresorhus/string-length uses it under the hood so it should fix the issues.

[^1]: https://tonsky.me/blog/unicode/, section How do I detect extended grapheme clusters then?

KucharczykL avatar Oct 05 '23 15:10 KucharczykL