@@ -372,7 +372,13 @@ bool MCClipboard::AddLiveCodeStyledText(MCDataRef p_pickled_text)
372372 // This type is optional as it may not be a faithful representation
373373 MCAutoDataRef t_html (ConvertStyledTextToHTML (p_pickled_text));
374374 if (*t_html != NULL )
375- t_success = t_item->AddRepresentation (t_type_string, *t_html);
375+ {
376+ MCAutoDataRef t_encoded;
377+ t_encoded = m_clipboard->EncodeHTMLFragmentForTransfer (*t_html);
378+ t_success = *t_encoded != nil;
379+ if (t_success)
380+ t_success = t_item->AddRepresentation (t_type_string, *t_encoded);
381+ }
376382 }
377383
378384 // Also attempt to add as plain text, so we have a fall-back
@@ -459,6 +465,12 @@ bool MCClipboard::AddHTML(MCDataRef p_html)
459465 if (t_item == NULL )
460466 return false ;
461467
468+ // Encode the HTML in the required format for the clipboard
469+ MCAutoDataRef t_encoded;
470+ t_encoded = m_clipboard->EncodeHTMLFragmentForTransfer (p_html);
471+ if (*t_encoded == nil)
472+ return false ;
473+
462474 // Add the data to the clipboard with the correct type
463475 MCStringRef t_type_string = m_clipboard->GetKnownTypeString (kMCRawClipboardKnownTypeHTML );
464476 if (t_type_string == NULL )
@@ -849,13 +861,19 @@ bool MCClipboard::CopyAsLiveCodeStyledText(MCDataRef& r_pickled_text) const
849861 MCAutoDataRef t_html;
850862 if (CopyAsData (kMCRawClipboardKnownTypeHTML , &t_html))
851863 {
852- // Convert to LiveCode styled text
853- MCDataRef t_pickled_text = ConvertHTMLToStyledText (*t_html);
854- if (t_pickled_text != NULL )
855- {
856- r_pickled_text = t_pickled_text;
857- return true ;
858- }
864+ MCAutoDataRef t_decodedhtml;
865+ t_decodedhtml.Reset (m_clipboard->DecodeTransferredHTML (*t_html));
866+
867+ if (*t_decodedhtml != nil)
868+ {
869+ // Convert to LiveCode styled text
870+ MCDataRef t_pickled_text = ConvertHTMLToStyledText (*t_decodedhtml);
871+ if (t_pickled_text != NULL )
872+ {
873+ r_pickled_text = t_pickled_text;
874+ return true ;
875+ }
876+ }
859877 }
860878
861879 // Finally, try plain text.
@@ -935,7 +953,17 @@ bool MCClipboard::CopyAsRTF(MCDataRef& r_rtf_data) const
935953
936954bool MCClipboard::CopyAsHTML (MCDataRef& r_html_data) const
937955{
938- return CopyAsData (kMCRawClipboardKnownTypeHTML , r_html_data);
956+ MCAutoDataRef t_data;
957+ if (!CopyAsData (kMCRawClipboardKnownTypeHTML , &t_data))
958+ return false ;
959+
960+ MCDataRef t_decoded = nil;
961+ t_decoded = m_clipboard->DecodeTransferredHTML (*t_data);
962+ if (t_decoded == nil)
963+ return false ;
964+
965+ r_html_data = t_decoded;
966+ return true ;
939967}
940968
941969bool MCClipboard::CopyAsPNG (MCDataRef& r_png) const
0 commit comments