-
Notifications
You must be signed in to change notification settings - Fork 7
Description
When HTML-to-Markdown conversion fails (e.g., malformed or unusual HTML), there is no way for developers to control the fallback. Once conversion is wrapped in try/catch and a default fallback (like wp_strip_all_tags) is used, theme and plugin authors may want to customize that fallback—for example, to use a different fallback, adjust formatting, or log/handle the error.
Describe the solution you'd like
Introduce a filter that runs when conversion throws, so the fallback text can be customized:
$body = apply_filters(
'markdown_alternate_conversion_error_fallback',
wp_strip_all_tags($content), // default fallback
$content,
$post,
$e
);Filter arguments:
string— The default fallback (e.g.wp_strip_all_tags($content))string— Original HTML contentWP_Post— The post objectThrowable— The caught exception
Return: The string to use as the markdown body when conversion fails.
Why do you think this feature is something we should consider for this plugin?
- Lets developers adapt fallback behavior without editing plugin code.
- Aligns with common WordPress plugin patterns (filters for customization).
- Keeps the plugin extensible while still providing a safe default.
Additional context
This complements a bug fix that wraps the League HTML-to-Markdown conversion in try/catch and uses wp_strip_all_tags as the default fallback. The filter only runs when an exception is thrown; it does not run for successful conversions.