OpenOffice.org in the Limelight

How CHIP Special Linux uses OpenOffice.org Writer as an editorial tool in a multiplatform publishing house.
HTML Format

Obtaining proper documents in HTML format is slightly more difficult. StarWriter and OpenOffice.org Writer produce sophisticated HTML, as shown in Figure 2. You can convert this HTML, however, by using a simple Perl script. I call mine soffice2html. At the beginning of the script, you should instruct it to replace line endings by spaces, like this:


s/\n/ /;

Next, you can replace some elements of the code with different ones. For example, using the commands:


s/<(\/?)B>/<$1STRONG>/g;
s/<(\/?)I>/<$1EM>/g;

you can replace all <B> ... </B> and <I> ... </I> tag pairs with <STRONG> ... </STRONG> and <EM> ... </EM> tag pairs, so bold and italic is noted according to established standards. You then can remove unwanted tags, such as:


s/<EM><EM>/<EM>/g;
s/<\/EM><\/EM>/<\/EM>/g;

After this, it is good idea to restore some line endings. Simple commands such as:


s/(.+?)</$1\n</g;
s/>(.+?)/>\n$1/g;

put the marks of the line end before and after each HTML tag. To make your script more professional, you can add the finishing touch by using the command:


print OUT "<!-- ", "soffice2html: ",
          scalar localtime, " -->\n";

This adds a comment to the processed HTML file, which is something like:


<!-- soffice2html: Wed Jul 23 17:34:35 2003 -->

Now, if you start with document.sxw and export it to document.html, you should process the latter one using the command soffice2html document.html (Figure 3). Filtering HTML files in this way produces better—that is, more standardized and more readable—code and from 15%–40% smaller files. The current version of the ooo-macro bundle includes the soffice2html script.

To produce a simple Macintosh text file from a document, you should save it in the Text Encoded file type that uses the appropriate character set. For Polish documents, for example, the valid set is Eastern Europe.

This method of exporting is good enough for common tasks, but it's not so good for typographic purposes. Our articles often need to use symbols for keystrokes when discussing specific tasks and other special characters. When you use the standard method to produce Macintosh text files, you lose all those characters. To keep them, you need a macro to convert the characters from UTF-8 to the Macintosh codepage. The appropriate macro, recode_utf_8_to_apple_macintosh, is a part of the ooo-macro bundle.

In order to produce a text file using the above-mentioned macro, run it and then save the document as a Text Encoded file type by using System character set and CR paragraph breaks. The file includes information that makes the typesetter's job faster and easier.

In the Limelight

Using OpenOffice.org Writer as an editorial tool allows you to process documents and share them among authors, proofreaders and typesetters in a way that is transparent for everyone involved. You need only Writer, some TrueType fonts, a small bundle of macros and the Perl script for preparing nice HTML files.

Resources for this article: www.linuxjournal.com/article/7925.

Cezary M. Kruk lives in Wroclaw, Poland. He is an editor for the Polish quarterly, CHIP Special Linux.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Are the Perl scripts available?

Hobgoblin's picture

Interesting reading - I was particularly interested in the way that 'clean' HTML can be obtained from the raw HTML output of Ooo writer. Are the Perl scripts available?

TIA
H.

It looks like these perl scri

Anonymous's picture

It looks like these perl scripts manipulate tags using regular expressions. There are too many edge cases for this to be a good idea. Much better would be to properly parse the HTML, tidy it and walk the DOM tree to remove unwanted elements. The HTML section at CPAN looks like a good place to start doing that. Mind you, there are also interfaces to manipulate OOo documents directly. Good luck, happy hacking!

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

Webcast
8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
On Demand
Moderated by Linux Journal Contributor Mike Diehl

Sign up and watch now

Sponsored by Skybot