douceur icon indicating copy to clipboard operation
douceur copied to clipboard

nbsp is replaced with space

Open shardnit opened this issue 8 years ago • 2 comments

The inliner library replaces   is replaced with a space character. In my opinion, inliner should leave   as it is. Here is a short test.

html := `
<html>
  <head>
  <style type="text/css">
    body {
      background-color: #f2f2f2;
    }
  </style>
  </head>
  <body>
    <p>&nbsp;</p>
  </body>
</html>`
inline, _ := inliner.Inline(html)
fmt.Println(inline)

This prints:

<html><head>

  </head>
  <body style="background-color: #f2f2f2;" bgcolor="#f2f2f2">
    <p> </p>

</body></html>

Any quick fix for this?

shardnit avatar Jul 12 '16 09:07 shardnit

it happens with

&copy;

too

rraymondseek avatar Nov 07 '16 05:11 rraymondseek

Stuck into the same problem, after some hours searching came up with a solution.

The problem is: the inliner library parses html using the standard library into tree, replacing all special html symbols with unicode ones (e.g. "&nbsp;" is replaced by "\u00a0"). So when you do

fmt.Println(inline)

the non-breaking space will be printed as an ordinary space.

I found an example solution there: https://gist.github.com/brandonrachal/10605780

Minimal playground test likely gives us the expected result: https://play.golang.org/p/rgYqA7x7jL3

Hope it'll help!

nexterot avatar Feb 29 '20 00:02 nexterot