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:
github.com/jarrett/rbbcode
To install:
gem sources -a 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
--
Posted via ruby-forum.com.