Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken table with <img> tag #251

Open
dalance opened this issue Feb 6, 2025 · 2 comments · May be fixed by #253
Open

Broken table with <img> tag #251

dalance opened this issue Feb 6, 2025 · 2 comments · May be fixed by #253

Comments

@dalance
Copy link
Contributor

dalance commented Feb 6, 2025

The table with <img> tag becomes broken by translation.

  • Source
| Ferris                                                                                                           | Meaning                                          |
| ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| <img src="img/ferris/does_not_compile.svg" class="ferris-explain" alt="Ferris with a question mark"/>            | This code does not compile!                      |
  • PO
#: src/chapter_1.md:5
msgid ""
"<img src=\"img/ferris/does_not_compile.svg\" class=\"ferris-explain\" alt="
"\"Ferris with a question mark\"/>"
msgstr ""
"<img src=\"img/ferris/does_not_compile.svg\" class=\"ferris-explain\" alt="
"\"Ferris with a question mark\"/>"

#: src/chapter_1.md:5
msgid "This code does not compile!"
msgstr "このコードはコンパイルできません!"
  • Generated HTML
                        <div class="table-wrapper"><table><thead><tr><th>Ferris</th><th>Meaning</th></tr></thead><tbody>
<tr><td><img src="img/ferris/does_not_compile.svg" class="ferris-explain" alt="Ferris with a question mark"/></td><td></td></tr>
<tr><td>このコードはコンパイルできません!</td><td></td></tr>
</tbody></table>
</div>
  • Original HTML
                        <div class="table-wrapper"><table><thead><tr><th>Ferris</th><th>Meaning</th></tr></thead><tbody>
<tr><td><img src="img/ferris/does_not_compile.svg" class="ferris-explain" alt="Ferris with a question mark"/></td><td>This code does not compile!</td></tr>
</tbody></table>
</div>

According to comparison with the original HTML, extra <tr> is appended, and there is empty <td></td> where the translated text should be inserted to.

@shinmili
Copy link

shinmili commented Feb 8, 2025

I'll work on it.

This seems to be a currently unsupported edge case of extract_events. It emits Events for the msgstr as if it were placed at the top-level (i.e. as an HTML block, not a raw HTML), and that causes reconstruct_markdown to emit an unnecessary newline after the tag.

@shinmili
Copy link

shinmili commented Feb 8, 2025

I have found #44 that fixed a similar issue, but only works for simple texts...

shinmili added a commit to shinmili/mdbook-i18n-helpers that referenced this issue Feb 8, 2025
If an msgstr for a table cell contains HTML that could be parsed as an
HTML block if it were put in the top-level, the table is rendered
incorrectly. The table row containing the cell gets interrupted in the
middle and split into two (or more, if there are more such cells)
incomplete rows.

Close google#251.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants