diff --git a/include/tidy.h b/include/tidy.h index a29e263..bc83b79 100644 --- a/include/tidy.h +++ b/include/tidy.h @@ -548,6 +548,8 @@ TIDY_EXPORT int TIDY_CALL tidySetOutCharEncoding(TidyDoc tdoc, /**< The /** This typedef represents the required signature for your provided callback ** function should you wish to register one with tidySetOptionCallback(). ** Your callback function will be provided with the following parameters. + ** Note that this is deprecated and you should instead migrate to + ** tidySetConfigCallback(). ** @param option The option name that was provided. ** @param value The option value that was provided ** @return Your callback function will return `yes` if it handles the provided @@ -560,12 +562,38 @@ typedef Bool (TIDY_CALL *TidyOptCallback)(ctmbstr option, ctmbstr value); ** configuration file options. Setting this callback allows a LibTidy ** application developer to examine command-line and configuration file options ** after LibTidy has examined them and failed to recognize them. + ** Note that this is deprecated and you should instead migrate to + ** tidySetConfigCallback(). ** @result Returns `yes` upon success. */ TIDY_EXPORT Bool TIDY_CALL tidySetOptionCallback(TidyDoc tdoc, /**< The document to apply the callback to. */ TidyOptCallback pOptCallback /**< The name of a function of type TidyOptCallback() to serve as your callback. */ ); +/** This typedef represents the required signature for your provided callback + ** function should you wish to register one with tidySetOptionCallback(). + ** Your callback function will be provided with the following parameters. + ** @param tdoc The document instance for which the callback was invoked. + ** @param option The option name that was provided. + ** @param value The option value that was provided + ** @return Your callback function will return `yes` if it handles the provided + ** option, or `no` if it does not. In the latter case, Tidy will issue + ** an unknown configuration option error. + */ +typedef Bool (TIDY_CALL *TidyConfigCallback)(TidyDoc tdoc, ctmbstr option, ctmbstr value); + +/** Applications using TidyLib may want to augment command-line and + ** configuration file options. Setting this callback allows a LibTidy + ** application developer to examine command-line and configuration file options + ** after LibTidy has examined them and failed to recognize them. + ** Note that this is deprecated and you should instead migrate to + ** tidySetConfigCallback(). + ** @result Returns `yes` upon success. + */ +TIDY_EXPORT Bool TIDY_CALL tidySetConfigCallback(TidyDoc tdoc, /**< The document to apply the callback to. */ + TidyConfigCallback pConfigCallback /**< The name of a function of type TidyConfigCallback() to serve as your callback. */ + ); + /** @} ** @name Option ID Discovery ** @{ diff --git a/src/config.c b/src/config.c index f47e452..cd1d20c 100644 --- a/src/config.c +++ b/src/config.c @@ -817,13 +817,14 @@ int TY_(ParseConfigFileEnc)( TidyDocImpl* doc, ctmbstr file, ctmbstr charenc ) option->parser( doc, option ); else { - if (NULL != doc->pOptCallback) + if ( (NULL != doc->pOptCallback) || (NULL != doc->pConfigCallback) ) { TidyConfigImpl* cfg = &doc->config; tmbchar buf[8192]; uint i = 0; tchar delim = 0; Bool waswhite = yes; + Bool response = yes; tchar c = SkipWhite( cfg ); @@ -854,7 +855,14 @@ int TY_(ParseConfigFileEnc)( TidyDocImpl* doc, ctmbstr file, ctmbstr charenc ) c = AdvanceChar( cfg ); } buf[i] = '\0'; - if (no == (*doc->pOptCallback)( name, buf )) + + if ( doc->pOptCallback ) + response = response && (*doc->pOptCallback)( name, buf ); + + if ( doc->pConfigCallback ) + response = response && (*doc->pConfigCallback)( tidyImplToDoc(doc), name, buf ); + + if (response == no) TY_(ReportUnknownOption)( doc, name ); } else diff --git a/src/tidy-int.h b/src/tidy-int.h index 7973c74..6bcfaf5 100755 --- a/src/tidy-int.h +++ b/src/tidy-int.h @@ -60,6 +60,7 @@ struct _TidyDocImpl TidyReportCallback reportCallback; TidyMessageCallback messageCallback; TidyOptCallback pOptCallback; + TidyConfigCallback pConfigCallback; TidyPPProgress progressCallback; /* Parse + Repair Results */ diff --git a/src/tidylib.c b/src/tidylib.c index 00906ca..9d7c0a2 100755 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -232,6 +232,17 @@ Bool TIDY_CALL tidySetOptionCallback( TidyDoc tdoc, TidyOptCallback pOptC return no; } +Bool TIDY_CALL tidySetConfigCallback(TidyDoc tdoc, TidyConfigCallback pConfigCallback) +{ + TidyDocImpl* impl = tidyDocToImpl( tdoc ); + if ( impl ) + { + impl->pConfigCallback = pConfigCallback; + return yes; + } + return no; +} + int TIDY_CALL tidyLoadConfig( TidyDoc tdoc, ctmbstr cfgfil ) {