Forum: Redcloth BBCode Fork of RedCloth

2a3914ab382405f8ea3813a45da422a9?d=identicon&s=25 Ryan Alyea (Guest)
on 2009-04-21 00:21
(Received via mailing list)
I can't believe I never announced this here. I have a custom coded
forum ( http://forum.fangamer.com/ ) built on Rails. Most of the
popular open source PHP forums just have their own interpretation for
BBCode, but not a common library. What's interesting is that there are
no good BBCode libraries or implementations for Ruby. The closest
thing I could find was a simple regex implementation that had all
kinds of problems.

I wanted to support Textile because Textile is awesome, but I needed
the old BBCode since older "pro" users would eviscerate me if I didn't
support it. I originally had a crappy regex on top of RedCloth, but it
was causing all kinds of weird page breaks with broken coding. So one
day during Christmas break, I forked RedCloth and wrote a whole path
that properly parses BBCode.

It's available here: http://github.com/ROFISH/redcloth

To invoke, use the bbcode option.
r = RedCloth.new( "Some text is meant to be *bold*, others [i]italic[/
i].", [:bbcode] )
r.to_html
#=> "<p>Some text is meant to be <strong>bold</strong>, others
<em>italic</em>.</p>"
There's also a :bbcode_only option that completely ignores Textile for
users that want to use a "Disable Textile" mode. A near complete test
set is available at test/bbcode.yml.

I dunno if this is any use for anybody here, but I had a fun time
learning Ragel and it's been running cleanly on my production server
for a couple months now. :D

Ryan Alyea
ryan@fangamer.com
A50dcaaf8e545e6cc1fb4e32919be6ad?d=identicon&s=25 Jason Garber (jgarber)
on 2009-04-21 18:10
(Received via mailing list)
That's great, Ryan!  Thanks for providing the Ruby community with a
way to parse BBCode.  I ran into that deficiency a few years ago when
trying to gradually replace parts of an old PHP system with Ruby.  I
think I just left the BBCode part in PHP. :-)

Would you consider splitting it off into a new piece of software, so
it's not "Ryan's fork of RedCloth" but rather a library people will
find when looking for a Ruby BBCode parser?  You may not have time to
get to it for awhile, but I think it would be really helpful.

The quick and dirty way is to just pull it into a repo of a new name.
I think your architecture, though, won't serve you well in the long
run.  You should find a way to connect with RedCloth straight from the
source and layer your BBCode functionality on top of it.  Here are a
few ways it could be done:
1.) Serial processing: Your package would be BBCode only.  The user
would run the document through your package  before running it through
RedCloth
2.) Plugin: not sure if this is possible, but I wonder if there'd be a
way to have Ragel include one scanner in another so it all gets
processed in one shot.  The user would install the RedCloth gem and
any plugin gems and those plugins would modify RedCloth behavior. Not
sure that would work—I can see lots of problems with this one.
3. RedCloth flavors: Yours would be RedCloth-BBCode and it would just
include RedCloth in vendor/ or something.

I want to make RedCloth the sort of thing that people can extend
without too much trouble, but also so it's easy for the end user to
keep up with RedCloth advances without having to wait for the
extension to merge in the changes from upstream—which will be very
slow if it's a painful merge process.

If you were to move your fork to a new project and start a clean fork
of RedCloth to make general changes you need for your library to be
compatible, I'd be glad to merge those in.

Good luck figuring it all out and thanks again,
Jason
D893e113b51a8f200d2abb3ed9e54143?d=identicon&s=25 Gaspard Bucher (gazoduc)
on 2009-04-23 09:25
(Received via mailing list)
I will soon run into the same need for zena's textile extensions:
"":45 ==> link to node 45
!33!  ==> show image 33
!:flop_med/this is a super label!:5.data ==> find image matching "flop",
size "med", label "this is a super label", link to the content of
document
5.

I really think there is only two ways to solve my issue:

1. two ragel parsers (zena + redcloth)
2. a single ragel parser (fork from redcloth)

I have not yet decided on what path to take, but since speed is
important
and parsing text twice seems like a waste, I would prefer going root
"2".

Gaspard
1dd2059bd7e320d7c9af42216ef071ea?d=identicon&s=25 Jarrett Colby (jcolby)
on 2009-06-01 17:58
Here comes a bit of shameless self-promotion, but hopefully it will be
helpful.

I just released the beta version of a standalone Ruby BB code parser as
a gem. It's called RbbCode, and my favorite thing about it is that it
gracefully handles invalid input. It's available on github at:

http://github.com/jarrett/rbbcode

To install:

gem sources -a http://gems.github.com
sudo gem install jarrett-rbbcode

It's lacking in documentation as of now (June 1, 2009). The RDoc is
pretty much non-existent. But you'll find a basic usage example in the
README.

Note that this is very new, so it likely has some bugs. If you find any,
please do submit an issue on github, and I'll fix the bug and
re-release. There's a halfway-decent spec suite in place, but it could
use a lot more examples.

Jason Garber wrote:
> That's great, Ryan!  Thanks for providing the Ruby community with a
> way to parse BBCode.  I ran into that deficiency a few years ago when
> trying to gradually replace parts of an old PHP system with Ruby.  I
> think I just left the BBCode part in PHP. :-)
>
> Would you consider splitting it off into a new piece of software, so
> it's not "Ryan's fork of RedCloth" but rather a library people will
> find when looking for a Ruby BBCode parser?  You may not have time to
> get to it for awhile, but I think it would be really helpful.
>
> The quick and dirty way is to just pull it into a repo of a new name.
> I think your architecture, though, won't serve you well in the long
> run.  You should find a way to connect with RedCloth straight from the
> source and layer your BBCode functionality on top of it.  Here are a
> few ways it could be done:
> 1.) Serial processing: Your package would be BBCode only.  The user
> would run the document through your package  before running it through
> RedCloth
> 2.) Plugin: not sure if this is possible, but I wonder if there'd be a
> way to have Ragel include one scanner in another so it all gets
> processed in one shot.  The user would install the RedCloth gem and
> any plugin gems and those plugins would modify RedCloth behavior. Not
> sure that would work—I can see lots of problems with this one.
> 3. RedCloth flavors: Yours would be RedCloth-BBCode and it would just
> include RedCloth in vendor/ or something.
>
> I want to make RedCloth the sort of thing that people can extend
> without too much trouble, but also so it's easy for the end user to
> keep up with RedCloth advances without having to wait for the
> extension to merge in the changes from upstream—which will be very
> slow if it's a painful merge process.
>
> If you were to move your fork to a new project and start a clean fork
> of RedCloth to make general changes you need for your library to be
> compatible, I'd be glad to merge those in.
>
> Good luck figuring it all out and thanks again,
> Jason
0f3aae94f702d9ec0ebe44d2168ca943?d=identicon&s=25 Kenneth     (kentorwow)
on 2010-04-13 22:50
how do you install this? especially on rails 3? putting

gem "redcloth", :git => "git://github.com/ROFISH/redcloth.git"

doesn't work.

and do nested tags like [quote][quote][/quote][/quote] work?
2a3914ab382405f8ea3813a45da422a9?d=identicon&s=25 Ryan Alyea (Guest)
on 2010-04-15 04:27
(Received via mailing list)
Using this is kinda complicated since it's really only geared towards my
particular forum.

Basically you need to:

1) git clone git://github.com/ROFISH/redcloth.git
2) cd redcloth
3) rake install

To use, you need to enable the BBCode path, since it'll use RedCloth
rules by default (this does BBCode and Textile together):

RedCloth.new(input,[:bbcode]).to_html

There's a few other random features, like disabling pieces of code (like
images) if you don't want them, and a bbcode_only codepath if you (or
your users) want to disable Textile completely. This is a line from my
posting logic:

RedCloth.new(self.body,[:no_span_caps,:filter_html,(self.disable_textile
? :bbcode_only : :bbcode),{:disable_inline=>[(:image unless
forum.can_post_images?),:del,:link_alias]}]).to_html

Ryan Alyea
ryan@fangamer.com
This topic is locked and can not be replied to.