Working with texts?
Boris Gaertner
Boris.Gaertner at gmx.net
Sat Jul 5 22:39:49 UTC 2003
Ingo Hohmann <ingo at 2b1.de> wrote:
> Hi All,
>
> I want to learn about working with texts, especially
>
> - parse something like swiki markup and create an attributed text.
Look at HtmlParser class>>example1
This takes a piece of HTML and creates an instance of HTMLDocument.
To see formatted text, execute this statement:
(Workspace new contents: HtmlParser example1 formattedText) openLabel:
'formatted Text'
> I know about TextStream for attributes, but
> - how do I create a hyperlink?
Copy this into a workspace and execute it:
| ts |
ts := TextStream on: (Text new).
ts nextPutAll: 'Squeak is a beautiful language. Look at '.
ts withAttribute: (TextURL new url: 'http\\:www.squeak.org')
do:
[ ts nextPutAll: 'http\\:www.squeak.org'].
ts nextPutAll: ' to learn more about it.'.
(Workspace new contents: ts contents) openLabel: 'Here is your Hyperlink:'
You see that an instance of TextURL is used to store a hyperlink.
TextURL is just a text attribute.
> - Is there an easier way than TexStream?
HtmlParser creates a HtmlDocument which is essentially a tree.
This approach has some important advantages, but it is even more
complicated than the use of TextStream. I think the use of TextStream
is quite easy.
>
> - How do I parse the text to display it as markup again?
>
> - Is there something like textToHtml and vice versa? (I guess Scamper
> has it, but I didn't find it)
Surprisingly, Text does not implement protocol to create HTML. (In the
standard image. It is quite possible that there are additions that I am not
aware of.) It is not very difficult to program this.
>
>
> Thanks in advance
>
> Ingo
>
Hope this helps - a bit
Boris
More information about the Squeak-dev
mailing list
|