Skip to content

Html api/tag processor self closing flag#4266

Closed
dmsnell wants to merge 1 commit intoWordPress:trunkfrom
dmsnell:html-api/tag-processor-self-closing-flag
Closed

Html api/tag processor self closing flag#4266
dmsnell wants to merge 1 commit intoWordPress:trunkfrom
dmsnell:html-api/tag-processor-self-closing-flag

Conversation

@dmsnell
Copy link
Copy Markdown
Member

@dmsnell dmsnell commented Mar 29, 2023

Introduce has_self_closing_flag() to the HTML Tag Processor, exposing whether a currently-matched tag contains the self-closing flag /, used when determining if one needs to look for a closing tag of the same name.

This enables structural parsing of an HTML document and is needed to identify self-closing HTML foreign elements.

Trac ticket #58009

cc: @adamziel @gziolo @ockham

@dmsnell dmsnell marked this pull request as ready for review March 29, 2023 13:48
}

/**
* Indicates if the currently matched tag contains the self-closing flag.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

Suggested change
* Indicates if the currently matched tag contains the self-closing flag.
* Indicates if the currently matched tag contains the <self-closing/> flag.

to make it a bit more illustrative? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was trying to follow the explicit constraint not to use HTML tags in summaries and tags

No HTML markup or Markdown of any kind should be used in the summary. If the text refers to an HTML element or tag, then it should be written as “image tag” or “img” element, not ““. - PHPDoc standards

Copy link
Copy Markdown
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @dmsnell! I left two minor (non-blocking) notes. LGTM otherwise! 😄

/**
* Data provider. HTML tags which might have a self-closing flag, and an indicator if they do.
*
* @return array[]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
* @return array[]
* @return array[].

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this even correct? most in the file don't have that period, and I would expect a period on a description, not following a type.

in either case, it's clear we need to clean up the consistency of it in the file. mind if I file a follow-up PR to do that all at one time?

return array(
// These should not have a self-closer, and will leave an element un-closed if it's assumed they are self-closing.
'Self-closing flag on non-void HTML element' => array( '<div />', true ),
'No self-closing flag on non-void HTML element' => array( '<div>', false ),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting the linter doesn't complain about a misaligned arrow 🤔 I hate to be that person, but all the arrows need to be at the same offset.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then don't be that person 😄

I'll try this out, but I think the linter complains here if we line up the arrows. it has some line-length threshold at which it separates the alignment of shorter lines and longer lines.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed: the alignment that looks right is rejected because it doesn't follow the specific linting rules. now go away and take your legibility with you! 🙃

'Self-closing flag after extra spaces' => array( '<div />', true ),
'Self-closing flag after attribute' => array( '<div id=test/>', true ),
'Self-closing flag after quoted attribute' => array( '<div id="test"/>', true ),
'Self-closing flag after boolean attribute' => array( '<div enabled/>', true ),
Copy link
Copy Markdown
Contributor

@adamziel adamziel Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding two more tests? I'm thinking of:

  • <img/> <- without a space between the tag name and a closer
  • <img / > <- / is actually an HTML attribute because of the trailing space.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gladly! these are great test cases to include, and thankfully it handles it right already.

@adamziel
Copy link
Copy Markdown
Contributor

adamziel commented Mar 30, 2023

LGTM! I just left a few minor notes.

@dmsnell dmsnell force-pushed the html-api/tag-processor-self-closing-flag branch 2 times, most recently from c605371 to 5d032d3 Compare April 1, 2023 18:14
Trac ticket: [#58009](https://core.trac.wordpress.org/ticket/58009#ticket)

In this patch we're adding `has_self_closing_flag()` to the HTML Tag Processor.
This exposes whether a currently-matched tag contains the self-closing flag `/`.

This information is critical for the evolution of the HTML API in order
to track and parse HTML structure, specifically, knowing whether an
HTML foreign element is self-closing or not.
@dmsnell dmsnell force-pushed the html-api/tag-processor-self-closing-flag branch 2 times, most recently from 6625190 to 18c1cb9 Compare April 1, 2023 18:22
@ockham
Copy link
Copy Markdown
Contributor

ockham commented Apr 4, 2023

Committed to Core trunk in r55619.

@ockham ockham closed this Apr 4, 2023
@dmsnell dmsnell deleted the html-api/tag-processor-self-closing-flag branch April 6, 2023 09:22
dmsnell added a commit to WordPress/gutenberg that referenced this pull request Apr 20, 2023
 - Support a few extra invalid comment syntaxes. WordPress/wordpress-develop#4256
 - Invalidate bookmarks which have been eliminated by enqueued changes. WordPress/wordpress-develop#4116
 - Expose whether the currently-matched tag has the self-closing flag. WordPress/wordpress-develop#4266
 - Avoid double-writing an attribute value if given case-variations of the name. WordPress/wordpress-develop#4337
dmsnell added a commit to WordPress/gutenberg that referenced this pull request Apr 21, 2023
 - Support a few extra invalid comment syntaxes. WordPress/wordpress-develop#4256
 - Invalidate bookmarks which have been eliminated by enqueued changes. WordPress/wordpress-develop#4116
 - Expose whether the currently-matched tag has the self-closing flag. WordPress/wordpress-develop#4266
 - Avoid double-writing an attribute value if given case-variations of the name. WordPress/wordpress-develop#4337
 - Linting updates from WordPress/wordpress-develop#4360.
dmsnell added a commit to WordPress/gutenberg that referenced this pull request Apr 24, 2023
 - Support a few extra invalid comment syntaxes. WordPress/wordpress-develop#4256
 - Invalidate bookmarks which have been eliminated by enqueued changes. WordPress/wordpress-develop#4116
 - Expose whether the currently-matched tag has the self-closing flag. WordPress/wordpress-develop#4266
 - Avoid double-writing an attribute value if given case-variations of the name. WordPress/wordpress-develop#4337
 - Linting updates from WordPress/wordpress-develop#4360.
 - Avoid losing previous updates in certain cases when seeking earlier in a document. WordPress/wordpress-develop#4345
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.

3 participants