# Extending RedCloth

**URL:** <https://www.ruby-forum.com/t/extending-redcloth/61281>\
**Category:** Ruby\
**Created:** [May 22, 2006, 6:50pm UTC](https://www.ruby-forum.com/t/extending-redcloth/61281 "2006-05-22T18:50:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_VSSSSlkerts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@Daniel\_VSSSSlkerts](https://www.ruby-forum.com/u/Daniel_VSSSSlkerts)\
**Post date:** [May 22, 2006, 6:50pm UTC](https://www.ruby-forum.com/t/extending-redcloth/61281/1 "2006-05-22T18:50:49Z")

</div>

Hi there, I’d like to extend RedCloth. For example I’d like that  
although expressions like _!C! Textline_ are substituted with

Text

What is the best/ruby way to achieve this? My ideas was:

a. write a extension for RedCloth and register to the RC base (is this  
possible?)

b. Extending the RedCloth class (aka patching)

Any ideas appreciated,

---

<div class="post-metadata">

**Author:** ![Daniel\_VSSSSlkerts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@Daniel\_VSSSSlkerts](https://www.ruby-forum.com/u/Daniel_VSSSSlkerts)\
**Post date:** [May 22, 2006, 7:41pm UTC](https://www.ruby-forum.com/t/extending-redcloth/61281/2 "2006-05-22T19:41:14Z")

</div>

Hi Daniel

Daniel VÃ¶lkerts wrote:

> Hi there, I’d like to extend RedCloth.

> b. Extending the RedCloth class (aka patching)

No idea if it is best, but that is what I did. Take a look halfway  
down:

[http://www.counsell.org/darcs/soks-development/lib/soks-view.rb](http://www.counsell.org/darcs/soks-development/lib/soks-view.rb)

The tricky bit was adjusting the order that things were done in the  
RULES array so that the different changes didn’t clash.

Tom

---

<div class="post-metadata">

**Author:** ![Daniel\_VSSSSlkerts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@Daniel\_VSSSSlkerts](https://www.ruby-forum.com/u/Daniel_VSSSSlkerts)\
**Post date:** [May 22, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/extending-redcloth/61281/3 "2006-05-22T19:50:10Z")

</div>

Tom Counsell schrieb:

> [http://www.counsell.org/darcs/soks-development/lib/soks-view.rb](http://www.counsell.org/darcs/soks-development/lib/soks-view.rb)
> 
> The tricky bit was adjusting the order that things were done in the  
> RULES array so that the different changes didn’t clash.

Thanks a lot. I would be helpful if there are any #register(…) methods  
were I can hook in my extensions and which handle the rule thing  
correctly. But for my needs I cascade the call, e.g. following the  
example on the RedCloth side:

s = RedCloth.new “_simple_ test with !C! Attention”

followed by a chain of s.gsub!(“”) goals. So I’m not  
threating the RedCoth thing and it is aware of further RedCloth updates  
(as I don’t any rules internally).

Thanks for your fast help,
