Skip to content

Issue 365 #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/tidyenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,16 @@ typedef enum
TidySortAttrAlpha /**< Sort attributes alphabetically */
} TidyAttrSortStrategy;

/** Mode controlling capitalization of things, such as attributes.
** @remark This enum's starting value is guaranteed to remain stable.
*/
typedef enum
{
TidyUppercaseNo = 0, /**< Don't uppercase. */
TidyUppercaseYes, /**< Do uppercase. */
TidyUppercasePreserve /**< Preserve case. */
} TidyUppercase;


/** @}
** @name Document Tree
Expand Down
6 changes: 3 additions & 3 deletions src/attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,15 +824,15 @@ static const Attribute* attrsLookup(TidyDocImpl* doc,

#if ATTRIBUTE_HASH_LOOKUP
for (p = attribs->hashtab[attrsHash(atnam)]; p && p->attr; p = p->next)
if (TY_(tmbstrcmp)(atnam, p->attr->name) == 0)
if (TY_(tmbstrcasecmp)(atnam, p->attr->name) == 0)
return p->attr;

for (np = attribute_defs; np && np->name; ++np)
if (TY_(tmbstrcmp)(atnam, np->name) == 0)
if (TY_(tmbstrcasecmp)(atnam, np->name) == 0)
return attrsInstall(doc, attribs, np);
#else
for (np = attribute_defs; np && np->name; ++np)
if (TY_(tmbstrcmp)(atnam, np->name) == 0)
if (TY_(tmbstrcasecmp)(atnam, np->name) == 0)
return np;
#endif

Expand Down
204 changes: 106 additions & 98 deletions src/config.c

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -1202,8 +1202,12 @@ static languageDefinition language_en = { whichPluralForm_en, {
"This option specifies if Tidy should output attribute names in upper "
"case. "
"<br/>"
"The default is <var>no</var>, which results in lower case attribute "
"names, except for XML input, where the original case is preserved. "
"When set to <var>no</var>, attribute names will be written in lower "
"case. Specifying <var>yes</var> will output attribute names in upper "
"case, and <var>preserve</var> can used to leave attribute names "
"untouched. "
"<br/>"
"When using XML input, the original case is always preserved. "
},
{/* Important notes for translators:
- Use only <code></code>, <var></var>, <em></em>, <strong></strong>, and
Expand Down
7 changes: 5 additions & 2 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3726,8 +3726,11 @@ static tmbstr ParseAttribute( TidyDocImpl* doc, Bool *isempty,
/* what should be done about non-namechar characters? */
/* currently these are incorporated into the attr name */

if ( !cfgBool(doc, TidyXmlTags) && TY_(IsUpper)(c) )
c = TY_(ToLower)(c);
if ( cfg(doc, TidyUpperCaseAttrs) != TidyUppercasePreserve )
{
if ( !cfgBool(doc, TidyXmlTags) && TY_(IsUpper)(c) )
c = TY_(ToLower)(c);
}

TY_(AddCharToLexer)( lexer, c );
lastc = c;
Expand Down
2 changes: 1 addition & 1 deletion src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4833,7 +4833,7 @@ void TY_(ParseDocument)(TidyDocImpl* doc)
if ( !htmlOut )
{
TY_(SetOptionBool)( doc, TidyUpperCaseTags, no );
TY_(SetOptionBool)( doc, TidyUpperCaseAttrs, no );
TY_(SetOptionInt)( doc, TidyUpperCaseAttrs, no );
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/pprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ static void PPrintAttribute( TidyDocImpl* doc, uint indent,
Bool xmlOut = cfgBool( doc, TidyXmlOut );
Bool xhtmlOut = cfgBool( doc, TidyXhtmlOut );
Bool wrapAttrs = cfgBool( doc, TidyWrapAttVals );
Bool ucAttrs = cfgBool( doc, TidyUpperCaseAttrs );
uint ucAttrs = cfg( doc, TidyUpperCaseAttrs );
Bool indAttrs = cfgBool( doc, TidyIndentAttributes );
uint xtra = AttrIndent( doc, node, attr );
Bool first = AttrNoIndentFirst( /*doc,*/ node, attr );
Expand Down Expand Up @@ -1287,7 +1287,7 @@ static void PPrintAttribute( TidyDocImpl* doc, uint indent,

if (c > 0x7F)
name += TY_(GetUTF8)(name, &c);
else if (ucAttrs)
else if (ucAttrs == TidyUppercaseYes)
c = TY_(ToUpper)(c);

AddChar(pprint, c);
Expand Down Expand Up @@ -1734,8 +1734,8 @@ static void PPrintXmlDecl( TidyDocImpl* doc, uint indent, Node *node )
saveWrap = WrapOff( doc );

/* no case translation for XML declaration pseudo attributes */
ucAttrs = cfgBool(doc, TidyUpperCaseAttrs);
TY_(SetOptionBool)(doc, TidyUpperCaseAttrs, no);
ucAttrs = cfg(doc, TidyUpperCaseAttrs);
TY_(SetOptionInt)(doc, TidyUpperCaseAttrs, no);

AddString( pprint, "<?xml" );

Expand All @@ -1749,7 +1749,7 @@ static void PPrintXmlDecl( TidyDocImpl* doc, uint indent, Node *node )
PPrintAttribute( doc, indent, node, att );

/* restore old config value */
TY_(SetOptionBool)(doc, TidyUpperCaseAttrs, ucAttrs);
TY_(SetOptionInt)(doc, TidyUpperCaseAttrs, ucAttrs);

if ( node->end <= 0 || doc->lexer->lexbuf[node->end - 1] != '?' )
AddChar( pprint, '?' );
Expand Down