WP Discourse HTML Format not carried over

(Darren) #1

I’m not sure if it is the plugin or a limitation somewhere in Discourse that is preventing the formatting of a Wordpress post from being carried over into discourse properly.

For example this Wordpress post has a table and a link to a YouTube video.

However these are not rendered in the forum post

BTW the link to the original article is link in the forum is surrounded in ‘small’ tags. I would suggest it would be better to have a css class to make styling it easier.

(Simon Cossar) #2

The issue with formatting is happening on the Discourse end. It is stripping out the table and iframe tags from the WordPress post. You can see how it works by creating a topic through the Discourse composer with table and iframe tags. The tags and the content inside of them will be removed.

It looks like you are using an iframe for displaying Youtube videos on your WordPress site. You can get videos to display on both WordPress and Discourse by just adding a link to the video on it’s own line in your WordPress post. If the video link is the first item in the post, you need to add a blank line above it.

This is a post with a Youtube video.


I don’t see a good simple solution for displaying a table from a WordPress post in a Discourse topic. I’ll look at it a bit more and see if I can come up with something.

The problem with this is the same as with iframe and table tags. If a class is added on the WordPress end it is stripped out when the post is parsed by Discourse. Discourse styles the small tag with font-size: 9px. To my eyes this is too small for any text. You can add a custom style to your forum to change that. If you only want it to effect small tags in posts, .cooked small { font-size: 80%; } should work.

(Darren) #3

Thanks for replying

The peculiar thing is that I pasted the link into the Wordpress post (in Text mode) so the iframe seems to have been added by Wordpress or something. I’ll have to see if I can find out why that is happening.

It would seem to be a useful thing to be able to insert tables into Discourse, I wonder why they strip them out and if they might change that?

I agree 9px is way too small and the css override will work for now. It seems however that by placing small tags on the link it is breaking the separation of content and style. I can see that the limitations all seem to be from the way Discourse strips html, has this been discussed with the DIscourse developers about perhaps changing it even if it is only for people with admin accounts if security is a concern?

(Eli the Bearded) #4

The onebox is supposed to be a teaser for the content, not the content itself. I expect that tables are troublesome because they are much harder to summarize into a fixed height area, and Discourse relies very heavily on known content sizes for layout.

(Darren) #5

I have found the problem with the iFrame. Since Wordpress 4.4, they merged the oEmbed feature into the core and this is inserting an iFrame. Perhaps there is some way for the plugin to parse the iframe tag and strip it down to the link only before importing into a Discorse post?

(Darren) #6

In a way I would prefer it if the ‘Show Full Post…’ button took you to the Wordpress page instead of expanding the post to show the full content. But the full post is there and most people will click that so having the table would be useful. But when I said tables would be useful in discourse, I meant in an ordinary post, there must be times people would like to show a table of some sort in their post, other more antiquated forums have support for tables.

(Eli the Bearded) #7

Previously Discourse did not support tables in posts without a plugin. With the new markdown engine that has changed, and tables can be added without a plugin. Maybe the next version of this plugin will be able to import tables for that “Show Full Post…” feature.

(Darren) #8

If the new the new markdown engine supports tables then in theory it should just be a case of whitelisting the table tags on imported content?

(Eli the Bearded) #9

The markdown engine supports markdown tables. Inside the engine those get coverted to HTML, but I’m not sure all tables would be easily converted so markdown. I’m not familiar with the syntax, and off-hand don’t know if row or column spans are available, fore example. As markdown tries to be a super simple syntax that looks good as plain ASCII, I can imagine a lot of the configurability of the HTML version is simplified away.

(Simon Cossar) #10

I’ve tried this out. WordPress is inserting the iframe when it displays the post. It doesn’t save it to the database. You can get a Youtube video to display on both WordPress and Discourse if you select the WP Discourse Publishing option ‘Use Full Post Content’. If you are publishing the full post to Discourse, you can remove the Show Full Post button by deselecting the Discourse ‘embed truncate’ option. (Go to your Discourse settings and search for ‘truncate’.)

To display a Youtube video in a truncated post, you need to whitelist iframes for the Youtube URL in a Discourse plugin. The downside of doing this is that it will allow all your users to embed Youtube iframes in posts.

There is an issue with Youtube videos, or any content that should be oneboxed, when it appears on the first line of a post that’s published from WordPress to Discourse. This should be fixed.

I think there has been some discussion about it. I don’t think it’s something they are interested in changing, but I could be wrong about that. You can whitelist HTML tags and classes through a Discourse plugin. This is probably the best approach for getting tables to display on Discourse from WordPress published posts.

(Darren) #11

Having switched to ‘Use Full Post Content’ and turned off truncate, both the Table and YouTube video show up in the post. Any ideas why there is a difference between the truncated and non-truncated versions?