Extending Bluecloth/Redcloth

I’d like to extend bleucloth or redcloth to support custom tags, e.g. I
want to use markup like this:

[pubmed:18332676]

which shall be extended to:
Behav Pharmacol.
2008 Mar;19(2):121-128.

Does anyone know, if this is possible and has some hints how to do
this?! I have not decided, wether I want to use redcloth or bluecloth,
I’ll take, whatever has the better extensibility…

Cheers&thx for any help
Stefan

I realize that it might be a pain to incorporate another mark up
language, but your syntax is very much like BBCode, and there is a
rails plugin for BBCode that allows easy customization of what tags/
replacements should be made to your text.
http://agilewebdevelopment.com/plugins/bbcodeizer
Quick and easy, if you don’t mind calling another function when you
render.

If you want it saved directly into the db as the link, then you could
make a simple before_save callback that regexed the tag into html…
though I don’t know how you would get the study/publisher information
to include in the tag from just the ID.

Good luck!

On Apr 10, 9:39 am, Stefan F. [email protected]

This looks almost like the thing I wanted: Unfortunately, the
replacement is a little more complex than what bbcodeize offers: Instead
of replacing the tag with a strin, I need to call a function, which
queries pubmed with the given id and fetches study/publisher info.
Preferably, I wanted to do this at render-time: If I place it in a
before_save, I either:
(a) have another field for the processed markup
(b) or find a way to undo the replacement for editing.

as (b) looks really ugly, I guess I will try a simple regex for
extracting the [pubmed:…]-tag - and store the results of the
processing in another field…

thx for the help!

Stephan,

I’d like to extend bleucloth or redcloth to support custom tags, e.g. I

want to use markup like this:

see:
http://nubyonrails.com/articles/about-this-blog-custom-textile

Google is your friend.

Alain

I’m having fun with this one… I’m actually working on something
similar for my site.

This might be overly complicated, but…

Assuming there is a table somewhere which links IDs to study/publisher
info…

Let’s say these BBCode style tags are used in “study_reviews” and that
there is a “study_review.body” field in the DB that has [pubmed] tags
in it…

First customize BBCodeizer to regex [pubmed:.*] in to <%= link_to
@pubmed.author + ". " + @pubmed.date, “www.foo.bar/” + @pubmed.id %>

The goal here is to get BBCodeizer to export the ERB, not do the
replacemets.

In your study_review controller have the application flow go something
like this…

Do a regex on the study_review.body for [pubmed:(.*)]
If found, regex out the ID from the tag
@pubmed=Pubmed.find(regex_resutl)

So when the bbcodeizer function is run during the view, it will
convert to ERB, which could then be processed again by rails?

Now that I am typing this out, I am doubting myself that the ERB will
ever get executed after coming out of the bbcodizer. But give it a
try…

On Apr 10, 10:33 am, Stefan F. [email protected]

see:
http://nubyonrails.com/articles/about-this-blog-custom-textile

Thx! Exactly, what I was looking for!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs