Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Last active February 3, 2020 08:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenharris/6078242 to your computer and use it in GitHub Desktop.
Save stephenharris/6078242 to your computer and use it in GitHub Desktop.
By default bbpress can be quite strict on the HTML it allows in posts (tags are whitelisted). The following loosens those restrictions and is taken from this post: http://buddypress.org/support/topic/tutorial-allow-more-html-tags-in-bp-forum-topics/
<?php
function myprefix_kses_allowed_tags($input){
return array_merge( $input, array(
// paragraphs
'p' => array(
'style' => array()
),
'span' => array(
'style' => array()
),
// Links
'a' => array(
'href' => array(),
'title' => array(),
'rel' => array()
),
// Quotes
'blockquote' => array(
'cite' => array()
),
// Code
'code' => array(),
'pre' => array(),
// Formatting
'em' => array(),
'strong' => array(),
'del' => array( 'datetime' => true, ),
// Lists
'ul' => array(),
'ol' => array( 'start' => true, ),
'li' => array(),
// Images
'img' => array(
'src' => true,
'border' => true,
'alt' => true,
'height' => true,
'width' => true,
)
));
}
add_filter( 'bbp_kses_allowed_tags', 'myprefix_kses_allowed_tags', 999, 1 );
?>
@chriscoyier
Copy link

@stephenharris
Copy link
Author

Sorry Chris, it seems like I suck at copy and pasting. The first gist was missing both a return a array_merge. (Also I used add_action rather than add_filter - but that doesn't really make a difference).

I'm surprised a load of errors didn't get thrown in your screencast...

I put the above snippet in my site's utility plug-in - but i'm sure your theme's functions.php or equivalent would work as well. I haven't got a test site with bbPress & MarkDown installed, but I'll give it a test later.

@chriscoyier
Copy link

Ooooh that helped =). So the paragraph tags thing is solved, but other stuff is kinda out of whack.

Here's a series of steps:

  1. User authors some totally legit Markdown
  2. Some it it renders OK, and no paragraphs anymore, but a lot of it does not.

    e.g. Three list items turned into to paragraphs, HTML stripped
  3. If you edit the very same post, what you get in the edit textarea is very different from what was posted.
  4. If you save that it's extra whacky.

What's cool is that WP-Markdown in the normal blog comments area of WordPress works perfectly:

So it's possible!


If you have time to work on this, I'd be happy to pay your freelance rate if you do that kinda thing. And of course have it just go into the open source plugin.

@stephenharris
Copy link
Author

Mmm.... For no.2 have you checked the actual HTML - it could be bullet points without the styling (At least, I recall having to tweak bbPress' css). On a test site everything rendered correctly (for admin / author ).

  1. Yup, can confirm an issue with editing posts - will need to look into it, but seems like the paragraph tags are stripped, before HTML is converted into markdown (?). At least lsits s So when you edit it you're not seeing the appropriate markdown - and hence re-saving (4) will save those errors to the database.

(Editing from the admin doesn't produce these errors, so maybe bbPress is doing something somewhere to the post content when editing it from the frontend.)

I'll try and take a proper look at this over the weekend. I do take on freelance work, but this is a plug-in I actively use and (try to) maintain. So if you want to buy me a beer, you can, but there's obligation :).

@chriscoyier
Copy link

Good thinking on checking the list styles, but sadly it really is not making a list out of them.

Maybe that's a good lead though - like why the heck would dashes get stripped before Markdown can see them?

I'll buy you many many cases of beer =)

@ajtruckle
Copy link

How can I add support for videos?

See:

https://bbpress.org/forums/topic/extra-tags-to-add-to-list-for-videos/#post-205701

I added:

'video'      => array(
	'controls' => true,
	'width'    => true,
	'height'   => true,
),
'source'     => array(
	'src'    => true
)

But it is not right. The source inner component gets stripped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment