[vwnc] export syntax-coloured Smalltalk code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[vwnc] export syntax-coloured Smalltalk code

Rob Vens-2
Hi, did anyone create a solution to get syntax-coloured Smalltalk code into a text processor or something? The rtf export facility from Heeg does not preserve text colours (nor does the html export).
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] export syntax-coloured Smalltalk code

paul weustink-4
I did this for HTML generation. You can use the Heeg html export when you change this a bit.

The HTMLWriter>>writeEmphasis: method is adapted such that it converts the ColorValue into an RGB integer value, and then dump this as a hex string in a span around the corresponding text. Also added different class styles for the known colors, such that a .CSS works with predefined colors for lets say variabes, or literals, etc.

Forgive the quick and dirty coding style, hope this helps.

Paul.


writeEmphasis: emphasisCollectionOrSymbol
        | e emps aValue aClass aStream |
        emps := emphasisCollectionOrSymbol copy.
        (emps isMemberOf: Array) ifFalse: [
                | anEmphasis |
                anEmphasis := emps.
                e := HtmlWriter  emphasisTable at: anEmphasis ifAbsent: [nil].
                (e isNil and: [(anEmphasis isKindOf: Association) and: [anEmphasis key == #color]]) ifTrue: [
                        aValue := anEmphasis value asColorRef.
                        aClass := (self lookupColors: aValue).
                        aClass isNil ifTrue: [
                                aStream := ByteString new.
                                aValue printOn: aStream paddedWith: $0 to: 6 base: 16.
                                e := '<span style="color:#', aStream contents , ';">'.
                        ]
                        ifFalse: [e := '<span class="', aClass asString, '">'.]
                ].
                e notNil ifTrue: [file nextPutAll: e].
        ]
        ifTrue: [
                emps := emps asOrderedCollection.
                emps do: [:anEmphasis |
                        e := HtmlWriter emphasisTable at: anEmphasis ifAbsent: [nil].
                        (e isNil and: [(anEmphasis isKindOf: Association) and: [anEmphasis key == #color]]) ifTrue: [
                                aValue := anEmphasis value asColorRef.
                                aClass := (self lookupColors: aValue).
                                aClass isNil ifTrue: [
                                        aStream := ByteString new.
                                        aValue printOn: aStream paddedWith: $0 to: 6 base: 16.
                                        e := '<span style="color:#', aStream contents , ';">'.
                                ] ifFalse: [e := '<span class="', aClass asString, '">'.].
                        ].
                        e notNil ifTrue: [file nextPutAll: e].
                ].
        ]

At 01:22 PM 3/5/2009, you wrote:
>Hi, did anyone create a solution to get syntax-coloured Smalltalk code into a text processor or something? The rtf export facility from Heeg does not preserve text colours (nor does the html export).
>_______________________________________________
>vwnc mailing list
>[hidden email]
>http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] export syntax-coloured Smalltalk code

Rob Vens-2
Hah, you would probably expect this response ... but could you shed some light on how you implemented the emphasis table for example in HTMLWriter? And the implementation of the lookupColors: and asColorRef methods?

2009/3/5 Paul Weustink <[hidden email]>
I did this for HTML generation. You can use the Heeg html export when you change this a bit.

The HTMLWriter>>writeEmphasis: method is adapted such that it converts the ColorValue into an RGB integer value, and then dump this as a hex string in a span around the corresponding text. Also added different class styles for the known colors, such that a .CSS works with predefined colors for lets say variabes, or literals, etc.

Forgive the quick and dirty coding style, hope this helps.

Paul.


writeEmphasis: emphasisCollectionOrSymbol
       | e emps aValue aClass aStream |
       emps := emphasisCollectionOrSymbol copy.
       (emps isMemberOf: Array) ifFalse: [
               | anEmphasis |
               anEmphasis := emps.
               e := HtmlWriter  emphasisTable at: anEmphasis ifAbsent: [nil].
               (e isNil and: [(anEmphasis isKindOf: Association) and: [anEmphasis key == #color]]) ifTrue: [
                       aValue := anEmphasis value asColorRef.
                       aClass := (self lookupColors: aValue).
                       aClass isNil ifTrue: [
                               aStream := ByteString new.
                               aValue printOn: aStream paddedWith: $0 to: 6 base: 16.
                               e := '<span style="color:#', aStream contents , ';">'.
                       ]
                       ifFalse: [e := '<span class="', aClass asString, '">'.]
               ].
               e notNil ifTrue: [file nextPutAll: e].
       ]
       ifTrue: [
               emps := emps asOrderedCollection.
               emps do: [:anEmphasis |
                       e := HtmlWriter emphasisTable at: anEmphasis ifAbsent: [nil].
                       (e isNil and: [(anEmphasis isKindOf: Association) and: [anEmphasis key == #color]]) ifTrue: [
                               aValue := anEmphasis value asColorRef.
                               aClass := (self lookupColors: aValue).
                               aClass isNil ifTrue: [
                                       aStream := ByteString new.
                                       aValue printOn: aStream paddedWith: $0 to: 6 base: 16.
                                       e := '<span style="color:#', aStream contents , ';">'.
                               ] ifFalse: [e := '<span class="', aClass asString, '">'.].
                       ].
                       e notNil ifTrue: [file nextPutAll: e].
               ].
       ]

At 01:22 PM 3/5/2009, you wrote:
>Hi, did anyone create a solution to get syntax-coloured Smalltalk code into a text processor or something? The rtf export facility from Heeg does not preserve text colours (nor does the html export).
>_______________________________________________
>vwnc mailing list
>[hidden email]
>http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: export syntax-coloured Smalltalk code

Ernest Micklei
Yesterday, I published a CodeHtmlHighlighting package to the public store
that can produce CSS based HTML from your Smalltalk method source
while respecting its original format. I will use this package in the
next version of soek.goodies.st.

^ Ernest

On Thu, Mar 5, 2009 at 4:44 PM, Rob Vens <[hidden email]> wrote:

> Hah, you would probably expect this response ... but could you shed some
> light on how you implemented the emphasis table for example in HTMLWriter?
> And the implementation of the lookupColors: and asColorRef methods?
>
> 2009/3/5 Paul Weustink <[hidden email]>
>>
>> I did this for HTML generation. You can use the Heeg html export when you
>> change this a bit.
>>
>> The HTMLWriter>>writeEmphasis: method is adapted such that it converts the
>> ColorValue into an RGB integer value, and then dump this as a hex string in
>> a span around the corresponding text. Also added different class styles for
>> the known colors, such that a .CSS works with predefined colors for lets say
>> variabes, or literals, etc.
>>
>> Forgive the quick and dirty coding style, hope this helps.
>>
>> Paul.
>>
>>
>> writeEmphasis: emphasisCollectionOrSymbol
>>        | e emps aValue aClass aStream |
>>        emps := emphasisCollectionOrSymbol copy.
>>        (emps isMemberOf: Array) ifFalse: [
>>                | anEmphasis |
>>                anEmphasis := emps.
>>                e := HtmlWriter  emphasisTable at: anEmphasis ifAbsent:
>> [nil].
>>                (e isNil and: [(anEmphasis isKindOf: Association) and:
>> [anEmphasis key == #color]]) ifTrue: [
>>                        aValue := anEmphasis value asColorRef.
>>                        aClass := (self lookupColors: aValue).
>>                        aClass isNil ifTrue: [
>>                                aStream := ByteString new.
>>                                aValue printOn: aStream paddedWith: $0 to:
>> 6 base: 16.
>>                                e := '<span style="color:#', aStream
>> contents , ';">'.
>>                        ]
>>                        ifFalse: [e := '<span class="', aClass asString,
>> '">'.]
>>                ].
>>                e notNil ifTrue: [file nextPutAll: e].
>>        ]
>>        ifTrue: [
>>                emps := emps asOrderedCollection.
>>                emps do: [:anEmphasis |
>>                        e := HtmlWriter emphasisTable at: anEmphasis
>> ifAbsent: [nil].
>>                        (e isNil and: [(anEmphasis isKindOf: Association)
>> and: [anEmphasis key == #color]]) ifTrue: [
>>                                aValue := anEmphasis value asColorRef.
>>                                aClass := (self lookupColors: aValue).
>>                                aClass isNil ifTrue: [
>>                                        aStream := ByteString new.
>>                                        aValue printOn: aStream paddedWith:
>> $0 to: 6 base: 16.
>>                                        e := '<span style="color:#',
>> aStream contents , ';">'.
>>                                ] ifFalse: [e := '<span class="', aClass
>> asString, '">'.].
>>                        ].
>>                        e notNil ifTrue: [file nextPutAll: e].
>>                ].
>>        ]
>>
>> At 01:22 PM 3/5/2009, you wrote:
>> >Hi, did anyone create a solution to get syntax-coloured Smalltalk code
>> > into a text processor or something? The rtf export facility from Heeg does
>> > not preserve text colours (nor does the html export).
>> >_______________________________________________
>> >vwnc mailing list
>> >[hidden email]
>> >http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc