[squeak-dev] The Inbox: Collections-eem.732.mcz

Tobias Pape Das.Linux at gmx.de
Wed Feb 8 20:47:58 UTC 2017


On 08.02.2017, at 19:59, Eliot Miranda <eliot.miranda at gmail.com> wrote:

> Hi All,
> 
>     I'd really like this to be in trunk.  I've just written a blog post in a Workspace using this code (http://www.mirandabanda.org/cogblog/2017/02/07/smalltalk-scanning-and-shcontrol-structures/) and it turns creating a blog post into a simple copyHtml paste operation from a workspace to (in my case) WordPress.  So any reviewers?

Care to explain it a litte bit? :)
It looks a bit complicated to my eyes.
Also, do you really want <pre>? (http://stackoverflow.com/questions/4611591/code-vs-pre-vs-samp-for-inline-and-block-code-snippets#4611735)

The HtmlReadWriter seems to (up until now) pretty directly map text attributes to html attributes.

You seem to want to differentiate code from non-code, so what about having a do-it attribute, that does exactly that?
Because now, there's also no back-reading of such html into a Text object, wich I find unfortunate.
I think, the readwriter should be able to read what it has written.

I know, it's a mere convenience thing, but still, its very procedural, and seeing #~~ in high-level code is strange to my eyes…

What would be really cool is to
	- mark the code as do-it
	- have the do-it present itself as <code> or <pre> on Html.

Btw: there's also an TextIndent attribute that we could leverage.

Best regards
	-Tobias


> 
> On Wed, Feb 8, 2017 at 10:55 AM, <commits at source.squeak.org> wrote:
> Eliot Miranda uploaded a new version of Collections to project The Inbox:
> http://source.squeak.org/inbox/Collections-eem.732.mcz
> 
> ==================== Summary ====================
> 
> Name: Collections-eem.732
> Author: eem
> Time: 8 February 2017, 10:55:41.894202 am
> UUID: c2c7f1c4-f586-4872-b2c7-6fb7f9cd6527
> Ancestors: Collections-dtl.731
> 
> Modify HtmlReadWriter to enclose indented text within <pre></pre> to preserve formatting of, for example, code.
> 
> =============== Diff against Collections-dtl.731 ===============
> 
> Item was added:
> + ----- Method: HtmlReadWriter>>linesWithAttributesIn:do: (in category 'writing') -----
> + linesWithAttributesIn: aText do: aBlock
> +       "Evauate aBlock with a string and the emphasis for that string, guaranteeing
> +        that if the string contains a line break, it occurs at the end of the line."
> +       aText runs withStartStopAndValueDo:
> +               [:start :stop :attributes | | att idx startIdx |
> +                startIdx := start.
> +                [att := aText attributesAt: startIdx.
> +                 idx := aText string indexOf: Character cr from: startIdx to: stop ifAbsent: stop.
> +                 aBlock value: (aText string copyFrom: startIdx to: idx) value: att.
> +                 idx < stop]
> +                       whileTrue:
> +                               [startIdx := idx + 1]]!
> 
> Item was changed:
>   ----- Method: HtmlReadWriter>>nextPutText: (in category 'accessing') -----
>   nextPutText: aText
> +       | atStartOfLine inIndent cr |
> +       atStartOfLine := true.
> +       inIndent := false.
> +       cr := Character cr.
> +       self linesWithAttributesIn: aText do:
> +               [:string :attributes | | indented |
> +               atStartOfLine ifTrue:
> +                       [indented := string first == Character tab.
> +                        indented ~~ inIndent ifTrue:
> +                               [stream nextPutAll: (indented ifTrue: ['<pre>'] ifFalse: ['</pre>']).
> +                                inIndent := indented]].
> +               attributes do: [:each | self writeStartTagFor: each].
> +               inIndent
> +                       ifTrue: [self writePresentationContent: string]
> +                       ifFalse: [self writeContent: string].
> +               attributes reverseDo: [:each | self writeEndTagFor: each].
> +               atStartOfLine := string last == cr].
> +       inIndent ifTrue:
> +               [stream nextPutAll: '</pre>']!
> -
> -       aText runs
> -               withStartStopAndValueDo: [:start :stop :attributes |
> -                       | att str |
> -                       att := aText attributesAt: start.
> -                       str := aText string copyFrom: start to: stop.
> -
> -                       att do: [:each | self writeStartTagFor: each].
> -                       self writeContent: str.
> -                       att reverse do: [:each | self writeEndTagFor: each]]!
> 
> Item was added:
> + ----- Method: HtmlReadWriter>>writePresentationContent: (in category 'writing') -----
> + writePresentationContent: aString
> +
> +       aString do: [:char |
> +               char = Character tab
> +                       ifTrue: [stream nextPutAll: '    ']
> +                       ifFalse: [(String htmlEntities keyAtValue: char ifAbsent: [])
> +                               ifNil: [stream nextPut: char]
> +                               ifNotNil: [:escapeSequence |
> +                                       stream
> +                                               nextPut: $&;
> +                                               nextPutAll: escapeSequence;
> +                                               nextPut: $;]]]!
> 
> Item was added:
> + ----- Method: SequenceableCollection>>indexOf:from:to:ifAbsent: (in category 'accessing') -----
> + indexOf: anElement from: start to: end ifAbsent: exceptionBlock
> +       "Answer the index of the first occurence of anElement from start to stop
> +        within the receiver. If the receiver does not contain anElement in the,
> +        range answer the       result of evaluating the argument, exceptionBlock."
> +
> +       start to: end do:
> +               [:index |
> +               (self at: index) = anElement ifTrue: [^index]].
> +       ^exceptionBlock value!
> 
> 
> 
> 
> 
> -- 
> _,,,^..^,,,_
> best, Eliot
> 



More information about the Squeak-dev mailing list