Added TidyConfigCallback and deprecated TidyOptCallback for consistency with
the remainder of the callbacks. TidyConfigCallback is now given a reference to the instance of the TidyDoc that caused the callback to occur. + TidyConfigCallback
This commit is contained in:
parent
fa18c51871
commit
f4c64966f0
|
@ -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
|
||||
** @{
|
||||
|
|
12
src/config.c
12
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
|
||||
|
|
|
@ -60,6 +60,7 @@ struct _TidyDocImpl
|
|||
TidyReportCallback reportCallback;
|
||||
TidyMessageCallback messageCallback;
|
||||
TidyOptCallback pOptCallback;
|
||||
TidyConfigCallback pConfigCallback;
|
||||
TidyPPProgress progressCallback;
|
||||
|
||||
/* Parse + Repair Results */
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue