Aymkdn / html-to-pdfmake

This module permits to convert HTML to the PDFMake format
https://aymkdn.github.io/html-to-pdfmake/index.html
MIT License
545 stars 88 forks source link

Text inside a <pre> tag is flattened #184

Closed GameDungeon closed 1 year ago

GameDungeon commented 1 year ago

In HTML the \

 tag is a preformatted text tag. All of the text inside it is supposed to stay in the same spot. Currently, the whitespace is being stripped and newlines removed, which breaks the functionality of the tag. This behavior makes it very difficult to, for example, display HTML syntax in the pdf as it all gets flattened into a single line.

Aymkdn commented 1 year ago

Could you please give some HTML sample code? I'll check that tomorrow.

GameDungeon commented 1 year ago

Testing it using your pages, this works in the HTML viewer and then is flattened in the generated PDF.

<div>
  <h1>Pre Tags</h1>
  <p>This is some sample CSS:</p>

  <pre>
a { 
    text-decoration: none; 
}
  </pre>
</div>
Aymkdn commented 1 year ago

That should now work with v2.4.21

GameDungeon commented 1 year ago

Thanks for making a change so quickly. One thing to note, pre tags apply their functionality to other tags inside them.

This is a very common pattern that does not quite work yet.

<div>
  <h1>Pre Tags</h1>
  <p>This is some sample CSS:</p>

  <pre><code>
a { 
    text-decoration: none; 
}
  </code></pre>
</div>
Aymkdn commented 1 year ago

OK, I've just added preserveLeadingSpaces:true to all the children of a PRE. I'm not sure it's the expected behavior 🤷‍♂

GameDungeon commented 1 year ago

That's similar to how it works in the spec, so that will probably be good enough generally. Thanks a ton.