progress with syntax-to-rtf

rjbs on 2007-09-05T14:24:57

I had really wanted to use the Kate syntax stuff, because it's pure Perl, but after I had it working, I decided that its Perl syntax highlighting wasn't good enough, and I wanted Vim's. So, I did what I had wanted to avoid and used Text::VimColor. I worked out some bugs, learned a lot about RTF, and added nice little things like proper option parsing.

I put it on my hacks page, along with a sample output file. Reading the RTF::Writer source with a clearer head made the problem I'd had with dashes clear. (It also makes me think that RTF::Writer needs to stop doing what it's doing.)

There's just one big thing bugging me, now. I can't find a way to change the background color of the document, which I think will have to be done with a default stylesheet or something. I'd create a file with a black background to inspect its contents, but I don't even see how to do that in TextEdit.

With a white background, the margins are white, and extra whitespace at the end of the file is white. I really want to be able to set the default background, to address this problem correctly.

Next up, I may attempt to write a very crude Vim colorscheme parser. With that done, it just becomes a matter of automating the highlighting of text in a Keynote text box.


Syntax::Highlight::Universal

mpeters on 2007-09-05T15:46:30

You could use Syntax::Highlight::Universal (it needs a patch from RT to help it compile). If you just have it tokenize and create the HTML from it, it's simply elements with classes. Then you can control every detail of the color using CSS.

I've done this before for with a Spork plugin that would let me easily wrap my code samples with something like .syntax perl
or .syntax html

It was really useful when I give multi language talks (Perl/JavaScript/HTML/CSS).

I never put my plugin up on CPAN or into SVN, so when I last upgraded laptops it got lost, but I hacked it together in one afternoon, so it couldn't be that hard.

Re:Syntax::Highlight::Universal

rjbs on 2007-09-05T15:54:34

I don't get it. How can CSS help me produce color RTF?

Re:Syntax::Highlight::Universal

mpeters on 2007-09-05T16:01:55

Well, I feel silly. For some reason I thought you were doing syntax hilighting into HTML and then converting to RTF. But you're using RTF::Writer, duh. Sorry for the noise...

Re:Syntax::Highlight::Universal

rjbs on 2007-09-05T16:34:52

No problem. If nothing else, now I know I can look at one more highlighting engine eventually! Thanks.

Kate, Vim, tidy?

n1vux on 2007-12-10T16:08:35

Is VIM's colorizing better than PerlTidy's for your purpose?

Re:Kate, Vim, tidy?

rjbs on 2007-12-10T19:05:57

I haven't tried it, but I'm guessing it will be -- only because it will be exactly what I'm used to seeing in my editor.

I'll try to check it out.

Re:Kate, Vim, tidy?

n1vux on 2007-12-18T19:48:35

PerlTidy is adjustable.

The Perl Advent Calendar uses perltidy -nnn -html -css=../style.css [* *] so the CSS file sets the colors.

You could edit that file to get the VIM look with PerlTidy. PerlTidy can also adapt its indenting etc. to suit most standards. E.g., I think PBP has Tidy definition of it's recommended format. Spod5 is a perl-based pod-to-S5 slide systm that can filter code through perltidy.