Skip to content

using context:'template' for Nokogiri::HTML5.fragment allows parsing of otherwise illegal fragments like <td> #2426

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

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

Conversation

jrochkind
Copy link

What are you trying to accomplish?

Fixes #2422, and allows render_inline in test to make Nokogiri HTML5 fragments that would otherwise be illegal based on lack of parent context, such as a straight <td> or <tr>

What approach did you choose and why?

Created ticket at nokogiri, sparklemotion/nokogiri#3536, and while the response was that nokogiri was working as expected, as HTML5 rules don't allow context-free parsing generally, and can't parse a (eg) <td> or <tr> without a parent <table>.

However, responder @stevecheckoway, graciously helped us think through it and realize that the (hard to find documented!) context: argument, when passed "template", would trigger HTML5 parsing rules that would allow closer to the arbitrary fragments we are used to with HTML4.

Steve suggested that in retrospect perhaps context: 'template' should have been the default for fragments, instead of "body" which is in fact the default. It's unclear why the context arg hasn't made it into generated nokogiri docs at all!

It's clear to me that this is the right move, and I can't think of any problems or even backwards incompatibilites it would cause.

Anything you want to highlight for special attention from reviewers?

Confirmed new test failed without change.

@jrochkind jrochkind force-pushed the render_inline_nokogiri_contextless branch from 01d666f to 6bc84f0 Compare August 11, 2025 03:31
@jrochkind
Copy link
Author

I don't understand the test failures, I don't think they have to do with me?

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.

version 4.0.0 render_inline in specs issues
1 participant