-
Notifications
You must be signed in to change notification settings - Fork 10
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
Markdown in feeds in WordPress #268
Comments
Dave, may be a bit rudimentary for your needs, but I have used the Jetpack plugin for Wordpress in the past (it has a lot of other nifty features as well making it a good addition to your Wordpress environment overall). https://wordpress.org/plugins/jetpack/ Here is an article on enabling Markdown thru Jetpack. Thanks for all you do for the community, keep digging! -Chris |
Gutenberg has the Markdown block so now natively supports Markdown without the need for Jetpack. So, at the most basic of levels I assume (I've not used WordPress in two and a half years) you could define a custom RSS feed template (I made one to factor for titleless posts) and use the Markdown source from the Gutenberg block — providing it's available (it would be surprising if it wasn't.) If you're looking to go deeper then using a PHP library to convert the post HTML to Markdown would be the easiest way before inserting it in a custom feed template. |
Sorry I don't have time to work on a plugin. But I agree it'd be a useful thing to do. There are two parts to the plugin:
I don't have any insight into number 2. But here are a few thoughts about number 1: The following is based on my rather sketchy understanding of Wordpress and the Block Editor, sorry. I've worked with Wordpress a lot, but I've never had time to acquire any real Wordpress development skill. I hope this is still useful. Wordpress sites used to store posts/pages in HTML. Now they are stored as a series of Blocks created by the block editor. At one time I found Wordpress can convert old HTML posts/pages to Blocks, but I don't remember whether it converts them all automatically, individually, or on command. (And I think I saw some poor conversion results.) Regardless, I'll assume that the plugin supports only Wordpress sites that have been upgraded to the Block Editor and all of the old HTML posts converted to Blocks. Out of the box, the plugin converts all of the blocks delivered with Wordpress to Markdown. The question is how to handle conversion of blocks added to the Wordpress installation by other plugins, themes, and so on. I wouldn't want the plugin to just ask each block to generate its HTML and then convert the HTML to Markdown. There are lots of HTML-to-Markdown converters out there (Random example from a DuckDuckgo search: Turndown). Years ago, when I found only one, it wasn't very good. Maybe they're better now. But I wonder whether the internal rendering of Blocks can be "hooked" by a plugin to produce Markdown rather than HTML? I sorta doubt it: Sure, there might be helper functions like "paragraph" and "link" that can be hooked, but I'll bet many Blocks generate detailed HTML directly. Ideally, the developer of the Block Editor had as one of their requirements: Blocks can render any markup, not just HTML, and here's the documentation on how to build any Block renderer you might need. Does anyone know whether they had that vision? Sorry to post lots of ideas without any specific answers. Dave's question just got me thinking, as usual. |
If using a library to convert HTML to Markdown I think the simplest solution would be to grab the HTML that would be put into a normal RSS feed, render that then reinsert it, it could be as part of a custom feed template. The trick is in finding a decent HTML to Markdown converter. I've got a test WP install hanging around so might have a look if I get time. |
colin, that's my thinking too. i hope you do look into it. ;-) |
There's PHP League's html-to-markdown which might be worth looking at as it supports the full Markdown syntax. I've put together a simple plugin that uses that library and adds a This is mostly the source code:
<?php
/**
* Plugin Name: Markdown in RSS Feed
* Plugin URI:
* Description: This plugin adds Markdown support to an RSS feed.
* Version: 1.0.0
* Author: Fernando Fernandes
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Requires PHP: 7.4
*/
require 'vendor/autoload.php';
use League\HTMLToMarkdown\HtmlConverter;
add_action( 'rss2_item', 'rss_feed_markdown_add_source_item' );
function rss_feed_markdown_add_source_item() {
$content = get_the_content();
$converter = new HtmlConverter(
array(
'strip_tags' => true
)
);
echo '<source:markdown>' . PHP_EOL;
echo $converter->convert( $content );
echo PHP_EOL . '</source:markdown>' . PHP_EOL;
} Here's a zip file to download and install on any WordPress site (required PHP 7.4+). What the plugin does is hook into rss2_item and print the corresponding I didn't test how it works together if using a Jetpack Markdown block in the post content, though. But might be a good starting point. Feel free to host it, Dave. |
That worked on a base WP install. Personally I would have gone with I tried it it with a Jetpack md block and things went a little wierd (the markdown wasn't converted in the After I disabled and re-enabled Jetpack and did a couple more tests it worked correctly. 🤷♂️ |
That's interesting! |
As I say, it was fine after deactivating/activating Jetpack again so not sure what was going on. |
BTW, this is how Markdown flows through FeedLand. The next step is to hook it up with Fernando's feed and make sure it works there too. |
Back in July 2022, I wrote about supporting Markdown in RSS feeds. This is something FeedLand does, as a feed reader and editor. I would love to see all content editors support it as well as feed readers. One product in particular I'd like to support Markdown is Wordpress. The challenge is to figure out how to convert the HTML in a post to Markdown and then to get a source:markdown element in the corresponding item in the feed. Here's a checklist that explains how it works. If you have any interest in working on a plugin that does this please post something in this thread. I will host a WordPress site that runs the plugin as a proof-of-concept.
The text was updated successfully, but these errors were encountered: