1717#include "tmbstr.h"
1818#include "utf8.h"
1919
20+ /* *** FOR DEBUG ONLY *** */
21+ #if !defined(NDEBUG ) && defined(_MSC_VER )
22+ /* #define DEBUG_PPRINT */
23+ /* #define DEBUG_INDENT */
24+ #ifdef DEBUG_PPRINT
25+ extern void dbg_show_node ( TidyDocImpl * doc , Node * node , int caller , int indent );
26+ #endif
27+ #ifdef DEBUG_INDENT
28+ #include "sprtf.h"
29+ #endif
30+ #endif
31+
2032/*
2133 Block-level and unknown elements are printed on
2234 new lines and their contents indented 2 spaces
@@ -640,7 +652,12 @@ static Bool CheckWrapIndent( TidyDocImpl* doc, uint indent )
640652 {
641653 WrapLine ( doc );
642654 if ( pprint -> indent [ 0 ].spaces < 0 )
655+ {
656+ #if !defined(NDEBUG ) && defined(_MSC_VER ) && defined(DEBUG_INDENT )
657+ SPRTF ("%s Indent from %d to %d\n" , __FUNCTION__ , pprint -> indent [ 0 ].spaces , indent );
658+ #endif
643659 pprint -> indent [ 0 ].spaces = indent ;
660+ }
644661 return yes ;
645662 }
646663 return no ;
@@ -705,7 +722,14 @@ void TY_(PFlushLine)( TidyDocImpl* doc, uint indent )
705722
706723 TY_ (WriteChar )( '\n' , doc -> docOut );
707724 pprint -> line ++ ;
708- pprint -> indent [ 0 ].spaces = indent ;
725+
726+ if (pprint -> indent [ 0 ].spaces != (int )indent )
727+ {
728+ #if !defined(NDEBUG ) && defined(_MSC_VER ) && defined(DEBUG_INDENT )
729+ SPRTF ("%s Indent from %d to %d\n" , __FUNCTION__ , pprint -> indent [ 0 ].spaces , indent );
730+ #endif
731+ pprint -> indent [ 0 ].spaces = indent ;
732+ }
709733}
710734
711735static void PCondFlushLine ( TidyDocImpl * doc , uint indent )
@@ -718,6 +742,14 @@ static void PCondFlushLine( TidyDocImpl* doc, uint indent )
718742
719743 TY_ (WriteChar )( '\n' , doc -> docOut );
720744 pprint -> line ++ ;
745+ }
746+
747+ /* Issue #390 - Whether chars to flush or not, set new indent */
748+ if ( pprint -> indent [ 0 ].spaces != (int )indent )
749+ {
750+ #if !defined(NDEBUG ) && defined(_MSC_VER ) && defined(DEBUG_INDENT )
751+ SPRTF ("%s Indent from %d to %d\n" , __FUNCTION__ , pprint -> indent [ 0 ].spaces , indent );
752+ #endif
721753 pprint -> indent [ 0 ].spaces = indent ;
722754 }
723755}
@@ -741,7 +773,13 @@ void TY_(PFlushLineSmart)( TidyDocImpl* doc, uint indent )
741773 pprint -> line ++ ;
742774 }
743775
744- pprint -> indent [ 0 ].spaces = indent ;
776+ if ( pprint -> indent [ 0 ].spaces != (int )indent )
777+ {
778+ #if !defined(NDEBUG ) && defined(_MSC_VER ) && defined(DEBUG_INDENT )
779+ SPRTF ("%s Indent from %d to %d\n" , __FUNCTION__ , pprint -> indent [ 0 ].spaces , indent );
780+ #endif
781+ pprint -> indent [ 0 ].spaces = indent ;
782+ }
745783}
746784
747785static void PCondFlushLineSmart ( TidyDocImpl * doc , uint indent )
@@ -757,8 +795,20 @@ static void PCondFlushLineSmart( TidyDocImpl* doc, uint indent )
757795 TY_ (WriteChar )( '\n' , doc -> docOut );
758796 pprint -> line ++ ;
759797 }
798+ }
760799
761- pprint -> indent [ 0 ].spaces = indent ;
800+ /*\
801+ * Issue #390 - Must still deal with fixing indent!
802+ * If TidyHideEndTags or TidyOmitOptionalTags, then
803+ * in certain circumstance no PrintEndTag will be done,
804+ * so linelen will be 0...
805+ \*/
806+ if (pprint -> indent [ 0 ].spaces != (int )indent )
807+ {
808+ #if !defined(NDEBUG ) && defined(_MSC_VER ) && defined(DEBUG_INDENT )
809+ SPRTF ("%s Indent from %d to %d\n" , __FUNCTION__ , pprint -> indent [ 0 ].spaces , indent );
810+ #endif
811+ pprint -> indent [ 0 ].spaces = indent ;
762812 }
763813}
764814
@@ -2026,6 +2076,9 @@ void PPrintScriptStyle( TidyDocImpl* doc, uint mode, uint indent, Node *node )
20262076
20272077 if ( node -> content && pprint -> indent [ 0 ].spaces != (int )indent )
20282078 {
2079+ #if !defined(NDEBUG ) && defined(_MSC_VER ) && defined(DEBUG_INDENT )
2080+ SPRTF ("%s Indent from %d to %d\n" , __FUNCTION__ , pprint -> indent [ 0 ].spaces , indent );
2081+ #endif
20292082 pprint -> indent [ 0 ].spaces = indent ;
20302083 }
20312084 PPrintEndTag ( doc , mode , indent , node );
@@ -2131,6 +2184,10 @@ void TY_(PPrintTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node )
21312184 doc -> progressCallback ( tidyImplToDoc (doc ), node -> line , node -> column , doc -> pprint .line + 1 );
21322185 }
21332186
2187+ #if !defined(NDEBUG ) && defined(_MSC_VER ) && defined(DEBUG_PPRINT )
2188+ dbg_show_node ( doc , node , 4 , GetSpaces ( & doc -> pprint ) );
2189+ #endif
2190+
21342191 if (node -> type == TextNode )
21352192 {
21362193 PPrintText ( doc , mode , indent , node );
@@ -2379,6 +2436,18 @@ void TY_(PPrintTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node )
23792436 TY_ (PFlushLineSmart )( doc , indent );
23802437 PPrintEndTag ( doc , mode , indent , node );
23812438 }
2439+ else if (hideend )
2440+ {
2441+ /* Issue #390 - must still deal with adjusting indent */
2442+ TidyPrintImpl * pprint = & doc -> pprint ;
2443+ if (pprint -> indent [ 0 ].spaces != (int )indent )
2444+ {
2445+ #if !defined(NDEBUG ) && defined(_MSC_VER ) && defined(DEBUG_INDENT )
2446+ SPRTF ("%s Indent from %d to %d\n" , __FUNCTION__ , pprint -> indent [ 0 ].spaces , indent );
2447+ #endif
2448+ pprint -> indent [ 0 ].spaces = indent ;
2449+ }
2450+ }
23822451 }
23832452
23842453 if (!indcont && !hideend && !nodeIsHTML (node ) && !classic )
0 commit comments