using context:'template' for Nokogiri::HTML5.fragment allows parsing of otherwise illegal fragments like <td> #2426
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thecontext
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.