Skip to content

Stability enhancements #17

@mathetos

Description

@mathetos

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:

  1. string — The default fallback (e.g. wp_strip_all_tags($content))
  2. string — Original HTML content
  3. WP_Post — The post object
  4. Throwable — 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.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions