Re: CSS and copy/pasting guidelines

On Wed, Apr 6, 2016 at 9:25 PM, fantasai <fantasai.lists@inkedblade.net>
wrote:
...

>
> HTML copying is a bit more complicated; there are three ways to do it:
>   a) Copy exact formatting.
>   b) Copy rich text for pasting into another document
>      such that it adopts the document's style.
>   c) Copy just the HTML, without any intelligence
>
> a) is solved by copy using style attributes or equivalent techniques
> to embed the formatting into the HTML. It is sometimes what's wanted,
> but I almost always want b). (I have pasted text into MS Word *so
> many times* and needed to 100% reformat it because of this problem
> with a). I have *never* wanted the font settings of the web page to
> come with the paste.)
>
> b) is solved by inlining the styles applied to elements *within* the
> selection, but not the styles inherited from outside the selection.
> This preserves things like bolding within the text, or complex
> constructs like blockquotes and tables within the text. But it lets
> the paste context control the font family and font size, which for
> short snippets is nearly always what you want and for longer snippets
> is probably still a more useful option.
>
> c) is similar to b); it is more advantageous for JS applications,
> pasting within the same application as the copy; perhaps less so
> for pasting from HTML into some external application.
>


Two years ago, cleaning up the paste that came from word processors in
JavaScript at times involved removing style and script elements (not sure
it has changed since then).

I wonder if it's possible to find a compromise on richtext paste
information that will work for several of the above mentioned use cases --
for example to promise not to change the HTML structure, but to add CSS
styling that the browser believes will be helpful at the moment the content
is pasted.

If the receiving application doesn't want any of the extra styling, it can
simply walk through the incoming nodes and remove all style elements and
tags. If the application wants to preserve this information, it can also do
that.

I assume this will work the same for word processors and other C/C++
programs.

The cleaning filter I used to maintain took paste input from Word and
LibreOffice, determined where there were footnotes based on classnames
(sdfootnoteanc/sdfootnotesym/sdfootnote) and then treated them differently
than the rest of the content. This is likely not what every app would want
to do, but if there is more information in the richtext available, it will
allow for a great number of apps to treat paste content to treat it in the
best possible way.

One example where I was not successful were citations in LibreOffice
handled by Zotero. Copying and pasting this, there was no semantic
information available that could have helped me in trying to recover the
citations.


>
>
> You really only want a) if you're trying to create a patchwork quilt
> of web page snippets, and that's a pretty rare use case and also has
> many other problems to solve as well given that CSS layout reflows
> into its container. I don't think it's a useful behavior. Between
> b) and c) I don't have a strong opinion, and leave that up to you
> experts. :)
>
> ~fantasai
>



-- 
Johannes Wilm
Fidus Writer
http://www.fiduswriter.org

Received on Thursday, 7 April 2016 15:04:38 UTC