Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.6.0 #39

Merged
merged 14 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Add a notes post type to WordPress. For your short notes.

## Description

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.
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.

### No titles

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

### Limited blocks

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.
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.

### Webmention support

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

## Changelog

### 1.6.0

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

### 1.5.0

* Improve text formatting of notes posted to Mastodon through [Share on Mastodon](https://wordpress.org/plugins/share-on-mastodon/):
Expand Down
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'ccbee4ae86a23daf7f60');
<?php return array('dependencies' => array('wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '508f05b7a61d9b3980de');
2 changes: 1 addition & 1 deletion build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 33 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 42 additions & 5 deletions includes/post-type-note.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function filter_allowed_block_types( $allowed_block_types, \WP_Post $post ) {
'core/gallery',
'core/image',
'core/list',
'core/list-item',
'core/paragraph',
'core/preformatted',
'core/pullquote',
Expand Down Expand Up @@ -207,6 +208,9 @@ function get_placeholder_title() {
function generate_sub_title( string $html ): string {
$sub_title = wp_strip_all_tags( $html );

// Stripe newline characters.
$sub_title = str_replace( array( "\r", "\n" ), '', $sub_title );

// At the risk of being complicated, determine the length of the translated "Note" pretext so
// that we can build a maximum string of 50 characters.
$string_lenth = 50 - strlen( get_placeholder_title() );
Expand Down Expand Up @@ -242,7 +246,7 @@ function get_formatted_title( array $post_data ): string {
// A paragraph has been found, we're moving on and using it for the title.
break;
} elseif ( 'core/quote' === $block['blockName'] ) {
$sub_title = transform_content( $post_data['post_content'] );
$sub_title = generate_sub_title( '&ldquo;' . trim( $post_data['post_content'] ) );

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

foreach ( $block['innerBlocks'] as $inner_block ) {
$content .= transform_block( $inner_block );
// Strip leading and trailing double quotation marks.
$content .= html_entity_decode(
preg_replace(
'/^(&quot;|&ldquo;|&rdquo;)|(&quot;|&ldquo;|&rdquo;)$/',
'',
htmlentities(
transform_block( $inner_block )
)
),
);
}

// Quotes use a dash before the citation is appended.
$content .= '” - ';
$content .= strip_html( trim( $block['innerHTML'] ) );
$citation = trim( ltrim( trim( strip_html( $block['innerHTML'] ) ), '-' ) );

if ( '' !== $citation ) {
$content .= '” - ' . $citation;
} else {
$content .= '”';
}
} elseif ( 'core/embed' === $block['blockName'] ) {
$content .= $block['attrs']['url'] ?? '';
} elseif ( 'core/preformatted' === $block['blockName'] ) {
// We should expect preservation of line breaks in preformatted blocks
// and some may appear as <br> tags by accident.
$content .= strip_html(
str_replace(
'<br>',
"\n",
trim( $block['innerHTML'] )
)
);
} elseif ( 'core/list' === $block['blockName'] ) {
$list_content = '';

foreach ( $block['innerBlocks'] as $inner_block ) {
$list_content .= transform_block( $inner_block );
}

$content .= rtrim( $list_content, "\n" );
} elseif ( 'core/list-item' === $block['blockName'] ) {
$content .= '- ' . strip_html( trim( $block['innerHTML'] ) ) . "\n";
} else {
$content .= strip_html( trim( $block['innerHTML'] ) );
}
Expand Down
Loading
Loading