RedCloth issues

A

Adam Shelly

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.

2) I found a pathological case. At first I thought it was due to the
literal text "<code>" 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:

<p>comment</p>
<pre><code>line = "\n"+misplaced</code></pre>

but it produces

<p>comment
“+misplaced</p>


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


Can I fix these by setting rules in the to_html call, or are these bugs?
-Adam
 
L

Louis J Scoras

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:

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</p>

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.

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.
 
L

Louis J Scoras

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.
 
L

Louis J Scoras

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.
 
A

Adam Shelly

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.

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 <strong> 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.

2) 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 <pre><code>...</code></pre> 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top