# Extending Bluecloth/Redcloth

**URL:** <https://www.ruby-forum.com/t/extending-bluecloth-redcloth/134404>\
**Category:** Rails\
**Created:** [April 10, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/extending-bluecloth-redcloth/134404 "2008-04-10T15:39:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![spiderware](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@spiderware](https://www.ruby-forum.com/u/spiderware)\
**Post date:** [April 10, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/extending-bluecloth-redcloth/134404/1 "2008-04-10T15:39:04Z")

</div>

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.](http://www.ncbi.nlm.nih.gov/pubmed/18332676)

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

---

<div class="post-metadata">

**Author:** ![spiderware](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@spiderware](https://www.ruby-forum.com/u/spiderware)\
**Post date:** [April 10, 2008, 4:19pm UTC](https://www.ruby-forum.com/t/extending-bluecloth-redcloth/134404/2 "2008-04-10T16:19:53Z")

</div>

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](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![spiderware](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@spiderware](https://www.ruby-forum.com/u/spiderware)\
**Post date:** [April 10, 2008, 4:33pm UTC](https://www.ruby-forum.com/t/extending-bluecloth-redcloth/134404/3 "2008-04-10T16:33:35Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![spiderware](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@spiderware](https://www.ruby-forum.com/u/spiderware)\
**Post date:** [April 10, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/extending-bluecloth-redcloth/134404/4 "2008-04-10T20:20:51Z")

</div>

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](http://nubyonrails.com/articles/about-this-blog-custom-textile)

Google is your friend.

Alain

---

<div class="post-metadata">

**Author:** ![spiderware](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@spiderware](https://www.ruby-forum.com/u/spiderware)\
**Post date:** [April 10, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/extending-bluecloth-redcloth/134404/5 "2008-04-10T17:23:40Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![spiderware](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@spiderware](https://www.ruby-forum.com/u/spiderware)\
**Post date:** [April 11, 2008, 8:09am UTC](https://www.ruby-forum.com/t/extending-bluecloth-redcloth/134404/6 "2008-04-11T08:09:27Z")

</div>

> see:  
> [http://nubyonrails.com/articles/about-this-blog-custom-textile](http://nubyonrails.com/articles/about-this-blog-custom-textile)

Thx! Exactly, what I was looking for!!
