Skip to content

Emoji spacing bug? #18

@dselivanov

Description

@dselivanov

Hey @hvalev. I found some weird behavior when table contains unicode emoji symbols. When table column contains emoji then markdown_table adds extra space which prevents table to be rendered correctly.. using emoji_spacing="mono" helps sometimes, but sometimes not. I can't figure out logic myself to fix it and send PR. Would be great if you can take a look.
Consider following example

from py_markdown_table.markdown_table import markdown_table
multiline_format = {"column_1": 10, "column_2": 40, "column_3": 40}
rows = [
    {"column_1": "question 2", "column_2": "🔴 FAIL", "column_3": "comment"},
    {"column_1": "question 1", "column_2": "🟢 PASS", "column_3": "comment"},
]
tbl = markdown_table(rows)
tbl.set_params(
    row_sep="always",
    multiline_delimiter=" ",
    padding_weight="right",
    quote=False,
    multiline=multiline_format,
    emoji_spacing = None
)
tbl_str = tbl.get_markdown()
print(tbl_str)

Notice that row 2 and 3 has extra space in column 2 and table can't be rendered correctly (pandoc -f markdown -t html5 -o output.html test.md):

+----------+----------------------------------------+----------------------------------------+
|column_1  |column_2                                |column_3                                |
+----------+----------------------------------------+----------------------------------------+
|question 2|🔴 FAIL                                  |comment                                 |
+----------+----------------------------------------+----------------------------------------+
|question 1|🟢 PASS                                  |comment                                 |
+----------+----------------------------------------+----------------------------------------+
Image

WIth emoji_spacing="mono" row 2 rendered correctly, but row 3 is not..

tbl = markdown_table(rows)
tbl.set_params(
    row_sep="always",
    multiline_delimiter=" ",
    padding_weight="right",
    quote=False,
    multiline=multiline_format,
    emoji_spacing="mono"
)
tbl_str = tbl.get_markdown()
print(tbl_str)
+----------+----------------------------------------+----------------------------------------+
|column_1  |column_2                                |column_3                                |
+----------+----------------------------------------+----------------------------------------+
|question 2|🔴 FAIL                                 |comment                                 |
+----------+----------------------------------------+----------------------------------------+
|question 1|🟢 PASS                                  |comment                                 |
+----------+----------------------------------------+----------------------------------------+
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions