Re: formatted HTML in a gtksourceview widget





On Wed, May 26, 2010 at 5:03 PM, Dirk Koopman <djk tobit co uk> wrote:
I have some (pre-parsed) HTML as a string (actually generated from a browser DOM). I wish to display this as nice formatted and highlighted HTML in a gtk-perl window. Tried plain Gtk2::SourceView, but that seems to give me one long line. HTML::Tidy seems only to do checking.
Gtk2::SourceView is very old, try to use Gtk2::SourView2 [1] instead.

Regarding the "one long line", you will need to format it your self. I'm afraid that no editor widget will do this for you as they will want to respect the initial formatting. I think that the easiest is to simply use XML::LibXML:

 use XML::LibXML;
 $string = XML::LibXML->new()->parse_string($string)->toString(1); # Or try with 2

You can also take a look at Xacobeo [2], which is written in Perl, feel free to rip the peaces from it but the main formatting logic is now in XS due to speed constraints. If you want a pure Perl implementation take a look at this old branch [3].

[1] http://search.cpan.org/perldoc?Gtk2::SourceView2
[2] http://code.google.com/p/xacobeo/
[3] http://github.com/potyl/xacobeo/blob/0.04/bin/xacobeo#L367

--
Emmanuel Rodriguez


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]