RedCloth bug and suggestion

J

Jim Menard

_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.—some text</p>

instead of

<blockquote>
<p>—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
 
W

why the lucky stiff

Jim said:
bq. -- some text

turns into

<p>bq.—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
 
J

Jim Menard

_why_,

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
 
B

Bret Pettichord

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

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


______________________________________
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
 
W

why the lucky stiff

Jim said:
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
 
J

Jim Menard

_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
 
D

Dave Thomas

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

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

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
 
W

why the lucky stiff

Jim said:
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
 
W

why the lucky stiff

Dave said:
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
 
J

Jim Menard

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
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
 
J

Jim Weirich

Jim said:
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 "<ul><li>...</li></ul>" 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
http://onestepback.org/articles/buildingwithrake/index.html. I used CSS
to configure the output for my 800x600 laptop.)

So, its pretty easy to use RDoc a backend.
 
J

Jim Menard

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
http://onestepback.org/articles/buildingwithrake/index.html. I used
CSS to configure the output for my 800x600 laptop.)

Can you share your enhancements?

Jim
--
Jim Menard, (e-mail address removed), http://www.io.com/~jimm/
Dash dash space newline
Four-line witty quotation
Perfect message end
-- Donald Welsh in rec.humor.oracle.d
 
G

Gavin Sinclair

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 "<ul><li>...</li></ul>" or
"\begin{itemize} \item ... \end{itemize}".

Unless I've missed something, you'll still be typing
"<ul><li>...</li></ul>" 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
 
D

Dave Thomas

Unless I've missed something, you'll still be typing
"<ul><li>...</li></ul>" 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 <ul> in sight...


Cheers

Dave
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top