3

Is there a standard and easy way how to remove comments from HTML templates (Thymeleaf) using a Maven plugin ? It would be nice if it can do this conventionally only for <body> content and leave browser hints in <head untouched.

I know I can filter Maven resources or use Thymeleaf comments by I am looking for ready solution.

ps-aux
  • 11,627
  • 25
  • 81
  • 128

1 Answers1

-1

This can be achieved in Maven by several techniques. The commonality in them being being the regular expression based replacement:

1 Maven Regex Replacement using the [Maven Replacer Plugin][1]

2 Maven Antrun Plugin Have an ANT target to replace the commented html. For example:

<fileset id="html.fileset"
    dir="${build.dir}"
    includes="**/*.jsp, **/*.php, **/*.html"/>

<!-- HTML Comments -->
<replaceregexp replace="" flags="g"
    match="\&lt;![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\&gt;">
    <fileset refid="html.fileset"/>
</replaceregexp>

<!-- Empty lines -->
<replaceregexp match="^\s+[\r\n]" replace="" flags="mg">
    <fileset refid="html.fileset"/>
</replaceregexp>

Ant target Source: Link Invoke this target using the Maven-antrun-plugin.

Ashoka
  • 935
  • 7
  • 20
  • 3
    Beware of the problems html parsing using regex MAY give: http://stackoverflow.com/a/1732454/1542723 – Ferrybig Jan 15 '16 at 10:45