Part 1 - Add basic infra for 'add-meta-charset' option

This commit is contained in:
Marcos Caceres 2016-10-04 14:29:06 +11:00
parent 92a872251b
commit 169bd38adf
6 changed files with 31 additions and 0 deletions

View file

@ -172,6 +172,7 @@ typedef enum
TidySkipNested, /**< Skip nested tags in script and style CDATA */
TidyStrictTagsAttr, /**< Ensure tags and attributes match output HTML version */
TidyEscapeScripts, /**< Escape items that look like closing tags in script tags */
TidyMetaCharset, /**< Adds/checks/fixes meta charset in the head, based on document type */
N_TIDY_OPTIONS /**< Must be last */
} TidyOptionId;

View file

@ -324,6 +324,7 @@ static const TidyOptionImpl option_defs[] =
{ TidySkipNested, MU, "skip-nested", BL, yes, ParseBool, boolPicks }, /* 1642186 - Issue #65 */
{ TidyStrictTagsAttr, MU, "strict-tags-attributes", BL, no, ParseBool, boolPicks }, /* 20160209 - Issue #350 */
{ TidyEscapeScripts, PP, "escape-scripts", BL, yes, ParseBool, boolPicks }, /* 20160227 - Issue #348 */
{ TidyMetaCharset, MS, "add-meta-charset", BL, yes, ParseBool, boolPicks }, /* 20161004 - Issue #456 */
{ N_TIDY_OPTIONS, XX, NULL, XY, 0, NULL, NULL }
};

View file

@ -2080,6 +2080,18 @@ static languageDefinition language_en = { whichPluralForm_en, {
"This option causes items that look like closing tags, like <code>&lt;/g</code> to be escaped "
"to <code>&lt;\\/g</code>. Set this option to 'no' if you do not want this."
},
{/* Important notes for translators:
- Use only <code></code>, <var></var>, <em></em>, <strong></strong>, and
<br/>.
- Entities, tags, attributes, etc., should be enclosed in <code></code>.
- Option values should be enclosed in <var></var>.
- It's very important that <br/> be self-closing!
- The strings "Tidy" and "HTML Tidy" are the program name and must not
be translated. */
TidyMetaCharset, 0,
"This option adds a meta element and sets the charset attribute to the encoding of the document."
"Set this option to 'yes' if you want this."
},
/********************************************************
** Console Application

View file

@ -1674,6 +1674,16 @@ Node *TY_(FindBody)( TidyDocImpl* doc )
return node;
}
/* Check meta charset*/
Bool TY_(TidyMetaCharset)( TidyDocImpl* doc )
{
AttVal *attval;
Node *node;
Node *head = TY_(FindHEAD)( doc );
printf("hello");
return no;
}
/* add meta element for Tidy */
Bool TY_(AddGenerator)( TidyDocImpl* doc )
{

View file

@ -491,6 +491,9 @@ Node* TY_(FindXmlDecl)(TidyDocImpl* doc);
/* Returns containing block element, if any */
Node* TY_(FindContainer)( Node* node );
/* Adds meta element and sets the charset */
Bool TY_(TidyMetaCharset)( TidyDocImpl* doc );
/* add meta element for Tidy */
Bool TY_(AddGenerator)( TidyDocImpl* doc );

View file

@ -1795,6 +1795,7 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc )
Bool xhtmlOut = cfgBool( doc, TidyXhtmlOut );
Bool xmlDecl = cfgBool( doc, TidyXmlDecl );
Bool tidyMark = cfgBool( doc, TidyMark );
Bool tidyMetaCharset = cfgBool( doc, TidyMetaCharset);
Bool tidyXmlTags = cfgBool( doc, TidyXmlTags );
Bool wantNameAttr = cfgBool( doc, TidyAnchorAsName );
Bool mergeEmphasis = cfgBool( doc, TidyMergeEmphasis );
@ -1898,6 +1899,9 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc )
if (tidyMark )
TY_(AddGenerator)(doc);
if (tidyMetaCharset)
TY_(TidyMetaCharset)(doc);
}
/* ensure presence of initial <?xml version="1.0"?> */