RedCloth bug and suggestion

why and fellow RedCloth users,

I think I’ve found a bug in RedCloth. Actually, I think it’s a bug in
Textile because the Textile site does the same thing. The text

bq. -- some text

turns into

<p>bq.&#8212;some text</p>

instead of

<blockquote>
	<p>&#8212;some text</p>
</blockquote>

It looks like RedCloth is following the Textile “spec” (though I can’t
find one anywhere). Is anyone else surprised by this output?

Also, I’d like to know if Textile is supposed to preserve newlines.
When I have text like

A paragraph that spans
multiple lines.

it gets translated to

<p>A paragraph that spans<br />
multiple lines.</p>

when what I would like is

<p>A paragraph that spans
multiple lines.</p>

Is there a setting I can change so that more than one newline starts a
new paragraph but a single newline does not?

Thank you.

Jim

···


Jim Menard, jimm@io.com, http://www.io.com/~jimm/
“I went on the Internet to find out how to prevent squirrel damage.”
– Betty March

Jim Menard wrote:

bq. -- some text

turns into

<p>bq.&#8212;some text</p>

The rule was: if an em-dash ‘–’ is surrounded by spaces, the spaces get
stripped, so the dash can snug up against the words it’s near.

But, in the case of a period, I think we should keep the space. So the
above should work now and sentences which start with an em-dash should
be easier to look on.

It looks like RedCloth is following the Textile “spec” (though I can’t
find one anywhere). Is anyone else surprised by this output?

The spec is the PHP source code, the regexps.

Also, I’d like to know if Textile is supposed to preserve newlines. When
I have text like

A paragraph that spans
multiple lines.

it gets translated to

<p>A paragraph that spans<br />
multiple lines.</p>

when what I would like is

<p>A paragraph that spans
multiple lines.</p>

Is there a setting I can change so that more than one newline starts a
new paragraph but a single newline does not?

No. Personally, I use YAML to handle the folding of my text. So the
above could be stored in my YAML:

--- >
A paragraph that spans
multiple lines.

Then, RedCloth.new( YAML::load( above_string ) ).to_html.

So, if you like, I could strip the folding code out of the old YAML.rb
and use it in RedCloth.

_why

why,

Jim Menard wrote:

bq. -- some text

turns into

bq.—some text

The rule was: if an em-dash ‘–’ is surrounded by spaces, the spaces
get stripped, so the dash can snug up against the words it’s near.

But, in the case of a period, I think we should keep the space. So
the above should work now and sentences which start with an em-dash
should be easier to look on.

Thank you.

Just a thought: should there be a magic string that forces the space to
stay there, like using “{}” in LaTeX?

No. Personally, I use YAML to handle the folding of my text. So the
above could be stored in my YAML:

— >
A paragraph that spans
multiple lines.

Then, RedCloth.new( YAML::load( above_string ) ).to_html.

Do you write your docs and Web pages in YAML? I’m writing things like
articles and documentation. In LaTeX, multiple lines turn into a single
justified paragraph.

So, if you like, I could strip the folding code out of the old YAML.rb
and use it in RedCloth.

That would be great. Again, if there was a way to turn that off (with
folding on by default), that would be nice.

Thank you.

Jim

···

On Apr 9, 2004, at 11:13 AM, why the lucky stiff wrote:

Jim Menard, jimm@io.com, http://www.io.com/~jimm/
“Hey, wait a minute. You’ve got both eyes! You’re no special agent.
You’re just some jerk who hates my moustache!” - The Tick

I’d like this too. I write textile in Emacs using auto-fill mode. This is
my current hack to remove the line breaks:

html = RedCloth.new( File.read( file )).to_html
html.gsub(/<br />/, ‘’)

But i know this isn’t a general solution.

If redcloth were to automatically fold lines, how would i indicate a line
that i don’t want to be folded? E.g. suppose i also have a mail address.
Would i just include <br> at the end of each line? Would textile need a
new directive?

Bret

···

At 10:13 AM 4/9/2004, why the lucky stiff wrote:

So, if you like, I could strip the folding code out of the old YAML.rb and
use it in RedCloth.


Bret Pettichord, Software Tester
Consultant - www.pettichord.com
Author - www.testinglessons.com
Blogger - www.io.com/~wazmo/blog

Homebrew Automation Seminar
April 30, Austin, Texas
www.pettichord.com/training.html

Jim Menard wrote:

So, if you like, I could strip the folding code out of the old YAML.rb
and use it in RedCloth.

That would be great. Again, if there was a way to turn that off (with
folding on by default), that would be nice.

checked into redcloth cvs. there’s a :fold_lines accessor which can be
used to toggle it.

r = RedCloth.new “… text …”
r.fold_lines = true
r.to_html

basically, it just treats single newlines like a space.

_why

why,

checked into redcloth cvs. there’s a :fold_lines accessor which can
be used to toggle it.

r = RedCloth.new “… text …”
r.fold_lines = true
r.to_htmlthrough

basically, it just treats single newlines like a space.

Thank you. It works for paragraphs, but not list items. If I have

* item one
* item two that spans
  multiple lines
* item three

the output is

<ul>
<li>item one</li>
	<li>item two that spans</li>
</ul> multiple lines
<ul>
<li>item three</li>
</ul>

RedCloth works by performing substitutions in the text all at once, if
I’m not mistaken. I’m not sure that this situation can be handled by
search-and-replace; I think you have to walk the string with a state
machine and further complicate Textile’s rules by saying “a line item
ends not with a newline but with multiple newlines or with the start of
a new line item”. Ugh.

Jim

···


Jim Menard, jimm@io.com, http://www.io.com/~jimm/
“No quantity can be harder to perceive and harder to measure than
innovation that never occurs.” – J. Gleik

Any reason you good folks didn’t just use the RDoc markup library for
all this? Adding backends to generate LaTeX (if you need it) is trivial
(I’ve got one lying around here somewhere that I wrote for Andy).

The markup library is independent of RDoc itself: I use it in RubLog,
for example.

Cheers

Dave

···

On Apr 10, 2004, at 6:39, Jim Menard wrote:

Thank you. It works for paragraphs, but not list items. If I have

  • item one
  • item two that spans
    multiple lines
  • item three

Jim Menard wrote:

Thank you. It works for paragraphs, but not list items. If I have

* item one
* item two that spans
  multiple lines
* item three

the output is

<ul>
<li>item one</li>
    <li>item two that spans</li>
</ul> multiple lines
<ul>
<li>item three</li>
</ul>

ok, well, folding was happening after lists and tables, but now i’ve
moved it to take place before. it still doesn’t work like the above.
currently, you can’t align the text like you have it above, it doesn’t
wrap lines which begin with spaces.

an equivalent for now would be:

 * item one
 * item two that spans
 multiple lines
 * item three

RedCloth works by performing substitutions in the text all at once, if
I’m not mistaken. I’m not sure that this situation can be handled by
search-and-replace; I think you have to walk the string with a state
machine and further complicate Textile’s rules by saying “a line item
ends not with a newline but with multiple newlines or with the start of
a new line item”. Ugh.

i’ve thought about moving to a full-fledged parser, but it’ll have to
wait a while.

_why

Dave Thomas wrote:

Any reason you good folks didn’t just use the RDoc markup library for
all this? Adding backends to generate LaTeX (if you need it) is trivial
(I’ve got one lying around here somewhere that I wrote for Andy).

do you mean use RDoc to write a Textile machine? or drop Textile and
stick with RDoc?

i was looking around RDoc’s SimpleMarkup classes today because I figured
your query meant the first. i had no idea RDoc could be extended for
new markups.

i hadn’t really thought about RDoc at all. i primarily wrote RedCloth
because I have friends who use Textile in other languages and i wanted
them to use Ruby for their websites. i also really like Textile and
wanted to use it in my book.

_why

Dave,

Any reason you good folks didn’t just use the RDoc markup library for
all this?

No good reason. I like trying shiny, new things; thus my
experimentation with Textile and RedCloth. It looks like Textile is too
simple for most of my needs.

I hadn’t thought of using RDoc, but that makes sense. Right now, I’m
working on a talk and I’m tired of typing “

” or
“\begin{itemize} \item … \end{itemize}”.

Adding backends to generate LaTeX (if you need it) is trivial (I’ve
got one lying around here somewhere that I wrote for Andy).

I will eventually publish the talk on my Web site, so I want one output
format to be XHTML and to use my style sheet.

I hadn’t yet played with writing a new RDoc back end. It’s time, but
only after I finish writing the talk. I’ve been procrastinating for too
long now.

The markup library is independent of RDoc itself: I use it in RubLog,
for example.

Jim

···


Jim Menard, jimm@io.com, http://www.io.com/~jimm/
“Master, does Emacs have the Buddha nature?” the novice asked.
“I don’t see why not. It’s got bloody well everything else.”
– John Fouhy

Jim Menard wrote:

Any reason you good folks didn’t just use the RDoc markup library for
all this?

No good reason. I like trying shiny, new things; thus my experimentation
with Textile and RedCloth. It looks like Textile is too simple for most
of my needs.

I hadn’t thought of using RDoc, but that makes sense. Right now, I’m
working on a talk and I’m tired of typing “

” or
“\begin{itemize} \item … \end{itemize}”.

I use RDoc as a backend to a presentation builder. I write all the
slides in RDoc format (with some enhancements) and then generate the
HTML for the presentation. (you can see an example at
Rake - Building with Rake. I used CSS
to configure the output for my 800x600 laptop.)

So, its pretty easy to use RDoc a backend.

···


– Jim Weirich jim@weirichhouse.org http://onestepback.org

“Beware of bugs in the above code; I have only proved it correct,
not tried it.” – Donald Knuth (in a memo to Peter van Emde Boas)

Unless I’ve missed something, you’ll still be typing

” in RDoc’s markup. Its shortcuts (“” etc)
are only valid for a single word, and are rendered invalid if that
word has anything untoward (like an underscore) in it.

Cheers,
Gavin

···

On Sunday, April 11, 2004, 3:31:40 AM, Jim wrote:

I hadn’t thought of using RDoc, but that makes sense. Right now, I’m
working on a talk and I’m tired of typing “

” or
“\begin{itemize} \item … \end{itemize}”.

Jim,

I use RDoc as a backend to a presentation builder. I write all the
slides in RDoc format (with some enhancements) and then generate the
HTML for the presentation. (you can see an example at
Rake - Building with Rake. I used
CSS to configure the output for my 800x600 laptop.)

Can you share your enhancements?

Jim

···


Jim Menard, jimm@io.com, http://www.io.com/~jimm/
Dash dash space newline
Four-line witty quotation
Perfect message end
– Donald Welsh in rec.humor.oracle.d

In RDoc, the list would be

  • first item
  • second
    item

Not a

    in sight…

    Cheers

    Dave

    ···

    On Apr 10, 2004, at 19:26, Gavin Sinclair wrote:

    On Sunday, April 11, 2004, 3:31:40 AM, Jim wrote:

    I hadn’t thought of using RDoc, but that makes sense. Right now, I’m
    working on a talk and I’m tired of typing “

    ” or
    “\begin{itemize} \item … \end{itemize}”.

    Unless I’ve missed something, you’ll still be typing

    ” in RDoc’s markup. Its shortcuts (“” etc)
    are only valid for a single word, and are rendered invalid if that
    word has anything untoward (like an underscore) in it.

Whoops. Brainfart :slight_smile:

Gavin

···

On Sunday, April 11, 2004, 11:38:09 AM, Dave wrote:

On Apr 10, 2004, at 19:26, Gavin Sinclair wrote:

On Sunday, April 11, 2004, 3:31:40 AM, Jim wrote:

I hadn’t thought of using RDoc, but that makes sense. Right now, I’m
working on a talk and I’m tired of typing “

” or
“\begin{itemize} \item … \end{itemize}”.

Unless I’ve missed something, you’ll still be typing

” in RDoc’s markup. Its shortcuts (“” etc)
are only valid for a single word, and are rendered invalid if that
word has anything untoward (like an underscore) in it.

In RDoc, the list would be

  • first item
  • second
    item

Not a

    in sight…