# RedCloth issues

**URL:** <https://www.ruby-forum.com/t/redcloth-issues/76938>\
**Category:** Ruby\
**Created:** [November 22, 2006, 4:40pm UTC](https://www.ruby-forum.com/t/redcloth-issues/76938 "2006-11-22T16:40:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 22, 2006, 4:40pm UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/1 "2006-11-22T16:40:53Z")

</div>

I used RedCloth for the first time for my Quiz entry, and I came  
across a few unexpected features…

1. something as simple as

text = \<\<EOT  
Double the value of ‘a’.

a\*=2

also double ‘b’

b\*=2  
EOT  
puts RedCloth.new(text).to\_html()

gets rendered with the stars in the code gone and the text turned bold  
between them.

1. I found a pathological case. At first I thought it was due to the  
literal text “`” inside a code block, but I reduced it to:`

text = \<\<EOT  
comment

```
  line = "\n"+misplaced

```

EOT  
puts RedCloth.new(text).to\_html()

It should return something like:

comment

```
line = "\n"+misplaced
```

but it produces

comment “+misplaced

```
<pre><code>line = "</code></pre>

```

Can I fix these by setting rules in the to\_html call, or are these  
bugs?  
-Adam

---

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 24, 2006, 9:39pm UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/2 "2006-11-24T21:39:01Z")

</div>

Adam S. wrote:

> I used RedCloth for the first time for my Quiz entry,

I thin it would be better if we stepped back about ten paces. Please say  
what your goal is. Is it to produce a presentable HTML version of plain  
text?

I ask because you are trying to use a Ruby package named RedCloth, whose  
purpose it is to convert ordinary text into presentable text, by way of  
…  
Textile, whose purpose it is to convert ordinary text into presentable  
text, by way of … HTML, whose purpose is to make presentable text out  
of  
ordinary text.

Not surprisingly, given this baroquely complex series of filters and  
layers:

> … I came  
> across a few unexpected features…

I would have been surprised if you had _not_ encountered such  
inconsistencies or “features” in such a complex scheme.

So again, please say what the disease is, not the remedy. Let’s try to  
work  
from there.

> Can I fix these by setting rules in the to\_html call, or are these bugs?

The only bug I see is the sheer complexity of the overall scheme.

---

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 25, 2006, 12:15am UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/3 "2006-11-25T00:15:37Z")

</div>

Louis J Scoras wrote:

/ …

> > Not surprisingly, given this baroquely complex series of filters and  
> > layers:
> > 
> > > … I came  
> > > across a few unexpected features…
> 
> Sheesh. What’s with the unabashed library hating lately? =)

I don’t actually hate the idea of using a library. I just feel bad for  
people who choose the wrong library, or who haven’t considered any other  
way to solve a problem.

> instead.

And he can’t figure out why, and I can. So I explained it.

> > I would have been surprised if you had _not_ encountered such  
> > inconsistencies or “features” in such a complex scheme.
> > 
> > So again, please say what the disease is, not the remedy. Let’s try to  
> > work from there.
> 
> He needs textile to be rendered correctly. That IS the problem.

No the problem is his having chosen RedCloth to try to solve a Textile  
problem, which was originally meant to solve an HTML problem, which was  
originally meant to solve a general markup problem.

/ …

> > The only bug I see is the sheer complexity of the overall scheme.
> 
> No, the concept is actually rather simple.

I’ll say – there is no chance that this elaborate, multilayered scheme  
will  
work. That part is very simple.

> It’s a minimal markup  
> language that exists because typing html by hand sucks.

And this represents the ultimate solution to the drudgery of writing  
HTML by  
hand. First, someone (now justly famous) wrote HTML to solve the problem  
that most markup languages were too hard to use. Then someone wrote  
Textile  
because HTML was too hard to use. Then someone wrote RedCloth because  
Textile was too hard to use.

And during this process, no one bothered to ask what the point was, or  
whether the process of layering would eventually get to a point where  
the  
entire scheme would collapse, and people would be reduced to writing  
simple  
solutions to simple problems.

---

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 24, 2006, 10:35pm UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/4 "2006-11-24T22:35:22Z")

</div>

On 11/24/06, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Not surprisingly, given this baroquely complex series of filters and layers:
> 
> > … I came  
> > across a few unexpected features…

Sheesh. What’s with the unabashed library hating lately? =)

He stated his problem adequately. He wanted something like this:

```
<p>Double the value of 'a'.</p>
<pre>a*=2</pre>
<p>also double 'b'</p>
<pre>b*=2</pre>

```

and got something like this,

```
<p>Double the value of 'a'. a <bold>=2 also double 'b' b</bold> 

```

2

instead.

> I would have been surprised if you had _not_ encountered such  
> inconsistencies or “features” in such a complex scheme.
> 
> So again, please say what the disease is, not the remedy. Let’s try to work  
> from there.

He needs textile to be rendered correctly. That IS the problem. See  
his sumission to the last rubyquiz.

> > Can I fix these by setting rules in the to\_html call, or are these bugs?

Sorry Adam, I’m not really sure. I’ve only used Markdown.

> The only bug I see is the sheer complexity of the overall scheme.

No, the concept is actually rather simple. It’s a minimal markup  
language that exists because typing html by hand sucks.

---

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 25, 2006, 2:15am UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/5 "2006-11-25T02:15:54Z")

</div>

On 11/24/06, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I don’t actually hate the idea of using a library. I just feel bad for  
> people who choose the wrong library, or who haven’t considered any other  
> way to solve a problem.

I know you don’t; but I think he did consider the problem more than  
you’re giving him credit for. HTML is obviously a very convenient  
output format, but the problem with it is that it isn’t easy to read.  
If you’re writing a system for documentation that needs to be readable  
and writable wiki markup is a good way to go. That’s what it was  
designed for.

> And he can’t figure out why, and I can. So I explained it.

Sure. But I disagree that it’s because the scheme he proposed is  
unworkable. You’re not suggesting that harder problems haven’t been  
solved are you?

> No the problem is his having chosen RedCloth to try to solve a Textile  
> problem, which was originally meant to solve an HTML problem, which was  
> originally meant to solve a general markup problem.

Don’t you think you’re being a little unfair? RedCloth doesn’t try to  
solve a textile problem. They are both the same layer. Similarly,  
HTML is a very real target.

```
Textile -> HTML

```

> I’ll say – there is no chance that this elaborate, multilayered scheme will  
> work. That part is very simple.

It can work, and it does work. This isn’t the first project to use  
textile.

> And this represents the ultimate solution to the drudgery of writing HTML by  
> hand. First, someone (now justly famous) wrote HTML to solve the problem  
> that most markup languages were too hard to use. Then someone wrote Textile  
> because HTML was too hard to use. Then someone wrote RedCloth because  
> Textile was too hard to use.
> 
> And during this process, no one bothered to ask what the point was, or  
> whether the process of layering would eventually get to a point where the  
> entire scheme would collapse, and people would be reduced to writing simple  
> solutions to simple problems.

I suppose we’ll just have to agree to disagree. I don’t think that  
this “scheme” is overly complicated. Just because there might be a  
bug in the implementation doesn’t mean that the problem is too  
complicated, nor that the tool is broken beyond fixing.

---

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 25, 2006, 8:16am UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/6 "2006-11-25T08:16:27Z")

</div>

Louis J Scoras wrote:

/ …

> > And he can’t figure out why, and I can. So I explained it.
> 
> Sure. But I disagree that it’s because the scheme he proposed is  
> unworkable. You’re not suggesting that harder problems haven’t been  
> solved are you?

The fact that much harder problems has been solved isn’t an argument  
that  
this one has been. 🙂

> > No the problem is his having chosen RedCloth to try to solve a Textile  
> > problem, which was originally meant to solve an HTML problem, which was  
> > originally meant to solve a general markup problem.
> 
> Don’t you think you’re being a little unfair? RedCloth doesn’t try to  
> solve a textile problem. They are both the same layer. Similarly,  
> HTML is a very real target.
> 
> ```
> Textile -> HTML
> 
> ```

All except the part where it didn’t work.

> > I’ll say – there is no chance that this elaborate, multilayered scheme  
> > will work. That part is very simple.
> 
> It can work, and it does work. This isn’t the first project to use  
> textile.

You are arguing that it should work in principle, even if it doesn’t  
work in  
fact. And I agree.

/ …

> I suppose we’ll just have to agree to disagree. I don’t think that  
> this “scheme” is overly complicated. Just because there might be a  
> bug in the implementation doesn’t mean that the problem is too  
> complicated, nor that the tool is broken beyond fixing.

Yes. Agreed. My point is that there are much simpler solutions.

---

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 25, 2006, 4:13pm UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/7 "2006-11-25T16:13:14Z")

</div>

On 11/25/06, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The fact that much harder problems has been solved isn’t an argument that  
> this one has been. 🙂

That’s not what I’m suggesting. Perhaps I misunderstand–indeed I’ve  
been known to do that from time to time =). You seem to be arguing  
that, due to the inherent complexity, the problem is insurmountable or  
at least so complex that its not worth the effort to find the  
solution.

I don’t really think it’s that hard of a problem.

> All except the part where it didn’t work.

_Chuckles._ Of course. The best-laid schemes o’ mice an’ men and all  
that.

> You are arguing that it should work in principle, even if it doesn’t work in  
> fact. And I agree.
> 
> Yes. Agreed. My point is that there are much simpler solutions.

And so we come to the point where both parties discover that there  
isn’t much disagreement over most of the substantive points. That  
being said, I need to ask what you think simpler solutions are. Mind  
you I ask this not in a glove-slapping, defend your honor type of way.  
On the contrary, I’d be genuinely interested in such a solution.

---

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 25, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/8 "2006-11-25T19:51:35Z")

</div>

Louis J Scoras wrote:

> On 11/25/06, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > The fact that much harder problems has been solved isn’t an argument that  
> > this one has been. 🙂
> 
> That’s not what I’m suggesting. Perhaps I misunderstand–indeed I’ve  
> been known to do that from time to time =).

Me too.

> You seem to be arguing  
> that, due to the inherent complexity, the problem is insurmountable or  
> at least so complex that its not worth the effort to find the  
> solution.

No, not at all. I am saying that a much simpler solution would work  
where  
this one will not.

> I don’t really think it’s that hard of a problem.

It doesn’t matter how hard or easy it is. It only matters that the OP  
can’t  
get the desired result from the present solution.

> And so we come to the point where both parties discover that there  
> isn’t much disagreement over most of the substantive points. That  
> being said, I need to ask what you think simpler solutions are. Mind  
> you I ask this not in a glove-slapping, defend your honor type of way.  
> On the contrary, I’d be genuinely interested in such a solution.

Very simple: tell me what the requirement is. I will then post a  
solution.  
The solution will (1) work, and (2) not be large or incomprehensible –  
or  
I will fail, and if that happens I will say so.

And further, if the solution I create were to be taken as a total  
solution  
to all such problems, and if the adopter didn’t even consider editing it  
to  
accommodate new cases, then it would become part of the problem, not the  
solution, just like the present “solution” is.

I suspect that the present difficulty arose because whoever wrote  
Textile  
did so to solve all imaginable problems with HTML formatting, then  
whoever  
wrote RedCloth did so to solve all imaginable problems with Textile  
formatting. I suspect both authors did this because it was easier to  
build  
onto the edifice than to try to understand and change the prior code.  
But  
both authors also wrote a lot of code to avoid leaving out any  
possibilities – except what the OP wants to do – and therefore their  
code  
is rather difficult to change.

Now we have an OP who can’t use RedCloth to talk to Textile to talk to  
HTML,  
to get presentable HTML. The solution is obvious – start over. I  
suspect  
that I can produce a solution in a few lines of Ruby, and if I can’t I  
will  
say so.

---

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [November 25, 2006, 9:29pm UTC](https://www.ruby-forum.com/t/redcloth-issues/76938/9 "2006-11-25T21:29:44Z")

</div>

On 11/25/06, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > in fact. And I agree.  
> > > The solution will (1) work, and (2) not be large or incomprehensible – or  
> > > I will fail, and if that happens I will say so.

Ok, I’ll jump back into my question, after a 2 day break for turkey  
gluttony.

I think the ‘requirement’ could be stated at two levels.

1. In the simplest case, it is to take a string formatted according to  
the RedCloth rules, and to have code blocks in that string render  
correctly. Where ‘correctly’ means that  
a) text inside code blocks is not interpreted as markup - specifically  
that pairs of asterisks don’t get replaced by **tags.  
b) all the words are rendered in the original order, so that given**
 
 

**text = \<\<EOT  
comment**

 

**```
   line = "\n"+misplaced**

**```**

 

**EOT  
puts RedCloth.new(text).to\_html()**

 

**the word ‘misplaced’ does not appear before ‘line’ in the resulting  
html.**

 
**1. The real requirement (needed for my RubyQuiz solution) is: Be able  
to enter code blocks in the ‘junebug’ wiki (which is built on the  
RedCloth and Camping libraries) and have the code render correctly, as  
defined above.**

 

**I actually found a ‘simple’ solution to all of these requirements:  
Don’t use markdown style code blocks (indicated by indenting 4 spaces)  
in RedCloth. Insert the**

 

**```
…
```**

 **tags yourself  
when entering code into the wiki. I can live with that - although it  
takes away some of the ease of use which led me to choose a wiki in  
the first place.**

 

**On the other hand, I think requirement 1b can be viewed as a failed  
unit test for RedCloth. RedCloth is supposed to support the markdown  
formatting rules, yet in this case you get misplaced text even if you  
restrict it to the markdown ruleset with  
`RedCloth.new(text).to_html(:markdown)`**

 

**I was hoping someone would address that issue.**

 

**-Adam**
