From 506f2741eaaca12c8d12a1016680b090c3648ad2 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 23 Jan 2024 10:12:41 -0700 Subject: [PATCH 1/2] Refactor heading regex to make IDs optional The previous regular expression (regex) for parsing HTML headings has been modified to make ID attributes optional. In addition, the order of matches variables for 'text' and 'id' in the ensuing code has also been updated correspondingly. This change fixes an issue where identifiers were not being successfully added to Apple News json output. --- includes/apple-exporter/components/class-heading.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/apple-exporter/components/class-heading.php b/includes/apple-exporter/components/class-heading.php index 187c2d50..2040c165 100644 --- a/includes/apple-exporter/components/class-heading.php +++ b/includes/apple-exporter/components/class-heading.php @@ -185,13 +185,13 @@ private static function split_image( string $html ): array { */ protected function build( $html ): void { // Match HTML headings, capture level, id value if set, and heading text. - if ( 0 === preg_match( '#(.*?)#si', $html, $matches ) ) { + if ( 0 === preg_match( '/]*?\sid="([^"]*?)")?[^>]*?>(.*?)<\/h\1>/si', $html, $matches ) ) { return; } $level = intval( $matches[1] ); - $text = $matches[5]; - $id = $matches[4] ?? null; + $id = $matches[2] ?? null; + $text = $matches[3]; // Parse and trim the resultant text, and if there is nothing left, bail. $text = trim( $this->parser->parse( $text ) ); From 8c42670e1f757b50464ff1581455e56e98c8fca5 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 23 Jan 2024 10:16:25 -0700 Subject: [PATCH 2/2] Update version number to 2.4.5 The version number in package.json, apple-news.php, class-apple-news.php, and readme.txt files has been updated from 2.4.4 to 2.4.5. --- apple-news.php | 2 +- includes/class-apple-news.php | 2 +- package.json | 2 +- readme.txt | 5 ++++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apple-news.php b/apple-news.php index 0f2410bb..379dc41d 100644 --- a/apple-news.php +++ b/apple-news.php @@ -14,7 +14,7 @@ * Plugin Name: Publish to Apple News * Plugin URI: http://github.com/alleyinteractive/apple-news * Description: Export and sync posts to Apple format. - * Version: 2.4.4 + * Version: 2.4.5 * Author: Alley * Author URI: https://alley.com * Text Domain: apple-news diff --git a/includes/class-apple-news.php b/includes/class-apple-news.php index 41052048..7af75f7c 100644 --- a/includes/class-apple-news.php +++ b/includes/class-apple-news.php @@ -50,7 +50,7 @@ class Apple_News { * @var string * @access public */ - public static string $version = '2.4.4'; + public static string $version = '2.4.5'; /** * Link to support for the plugin on WordPress.org. diff --git a/package.json b/package.json index 88e4f8e4..b53467c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "publish-to-apple-news", - "version": "2.4.4", + "version": "2.4.5", "license": "GPLv3", "main": "index.php", "engines": { diff --git a/readme.txt b/readme.txt index 0243e88b..fd1aadb8 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: publish, apple, news, iOS Requires at least: 6.3 Tested up to: 6.4.2 Requires PHP: 8.0 -Stable tag: 2.4.4 +Stable tag: 2.4.5 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl.html @@ -46,6 +46,9 @@ Please visit our [wiki](https://github.com/alleyinteractive/apple-news/wiki) for == Changelog == += 2.4.5 = +* Fixes regular expression for adding identifiers. + = 2.4.4 = * Enhancement: Adds support for the anchor links.