From 3c721d8bf871b1a930727191187a103f9d3497c9 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Sun, 1 Feb 2015 21:16:17 +0800 Subject: [PATCH] #72, avoid showing some warnings when show-body-only. --- src/parser.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/parser.c b/src/parser.c index 8cca87c..439beeb 100644 --- a/src/parser.c +++ b/src/parser.c @@ -4319,6 +4319,29 @@ static void AttributeChecks(TidyDocImpl* doc, Node* node) } } +/* + Need to know to avoid error-reporting + */ +Bool showingBodyOnly( TidyDocImpl* doc) +{ + Node* node; + + TidyTriState bodyOnly = doc->config.value[TidyBodyOnly].v; + + switch( bodyOnly ) + { + case TidyNoState: + return no; + case TidyYesState: + return yes; + default: + node = TY_(FindBody)( doc ); + if (node && node->implicit ) + return yes; + } + return yes; +} + /* HTML is the top level element */ @@ -4414,7 +4437,8 @@ void TY_(ParseDocument)(TidyDocImpl* doc) else html = node; - if (!TY_(FindDocType)(doc)) + /* #72, avoid MISSING_DOCTYPE if show-body-only. */ + if (!TY_(FindDocType)(doc) && !showingBodyOnly(doc)) TY_(ReportError)(doc, NULL, NULL, MISSING_DOCTYPE); TY_(InsertNodeAtEnd)( &doc->root, html); @@ -4439,7 +4463,11 @@ void TY_(ParseDocument)(TidyDocImpl* doc) if (!TY_(FindTITLE)(doc)) { Node* head = TY_(FindHEAD)(doc); - TY_(ReportError)(doc, head, NULL, MISSING_TITLE_ELEMENT); + /* #72, avoid MISSING_TITLE_ELEMENT if show-body-only (but allow InsertNodeAtEnd to avoid new warning) */ + if (!showingBodyOnly(doc)) + { + TY_(ReportError)(doc, head, NULL, MISSING_TITLE_ELEMENT); + } TY_(InsertNodeAtEnd)(head, TY_(InferredTag)(doc, TidyTag_TITLE)); } @@ -4625,6 +4653,7 @@ void TY_(ParseXMLDocument)(TidyDocImpl* doc) TY_(FixXmlDecl)( doc ); } + /* * local variables: * mode: c