Open sirex opened 9 years ago
This issue is related to https://github.com/deezer/html-linter/issues/6
Currently it is being done in that way, so line numbers and positions remain the same. Or otherwise the error reported by html-linter won't be easy to find. In your first example the line number reported would be wrong and in the second, the column would be wrong.
Do you have any ideas on how we could address this, retaining the same line numbers and columns?
OK, now I understand why cleaner is implemented that way.
One possible solution that comes to my mind is that template cleaner could provide line and column transformation table.
For example, having following input:
{% if true %}
<p>{% if false %}2{% endif %}</p>
{% endif %}
template cleaner provides this output:
<p>2</p>
and also emits following transformation table:
table = {
1: (2, {
1: 1, # <
2: 2, # p
3: 3, # >
4: 18, # 2 -> {% if false %}2
5: 30, # < -> {% endif %}<
6: 31, # /
7: 32, # p
8: 33, # >
}),
}
Then, when someone would need to get original position for example of first line and forth column (transform(table, 1, 4)
) from output, he could do this:
def transform(table, line, column)
line, cols = table[line]
return line, cols[column]
# transform(table, 1, 4) -> (2, 18)
The only question is how difficult it is to generate such transformation table?
Current Jinja cleaner implementation is not very smart, it just replaces all tamplate tags to speces.
But I thing it should be smarter and detect places where tags should be completely removed and where replaced to something.
My suggestions:
Remove whole line if tag takes whole line.
For example this:
Should output:
Remove inline tags completely.
For example this:
Should be replaced to this:
But of course, this should depend on tag, for example,
{% trans "" %}
should always be replace to some content.What do you think?