diff --git a/src/lexer.c b/src/lexer.c index 664f806..7020006 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1055,9 +1055,17 @@ static void ParseEntity( TidyDocImpl* doc, GetTokenMode mode ) if (semicolon) TY_(AddCharToLexer)( lexer, ';' ); } - else /* naked & */ - TY_(ReportEntityError)( doc, UNESCAPED_AMPERSAND, + else + { + /*\ + * Issue #207 - A naked & is allowed in HTML5, as an unambiguous ampersand! + \*/ + if (TY_(HTMLVersion)(doc) != HT50) + { + TY_(ReportEntityError)( doc, UNESCAPED_AMPERSAND, lexer->lexbuf+start, ch ); + } + } } else { diff --git a/src/pprint.c b/src/pprint.c index 6a50b7b..7294d04 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -982,6 +982,14 @@ static void PPrintText( TidyDocImpl* doc, uint mode, uint indent, ixWS = TextStartsWithWhitespace( doc->lexer, node, ix+1, mode ); ix = IncrWS( ix, end, indent, ixWS ); } + else if (( c == '&' ) && (TY_(HTMLVersion)(doc) == HT50) && + (((ix + 1) == end) || ((ix + 1) < end) && (isspace(doc->lexer->lexbuf[ix+1]))) ) + { + /*\ + * Issue #207 - This is an unambiguous ampersand need not be 'quoted' in HTML5 + \*/ + PPrintChar( doc, c, (mode | CDATA) ); + } else { PPrintChar( doc, c, mode );