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

Inline Code Block Handling Issue in Chromium-Based Browsers #1102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WellWells
Copy link

@WellWells WellWells commented Dec 6, 2024

Dear Owner,

Regarding the handling of inline code blocks, I’ve encountered an issue specifically in Microsoft Edge. When translating, it moves all <code> tags to the end of the paragraph, causing formatting disruptions and readability challenges.

After testing, I found that wrapping <code> tags with <span> resolves the issue, allowing proper parsing and translation.

This issue seems to stem from the browser itself. Notably, it does not occur in Safari. Initially, I thought this was limited to Edge, but further investigation revealed that all Chromium-based browsers exhibit this behavior when processing <code> tags. They tend to move these tags to the end of the text block during translation.

Interestingly, this bug appears to have existed since 2020 (or perhaps even earlier), as documented in the following references:

  1. Edge's built-in translation breaks typography

  2. The translator always move the code tag content to the end

As a workaround, adding <span> tags around the <code> blocks has proven to be an effective solution. While not ideal, it ensures readability and proper translation behavior across affected browsers. I hope this insight can help others encountering the same issue.

Best regards,
Wells

@WellWells
Copy link
Author

WellWells commented Dec 6, 2024

The demo page is shown below as an example:

Original Page:
image

Chrome Rendering

Chrome Translate Result

Edge Rendering

Edge Translate Result

After wrapping the inline code block with a tag, the updated rendering is as follows:

Edge Translate Result After adding span tag

Chrome does not always render successfully. For instance, on the Mozilla Developer page, the rendering fails: MDN Documentation: <span> Element

Chrome Rendering Issue

The issue can be resolved by wrapping the <code> tag within a <span> tag.

@CaiJimmy
Copy link
Owner

Thanks for reporting this!

Hugo does not provide a render hook for the inline code block, so the only way to fix this would be via Javascript (which may cause layout shift) or regex replacement. Both are pretty bad solutions. I really hope Edge fixes this bug themselves.

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 this pull request may close these issues.

2 participants