From 1ac50fccb3838b094732f11fc1a211dc719cd284 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Wed, 8 Feb 2017 13:53:37 -0500 Subject: [PATCH] Pretty up output of empty script tags. - No longer break script tags up on two lines if there is content. However output is still subject to the `--wrap` behavior. - Previous behavior intact if there is content. Todo. - Associate this with a new Tidy option. --- src/pprint.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pprint.c b/src/pprint.c index a4f2aef..110cfbe 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -2000,7 +2000,11 @@ void PPrintScriptStyle( TidyDocImpl* doc, uint mode, uint indent, Node *node ) PPrintTag( doc, mode, indent, node ); - TY_(PFlushLineSmart)(doc, indent); + /* SCRIPT may have no content such as when loading code via its SRC attribute. + In this case we don't want to flush the line, preferring to keep the required + closing SCRIPT tag on the same line. */ + if ( node->content != NULL ) + TY_(PFlushLineSmart)(doc, indent); if ( xhtmlOut && node->content != NULL ) { @@ -2053,7 +2057,9 @@ void PPrintScriptStyle( TidyDocImpl* doc, uint mode, uint indent, Node *node ) contentIndent = TextEndsWithNewline( doc->lexer, content, CDATA ); } - if ( contentIndent < 0 ) + /* Only flush the line if these was content present so that the closing + SCRIPT tag will stay on the same line. */ + if ( contentIndent < 0 && node->content != NULL ) { PCondFlushLineSmart( doc, indent ); contentIndent = 0;