Make WordPress Core

Opened 2 years ago

Last modified 16 months ago

#55930 new defect (bug)

Provide comment syntax for templates and template parts

Reported by: wprediscovered's profile wprediscovered Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 6.0
Component: General Keywords:
Focuses: Cc:

Description

Thanks to all of you for working on this great Free Software project!

I'm trying to add copyright and license information to my theme. I do so using SPDX headers using REUSE tool https://reuse.software. This adds information to the .html files using HTML comments (<!-- ... -->).

The Site Editor in WordPress 6.0 doesn't seem able to handle with regular HTML comments in templates and template parts.

On a new theme created using new-empty-theme.php this results in the following index.html page for example:

<!--
SPDX-FileCopyrightText: 2019-2022 WordPress Theme Experiments contributors

SPDX-License-Identifier: GPL-2.0-or-later
-->

<!-- wp:template-part {"slug":"header","tagName":"header"} /-->

<!-- wp:query {"queryId":1,"query":{"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","sticky":""}} -->
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->

<!-- wp:post-excerpt /-->
<!-- /wp:post-template -->
<!-- /wp:query -->

It renders just fine, but in the Site Editor these comments of templates and template parts get treated as blocks. This results in an error for each template and page template that has the HTML annotations: "This block has encountered an error and cannot be previewed.'"

https://user-images.githubusercontent.com/7458098/172100897-8fdc7d30-13c1-443d-b951-d9d004c73118.png

Copying the block contents (source code) the resulting output is as follows:

<p><!--
SPDX-FileCopyrightText: 2019-2022 WordPress Theme Experiments contributors

SPDX-License-Identifier: GPL-2.0-or-later
--></p>

So it seems that the comment is treated as a paragraph.

Besides this being valid HTML, I couldn't find anything about a separate comment syntax in the https://developer.wordpress.org/themes/block-themes/templates-and-template-parts/ documentation.

I expect the Site Editor to ignore non-wp comments rather than trying to parse them as blocks.

I documented some other experiences with using REUSE on WordPress themes in an issue at the REUSE project: https://github.com/fsfe/reuse-tool/issues/537

Change History (2)

#1 @manfcarlo
2 years ago

According to your screenshot, the comment is being parsed into a Classic block, which I think is the correct behaviour. I can't see ignoring comments from the parser being an option because special HTML comments such as <!--nextpage--> and <!--more--> need to be handled. The addition of paragraph tags and the error message are not appropriate though and lead me to wonder if the fault lies with TinyMCE.

#2 @manfcarlo
16 months ago

It looks like this was also reported at https://github.com/WordPress/gutenberg/issues/47212 and there is already some discussion happening.

Note: See TracTickets for help on using tickets.