Skip to content

Commit

Permalink
1.3.4dev: fix JinjaChecker
Browse files Browse the repository at this point in the history
 - add a few jinjacheck: "..." OK hints
 - ignore some XHTML errors completely (as they correspond to valid HTML5)

Refs #12677.


git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@16861 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
cboos committed Jan 7, 2019
1 parent c8a0869 commit bf5f785
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
30 changes: 21 additions & 9 deletions contrib/jinjachecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ def print_statement(filename, s, warn=None, quiet=False):
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" \
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'''

IGNORED_XHTML_ERRORS = [
('Element style does not carry attribute type',
'<style> without "type" attribute'),
('Element script does not carry attribute type',
'<script> without "type" attribute'),
]


def check_html(filename, html_lines, html_hints, quiet):
"""Validates the given HTML (as XHTML actually)
Expand Down Expand Up @@ -363,16 +370,21 @@ def check_html(filename, html_lines, html_hints, quiet):
errors.append((entry.line, entry.column, entry.message))
real_errors = []
def process_error(linenum, col, msg):
hint_linenum = hint = None
while html_hints:
hint_linenum, hint = html_hints[0]
if hint_linenum >= linenum or len(html_hints) == 1:
hint_linenum = hint = ignored = None
for e, comment in IGNORED_XHTML_ERRORS:
if e == msg:
ignored = ' (IGNORED "%s")' % comment
break
del html_hints[0]
if hint and hint in msg:
del html_hints[0]
ignored = ' (IGNORED "%s")' % hint
else:
if not ignored:
while html_hints:
hint_linenum, hint = html_hints[0]
if hint_linenum >= linenum or len(html_hints) == 1:
break
del html_hints[0]
if hint and hint in msg:
del html_hints[0]
ignored = ' (IGNORED "%s")' % hint
if not ignored:
real_errors.append(linenum)
ignored = ''
print('%s:%s:%s: %s%s' % (filename, linenum, col, msg, ignored))
Expand Down
5 changes: 3 additions & 2 deletions trac/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<noscript>
<style>
.trac-noscript { display: none !important }
</style>
</style> {# jinjacheck: "got (style )" OK #}
</noscript>
# if trac_error_rendering is undefined and 'SEARCH_VIEW' in perm:
<link type="application/opensearchdescription+xml" rel="search"
Expand Down Expand Up @@ -100,6 +100,7 @@
<!-- end of site_head.html -->
<!-- # endblock head (content inherited from layout.html) -->
# endblock head
## jinjacheck: "got (title meta meta meta link noscript link script script script )" OK
</head>

<body>
Expand Down Expand Up @@ -144,7 +145,7 @@
# endif
# for script in chrome.late_scripts:
${script.prefix}<script>
jQuery.loadScript("${script.href}", "${script.type}", "${script.charset}");
jQuery.loadScript("${script.attrs.src}", "${script.attrs.type}");
</script>${script.suffix}
# endfor

Expand Down
4 changes: 2 additions & 2 deletions trac/templates/theme.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#}
## This is Trac's default theme
<!DOCTYPE html>
<html lang="${trac_lang}">
<html lang="${trac_lang}"> {# jinjacheck: "attribute lang" OK #}
<head>
<!-- # block head (placeholder in theme.html) -->
# block head
Expand Down Expand Up @@ -166,5 +166,5 @@ <h2>${_("Context Navigation")}</h2>
<!-- end of site_footer.html -->
<!-- # endblock body (content inherited from theme.html) -->
# endblock body
</body>
</body> {# jinjacheck: "got (html)" OK #}
</html>

0 comments on commit bf5f785

Please sign in to comment.