use-livecode Digest, Vol 172, Issue 22

Brian Milby brian at milby7.com
Mon Jan 15 23:13:16 EST 2018


Here is a function for Windows that will replace <p> with <div> and include
" " for multiple spaces.  It retains the other formatting.  (It won't
catch paragraph level formatting as is though.)  So if you are copying
code, this could be used to clean it for paste as rich text:

*on* mouseUp
   *local* tFormat, tClipboard
   *lock* clipboard
   *put* "HTML Format" into tFormat
   *put* the rawClipboardData[tFormat] into tClipboard
   *replace* "<p>" with "<div>" in tClipboard
   *replace* "</p>" with "</div>" in tClipboard
   *replace* "  " with "  " in tClipboard
   *replace* "  " with "  " in tClipboard
   *set* the itemdel to ":"
   *put* format("%10d", offset("<!--End", tClipboard) - 1) into item 2 of
line 5 of tClipboard
   *put* format("%10d", offset("<!--End", tClipboard) + 32) into item 2 of
line 3 of tClipboard
   *set* the rawClipboardData[tFormat] to tClipboard
   *unlock* clipboard
*end* mouseUp

The code for MacOS is simpler (the 2 put's following the itemdel are not
needed, the format name is "public.html", not sure about Linux).  I copied
the above code in LC and then clicked the button to fix it before pasting
here.

Changing the tags is probably a good thing to do in the engine code.  I'm
not so sure about the spaces though.

On Thu, Jan 11, 2018 at 2:43 PM Brian Milby <brian at milby7.com> wrote:

> The problem in this case is the HTML format data (and possibly RTF) on the
> clipboard. Testing in Windows, if I just put the LC styled text and plain
> text on the clipboard, it works to get plain text outside of LC but retain
> formatting inside. If I try to paste the RTF or LC data into Excel, I just
> get a beep. HTML gives the double space text. The plain text formats work
> as expected. So if the destination application accepts HTML, that is what
> it takes.
>
> This does not mean that the clipboard data is necessarily correct right
> now. I’m not sure wrapping single spaced text in <P> tags is correct. I’m
> not an expert there, so this may be an area that could be improved.
> On Thu, Jan 11, 2018 at 1:51 PM Richard Gaskin via use-livecode <
> use-livecode at lists.runrev.com> wrote:
>
>> Richard Burkett wrote:
>>
>>  > on mouseUp
>>  >    put fld "myField" into tClip
>>  >    lock the clipBoard
>>  >    set the ClipboardData to empty
>>  >    set the ClipboardData to tClip
>>  >    put the clipboardData["text"] into tClip
>>  >    set the rawclipBoardData to empty
>>  >    if the platform is "MacOS" then
>>  >       set the rawClipboardData["public.utf8-plain-text"] \
>>  >             to textEncode(tClip, "UTF-8" )   -- OSX
>>  >    else if the platform is "Linux" then
>>  >       set the rawClipboardData["text/plain;charset=utf-8"] \
>>  >             to textEncode(tClip, "UTF-8" ) -- Linux
>>  >    else if the platform contains "Win" then
>>  >       set the rawClipboardData["CF_UNICODE"] \
>>  >             to textEncode(tClip, "UTF-16" ) -- Windows
>>  >    end if
>>  >    unlock the clipBoard
>>  > end mouseUp
>>
>> Nice, but not as nice as:
>>
>>    copy
>>
>> I appreciate that we have the flexibility to do arcane things with the
>> Clipboard when needed, but shouldn't the copy command handle the most
>> common cases without requiring new users to research and experiment in
>> the hope of arriving at the above block of code?
>>
>> --
>>   Richard Gaskin
>>   Fourth World Systems
>>   Software Design and Development for the Desktop, Mobile, and the Web
>>   ____________________________________________________________________
>>   Ambassador at FourthWorld.com                http://www.FourthWorld.com
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>



More information about the use-livecode mailing list