What's the best way to write a Textile-to-PDF::Writer converter?

A

Andreas Semt

Hello list!

I am relative new to Ruby, so i ask:
What's the best way to develop a *pure* Ruby Textile-to-PDF::Writer
converter? I use the Soks Wiki (http://rubyforge.org/projects/soks/ by
Tom Counsell) for documentation purpose on work (on a W2K Pro Box). This
wiki saves the page content in flat text files in the Textile Markup
language, so i want a converter to generate PDF files from these Textile
files. Austin Ziegler has a RubyForge project
(http://rubyforge.org/projects/ruby-pdf/) for writing PDF files in Ruby.
So all parts of my imaginary pure Ruby Textile-to-PDF::Writer converter
are there, however i wonder how to use them?

Thanks for any help or suggestions!

Greetings,
Andreas
 
A

Austin Ziegler

I am relative new to Ruby, so i ask:
What's the best way to develop a *pure* Ruby Textile-to-PDF::Writer
converter? I use the Soks Wiki (http://rubyforge.org/projects/soks/ by
Tom Counsell) for documentation purpose on work (on a W2K Pro Box). This
wiki saves the page content in flat text files in the Textile Markup
language, so i want a converter to generate PDF files from these Textile
files. Austin Ziegler has a RubyForge project
(http://rubyforge.org/projects/ruby-pdf/) for writing PDF files in Ruby.
So all parts of my imaginary pure Ruby Textile-to-PDF::Writer converter
are there, however i wonder how to use them?

I don't know, offhand, but if you want to definitely do this and
contribute it to PDF::Writer, I will happily work with you on that --
this has been part of a goal of PDF::Writer (the specification of a
better formatting language than the simple one that I support right
now).

My problem is mostly that I don't really know Textile, and I'm deep in
the middle of Text::Format, with a bit of review of a new port of
Text::Reform. After that, I *must* work on Diff::LCS and Ruwiki again,
but I also need to get a PDF::Writer release out the door that
captures a font fix that I made last week (so you definitely want the
CVS HEAD version of PDF::Writer).

By contributing something like this to PDF::Writer, I will also make
sure that as the API for PDF::Writer changes (and I promise that it
will), the converter is kept up to date.

-austin
 
J

John Labovitz

I don't know, offhand, but if you want to definitely do this and
contribute it to PDF::Writer, I will happily work with you on that --
this has been part of a goal of PDF::Writer (the specification of a
better formatting language than the simple one that I support right
now).

(This is mostly a response to Andreas; it probably won't be news to
Austin.)

I've been using PDF::Writer to do some graphical charting, so I'm not
so familiar with its text processing. But I'll take a guess on how to
do this.

When you use the #ez_text method, the text you pass in can be a big
block of text, possibly spanning multiple pages. The text can have
HTML-like markup. The text processing code in PDF::Writer will
apparently handle all the details of wrapping lines, spacing
paragraphs, and breaking pages. So for a first pass (assuming you
don't need to control page breaks), you might work on a simple
Textile-to-ez_text converter.

If you haven't seen it, you should look at RedCloth, which is an
implementation of a Textile-to-HTML converter. It doesn't appear to be
very extensible -- its HTML generation seems all wrapped up in the
parsing -- but at only 1000 lines of code, maybe it would be a good
thing to build on.

--
John Labovitz
Macintosh support, research, and software development
John Labovitz Consulting, LLC
(e-mail address removed) | +1 503.949.3492 |
www.johnlabovitz.com/consulting
 
A

Andreas Semt

Hello Austin!

I want just a little converter for my Soks content, no big deal. However
i could (later) expand this little converter to a more general tool for
converting Textile-to-PDF using PDF::Writer.
(This is mostly a response to Andreas; it probably won't be news to
Austin.)

I've been using PDF::Writer to do some graphical charting, so I'm not so
familiar with its text processing. But I'll take a guess on how to do
this.

When you use the #ez_text method, the text you pass in can be a big
block of text, possibly spanning multiple pages. The text can have
HTML-like markup. The text processing code in PDF::Writer will
apparently handle all the details of wrapping lines, spacing paragraphs,
and breaking pages. So for a first pass (assuming you don't need to
control page breaks), you might work on a simple Textile-to-ez_text
converter.

Hello John!

Thanks for that hint. However "ez_text" does not support formatting of
any kind (for example: bold, italic, ...). So i will use other methods.
If you haven't seen it, you should look at RedCloth, which is an
implementation of a Textile-to-HTML converter. It doesn't appear to be
very extensible -- its HTML generation seems all wrapped up in the
parsing -- but at only 1000 lines of code, maybe it would be a good
thing to build on.

Yes, it's a good starting point. "redcloth.rb" and Austin Ziegler's
"readme.rb" example will guide me ;-)

Greetings,
Andreas
 
J

John Labovitz

Thanks for that hint. However "ez_text" does not support formatting of
any kind (for example: bold, italic, ...). So i will use other
methods.

Ah. #ez_text supports "callbacks" for formatting, but #add_text (in
the base class) *does* support <b> and <i> formatting.

--
John Labovitz
Macintosh support, research, and software development
John Labovitz Consulting, LLC
(e-mail address removed) | +1 503.949.3492 |
www.johnlabovitz.com/consulting
 
A

Andreas Semt

Austin said:
I don't know, offhand, but if you want to definitely do this and
contribute it to PDF::Writer, I will happily work with you on that --
this has been part of a goal of PDF::Writer (the specification of a
better formatting language than the simple one that I support right
now).

My problem is mostly that I don't really know Textile, and I'm deep in
the middle of Text::Format, with a bit of review of a new port of
Text::Reform. After that, I *must* work on Diff::LCS and Ruwiki again,
but I also need to get a PDF::Writer release out the door that
captures a font fix that I made last week (so you definitely want the
CVS HEAD version of PDF::Writer).

By contributing something like this to PDF::Writer, I will also make
sure that as the API for PDF::Writer changes (and I promise that it
will), the converter is kept up to date.

-austin

Hello Austin!

a question to your "readme.rb" example file: In the "data.txt" file you say:
--- snip ---
# <b></b> <i></i> can be used within the text with gleeful abandon
--- snap ---

Could you *please* explain how you parse these "bold" and "italic" tags
in the "readme.rb" file? I have not discovered it yet :-(


John said:
Ah. #ez_text supports "callbacks" for formatting, but #add_text (in the base class) *does* support <b> and <i> formatting.

Hello John!

Thanks ... will use the #add_text method.

Greetings,
Andreas
 
A

Austin Ziegler

Hello Austin!

a question to your "readme.rb" example file: In the "data.txt"
file you say: --- snip --- # <b> </b> <i> </i> can be used within
the text with gleeful abandon --- snap ---

Could you *please* explain how you parse these "bold" and "italic"
tags in the "readme.rb" file? I have not discovered it yet :-(

Look at writer.rb:398 (set_current_font); it refers to
@current_text_state. This is set (currently) in
prvt_check_text_directive1 (line 646). It's an awful hack, but this
is what was in the original code. This is the sort of thing that I
hope to greatly improve in the future. That is to say that <b> and
<i> are built into the writer and are only supported if the font(s)
involved support them. That latter restriction will probably always
be true, but ...

-austin
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top