diff --git a/console/tidy.c b/console/tidy.c index 891a199..fce4d94 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -548,18 +548,6 @@ static void GetOption(TidyDoc tdoc, /**< The tidy document. */ /* Handle special cases first. */ switch ( optId ) { - case TidyDoctype: - d->type = "DocType"; - d->vals = NULL; - { - ctmbstr sdef = NULL; - sdef = tidyOptGetCurrPick( tdoc, TidyDoctypeMode ); - if ( !sdef || *sdef == '*' ) - sdef = tidyOptGetValue( tdoc, TidyDoctype ); - d->def = sdef; - } - break; - case TidyInlineTags: case TidyBlockTags: case TidyEmptyTags: diff --git a/src/config.c b/src/config.c index 2fd89d7..7810537 100644 --- a/src/config.c +++ b/src/config.c @@ -180,7 +180,7 @@ static const TidyOptionImpl option_defs[] = { TidyCSSPrefix, MR, "css-prefix", ST, 0, ParseCSS1Selector, NULL, "c" }, { TidyCustomTags, IR, "new-custom-tags", ST, 0, ParseList, NULL }, /* 20170309 - Issue #119 */ { TidyDecorateInferredUL, MX, "decorate-inferred-ul", BL, no, ParsePickList, &boolPicks }, - { TidyDoctype, DT, "doctype", ST, 0, ParseDocType, &doctypePicks }, + { TidyDoctype, DT, "doctype", ST, TidyDoctypeAuto, ParseDocType, &doctypePicks }, #ifndef DOXYGEN_SHOULD_SKIP_THIS { TidyDoctypeMode, IR, "doctype-mode", IN, TidyDoctypeAuto, NULL, &doctypePicks }, #endif @@ -385,6 +385,28 @@ static Bool SetOptionValue( TidyDocImpl* doc, TidyOptionId optId, ctmbstr val ) } +ctmbstr TY_(GetPickListLabelForPick)( TidyOptionId optId, uint pick ) +{ + const TidyOptionImpl* option = TY_(getOption)( optId ); + + if ( option && option->pickList ) + { + uint ix = 0; + const PickListItem *item = NULL; + + /* Loop through the picklist until index matches the value. */ + while ( (item = &(*option->pickList)[ ix ]) && item->label && ixlabel ) + return item->label; + } + + return NULL; +} + + Bool TY_(SetOptionInt)( TidyDocImpl* doc, TidyOptionId optId, ulong val ) { Bool status = ( optId < N_TIDY_OPTIONS ); diff --git a/src/config.h b/src/config.h index 56811c5..2cf958c 100644 --- a/src/config.h +++ b/src/config.h @@ -203,6 +203,14 @@ void TY_(InitConfig)( TidyDocImpl* doc ); void TY_(FreeConfig)( TidyDocImpl* doc ); +/** Gets the picklist label for a given value. + ** @param optId the option id having a picklist to check. + ** @param pick the picklist item to retrieve. + ** @returns The label for the pick. + */ +ctmbstr TY_(GetPickListLabelForPick)( TidyOptionId optId, uint pick ); + + /** Sets the integer value for the given option Id. ** @param doc The Tidy document. ** @param optId The option ID to set. diff --git a/src/tidylib.c b/src/tidylib.c index e558c20..b965300 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -366,6 +366,12 @@ TidyConfigCategory TIDY_CALL tidyOptGetCategory( TidyOption topt ) ctmbstr TIDY_CALL tidyOptGetDefault( TidyOption topt ) { const TidyOptionImpl* option = tidyOptionToImpl( topt ); + /* Special case for TidyDoctype, because it is declared as string */ + if ( option && option->id == TidyDoctype ) + { + const TidyOptionImpl* newopt = TY_(getOption)( TidyDoctypeMode ); + return TY_(GetPickListLabelForPick)( TidyDoctypeMode, newopt->dflt ); + } if ( option && option->type == TidyString ) return option->pdflt; /* Issue #306 - fix an old typo hidden by a cast! */ return NULL; @@ -375,6 +381,14 @@ ulong TIDY_CALL tidyOptGetDefaultInt( TidyOption topt ) const TidyOptionImpl* option = tidyOptionToImpl( topt ); if ( option && option->type != TidyString ) return option->dflt; + + /* Special case for TidyDoctype, because it has a picklist */ + if ( option->id == TidyDoctype ) + { + const TidyOptionImpl* newopt = TY_(getOption)( TidyDoctypeMode ); + return newopt->dflt; + } + return ~0U; } Bool TIDY_CALL tidyOptGetDefaultBool( TidyOption topt ) @@ -411,11 +425,26 @@ ctmbstr TIDY_CALL tidyOptGetNextPick( TidyOption topt, TidyIterator* pos ) ctmbstr TIDY_CALL tidyOptGetValue( TidyDoc tdoc, TidyOptionId optId ) { - TidyDocImpl* impl = tidyDocToImpl( tdoc ); - ctmbstr optval = NULL; - if ( impl ) - optval = cfgStr( impl, optId ); - return optval; + TidyDocImpl* impl = tidyDocToImpl( tdoc ); + ctmbstr optval = NULL; + if ( impl ) + { + if ( optId == TidyDoctype ) + { + /* Special case for TidyDoctype, because it has a picklist and is a string. */ + uint pick = tidyOptGetInt( tdoc, TidyDoctypeMode ); + if ( pick != TidyDoctypeUser ) + { + optval = TY_(GetPickListLabelForPick)( TidyDoctypeMode, pick ); + } else { + optval = cfgStr( impl, optId ); + } + } else { + /* Standard case. */ + optval = cfgStr( impl, optId ); + } + } + return optval; } Bool TIDY_CALL tidyOptSetValue( TidyDoc tdoc, TidyOptionId optId, ctmbstr val ) { @@ -437,7 +466,13 @@ ulong TIDY_CALL tidyOptGetInt( TidyDoc tdoc, TidyOptionId optId ) TidyDocImpl* impl = tidyDocToImpl( tdoc ); ulong opti = 0; if ( impl ) - opti = cfg( impl, optId ); + { + /* Special case for TidyDoctype, because it has a picklist */ + if ( optId == TidyDoctype ) + opti = cfg( impl, TidyDoctypeMode); + else + opti = cfg( impl, optId ); + } return opti; } @@ -445,7 +480,13 @@ Bool TIDY_CALL tidyOptSetInt( TidyDoc tdoc, TidyOptionId optId, ulong val { TidyDocImpl* impl = tidyDocToImpl( tdoc ); if ( impl ) - return TY_(SetOptionInt)( impl, optId, val ); + { + /* Special case for TidyDoctype, because it has a picklist */ + if ( optId == TidyDoctype ) + return TY_(SetOptionInt)( impl, TidyDoctypeMode, val ); + else + return TY_(SetOptionInt)( impl, optId, val ); + } return no; } @@ -480,24 +521,8 @@ ctmbstr TIDY_CALL tidyOptGetEncName( TidyDoc tdoc, TidyOptionId optId ) ctmbstr TIDY_CALL tidyOptGetCurrPick( TidyDoc tdoc, TidyOptionId optId ) { - const TidyOptionImpl* option = TY_(getOption)( optId ); - - if ( option && option->pickList ) - { - uint ix = 0; - uint pick = tidyOptGetInt( tdoc, optId ); - const PickListItem *item = NULL; - - // loop through the picklist until index matches the value - while ( (item = &(*option->pickList)[ ix ]) && item->label && ixlabel ) - return item->label; - } - - return NULL; + uint pick = tidyOptGetInt( tdoc, optId ); + return TY_(GetPickListLabelForPick)( optId, pick ); }