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

Small issue with footnotes #70

Closed
edent opened this issue May 3, 2023 · 7 comments
Closed

Small issue with footnotes #70

edent opened this issue May 3, 2023 · 7 comments

Comments

@edent
Copy link

edent commented May 3, 2023

Note sure if this is a problem with the plugin or WordPress.

This post contains Markdown Footnotes: https://shkspr.mobi/blog/2023/05/how-can-i-have-a-side-hustle-when-i-dont-want-to-pay-for-anything/

I've been reading various entrepreneur books and blog posts[^bad]. One thing they all emphasise is that success often comes from finding a problem that you yourself would pay money to solve.
[^bad]: I am aware that they paint a distorted picture of reality.

When shared to Mastodon, it gets rendered as I've been reading various entrepreneur books and blog posts1. One thing they all ...

That is, the 1 becomes a 1.

See https://mastodon.social/@Edent/110304539708556169

@janboddez
Copy link
Owner

janboddez commented May 3, 2023

So, the callback function you use to generate the status content must parse shortcodes (or Markdown, whatever). It probably outputs <sup>1</sup> or similar. Not sure if you then strip those tags or if Mastodon does (I think the former, Mastodon tends to just escape HTML it does not support).

You could probably adjust the callback to delete the footnote links altogether. Or stop it from parsing shortcodes and output the raw Markdown. Or …

@janboddez
Copy link
Owner

janboddez commented May 3, 2023

I.e., the plugin by default only posts a title and permalink. Anything beyond that is the product of a custom callback. If that callback itself calls, e.g., the_content(), then it will also apply all relevant filters …

Edit: I first wrote get_the_content() but that function does not filter $post->post_content.

@janboddez
Copy link
Owner

janboddez commented Jun 21, 2023

@edent Saw another occurrence of this on your Mastodon account, and got reminded of this issue. Wanted to check out https://shkspr.mobi/blog/2022/11/better-sharing-of-wordpress-posts-to-mastodon/ to see if I could help improve your callback function (something like preg_replace( '~<sup[^>]*>.*?</sup>~', '', $status )), but apparently the post content got replaced with a sort of Mastodon embed.

@edent
Copy link
Author

edent commented Jun 21, 2023

Wooops! Think I've fixed it.

@edent
Copy link
Author

edent commented Jun 23, 2023

A good blog post to look at might be https://shkspr.mobi/blog/2023/06/your-phone-is-a-cdo/

Which was auto shared as https://mastodon.social/@Edent/110576330656136247

@janboddez
Copy link
Owner

@edent That's the one I saw!

So, this is not an issue with the plugin. What happens is get_the_excerpt($post) (in your share_on_mastodon_status filter callback) strips all HTML.

In your HTML, there's something like, in this case, <sup id="fnref-43577-pro"><a href="#fn-43577-pro" class="jetpack-footnote" title="Read footnote.">1</a></sup>. And get_the_excerpt turns that particular bit of HTML into ... 1. So that's why it shows like that on Mastodon.

A possible solution is to "roll your own" excerpts, i.e., get $post->post_content, run it through the the_content filters, then appy a preg_replace() similar to the one above to get rid of the footnote links prior to stripping all HTML tags, and, finally, shorten it.

@janboddez
Copy link
Owner

// Dynamically generate an excerpt off the post content.
$excerpt = apply_filters( 'the_content', $post->post_content );
// Remove footnotes.
$excerpt = preg_replace( '~<sup[^>]*>.*?</sup>~', '', $excerpt );
// Actually generate the excerpt. This calls `wp_trim_words()` under the hood, which strips away HTML tags.
$excerpt = wp_trim_excerpt( $excerpt );

Or maybe you could temporarily unhook the Jetpack (?) filter/action that is responsible for generating the footnotes or something. (But you might then end up with something else in your markup that you don't necessarily want there.)

Untested, but you get the idea. And you could then use that "excerpt" instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants