[squeak-dev] The Trunk: Collections-mt.886.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Mon Apr 20 12:03:44 UTC 2020


> It has nothing to do with collections.

Why not? The target format, Text, is a Collection.

Best,
Marcel
Am 20.04.2020 13:52:10 schrieb Levente Uzonyi <leves at caesar.elte.hu>:
On Mon, 20 Apr 2020, Marcel Taeumel wrote:

> > Still strange that such things are in Collections.
>
> There has been a discussion on this list about CollectionsExtras. Maybe we should follow up on that.

An HTML to text converter wouldn't fit into CollectionsExtras either. It
has nothing to do with collections.


Levente

>
> Best,
> Marcel
>
> Am 18.04.2020 15:29:14 schrieb Thiede, Christoph :
>
> Great idea!
>
>
> > Still strange that such things are in Collections.
>
> __________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
> Von: Squeak-dev im Auftrag von Jakob Reschke
> Gesendet: Freitag, 17. April 2020 19:45:38
> An: squeak-dev at lists.squeakfoundation.org
> Betreff: Re: [squeak-dev] The Trunk: Collections-mt.886.mcz
> Still strange that such things are in Collections.
>
> Am Fr., 17. Apr. 2020 um 16:56 Uhr schrieb :
> >
> > Marcel Taeumel uploaded a new version of Collections to project The Trunk:
> > http://source.squeak.org/trunk/Collections-mt.886.mcz
> >
> > ==================== Summary ====================
> >
> > Name: Collections-mt.886
> > Author: mt
> > Time: 17 April 2020, 4:56:30.33186 pm
> > UUID: c7d64e56-0d06-e34f-8a61-8f5a7eb9277d
> > Ancestors: Collections-eem.885
> >
> > To our HTML-to-Text converter, add support for tags. Either download an image (or picture) from the Web or evaluate some code to retrieve either a Form or a Morph. As documented in #httpGetImage:, this complements the support of "code://" in TextURL.
> >
> > =============== Diff against Collections-eem.885 ===============
> >
> > Item was added:
> > + ----- Method: HtmlReadWriter>>httpGetImage: (in category 'private') -----
> > + httpGetImage: url
> > + "To not add a direct dependency to WebClient, provide this hook for getting am image from an HTTP url. Maybe we can have this via an AppRegistry at some point. Maybe extend WebBrowser."
> > +
> > + (url beginsWith: 'code://') ifTrue: [
> > + "Same support for Smalltalk expressions as in TextURL >> #actOnClickFor:."
> > + ^ ([Compiler evaluate: (url allButFirst: 7)] ifError: [nil])
> > + ifNotNil: [:object | object isForm ifTrue: [object] ifFalse: [nil]]].
> > +
> > + ^ (Smalltalk classNamed: 'WebClient') ifNotNil: [:client |
> > + ([client httpGet: url] ifError: [nil]) ifNotNil: [:response |
> > + response code = 200 ifFalse: [nil] ifTrue: [
> > + [Form fromBinaryStream: response content asByteArray readStream]
> > + ifError: [nil]]]]!
> >
> > Item was added:
> > + ----- Method: HtmlReadWriter>>mapImgTag: (in category 'mapping') -----
> > + mapImgTag: aTag
> > +
> > + | result startIndex stopIndex attribute src form |
> > + result := OrderedCollection new.
> > +
> > + ""
> > + attribute := 'src'.
> > + startIndex := aTag findString: attribute.
> > + startIndex > 0 ifTrue: [
> > + startIndex := aTag findString: '"' startingAt: startIndex+attribute size.
> > + startIndex > 0
> > + ifTrue: [stopIndex := aTag findString: '"' startingAt: startIndex+1]
> > + ifFalse: [
> > + "URLs without quotes..."
> > + startIndex := aTag findString: '=' startingAt: startIndex+attribute size.
> > + stopIndex := aTag findString: '>' startingAt: startIndex+1].
> > + src := aTag copyFrom: startIndex+1 to: stopIndex-1.
> > + form := (self httpGetImage: src) ifNil: [(Form dotOfSize: 12 color: Color veryLightGray)].
> > + result
> > + add: form asTextAnchor;
> > + add: (TextColor color: Color transparent)].
> > + ^ result!
> >
> > Item was changed:
> > ----- Method: HtmlReadWriter>>mapTagToAttribute: (in category 'mapping') -----
> > mapTagToAttribute: aTag
> >
> > aTag = '' ifTrue: [^ {TextEmphasis bold}].
> > aTag = '' ifTrue: [^ {TextEmphasis italic}].
> > aTag = '' ifTrue: [^ {TextEmphasis underlined}].
> > aTag = '' ifTrue: [^ {TextEmphasis struckOut}].
> > aTag = '' ifTrue: [^ self mapCodeTag].
> > aTag = '
' ifTrue: [self breakLines: false. ^ {}].
> > (#('' ) anySatisfy: [:ea | aTag beginsWith: ea])
> > ifTrue: [^(self mapAlignmentTag: aTag) union: (self mapContainerTag: aTag)].
> > (aTag beginsWith: '
> > (aTag beginsWith: '
> > + (aTag beginsWith: '
> >
> > "h1, h2, h3, ..."
> > (aTag second = $h and: [aTag third isDigit])
> > ifTrue: [^ {TextEmphasis bold}].
> >
> > ^ {}!
> >
> > Item was changed:
> > ----- Method: HtmlReadWriter>>processEmptyTag: (in category 'reading') -----
> > processEmptyTag: aTag
> >
> > (aTag beginsWith: '
> > self addCharacter: Character cr.
> > ^ self].
> >
> > + (aTag beginsWith: '
> > + ^ self processStartTag: aTag].
> > +
> > (self isTagIgnored: aTag)
> > ifTrue: [^ self].
> >
> > "TODO... what?"!
> >
> > Item was added:
> > + ----- Method: HtmlReadWriter>>processEndTagEagerly: (in category 'reading') -----
> > + processEndTagEagerly: aTag
> > + "Not all tags need an end tag. Simulate that here."
> > +
> > + (aTag beginsWith: '
> > + ifTrue: [^ self processEndTag: ''].!
> >
> > Item was changed:
> > ----- Method: HtmlReadWriter>>processStartTag: (in category 'reading') -----
> > processStartTag: aTag
> >
> > | index |
> > (self isTagIgnored: aTag) ifTrue: [^ self].
> >
> > index := count - offset.
> >
> > aTag = '
' ifTrue: [
> > self addCharacter: Character cr.
> > ^ self].
> > +
> > (aTag beginsWith: '
> > + self addString: Character startOfHeader asString.
> > + offset := offset + 1.
> > + index := index - 1].
> > - self addString: '[image]'.
> > - ^ self].
> >
> > self processRunStackTop. "To add all attributes before the next tag adds some."
> >
> > "Copy attr list and add new attr."
> > runStack push: ({runStack top first copy addAll: (self mapTagToAttribute: aTag); yourself. index + 1 . index + 1}).
> > +
> > + "For tags such as , we should simulate the closing tag because there won't be any."
> > + self processEndTagEagerly: aTag.!
> > - !
> >
> >
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200420/16ab3669/attachment.html>


More information about the Squeak-dev mailing list