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

Run HTML template files through a code formatter on safe to make markup more readable #752

Open
fabiankaegy opened this issue Dec 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@fabiankaegy
Copy link
Member

Currently, template files that get saved via the Create Block Theme are just exported with whatever code formatting they already had. Especially when these templates are built in the site editor that means that the code isn't formatted at all.

Here is an example of the 404 template from the 2024 theme:

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

<!-- wp:group {"tagName":"main","style":{"spacing":{"margin":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|50"},"blockGap":"var:preset|spacing|30"}},"layout":{"type":"constrained"}} -->
<main class="wp-block-group" style="margin-top:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--50)"><!-- wp:heading {"level":1} -->
<h1 class="wp-block-heading" id="page-not-found">Page Not Found</h1>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The page you are looking for does not exist, or it has been moved. Please try searching using the form below.</p>
<!-- /wp:paragraph -->

<!-- wp:search {"label":"Search","showLabel":false,"buttonText":"Search","fontSize":"medium"} /--></main>
<!-- /wp:group -->

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

This code is much harder to read and review than if it would be indented properly.

Here is the same code formatted correctly:

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

<!-- wp:group {"tagName":"main","style":{"spacing":{"margin":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|50"},"blockGap":"var:preset|spacing|30"}},"layout":{"type":"constrained"}} -->
<main class="wp-block-group" style="margin-top:var(--wp--preset--spacing--50);margin-bottom:var(--wp--preset--spacing--50)">
	
	<!-- wp:heading {"level":1} -->
	<h1 class="wp-block-heading" id="page-not-found">Page Not Found</h1>
	<!-- /wp:heading -->

	<!-- wp:paragraph -->
	<p>The page you are looking for does not exist, or it has been moved. Please try searching using the form below.</p>
	<!-- /wp:paragraph -->

	<!-- wp:search {"label":"Search","showLabel":false,"buttonText":"Search","fontSize":"medium"} /-->
	
</main>
<!-- /wp:group -->

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

This is a very basic example. But the more complex these templates get the more pronounced this issue is.

The reasons I think it would be worth including some standardized code formatting in Create Block Theme are:

  • Especially in teams that work on a theme code often needs to get reviewed. Having the code formated nicely makes that much easier.
  • If every person working on the code manually formats their code the Git diffs that get generated when the template is exported via Create Block Theme are much larger than they need to be which makes it much harder to understand what the actual change was.
@fabiankaegy fabiankaegy added the enhancement New feature or request label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant