RedCloth issues

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

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.

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.

On 11/24/06, Paul L. [email protected] 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.

On 11/24/06, Paul L. [email protected] 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.

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. :slight_smile:

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.

On 11/25/06, Paul L. [email protected] wrote:

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

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.

Louis J Scoras wrote:

On 11/25/06, Paul L. [email protected] wrote:

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

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.

On 11/25/06, Paul L. [email protected] 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