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

Eliot Miranda eliot.miranda at gmail.com
Thu Feb 9 20:02:28 UTC 2017


On Thu, Feb 9, 2017 at 11:44 AM, Bert Freudenberg <bert at freudenbergs.de>
wrote:

> On Thu, Feb 9, 2017 at 8:16 PM, Eliot Miranda <eliot.miranda at gmail.com>
> wrote:
>
>> Tobias,
>>
>>   ignore my email.  I'm reviewing your code.  But I will say that adding
>> inst vars is making things more complicated too.  I added three methods to
>> achieve what I wanted and you've added 8 and an inst var ;-)
>>
>
> The problem with your indentation-based approach was that when just
> copying a whole method as HTML, it would insert a <pre> tag *after* the
> method pattern (because that was the first indented line).
>

Thats not quite true.  My code adds the <pre> before indenting because of
the variable initializations.  But it does indeed insert the closing </pre>
after the last carriage return and that's a bug.



> That's why Tobi added the TextDoit stuff, to specifically mark code ...
> It's still not ideal but we couldn't come up with a better way for unifying
> your blog-post-in-a-workspace with the regular just-copy-some-code. Ideas
> welcome :)
>

When examining the end of line, the code could easily peek ahead and look
at the next line.  This would allow it to add the </pre> before the last
carriage return.  So to sketch the algorithm, the high-level iterator over
texts breaks text into lines, arranging that line breaks occur only as the
last character of the text, and the iterator provides the next character
after the line break, or nil of none.  The code can then easily arrange to
add the closing </pre> before the carriage return since it is informed of
the character following the line break:

*linesWithAttributesIn:* aText *do:* aTrinaryBlock

    "Evauate aTrinaryBlock 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, and the     chanarcter following the
line break if it exists."    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.          aTrinaryBlock            value: (aText string
copyFrom: startIdx to: idx)            value: att            value:
(idx < stop ifTrue: [aText string at: idx + 1]).          idx < stop]
          whileTrue:                [startIdx *:=* idx + 1]]



BTW, it would be *really cool* if "copy html" also copied the generated
text to the system (OS) paste buffer as formatted HTML so I wouldn't have
to paste the generated HTML into a Workspace, say "export to file...", open
the HTML file in a web browser, and copy that text :-(  (or am I missing a
trick??)


> - Bert -
>
>
>
>


-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20170209/9a0af9d5/attachment.html>


More information about the Squeak-dev mailing list