Skip to content

Option for ignoring regex #482

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

Closed
FlorianUekermann opened this issue Jan 22, 2017 · 4 comments
Closed

Option for ignoring regex #482

FlorianUekermann opened this issue Jan 22, 2017 · 4 comments

Comments

@FlorianUekermann
Copy link

FlorianUekermann commented Jan 22, 2017

A common issue is that tidy is fundamentally incompatible with most template engines.
It would be convenient if tidy could treat strings that match a particular regular expression the same way it treats comments.

Alternatively just preventing the addition of completely new pairs of tags would go a long way.

Small example to illustrate a typical case where not adding new tags or ignoring {{[^}]+}} would help:

<ul>
{{range .Models}}
<li>{{.Name}}</li>
{{end}}
</ul>

should not change at all, but is at the moment replaced by

<ul>
<li style="list-style: none">{{range .Models}}</li>
<li>{{.Name}}</li>
<li style="list-style: none">{{end}}</li>
</ul>
@geoffmcl
Copy link
Contributor

@MaVo159 thanks for the issue.

What version of tidy are you using? With your input, and --show-body-only yes --show-info no I get, with current tidy 5.3.14 -

No warnings or errors were found.

Info: Document content looks like HTML5
<ul>{{range .Models}}
<li>{{.Name}}</li>
{{end}}</ul>

Yes, there has been some re-lining of the code, but no additional <li style="list-style: none"> added?

There has been some previous discussion on something like this... see #282, #310, #396, #447, and maybe others...

Look forward to further comments... thanks...

@geoffmcl geoffmcl added this to the 5.3 milestone Jan 29, 2017
@FlorianUekermann
Copy link
Author

Thanks. Nice to see that this particular case is not an issue anymore. I am using 5.2.0. (debian testing)
I'll leave this open since I think the proposal may still have merit. Even if you keep fixing issues like this for new templating engines, many users are years behind the current development version, so offering a general solution may be worthwhile.

I think this is all I can contribute to the discussion, since I don't know the project very well. Feel free to close.

@balthisar
Copy link
Member

Closed by request of @MaVo159.

@lyda
Copy link

lyda commented Dec 22, 2017

This is still an issue I think. This snippet generates two warnings:

  1. On the {{range .}} line: plain text isn't allowed in <tr> elements
  2. On the <img line: <img> attribute "width" has invalid value "{{.ThumbX}}"

A regex to ignore these would just be {{[^}]*}} which would get most of the template cruft and allow the remaining html to be sanity checked.

<table summary="Stuff">
  <tr>
  {{range .}}
    <td valign="top">
      <img src="{{.Thumb}}" height="{{.ThumbY}}" width="{{.ThumbX}}" alt="{{.Alt}}">
    </td>
  {{end}}
  </tr>
</table>

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

No branches or pull requests

4 participants