Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I don't know why you're not having any luck with HTML syntax highlighting in vim. Try
    :set ft=html


    • Oh, that always worked. This is what I do for the compose-window. But when reading an entry I'd rather not have the highlighted HTML-source but a nicely layed-out text document. I would have especeted that something like that already exists for vim. I couldn't find anything suitable though.
      • Oh, oh, I see. Could you pipe the file to lynx? Something like:
        :%!lynx -


        • Could you pipe the file to lynx?

          Hmmh, looks as though lynx can't read HTML stream-wise. Same limitation applies to links. w3m however can do it but doesn't appear to understand this sort of HTML-bastardism. The result is basically identical to what got piped in. ":%!html2text -nobs" works but then there are no linebreaks for Plain Old Text format.

          Currently, I use IPC::Open2 to do it inside my module:

          sub get_entry {
                  my $id = shift or return;
                  my $ret = $S->get_entry($id);
                  return if _had_error($ret) or (my $entry = $ret->result);
                  my $pid = open2 (\*OUT, \*IN, "html2text", "-style", "pretty", "-nobs");
                  $entry->{body} =~ s"<(/?)ecode>"<$1code>"g;
                  $entry->{body} =~ s"\n"<br>"g;
                  $entry->{body} =~
                            '<code>' . do { (my $s = $1) =~ s/\s/&nbsp;/g;$s } . '</code>'"gsex;
                  return $entry->{body} if $@ =~ /^open2:/;
                  print IN $entry->{body};
                  close IN;
                  my @output = <OUT>;
                  waitpid $pid, 0;
                  return join "\015", @output;

          I'd really like to use something like HTML::FormatText. But it expects an HTML::TreeBuilder object to render. I have my doubts that it is that easy to turn the journal entry sources into such a tree since they aren't complete HTML documents.

          Anyway, the whole business keeps me busy and is intriguing so I am not even complaining that much. ;-)