Open
Conversation
Fixes ProgressPlanner#17 markdown_alternate_conversion_error_fallback filter added — when HTML-to-Markdown conversion throws, the fallback is now filterable. Filter signature: $default_fallback (string) — default value: wp_strip_all_tags() + html_entity_decode() $content (string) — original HTML $post (WP_Post) $e (Throwable) — the caught exception Example usage: add_filter('markdown_alternate_conversion_error_fallback', function($fallback, $content, $post, $e) { // Custom fallback logic, e.g. log the error, return different markup, etc. return $fallback; // or your custom string }, 10, 4); add_filter('markdown_alternate_conversion_error_fallback', function($fallback, $content, $post, $e) { // Custom fallback logic, e.g. log the error, return different markup, etc. return $fallback; // or your custom string}, 10, 4); The try/catch is in place because the filter only runs when conversion fails. No other stability changes (hierarchical pages, Accept header) are included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #17
Adds the
markdown_alternate_conversion_error_fallbackfilter so theme and plugin authors can customize what is returned when HTML-to-Markdown conversion throws an exception.Context
Developers currently have no way to customize the fallback when HTML-to-Markdown conversion fails (e.g. malformed or unusual HTML). This PR adds a filter that runs only when conversion throws, letting them change the fallback (e.g. logging, custom formatting, or different plain-text handling). The default remains
wp_strip_all_tags()plushtml_entity_decode(); the filter simply makes that behavior overrideable.Summary
This PR can be summarized in the following changelog entry:
markdown_alternate_conversion_error_fallbackfilter so developers can customize the fallback output when HTML-to-Markdown conversion throws an exception.Relevant technical choices:
apply_filters('markdown_alternate_conversion_error_fallback', $default_fallback, $content, $post, $e)— passes the default fallback, raw HTML, post object, and exception so implementations can log, inspect, or fully replace the fallback.wp_strip_all_tags()andhtml_entity_decode()for plain-text output, matching the bug-fix behavior.\Throwable: Handles bothExceptionandErrorto avoid uncaught PHP 7+ errors.Test instructions
markdown_alternate_conversion_error_fallbackthat returns custom text (e.g."Conversion failed")..mdURL.Relevant test scenarios
UI changes
Documentation
Quality assurance
Closes #17