Skip to content

Commit 949ad9d

Browse files
authored
Merge pull request htacg#998 from htacg/issue_523
Fixes htacg#523.
2 parents a873a19 + b5d28d7 commit 949ad9d

File tree

6 files changed

+102
-1
lines changed

6 files changed

+102
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Config for test case.
2+
tidy-mark: no
3+
indent: no
4+
wrap: 99999
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
This test case is for issue #523, in which a space is placed after the
3+
closing tag of certain elements. For example below, a space is added after
4+
the first script closing tag and after the img tag.
5+
-->
6+
<!DOCTYPE html>
7+
<html>
8+
<head>
9+
<title>test</title>
10+
</head>
11+
<body>
12+
<script type="text/javascript">
13+
</script>
14+
<script type="text/javascript">
15+
</script>
16+
<h1>Hello</h1>
17+
<script type="text/javascript">
18+
</script>
19+
<img src="hi.jpg">
20+
<script type="text/javascript">
21+
</script>
22+
<p>This is a block level element, and as such, is capable of inlining inline elements.<script type="text/javascript">let x = "Hello, world"</script> Scripts are inline elements, so this script should be included in the flow.</p>
23+
<script type="text/javascript"></script><img src="bye.jpg"><script type="text/javascript"></script>
24+
<hr>
25+
<p>This is another paragraph with an <img src="meh.jpg"> tag inline.</p>
26+
<img src="one.jpg"><img src="two.jpg"><img src="three.jpg">
27+
</body>
28+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!--
2+
This test case is for issue #523, in which a space is placed after the
3+
closing tag of certain elements. For example below, a space is added after
4+
the first script closing tag and after the img tag.
5+
-->
6+
<!DOCTYPE html>
7+
<html>
8+
<head>
9+
<title>test</title>
10+
</head>
11+
<body>
12+
<script type="text/javascript"></script>
13+
<script type="text/javascript"></script>
14+
<h1>Hello</h1>
15+
<script type="text/javascript"></script><img src="hi.jpg">
16+
<script type="text/javascript"></script>
17+
<p>This is a block level element, and as such, is capable of inlining inline elements.
18+
<script type="text/javascript">
19+
let x = "Hello, world"
20+
</script> Scripts are inline elements, so this script should be included in the flow.</p>
21+
<script type="text/javascript"></script><img src="bye.jpg">
22+
<script type="text/javascript"></script>
23+
<hr>
24+
<p>This is another paragraph with an <img src="meh.jpg"> tag inline.</p>
25+
<img src="one.jpg"><img src="two.jpg"><img src="three.jpg">
26+
</body>
27+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
line 19 column 1 - Warning: <img> lacks "alt" attribute
2+
line 23 column 41 - Warning: <img> lacks "alt" attribute
3+
line 25 column 38 - Warning: <img> lacks "alt" attribute
4+
line 26 column 1 - Warning: <img> lacks "alt" attribute
5+
line 26 column 20 - Warning: <img> lacks "alt" attribute
6+
line 26 column 39 - Warning: <img> lacks "alt" attribute
7+
Info: Document content looks like HTML5
8+
Tidy found 6 warnings and 0 errors!
9+
10+
The alt attribute should be used to give a short description
11+
of an image; longer descriptions should be given with the
12+
longdesc attribute which takes a URL linked to the description.
13+
These measures are needed for people using non-graphical browsers.
14+
15+
For further advice on how to make your pages accessible
16+
see https://www.w3.org/WAI/GL.
17+
About HTML Tidy: https://github.com/htacg/tidy-html5
18+
Bug reports and comments: https://github.com/htacg/tidy-html5/issues
19+
Official mailing list: https://lists.w3.org/Archives/Public/public-htacg/
20+
Latest HTML specification: https://html.spec.whatwg.org/multipage/
21+
Validate your HTML documents: https://validator.w3.org/nu/
22+
Lobby your company to join the W3C: https://www.w3.org/Consortium
23+
24+
Do you speak a language other than English, or a different variant of
25+
English? Consider helping us to localize HTML Tidy. For details please see
26+
https://github.com/htacg/tidy-html5/blob/master/README/LOCALIZE.md

regression_testing/cases/legacy-expects/case-443678.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</style>
1919
</head>
2020
<body>
21-
Just a test.
21+
Just a test.
2222
<script>
2323

2424
test();

src/parser.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ static Bool CleanLeadingWhitespace(TidyDocImpl* ARG_UNUSED(doc), Node* node)
413413

414414
if (node->parent->tag && node->parent->tag->parser == TY_(ParseScript))
415415
return no;
416+
417+
/* #523, prevent blank spaces after script if the next item is script.
418+
* This is actually more generalized as, if the preceding element is
419+
* a body level script, then indicate that we want to clean leading
420+
* whitespace.
421+
*/
422+
if ( node->prev && nodeIsSCRIPT(node->prev) && nodeIsBODY(node->prev->parent) )
423+
return yes;
416424

417425
/* <p>...<br> <em>...</em>...</p> */
418426
if (nodeIsBR(node->prev))
@@ -454,6 +462,14 @@ static Bool CleanTrailingWhitespace(TidyDocImpl* doc, Node* node)
454462
if (node->parent->tag && node->parent->tag->parser == TY_(ParseScript))
455463
return no;
456464

465+
/* #523, prevent blank spaces after script if the next item is script.
466+
* This is actually more generalized as, if the next element is
467+
* a body level script, then indicate that we want to clean trailing
468+
* whitespace.
469+
*/
470+
if ( node->next && nodeIsSCRIPT(node->next) && nodeIsBODY(node->next->parent) )
471+
return yes;
472+
457473
next = node->next;
458474

459475
/* <p>... </p> */

0 commit comments

Comments
 (0)