Problem/Motivation
When translating text > 20000 characters that contains html, the text can be split inside a html tag. For example, my html contains entity_embed entities. On certain long text pieces, they get chopped in half right in the middle of the entity embed entities. This results in image displaying incorrectly.

Steps to reproduce
Generate a node that is at least 20000 characters long and embed an entity exactly at 20000 characters so it gets chopped up.
Proposed resolution
The code should check for the last opening HTML tag between the start of the substring and the split point. If it has a corresponding closing tag or is a void element and a > is found within the split point, close at the end of the closing tag. If the corresponding closing tag is not found, split before the opening tag. If the text doesn't contain html, the normal split point will be used and this will never run.

Image is displaying fine after the change is introduced ^
Remaining tasks
Write the code and add some tests. We should initilialize the client via a factory to make it easier to add a test.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Issue fork tmgmt_google_v3-3576675
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
achapWorked on this in the last couple of days but still needs more work. It turns out finding where to split text so it doesn't get chopped in the middle of some html is quite complicated. I used the symfony dom crawler to find the last tag in some text, however, it is quite forgiving for faulty html and will close off chopped off html, so it can't be used for validation. Looked into using libxml directly for validation, but it doesn't consider custom html tags like those from entity embed e.g. as valid html. So I had to write some custom validation. Given the complexity I thought adding a test would be good. To do that, though I needed to move the client initilialisation to a factory so that it can be mocked in tests.
I think it is 80% there but if someone can think of an easier way to do this I'm all ears.
Comment #4
kallado commented@achap Thanks for all the work I'm on a really busy schedule right now but I'll try to have a look at this asap.
Comment #5
achapI added some more test cases and introduced a check for html before trying to find a split point. Also updated the issue summary to make the problem clearer.
I think it's ready for review now.
Comment #6
achap