A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.946.mcz==================== Summary ====================
Name: Collections-ct.946
Author: ct
Time: 6 May 2021, 10:16:21.568835 pm
UUID: bccb3d02-408c-0a49-8276-6900a779892c
Ancestors: Collections-mt.943
Makes HtmlReadWriter robust against invalid CSS colors. CSS is too complex to be covered completely in our simple HTML parser. For example, the following failed before:
'<span style="color: rgb(0, 0, 0)">hi</span>' asTextFromHtml.
=============== Diff against Collections-mt.943 ===============
Item was changed:
----- Method: HtmlReadWriter>>mapContainerTag: (in category 'mapping') -----
mapContainerTag: aTag
| result styleStart styleEnd styleAttributes |
result := OrderedCollection new.
+ styleStart := (aTag findString: 'style="') + 7.
+ styleStart <= 7 ifTrue: [^ #()].
- styleStart := (aTag findString: 'style="' ) + 7.
- styleStart <= 7 ifTrue: [^#()].
styleEnd := (aTag findString: '"' startingAt: styleStart) - 1.
styleAttributes := (aTag copyFrom: styleStart to: styleEnd) subStrings: ';'.
+ styleAttributes do: [:ea | | keyValue key value |
- styleAttributes do: [:ea | |keyValue key value|
keyValue := (ea subStrings: ':') collect: [:s | s withBlanksTrimmed].
key := keyValue first asLowercase.
value := keyValue second.
keyValue size = 2 ifTrue: [
+ key = 'color' ifTrue: [ | color |
+ color := [Color fromString: value] ifError: [nil].
+ color ifNotNil: [result add: (TextColor color: color)]].
- key = 'color' ifTrue: [result add: (TextColor color: (Color fromString: value))].
(key beginsWith: 'font') ifTrue: [
+ (value includesSubstring: 'bold') ifTrue: [result add: TextEmphasis bold].
+ (value includesSubstring: 'italic') ifTrue: [result add: TextEmphasis italic]]]].
- (value includesSubstring: 'bold')
- ifTrue: [result add: TextEmphasis bold].
- (value includesSubstring: 'italic')
- ifTrue: [result add: TextEmphasis italic]]]].
^ result!