diff --git a/readme.txt b/readme.txt
index 22064dd..4074e75 100644
--- a/readme.txt
+++ b/readme.txt
@@ -103,6 +103,9 @@ Yes, as an opt-in. With `add_filter( 'markdown_alternate_skip_noindexed', '__ret
== Changelog ==
= Unreleased =
+* Fixed cover block images running into the first inner heading
+* Omitted aria-hidden and data-URI images from Markdown
+* Preserved iframe embeds as links instead of dropping their content
* Added Markdown versions of category and tag archives, and of WooCommerce product category, tag and brand archives
* Changed frontmatter links to terms of taxonomies that are not served to point to their HTML archive instead of a `.md` URL that returned 404
* Changed frontmatter links to terms to absolute URLs, like the links in the body
diff --git a/src/Converter/EmbedConverter.php b/src/Converter/EmbedConverter.php
new file mode 100644
index 0000000..4b81d9e
--- /dev/null
+++ b/src/Converter/EmbedConverter.php
@@ -0,0 +1,56 @@
+getAttribute( 'src' ), ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
+ if ( ! preg_match( '~^(?:https?://|/|\.\.?/)~i', $url ) || preg_match( '/[\x00-\x1f\x7f]/', $url ) ) {
+ return '';
+ }
+
+ // Encode characters that would terminate a Markdown link destination.
+ $url = str_replace(
+ array( ' ', '(', ')', '<', '>', '\\' ),
+ array( '%20', '%28', '%29', '%3C', '%3E', '%5C' ),
+ $url
+ );
+ $title = trim( (string) preg_replace( '/\s+/u', ' ', html_entity_decode( $element->getAttribute( 'title' ), ENT_QUOTES | ENT_HTML5, 'UTF-8' ) ) );
+ if ( '' === $title ) {
+ $title = $url;
+ }
+ $title = str_replace(
+ array( '\\', '[', ']', '*', '_', '`', '<', '>' ),
+ array( '\\\\', '\\[', '\\]', '\\*', '\\_', '\\`', '\\<', '\\>' ),
+ $title
+ );
+ return '[' . $title . '](' . $url . ")\n\n";
+ }
+
+ /**
+ * Tags converted by this fallback.
+ *
+ * @return string[] Supported tags.
+ */
+ public function getSupportedTags(): array { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid -- Library interface.
+ return array( 'iframe' );
+ }
+}
diff --git a/src/Converter/ImageConverter.php b/src/Converter/ImageConverter.php
new file mode 100644
index 0000000..bf52b4b
--- /dev/null
+++ b/src/Converter/ImageConverter.php
@@ -0,0 +1,41 @@
+getAttribute( 'src' ) ), 'data:' ) ) {
+ return '';
+ }
+ for ( $ancestor = $element; null !== $ancestor; $ancestor = $ancestor->getParent() ) {
+ if ( 'true' === strtolower( trim( $ancestor->getAttribute( 'aria-hidden' ) ) ) ) {
+ return '';
+ }
+ }
+
+ $markdown = parent::convert( $element );
+ // Cover backgrounds precede a div of inner blocks without a wrapping paragraph.
+ if ( preg_match( '/(?:^|\s)wp-block-cover__image-background(?:\s|$)/', $element->getAttribute( 'class' ) ) ) {
+ $markdown .= "\n\n";
+ }
+ return $markdown;
+ }
+}
diff --git a/src/Converter/MarkdownConverter.php b/src/Converter/MarkdownConverter.php
index d10b1c6..67d5861 100644
--- a/src/Converter/MarkdownConverter.php
+++ b/src/Converter/MarkdownConverter.php
@@ -34,7 +34,7 @@ public function __construct() {
$this->converter = new HtmlConverter([
'header_style' => 'atx',
'strip_tags' => true,
- 'remove_nodes' => 'script style iframe',
+ 'remove_nodes' => 'script style',
'hard_break' => false,
'list_item_style' => '-',
]);
@@ -49,6 +49,8 @@ public function __construct() {
// The library already ships table_pipe_escape and table_caption_side
// defaults for this converter — only the registration is missing.
$this->converter->getEnvironment()->addConverter( new TableConverter() );
+ $this->converter->getEnvironment()->addConverter( new ImageConverter() );
+ $this->converter->getEnvironment()->addConverter( new EmbedConverter() );
}
/**
diff --git a/src/Output/ContentRenderer.php b/src/Output/ContentRenderer.php
index 550c657..2f79b16 100644
--- a/src/Output/ContentRenderer.php
+++ b/src/Output/ContentRenderer.php
@@ -26,7 +26,7 @@ class ContentRenderer {
*
* @var int
*/
- private const CACHE_SCHEMA = 1;
+ private const CACHE_SCHEMA = 2;
/**
* The HTML to Markdown converter.
diff --git a/tests/conversion.php b/tests/conversion.php
new file mode 100644
index 0000000..38a4eba
--- /dev/null
+++ b/tests/conversion.php
@@ -0,0 +1,80 @@
+
Before
after.

Keep text.

Text
Before
After
' ) ); + md_alt_assert_contains( '](/local/video)', ( new MarkdownConverter() )->convert( '' ) ); + md_alt_assert_same( '[//example.com/video](//example.com/video)', ( new MarkdownConverter() )->convert( '' ) ); +}; + +$md_alt_tests['Embed attributes cannot introduce executable links or raw HTML'] = static function () { + $converter = new MarkdownConverter(); + foreach ( array( 'javascript:alert(1)', 'data:text/html,bad', 'file:///private/file', 'about:blank', 'vbscript:bad' ) as $src ) { + md_alt_assert_same( '', $converter->convert( '' ) ); + } + md_alt_assert_same( '', $converter->convert( '' ) ); + $output = $converter->convert( '' ); + md_alt_assert_same( '[A \\[title\\] \\<img src="data:image/png;base64,AAAA">\n<iframe src="https://example.com/embed"></iframe>';
+ $output = ( new MarkdownConverter() )->convert( $html );
+ md_alt_assert_contains( '