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

Transformer: Strip comments #13

Closed
3 tasks
schlessera opened this issue Mar 27, 2020 · 7 comments
Closed
3 tasks

Transformer: Strip comments #13

schlessera opened this issue Mar 27, 2020 · 7 comments
Assignees
Labels
Milestone

Comments

@schlessera
Copy link
Collaborator

Feature description

Add logic to the existing Minify transformer so that it strips unneeded comments.

A configuration will be needed to let users add to that patterns of comments to skip.

Related ampproject/amp-wp#4213


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Generated HTML output from the Optimizer is minified
  • All non-essential HTML comments in the minified output have been removed
  • Users can use a configuration value to retain a given comment or family of comments

Implementation brief

QA testing instructions

  1. Verify: AMP optimization is enabled
  2. Go to the AMP version of a page
  3. use "View Source..." on the page to see the generated HTML markup
  4. Verify: The generated HTML markup is minified
  5. Verify: Non-essential comments have been removed

Demo

Changelog entry

@westonruter
Copy link
Member

Previously: ampproject/amp-wp#2842.

@schlessera schlessera transferred this issue from ampproject/amp-wp Nov 6, 2020
@schlessera
Copy link
Collaborator Author

Fixed via #251

@schlessera schlessera added this to the 0.8.0 milestone Oct 19, 2021
@DrLightman
Copy link

DrLightman commented Apr 12, 2022

Hello, I need HTML comments to be present in my AMP page.

I don't understand if is this feature that is removing them, how can I verify?
I don't see an option to toggle this on/off in the settings screen.

@ediamin
Copy link
Collaborator

ediamin commented Apr 12, 2022

@DrLightman Yes, the MinifyHTML transformer strips out the comments by default.

I don't see an option to toggle this on/off in the settings screen.

Are you using AMP WP plugin?

@DrLightman
Copy link

Hi @ediamin

Yes the official plugin from here https://wordpress.org/plugins/amp/ (/wp-content/plugins/amp/amp.php)

Ok so I mighy hack in the code you kindly provided by setting that to false, if a filter is not available.

@ediamin
Copy link
Collaborator

ediamin commented Apr 12, 2022

You can use the amp_optimizer_config filter. You can try this snippet,

use AmpProject\Optimizer\Configuration\MinifyHtmlConfiguration;
use AmpProject\Optimizer\Transformer\MinifyHtml;

function minifyhtml_disable_remove_comments( $config ) {
	$config[ MinifyHtml::class ] = [
		MinifyHtmlConfiguration::REMOVE_COMMENTS => false,
	];

	return $config;
}

add_filter( 'amp_optimizer_config', 'minifyhtml_disable_remove_comments' );

@DrLightman
Copy link

Thank you very much @ediamin !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants