Page 1 of 1

Copy and Paste looses text formatting

PostPosted: Tue Mar 06, 2018 9:58 pm
by Zinn
Copy and Paste from Firefox to BlackBox looses formatting and arrives as plain text only.
When I Copy and Paste form Firefox to Word or LibreOffice Writer the formatting is OK.
Copy then from Word or LibreOffice Writer to BlackBox it works too.
Why it doesn't work the direct copy from Firefox to BlackBox?
It doesn't matter which version of BlackBox I use (1.6, 1.7, 1.7.1). I have the same behaviour.
I know that it did work in the past with BB 1.6.
I don't know when I lost this functionality.
Any hints what I can do?
- Helmut

Re: Copy and Paste looses text formatting

PostPosted: Tue Mar 06, 2018 10:20 pm
by Josef Templ
The browsers that I have checked (IExplorer, Chrome, Firefox) export the clipboard as plain text or Html.
Since BlackBox has no Html importer there is only plain text left.
Word or Libre Office also offer an Html importer and an Rtf exporter that fits with
the Rtf importer of BlackBox.

Maybe there is a Firefox plugin that adds an Rtf exporter to Firefox.
In principle it would be a nice project to add an Html importer to BlackBox but with
CSS it is a lot of work.

- Josef

Re: Copy and Paste looses text formatting

PostPosted: Mon Mar 12, 2018 7:19 am
by Zinn
During my test with Rem and Copy & Paste I found an error inside HostTextConv

Copy from Firefox via Libre Writer works OK
Copy from Firefox via Office Word looses the hyperlink address.

Solution:
Add in HostTextConv (or in Strings ???)

PROCEDURE LeftTrim (VAR str: ARRAY OF CHAR);
(* strip leading space from str *)
CONST tab = 9X; space = 20X; nbsp = 0A0X;
VAR i, n: INTEGER;
BEGIN
i := 0; WHILE (str[i] = space) OR (str[i] = tab) OR (str[i] = nbsp) DO INC(i) END;
IF i > 0 THEN
n := LEN(str$);
IF i < n THEN Strings.Extract(str, i, n - i, str) ELSE (* str is all spaces *) str[0] := 0X END
END
END LeftTrim;

and

...
ELSIF comm = "fldrslt" THEN (* field result *)
dest := text;
LeftTrim(fieldStr);
fieldStr[9] := 0X;
IF fieldStr = "HYPERLINK" THEN
...

Re: Copy and Paste looses text formatting

PostPosted: Mon Mar 12, 2018 8:35 am
by Bernhard
Since BlackBox has no Html importer there is only plain text left.


@helmut: I thought there is one in CPC: http://zinnamturm.eu/downloadsDH.htm#Html

and another question: there are extensions (at least for Firefox) extensions to have also Markdown Syntax in the clipboard. I have been tempted since quite some time to create a (configurable) Markdown importer/exporter, but I did not find the time to follow up that idea ... could that be also a solution for this Problem?

Re: Copy and Paste looses text formatting

PostPosted: Mon Mar 12, 2018 10:23 am
by Zinn
Bernhard, yes this can be another solution for my problem.
Saving the website as html and load them to BlackBox.

Currently I think about different kind of cut & paste (plain text & text including formatting)
However the correction above should be done. It doesn't matter which way we go.

Re: Copy and Paste looses text formatting

PostPosted: Mon Mar 12, 2018 11:29 am
by Bernhard
I don't have any ideas how the clipboard carries over formatting, but since Sepp mentioned RTF and/or HTML importers, I thought that it may depend on it or work with the importer ...

Re: Copy and Paste looses text formatting

PostPosted: Mon Mar 12, 2018 1:37 pm
by Josef Templ
For supporting HTML clipboard data it would be required to register an
appropriate HTML data converter (typically done in Config) via a call like this:

Code: Select all
OleData.Register("HostTextConv.ImportDHtml", "HostTextConv.ExportDHtml", "HTML Format", "TextViews.View", {});


HTML data is transferred as plain Utf-8 text but with an additional header that specifies some properties
(fragment start, fragment end, etc.) of the html fragment to be transferred.
Here is an example of the transferred data as provided by Chrome.
It looks similar when exported from Internet Explorer.

Code: Select all
Version:0.9
StartHTML:0000000170
EndHTML:0000000815
StartFragment:0000000206
EndFragment:0000000779
SourceURL:http://blackboxframework.org/index.php?cID=home,en-us
<html>
<body>
<!--StartFragment--><h1 style="margin: 0px 0px 15px; padding: 0px; font-size: 1.714em; font-weight: normal; font-family: PTSansBold, arial, sans-serif; font-style: normal; color: rgb(24, 24, 24); line-height: 1.2; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">What is BlackBox/Component Pascal?</h1><!--EndFragment-->
</body>
</html>


- Josef

Re: Copy and Paste looses text formatting

PostPosted: Mon Mar 12, 2018 2:17 pm
by Josef Templ
Zinn wrote:However the correction above should be done. It doesn't matter which way we go.


I agree. There is actually one more little problem with the existing code.
It leaves the closing double quote in the link. This is ignored by browsers, as far as I have tested,
but it should also be fixed. The fix is simple; change

Code: Select all
fieldStr[LEN(fieldStr$)-1] := 0X;

to

Code: Select all
fieldStr[LEN(fieldStr$)-2] := 0X;


It should also be checked in the RTF spec if there is always a double quote around the link.

- Josef