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
560 stars 88 forks source link

p inside td #31

Closed zoozalp closed 4 years ago

zoozalp commented 4 years ago

Hi,

I'm having a styling problem with the following html. Can you please help me figure this out?

<table border="1">
<tr>
<td>
<p><p> </p></p><p>BEN VE AİLEM</p><p><p> </p></p><p><span style="color: rgb(91, 155, 213);">ICH UND MEINE FAMILIE</span></p><p><p> </p></p><p><span style="color: rgb(91, 155, 213);"> </span></p><p><p> </p></p><p>Tanışma</p><p><p> </p></p><p><span style="color: rgb(91, 155, 213);">Kennenlernen</span></p><p><p> </p></p><p><span style="color: rgb(84, 141, 212);"> </span></p>
</td>
</tr>
</table>

The problem also exists in the playground.

image

Aymkdn commented 4 years ago

Can you replace your <p></p> with <br>? If yes, then it will work.

If you cannot, then I'll have to take some time to think about it... As it's Christmas holidays I may not have time to check it before at least a few days.

zoozalp commented 4 years ago

Nice catch! Content is coming from Quill. I'll try to replace as you suggested on the fly and see how it works.

zoozalp commented 4 years ago

It worked for the sample html I posted above but unfortunately it doesn't work for the rest of the document.

Here is another example;

<table border="1">
            <tbody>
                <tr>
                    <td align="center" valign="top">
                        <p>TARİH</p>
                        <p style="color: blue;">DATUM</p>
                    </td>
                    <td align="center" valign="top">
                        <p>ÜNİTE VE KONULAR</p>
                        <p style="color: blue;">LEKTIONEN UND THEMEN</p>
                    </td>
                </tr>
            </tbody>
</table>

image

Aymkdn commented 4 years ago

Ok. I'll review it later this week or sometime next week.

Aymkdn commented 4 years ago

It looks like the issue is related to PDFMake and not to my library. Inside cells, we have to use \n to have the texte on several lines (based on PDFMake website).

So, I guess you're stuck with using <br>. You can inject <br> after your </p> in your HTML code. For example:

yourHTMLcode.replace(/<\/p>\n(\s+)?<p/g,'</p><br><p')

It will return (using your last example):

<table border="1">
  <tbody>
    <tr>
      <td align="center" valign="top">
        <p>TARİH</p><br><p style="color: blue;">DATUM</p>
      </td>
      <td align="center" valign="top">
        <p>ÜNİTE VE KONULAR</p><br><p style="color: blue;">LEKTIONEN UND THEMEN</p>
      </td>
    </tr>
  </tbody>
</table>

And, once translated by html-to-pdfmake: Capture