Skip to content

Commit

Permalink
New merge-emphasis & coerce-endtags options added.
Browse files Browse the repository at this point in the history
Fixes #19.
  • Loading branch information
sideshowbarker committed Mar 17, 2012
1 parent 3ed33a1 commit 1052c2b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/tidyenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ typedef enum
TidyQuiet, /**< No 'Parsing X', guessed DTD or summary */
TidyIndentContent, /**< Indent content of appropriate tags */
/**< "auto" does text/block level content indentation */
TidyCoerceEndTags, /**< Coerce end tags from start tags where probably intended */
TidyHideEndTags, /**< Suppress optional end tags */
TidyXmlTags, /**< Treat input as XML */
TidyXmlOut, /**< Create output as XML */
Expand Down Expand Up @@ -199,6 +200,7 @@ typedef enum
#else
TidyPunctWrapNotUsed,
#endif
TidyMergeEmphasis, /**< Merge nested B and I elements */
TidyMergeDivs, /**< Merge multiple DIVs */
TidyDecorateInferredUL, /**< Mark inferred UL elements with no indent CSS */
TidyPreserveEntities, /**< Preserve entities */
Expand Down
50 changes: 49 additions & 1 deletion quickref.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<h1 id="top">Quick Reference</h1>
<h2>HTML Tidy Configuration Options</h2>
<p>Version: <a href="https://github.com/w3c/tidy-html5/tree/5c4d2e5">https://github.com/w3c/tidy-html5/tree/5c4d2e5</a></p>
<p>Version: <a href="https://github.com/w3c/tidy-html5/tree/3a9a794">https://github.com/w3c/tidy-html5/tree/3a9a794</a></p>
<p>
<a class="h3" href="#MarkupHeader">HTML, XHTML, XML</a>
<br />
Expand Down Expand Up @@ -88,6 +88,13 @@ <h2>HTML Tidy Configuration Options</h2>
<td>Boolean</td>
<td>no</td>
</tr>
<tr>
<td>
<a href="#coerce-endtags">coerce-endtags</a>
</td>
<td>Boolean</td>
<td>yes</td>
</tr>
<tr>
<td>
<a href="#css-prefix">css-prefix</a>
Expand Down Expand Up @@ -251,6 +258,13 @@ <h2>HTML Tidy Configuration Options</h2>
<td>AutoBool</td>
<td>auto</td>
</tr>
<tr>
<td>
<a href="#merge-emphasis">merge-emphasis</a>
</td>
<td>Boolean</td>
<td>yes</td>
</tr>
<tr>
<td>
<a href="#merge-spans">merge-spans</a>
Expand Down Expand Up @@ -866,6 +880,23 @@ <h2>HTML Tidy Configuration Options</h2>
<tr>
<td>&#160;</td>
</tr>
<tr>
<td class="tabletitle" valign="top" id="coerce-endtags">coerce-endtags</td>
<td class="tabletitlelink" valign="top" align="right">
<a href="#top">Top</a>
</td>
</tr>
<tr>
<td valign="top">Type: <strong>Boolean</strong><br />
Default: <strong>yes</strong><br />Example: <strong>y/n, yes/no, t/f, true/false, 1/0</strong></td>
<td align="right" valign="top"></td>
</tr>
<tr>
<td colspan="2">This option specifies if Tidy should coerce a start tag into an end tag in cases where it looks like an end tag was probably intended; for example, given &lt;span&gt;foo &lt;b&gt;bar&lt;b&gt; baz&lt;/span&gt;, Tidy will output &lt;span&gt;foo &lt;b&gt;bar&lt;/b&gt; baz&lt;/span&gt;. </td>
</tr>
<tr>
<td>&#160;</td>
</tr>
<tr>
<td class="tabletitle" valign="top" id="css-prefix">css-prefix</td>
<td class="tabletitlelink" valign="top" align="right">
Expand Down Expand Up @@ -1271,6 +1302,23 @@ <h2>HTML Tidy Configuration Options</h2>
<tr>
<td>&#160;</td>
</tr>
<tr>
<td class="tabletitle" valign="top" id="merge-emphasis">merge-emphasis</td>
<td class="tabletitlelink" valign="top" align="right">
<a href="#top">Top</a>
</td>
</tr>
<tr>
<td valign="top">Type: <strong>Boolean</strong><br />
Default: <strong>yes</strong><br />Example: <strong>y/n, yes/no, t/f, true/false, 1/0</strong></td>
<td align="right" valign="top"></td>
</tr>
<tr>
<td colspan="2">This option specifies if Tidy should merge nested &lt;b&gt; and &lt;i&gt; elements; for example, for the case &lt;b class="rtop-2"&gt;foo &lt;b class="r2-2"&gt;bar&lt;/b&gt; baz&lt;/b&gt;, Tidy will output &lt;b class="rtop-2"&gt;foo bar baz&lt;/b&gt;. Note that if you set this option to "no" Tidy will by default still attempt to correct some cases of nested &lt;b&gt; and &lt;i&gt; elements; for example, given &lt;span&gt;foo &lt;b&gt;bar &lt;b&gt;baz&lt;/b&gt;&lt;/b&gt; &lt;/span&gt;, Tidy will output &lt;span&gt;foo &lt;b&gt;bar baz&lt;/b&gt;&lt;/span&gt;. To suppress that behavior, set the coerce-endtags option to "no". </td>
</tr>
<tr>
<td>&#160;</td>
</tr>
<tr>
<td class="tabletitle" valign="top" id="merge-spans">merge-spans</td>
<td class="tabletitlelink" valign="top" align="right">
Expand Down
2 changes: 2 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ static const TidyOptionImpl option_defs[] =
{ TidyShowWarnings, DG, "show-warnings", BL, yes, ParseBool, boolPicks },
{ TidyQuiet, MS, "quiet", BL, no, ParseBool, boolPicks },
{ TidyIndentContent, PP, "indent", IN, TidyNoState, ParseAutoBool, autoBoolPicks },
{ TidyCoerceEndTags, MU, "coerce-endtags", BL, yes, ParseBool, boolPicks },
{ TidyHideEndTags, MU, "hide-endtags", BL, no, ParseBool, boolPicks },
{ TidyXmlTags, MU, "input-xml", BL, no, ParseBool, boolPicks },
{ TidyXmlOut, MU, "output-xml", BL, no, ParseBool, boolPicks },
Expand Down Expand Up @@ -311,6 +312,7 @@ static const TidyOptionImpl option_defs[] =
#if SUPPORT_ASIAN_ENCODINGS
{ TidyPunctWrap, PP, "punctuation-wrap", BL, no, ParseBool, boolPicks },
#endif
{ TidyMergeEmphasis, MU, "merge-emphasis", BL, yes, ParseBool, boolPicks },
{ TidyMergeDivs, MU, "merge-divs", IN, TidyAutoState, ParseAutoBool, autoBoolPicks },
{ TidyDecorateInferredUL, MU, "decorate-inferred-ul", BL, no, ParseBool, boolPicks },
{ TidyPreserveEntities, MU, "preserve-entities", BL, no, ParseBool, boolPicks },
Expand Down
18 changes: 18 additions & 0 deletions src/localize.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ static const TidyOptionDoc option_docs[] =
{TidyHideComments,
"This option specifies if Tidy should print out comments. "
},
{TidyCoerceEndTags,
"This option specifies if Tidy should coerce a start tag into an end tag "
"in cases where it looks like an end tag was probably intended; "
"for example, given &lt;span&gt;foo &lt;b&gt;bar&lt;b&gt; baz&lt;/span&gt;, "
"Tidy will output &lt;span&gt;foo &lt;b&gt;bar&lt;/b&gt; baz&lt;/span&gt;. "
},
{TidyHideEndTags,
"This option specifies if Tidy should omit optional end-tags when "
"generating the pretty printed markup. This option is ignored if you are "
Expand Down Expand Up @@ -504,6 +510,18 @@ static const TidyOptionDoc option_docs[] =
"that takes a list of predefined values to lower case. This is required "
"for XHTML documents. "
},
{TidyMergeEmphasis,
"This option specifies if Tidy should merge nested &lt;b&gt; and &lt;i&gt; "
"elements; for example, for the case "
"&lt;b class=\"rtop-2\"&gt;foo &lt;b class=\"r2-2\"&gt;bar&lt;/b&gt; baz&lt;/b&gt;, "
"Tidy will output &lt;b class=\"rtop-2\"&gt;foo bar baz&lt;/b&gt;. "
"Note that if you set this option to \"no\" Tidy will by default still "
"attempt to correct some cases of nested &lt;b&gt; and &lt;i&gt; elements; "
"for example, given "
"&lt;span&gt;foo &lt;b&gt;bar &lt;b&gt;baz&lt;/b&gt;&lt;/b&gt; &lt;/span&gt;, "
"Tidy will output &lt;span&gt;foo &lt;b&gt;bar baz&lt;/b&gt;&lt;/span&gt;. "
"To suppress that behavior, set the coerce-endtags option to \"no\". "
},
{TidyMergeDivs,
"Can be used to modify behavior of -c (--clean yes) option. "
"This option specifies if Tidy should merge nested &lt;div&gt; such as "
Expand Down
7 changes: 5 additions & 2 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,7 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode )
&& !nodeIsSUP(node)
&& !nodeIsQ(node)
&& !nodeIsSPAN(node)
&& cfgBool(doc, TidyCoerceEndTags)
)
{
/* proceeds only if "node" does not have any attribute and
Expand Down Expand Up @@ -1617,7 +1618,8 @@ void TY_(ParseInline)( TidyDocImpl* doc, Node *element, GetTokenMode mode )
/* #427827 - fix by Randy Waki and Bjoern Hoehrmann 23 Aug 00 */
/* other fixes by Dave Raggett */
/* if (node->attributes == NULL) */
if (node->type != EndTag && node->attributes == NULL)
if (node->type != EndTag && node->attributes == NULL
&& cfgBool(doc, TidyCoerceEndTags) )
{
node->type = EndTag;
TY_(ReportError)(doc, element, node, COERCE_TO_ENDTAG);
Expand Down Expand Up @@ -3022,7 +3024,8 @@ void TY_(ParseTitle)(TidyDocImpl* doc, Node *title, GetTokenMode ARG_UNUSED(mode
Node *node;
while ((node = TY_(GetToken)(doc, MixedContent)) != NULL)
{
if (node->tag == title->tag && node->type == StartTag)
if (node->tag == title->tag && node->type == StartTag
&& cfgBool(doc, TidyCoerceEndTags) )
{
TY_(ReportError)(doc, title, node, COERCE_TO_ENDTAG);
node->type = EndTag;
Expand Down
4 changes: 3 additions & 1 deletion src/tidylib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1246,13 +1246,15 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc )
Bool tidyMark = cfgBool( doc, TidyMark );
Bool tidyXmlTags = cfgBool( doc, TidyXmlTags );
Bool wantNameAttr = cfgBool( doc, TidyAnchorAsName );
Bool mergeEmphasis = cfgBool( doc, TidyMergeEmphasis );
Node* node;

if (tidyXmlTags)
return tidyDocStatus( doc );

/* simplifies <b><b> ... </b> ...</b> etc. */
TY_(NestedEmphasis)( doc, &doc->root );
if ( mergeEmphasis )
TY_(NestedEmphasis)( doc, &doc->root );

/* cleans up <dir>indented text</dir> etc. */
TY_(List2BQ)( doc, &doc->root );
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
static const char TY_(release_date)[] = "https://github.com/w3c/tidy-html5/tree/3a9a794";
static const char TY_(release_date)[] = "https://github.com/w3c/tidy-html5/tree/3ed33a1";

0 comments on commit 1052c2b

Please sign in to comment.