[ENH]Html table (very crude version)

Karl Ramberg karl.ramberg at chello.se
Tue Aug 21 08:15:41 UTC 2001


"Richard A. O'Keefe" wrote:
> 
> Karl Ramberg <karl.ramberg at chello.se> wrote:
>         I like to torture my self so I decided to add tables to
>         the html parser, so Scamper would do more justice to all
>         those wonderful web pages out there.  ...
>         I would love to get some feedback to how to proceed and
>         encouragement if this is a worth while PITA.
> 
> *GREAT*.  The absence of table support has been a major limitation in
> Scamper.  Obviously because tables are often useful, but also because
> a _huge_ number of web pages abuse them to get a particular layout.
> 
> I note that quite a few well-established web browsers have trouble
> *printing* tables that have been given pixel sizes instead of
> percentage sizes.  For example, when I try to print the documentation
> for Bobby, a strip of text down the right margin is missing.
> 
> So there are at least some cases where ignoring the attributes is the
> *best* thing to do.

Thanks for the reply. I'm currently trying to figure out the best
approach to swallow and digest this monster. 
The version I posted to the list has some limitations.
I'll describe the situation:
Here is a small table in html:
<HTML>
<HEAD>
<TITLE>SmallTable</TITLE>
</HEAD>
<BODY>
<TABLE >
	<TR>
		<TD ><A HREF="http://www.squeak.org"><IMG SRC="mouse.jpg"></A></TD>
		<TD ><A HREF="http://www.squeak.org">two</A></TD>
		<TD >three</TD>
	</TR>
</TABLE>
</BODY>
</HTML>

To describe it simple:
Scamper stores the parsed html in instVar document:
	document _ (HtmlParser parse: (ReadStream on: pageSource)).
	
Then it defines a formatter who makes a nice text of the parsed
html with attributes and puts it in instVar formattedPage:
	formatter _ HtmlFormatter preferredFormatterClass new.
	formatter browser: self.
	formatter baseUrl: currentUrl.
	document addToFormatter: formatter.
	formattedPage _ formatter text.

Scamper then adds a WebPageMorph to show the result:
^WebPageMorph
		on: self 
		bg: #backgroundColor 
		text: #formattedPage 
		readSelection: #formattedPageSelection 
		menu: #menu:shifted:

So here is what I have done to make a table: 
The formatter analyses each tag and takes appropriate action
for each. Text is added as text. Images are added as morphs.
This works well because Squeaks texts can contain texts and morphs 
and they can be URLs etc. 
Then enter TABLE. A table is a deep nested messy structure who 
can contain multiple different elements. 
It's the table, within that tableRows and within that again
tableCells. And tableCells can contain everything...
My first approach to make tables was this:
Upon a <TABLE> tag add a morph tho the text. Upon a <TR>
tag add a row morph to the morph. And then upon a <TD> add a 
cell morph to the row morph. And then add whatever to the cell
again. But then a problem occures: if whatever added to the 
cell is a anchor/link there is no way to tell the text
whats going on because the original text only handles anchors/links
at first level, and now we are at least 4 levels into a morph.
The table cell must contain a new text/ WebPageMorph. 
And I must define a new formatter to lay out this again...
This is where I am at the moment. Anybody got a better way of
doing this please pitch in...
Karl




More information about the Squeak-dev mailing list