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

default true CLI options can't be disabled ("include-auto-generated-tags") #860

Closed
bulk88 opened this issue Oct 17, 2017 · 0 comments · Fixed by #892
Closed

default true CLI options can't be disabled ("include-auto-generated-tags") #860

bulk88 opened this issue Oct 17, 2017 · 0 comments · Fixed by #892

Comments

@bulk88
Copy link

bulk88 commented Oct 17, 2017

given file

<html><head><meta name="mobileoptimized" content="0"></head><body>
<a href="#1">&nbsp;1&nbsp;</a> 
<a href="#2">&nbsp;2&nbsp;</a> 
<a href="#3">&nbsp;3&nbsp;</a> 
<a href="#4">&nbsp;4&nbsp;</a> 
<a href="#5">&nbsp;5&nbsp;</a>
<br><br>
<a name="1">1: <a href="#A">A</a><br>
<a name="2">2: <a href="#B">B</a><br>
<a name="3">3: <a href="#C">C</a><br>
<a name="4">4: <a href="#D">D</a><br>
<a name="5">5: <a href="#E">E</a><br>
<br><br>
<a name="A"><a href="s.htm#A1">Page 1</a><br>
<a name="B"><a href="s.htm#A2">Page 2</a><br>
<a name="C"><a href="s.htm#A3">Page 3</a><br>
<a name="D"><a href="s.htm#A4">Page 4</a><br>
<a name="E"><a href="s.htm#A5">Page 5</a><br>
</body></html>

which has target anchors with no contents and no closing tag. No closing tag is on purpose for space optimization, since HTML prohibits an A tag in an A tag and implicitly closes the last one when it encounters an opening A tag. I am using the following line to minify this HTML file.

html-minifier --collapse-boolean-attributes --collapse-whitespace  --html5 --remove-attribute-quotes --remove-comments  --remove-empty-attributes --remove-optional-tags  --remove-redundant-attributes --remove-script-type-attributes  --remove-style-link-type-attributes --remove-tag-whitespace  --sort-attributes --sort-class-name --trim-custom-fragments  --use-short-doctype --minify-js -o testm.htm test.htm

gives

<meta content=0 name=mobileoptimized><a href=#1>&nbsp;1&nbsp;</a> <a href=#2>&nbsp;2&nbsp;</a> <a href=#3>&nbsp;3&nbsp;</a> <a href=#4>&nbsp;4&nbsp;</a> <a href=#5>&nbsp;5&nbsp;</a><br><br><a name=1>1: <a href=#A>A</a><br><a name=2>2: <a href=#B>B</a><br><a name=3>3: <a href=#C>C</a><br><a name=4>4: <a href=#D>D</a><br><a name=5>5: <a href=#E>E</a><br><br><br><a name=A><a href=s.htm#A1>Page 1</a><br><a name=B><a href=s.htm#A2>Page 2</a><br><a name=C><a href=s.htm#A3>Page 3</a><br><a name=D><a href=s.htm#A4>Page 4</a><br><a name=E><a href=s.htm#A5>Page 5</a><br></a></a></a></a></a></a></a></a></a></a>

with all those extra "</a>"s. Adding "--include-auto-generated-tags" doesn't change the output, since the default for "includeAutoGeneratedTags" is true. "--noinclude-auto-generated-tags" and "--no-include-auto-generated-tags" dont change the output either.

"--include-auto-generated-tags 0" breaks everything

Cannot read 0
ENOENT: no such file or directory, open 'C:\Documents and Settings\Owner\Desktop
\htmpages\0'

If I use the following JSON config

{
  "collapseBooleanAttributes": true,
  "collapseWhitespace": true,
  "html5": true,
  "removeAttributeQuotes": true,
  "removeComments": true,
  "removeEmptyAttributes": true,
  "removeEmptyElements": true,
  "removeOptionalTags": true,
  "removeRedundantAttributes": true,
  "removeScriptTypeAttributes": true,
  "removeStyleLinkTypeAttributes": true,
  "removeTagWhitespace": true,
  "sortAttributes": true,
  "sortClassName": true,
  "trimCustomFragments": true,
  "useShortDoctype": true,
  "minifyJS": true
}

it produces the extra "</a>"s. If I add "includeAutoGeneratedTags": false to the config file, the extra "</a>"s are gone. So its not possible AFAIK to turn off includeAutoGeneratedTags from the CLI.

bulk88 added a commit to bulk88/tinymta that referenced this issue Oct 17, 2017
kangax/html-minifier#860 extra "</a>" close tags
were being added, and couldn't be disabled in minified output, because
"includeAutoGeneratedTags" can't be set to false from cmd line,this commit
is for a future commit
alexlamsl added a commit that referenced this issue Mar 14, 2018
alexlamsl added a commit that referenced this issue Mar 14, 2018
bulk88 added a commit to bulk88/html-minifier that referenced this issue Apr 14, 2021
the fix for kangax#860 enabled disabling these 2 flags from the command line
but also made them uncontrollable from the JSON config file

old commander.js (not 2021 commander.js) assigns boolean true
unconditionally as defaultValue for all --no- arguments, when minifier
fuses command line and JSON config file options together in cli.js's
createOptions(), it sees program["includeAutoGeneratedTags"] = true and
ignored config["includeAutoGeneratedTags"], in my case "= false". Delete
the defaultValue/key from commander.js object before parsing user's ARGV
to solve the bug.
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 a pull request may close this issue.

1 participant