Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk HTML Renderer (Proof of Concept)

Status
Not open for further replies.

Kirsle

Programmer
Jan 21, 2006
1,179
US
I'm just posting here to tell y'all about my latest great achievement: I've programmed a pretty functional Perl Tk program which renders HTML code in a Text widget.

The reason I did it was because the already existing modules, Tk::HTML and Tk::HTMLText, were more built by its author specifically to use in his "tkweb" program, and aren't easily useable as an actual Text widget.

So, first, here's a screenshot:

html11.png


It supports and successfully renders the following HTML tags and attributes:

Code:
<BODY> (bgcolor, link, vlink, alink, text)
<H1> - <H7>
<BLOCKQUOTE>
<A> (href, target)
<B>, <I>, <U> <S>
<CENTER>, <LEFT> <RIGHT>
<SUP>, <SUB>
<FONT> (face, size, color, back (highlight color))

Right now it's just in the "Proof of Concept" stage, as it was built in this Tk app for testing purposes. I eventually plan to make it into a module, probably named Tk::HyperText, where it can be put to practical use in real Tk applications.

I hopefully aim for this functionality:
Code:
use Tk::HyperText;

my $html = $mw->Scrolled ("HyperText")->pack;

$html->insert ("end","<b>Hello, world!</b>");

i.e... just like Tk::Text, but with the automatic rendering of any HTML inserted into it. :)

I gave it its own webpage on my site, here: On it are links to more screenshots and a download link.

Here's a direct link to the source:
Reply here if you have anything to comment about it. :)

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
looks interesting. [smile]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Keep at it Kirsle, and make the life of mere mortals like me easy, using modules.

On a diff subject, I've been reading up on Perl6 and parrott, which in one of the docs stated that Perl6 is not funded hence is taking a while to develop. I Perl dying and Ruby || D || PHP will take over in the near future...say it ain't so...
 
I spent the greater part of the day turning this into a Perl module. I just uploaded it to CPAN as Tk::HyperText, but it'll take a little while to show up there.

Another download link is:
Included in the distribution is a demonstration program, which makes a rather simple web browser in Perl Tk for viewing the HTML documents in the "demolib" folder, which also have links to one another, and some links to external web sites (but those links open in your own web browser).

The list of supported tags grows:

Code:
  <html>, <head>
  <title>      *calls -titlecommand when found
  <body>       (bgcolor, link, vlink, alink, text)
  <font>       (face, size, color, back)
  <a>          (href, target)
  <blockquote>
  <p>, <br>
  <pre>
  <code>, <tt>
  <center>, <right>, <left>
  <h1> - <h6>
  <sup>, <sub>
  <b>, <strong>
  <i>, <em>
  <u>, <ins>
  <s>, <del>

Support for the <img> tag was almost included, but for some unknown reason, Perl Tk would crash when trying to insert the image into the text widget. I'd done it before, on Windows, with no problem in other programs, but it fails for me on Linux. It's on my to-do list to check it out though, and it might be added in a later version.

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top