Experimentally working.

This commit is contained in:
Jim Derry 2017-10-07 11:04:18 -04:00
parent 2e2062ddec
commit 483d17e39b
4 changed files with 51 additions and 9 deletions

View File

@ -243,6 +243,9 @@ extern "C" {
FN(NOFRAMES_CONTENT) \
FN(NON_MATCHING_ENDTAG) \
FN(OBSOLETE_ELEMENT) \
FN(OPTION_REMOVED) \
FN(OPTION_REMOVED_APPLIED) \
FN(OPTION_REMOVED_UNAPPLIED) \
FN(PREVIOUS_LOCATION) \
FN(PROPRIETARY_ATTR_VALUE) \
FN(PROPRIETARY_ATTRIBUTE) \

View File

@ -303,7 +303,12 @@ static const TidyOptionImpl option_defs[] =
};
/* List of deprecated options and their replacements. */
/* Deleted options. This array keeps track of options that have been
** removed from Tidy, and suggests a replacement. When a deleted option is
** used, client programs will have the opportunity to consume the option
** first via the callback, and if not handled by the callback, will be
** handled by Tidy, generally by setting an alternate or new option.
*/
static const struct {
ctmbstr name; /**< name of the deprecated option */
TidyOptionId replacementId; /**< Id of the replacement option, or 0 if none. */
@ -503,7 +508,11 @@ static void ReparseTagDecls( TidyDocImpl* doc, uint changedUserTags )
}
/* returns the option id of the replacement Tidy option for optName. */
/* Returns the option id of the replacement Tidy option for optName. Because
** an option might not have a replacement (0, TidyUnknownOption), a return
** value of N_TIDY_OPTIONS indicates an error, i.e., that the option isn't
** in the deprecated list.
*/
static TidyOptionId getOptionReplacement( ctmbstr optName )
{
uint i = 0;
@ -519,26 +528,31 @@ static TidyOptionId getOptionReplacement( ctmbstr optName )
}
/* indicates whether or not optName is deprecated */
/* Indicates whether or not optName is deprecated */
static Bool isOptionDeprecated( ctmbstr optName )
{
return getOptionReplacement( optName ) != N_TIDY_OPTIONS;
}
/* forward declaration */
/* Forward declaration */
Bool GetPickListValue();
/* substitute the new option for the deprecated one. */
/* Aubstitute the new option for the deprecated one. */
static Bool subDeprecatedOption( TidyDocImpl* doc, ctmbstr oldName, ctmbstr oldValue)
{
TidyOptionId newOptId = getOptionReplacement( oldName );
ctmbstr newName = TY_(getOption)( newOptId )->name;
TidyDoc tdoc = tidyImplToDoc( doc );
if ( newOptId == TidyUnknownOption )
{
printf("%s has been removed, and there is no replacement.\n", oldName);
TY_(Report)( doc, NULL, NULL, OPTION_REMOVED, oldName );
return no;
}
/********************/
/* `show-body-only` */
/********************/
if ( TY_(tmbstrcasecmp)( oldName, "show-body-only" ) == 0 )
{
uint value;
@ -548,22 +562,24 @@ static Bool subDeprecatedOption( TidyDocImpl* doc, ctmbstr oldName, ctmbstr oldV
{
if ( value == TidyNoState )
{
printf("show-body-only is deprecated; use show-markup. No action taken.\n");
TY_(Report)( doc, NULL, NULL, OPTION_REMOVED_UNAPPLIED, oldName, newName );
TY_(SetOptionBool)( doc, newOptId, value );
}
else
{
TY_(SetOptionBool)( doc, newOptId, value );
printf("show-body-only has been removed; use show-markup, which has been set to `body-only`.\n");
ctmbstr val = tidyOptGetCurrPick( tdoc, newOptId );
TY_(Report)( doc, NULL, NULL, OPTION_REMOVED_APPLIED, oldName, newName, val );
}
}
else
{
printf("Report bad argument %s\n", oldValue);
printf("-->Report bad argument %s\n", oldValue);
}
return yes;
}
return no;
}

View File

@ -1906,6 +1906,9 @@ static languageDefinition language_en = { whichPluralForm_en, {
{ NOFRAMES_CONTENT, 0, "%s not inside 'noframes' element" },
{ NON_MATCHING_ENDTAG, 0, "replacing unexpected %s with </%s>" },
{ OBSOLETE_ELEMENT, 0, "replacing obsolete element %s with %s" },
{ OPTION_REMOVED, 0, "option \"%s\" no longer exists, and no replacement could be found." },
{ OPTION_REMOVED_APPLIED, 0, "option \"%s\" replaced with \"%s\", which Tidy has set to \"%s\"." },
{ OPTION_REMOVED_UNAPPLIED, 0, "option \"%s\" replaced with \"%s\", but Tidy could not set it for you." },
{ PREVIOUS_LOCATION, 0, "<%s> previously mentioned" },
{ PROPRIETARY_ATTR_VALUE, 0, "%s proprietary attribute value \"%s\"" },
{ PROPRIETARY_ATTRIBUTE, 0, "%s proprietary attribute \"%s\"" },

View File

@ -345,6 +345,9 @@ static struct _dispatchTable {
{ NOFRAMES_CONTENT, TidyWarning, formatStandard },
{ NON_MATCHING_ENDTAG, TidyWarning, formatStandard },
{ OBSOLETE_ELEMENT, TidyWarning, formatStandard },
{ OPTION_REMOVED, TidyConfig, formatStandard },
{ OPTION_REMOVED_APPLIED, TidyConfig, formatStandard },
{ OPTION_REMOVED_UNAPPLIED, TidyConfig, formatStandard },
{ PREVIOUS_LOCATION, TidyInfo, formatStandard },
{ PROPRIETARY_ATTR_VALUE, TidyWarning, formatAttributeReport },
{ PROPRIETARY_ATTRIBUTE, TidyWarning, formatAttributeReport },
@ -749,12 +752,29 @@ TidyMessageImpl *formatStandard(TidyDocImpl* doc, Node *element, Node *node, uin
} break;
case STRING_UNKNOWN_OPTION:
case OPTION_REMOVED:
{
ctmbstr str;
if ( (str = va_arg( args, ctmbstr)) )
return TY_(tidyMessageCreateWithLexer)(doc, code, level, str);
} break;
case OPTION_REMOVED_UNAPPLIED:
{
ctmbstr s1 = va_arg( args, ctmbstr );
ctmbstr s2 = va_arg( args, ctmbstr );
return TY_(tidyMessageCreateWithLexer)(doc, code, level, s1, s2);
}
case OPTION_REMOVED_APPLIED:
{
ctmbstr s1 = va_arg( args, ctmbstr );
ctmbstr s2 = va_arg( args, ctmbstr );
ctmbstr s3 = va_arg( args, ctmbstr );
return TY_(tidyMessageCreateWithLexer)(doc, code, level, s1, s2, s3);
}
case BAD_SURROGATE_LEAD:
case BAD_SURROGATE_PAIR:
case BAD_SURROGATE_TAIL: