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

p is not a valid child element of div #184

Closed
SebRollen opened this issue Jul 26, 2022 · 4 comments
Closed

p is not a valid child element of div #184

SebRollen opened this issue Jul 26, 2022 · 4 comments

Comments

@SebRollen
Copy link

Ran into this issue today, where sablon would not convert html where a p tag was a child element of a div tag. This was surprising to me, but I can see that the config file indeed says that div tags can only hold inline elements: https://github.com/senny/sablon/blob/master/lib/sablon/configuration/configuration.rb#L63

This seems inconsistent with the HTML standard which lists that any flow content (which includes p) can be a child of div tags:
Div: https://html.spec.whatwg.org/#the-div-element

@SebRollen
Copy link
Author

I tried updating the line to also allow _block elements as children of div tags. This let me generate the word doc, but I ran into corruption issues when opening the document. Would appreciate some pointers to understand why this would not work

@senny
Copy link
Owner

senny commented Jul 27, 2022

Hi @SebRollen, it's been a long while since I worked on Sablon. I don't have any direct pointers for you where to look but I can tell you that Sablon by no means tries to implement complete compliance with the HTML standard. HTML insertion is a compromise and contains lots of trade-offs. It is certainly not in a state where it could render any valid HTML you give it.

Without having looked closer, I'd assume that block elements can not be nested in WordML. As both div and p tags translate to a wordML block, this results in the corruption you observe.

I would recommend that you transform the html before you feed it to Sablon.

@stadelmanma
Copy link
Collaborator

stadelmanma commented Jul 29, 2022

@SebRollen that is expected behavior, WordML has more rules and is less forgiving than HTML so some concessions needed to be made to allow mapping from HTML -> WordML. I suppose one could tweak the code to treat any child of a block tag as an inline tag then you'd be allowed to do <div><p>[content]</p></div> and it'd render as if it was <div><span>[content]</span><div>. I haven't looked at the code in ages but I suspect there might be a few other "gotchas" adding in that flexibility.

@SebRollen
Copy link
Author

@senny @stadelmanma Thank you both, I think I was focusing too much on the HTML side of things rather than the WordML standard - just because something is allowed from one side obviously doesn't mean there's a direct mapping to the other standard.

We've found a way to work around this issue by tweaking our HTML slightly, so I'll close the issue as this doesn't necessarily seem like something that could or should be fixed in Sablon.

Thanks again!

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

No branches or pull requests

3 participants