From f45a99db2daf4404e21656e968c90dd730bca6f8 Mon Sep 17 00:00:00 2001 From: Mike Little Date: Fri, 27 Feb 2026 17:10:57 +0000 Subject: [PATCH] Upgrade erusev/parsedown from 1.7.4 to 1.8.0 Update the parsedown dependency to the latest stable release (1.8.0) which includes security fixes and improved CommonMark compliance. Update MarkdownParser::blockHeader() to use the 1.8.0 element structure where handler is now an array with function/argument/destination keys, and child elements use the 'elements' key directly. This also fixes a pre-existing bug where header anchor IDs were empty because sanitize_title_with_dashes() was processing raw Parsedown inline tokens instead of plain text. Co-Authored-By: Claude Opus 4.6 (cherry picked from commit f698bcbdd7ae0c6f0b7fc500657d6ca3144a7e3f) --- composer.json | 2 +- inc/class-markdownparser.php | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 51655a25..4fa85a9b 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "require": { "php": ">=8.2", - "erusev/parsedown": "~1.7.4", + "erusev/parsedown": "~1.8.0", "mustangostang/spyc": "^0.6.3" }, "extra": { diff --git a/inc/class-markdownparser.php b/inc/class-markdownparser.php index 1702a76f..3de2b498 100644 --- a/inc/class-markdownparser.php +++ b/inc/class-markdownparser.php @@ -176,12 +176,17 @@ protected function inlineInternalLink( $result, $parts ) { */ protected function blockHeader( $data ) { $block = parent::blockHeader( $data ); - $id = sanitize_title_with_dashes( $block['element']['text'] ); + if ( empty( $block ) ) { + return $block; + } + + $text = $block['element']['handler']['argument']; + $id = sanitize_title_with_dashes( $text ); // Use a manual ID if provided. - if ( preg_match( '/^(.+) ?\{#(.+?)\}$/', $block['element']['text'], $matches ) ) { + if ( preg_match( '/^(.+) ?\{#(.+?)\}$/', $text, $matches ) ) { $id = $matches[2]; - $block['element']['text'] = $matches[1]; + $block['element']['handler']['argument'] = $matches[1]; } return [ @@ -192,8 +197,7 @@ protected function blockHeader( $data ) { 'id' => $id, 'class' => 'header-anchor', ], - 'handler' => 'elements', - 'text' => [ $block['element'] ], + 'elements' => [ $block['element'] ], ], ]; }