Copy HTML with CSS to Libre Office

css, html, libreoffice

Solution

It seems that the style of `<body>` is discarded and only inline CSS is used when you copy and paste. For me, copying from Firefox and pasting in LibreOffice, the following HTML didn't retain formatting:

<head>
  <style type="text/css">
    body { font-family: sans-serif; font-size: 15px; }
    span { color: red; }
  </style>
</head>
<body>
  Lorem ipsum <span>dolor</span> sit amet.
</body>

and

<body style="font-family: sans-serif; font-size: 15px;">
  Lorem ipsum dolor sit amet.
</body>

But the following worked as expected:

<body>
  <div style="font-family: sans-serif; font-size: 15px;">
    Lorem ipsum <span style="color: red;" >dolor</span> sit amet.
  </div>
</body>

Problem

I have an HTML page styled with CSS. I would like to copy it to Libre Office Writer, so that I can edit it. However, when I copy & paste, only the HTML is copied, without the style. I tried "Paste Special - HTML" and got the same results. I use Libre Office 3.5.3.2 on Ubuntu 12.04.

Original source