Skip to content

Commit 2e44b44

Browse files
authored
Merge pull request #39 from jeremyfelt/release/1.6.0
Release 1.6.0
2 parents 73beb76 + 6d2ed7e commit 2e44b44

10 files changed

+3353
-3131
lines changed

README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Add a notes post type to WordPress. For your short notes.
44

55
## Description
66

7-
Shortnotes adds a custom post type, **Notes**, intended for use when publishing short pieces of content, similar to that found on Twitter, Instagram, and other social networks.
7+
Shortnotes adds a custom post type, **Notes**, used to publish short pieces of content on your website, similar to social networks like Mastodon, Twitter, or Instagram.
88

99
### No titles
1010

@@ -16,7 +16,7 @@ A title **is** generated automatically from note content and is used as the note
1616

1717
### Limited blocks
1818

19-
The **Notes** post type uses only basic content blocks like paragraph, image, gallery, video, and embed. Using a defined list of relatively simple blocks helps to keep notes simple.
19+
The **Notes** post type supports basic content blocks like paragraph, list, quote, image, preformatted text, gallery, video, and embed. Using a defined list of relatively simple blocks helps to keep notes simple.
2020

2121
### Webmention support
2222

@@ -55,6 +55,16 @@ Those adjustments (a) remove the display of a title for the note post type and (
5555

5656
## Changelog
5757

58+
### 1.6.0
59+
60+
* Improve title generation when a note starts with a quote.
61+
* Improve text formatting of notes posted to Mastodon through [Share on Mastodon](https://wordpress.org/plugins/share-on-mastodon/):
62+
* Avoid duplicate dashes when a note with a quote is transformed for Mastodon.
63+
* Remove leading and trailing double quotes of all flavors when a note with a quote is transformed for Mastodon.
64+
* Ensure persisting line breaks for preformatted blocks with `<br>` tags.
65+
* Improve handling of lists and list items when transforming content for Mastodon.
66+
* Update `@wordpress/scripts` dependency to 26.8.0.
67+
5868
### 1.5.0
5969

6070
* Improve text formatting of notes posted to Mastodon through [Share on Mastodon](https://wordpress.org/plugins/share-on-mastodon/):

build/index.asset.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'ccbee4ae86a23daf7f60');
1+
<?php return array('dependencies' => array('wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '508f05b7a61d9b3980de');

build/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.lock

+33-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/post-type-note.php

+42-5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ function filter_allowed_block_types( $allowed_block_types, \WP_Post $post ) {
174174
'core/gallery',
175175
'core/image',
176176
'core/list',
177+
'core/list-item',
177178
'core/paragraph',
178179
'core/preformatted',
179180
'core/pullquote',
@@ -207,6 +208,9 @@ function get_placeholder_title() {
207208
function generate_sub_title( string $html ): string {
208209
$sub_title = wp_strip_all_tags( $html );
209210

211+
// Stripe newline characters.
212+
$sub_title = str_replace( array( "\r", "\n" ), '', $sub_title );
213+
210214
// At the risk of being complicated, determine the length of the translated "Note" pretext so
211215
// that we can build a maximum string of 50 characters.
212216
$string_lenth = 50 - strlen( get_placeholder_title() );
@@ -242,7 +246,7 @@ function get_formatted_title( array $post_data ): string {
242246
// A paragraph has been found, we're moving on and using it for the title.
243247
break;
244248
} elseif ( 'core/quote' === $block['blockName'] ) {
245-
$sub_title = transform_content( $post_data['post_content'] );
249+
$sub_title = generate_sub_title( '&ldquo;' . trim( $post_data['post_content'] ) );
246250

247251
// A quote has been found, use its plain text equivalent and move on.
248252
break;
@@ -453,14 +457,47 @@ function transform_block( array $block ): string {
453457
$content .= '';
454458

455459
foreach ( $block['innerBlocks'] as $inner_block ) {
456-
$content .= transform_block( $inner_block );
460+
// Strip leading and trailing double quotation marks.
461+
$content .= html_entity_decode(
462+
preg_replace(
463+
'/^(&quot;|&ldquo;|&rdquo;)|(&quot;|&ldquo;|&rdquo;)$/',
464+
'',
465+
htmlentities(
466+
transform_block( $inner_block )
467+
)
468+
),
469+
);
457470
}
458471

459-
// Quotes use a dash before the citation is appended.
460-
$content .= '” - ';
461-
$content .= strip_html( trim( $block['innerHTML'] ) );
472+
$citation = trim( ltrim( trim( strip_html( $block['innerHTML'] ) ), '-' ) );
473+
474+
if ( '' !== $citation ) {
475+
$content .= '” - ' . $citation;
476+
} else {
477+
$content .= '';
478+
}
462479
} elseif ( 'core/embed' === $block['blockName'] ) {
463480
$content .= $block['attrs']['url'] ?? '';
481+
} elseif ( 'core/preformatted' === $block['blockName'] ) {
482+
// We should expect preservation of line breaks in preformatted blocks
483+
// and some may appear as <br> tags by accident.
484+
$content .= strip_html(
485+
str_replace(
486+
'<br>',
487+
"\n",
488+
trim( $block['innerHTML'] )
489+
)
490+
);
491+
} elseif ( 'core/list' === $block['blockName'] ) {
492+
$list_content = '';
493+
494+
foreach ( $block['innerBlocks'] as $inner_block ) {
495+
$list_content .= transform_block( $inner_block );
496+
}
497+
498+
$content .= rtrim( $list_content, "\n" );
499+
} elseif ( 'core/list-item' === $block['blockName'] ) {
500+
$content .= '- ' . strip_html( trim( $block['innerHTML'] ) ) . "\n";
464501
} else {
465502
$content .= strip_html( trim( $block['innerHTML'] ) );
466503
}

0 commit comments

Comments
 (0)