ecency / render-helper

Render helper for Ecency social apps, markdown2html and markdown2amp. Package name @ecency/render-helper
https://ecency.com
MIT License
3 stars 10 forks source link

Table parsing issue #36

Open noumantahir opened 2 years ago

noumantahir commented 2 years ago

I have a clear lead on table rendering issue, but I have literally no idea how to fix it.....Need assistance @here since it is more html related....

The input we are getting from the post is missing closing</tr> tags that is causing the malfunction, if we put the tags manually, the problem goes away, but obviously we cannot always control such conditions. Details below elaborate my findings after experimenting with input post body for some time. I have put together a simplified table to replicate the source of issue.

        <table>
        <thead>
        <tr><th>Table 1 Header 1</th><th>Table 1 Header 2</th></tr>
        </thead>
        <tbody>
        <tr><td>Table 1 Body 1</td>
        <td>Table 1 Body 2</td>
        </tbody>
        </table>
        <table>
        <thead>
        <tr><th>Table 2 Header 1</th><th>Table 2 Header 2</th></tr>
        </thead>
        <tbody>
        <tr><td>Table 2 Body 1</td>
        <td>Table 2 Body 2</td> 
        </tbody>
        </table>

Body images show the input and output we are getting from render-helper.
 Screenshot 2022-02-23 at 1 03 07 PM

Screenshot 2022-02-23 at 12 57 42 PM

Code image show where everything goes south. Screenshot 2022-02-23 at 12 59 30 PM

Since closing table tags was removed the renderer tries to cramp everything in a single table, The resulting table is rendered something like this. Screenshot 2022-02-23 at 1 03 59 PM

However if we feed the sample post body directly to renderer, it works just fine even without the closing </tr> tags in table body. This leads me to conclusion that only if we are able to make render-helper not remove the closing table tags </table> that should as well fix the rendering issue we are experiencing. Screenshot 2022-02-23 at 1 07 30 PM

noumantahir commented 2 years ago

One hack I can think of is, before processing or html, check if there exist a</tr> tag just before </tbody>, if it does not, place one and process the body.

BEOFRE:

 <table>
<table>
    <thead>
        <tr>
            <th>Table 1 Header 1</th>
            <th>Table 1 Header 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Table 1 Body 1</td>
            <td>Table 1 Body 2</td>
    </tbody>
</table>

AFTER

<table>
    <thead>
        <tr>
            <th>Table 1 Header 1</th>
            <th>Table 1 Header 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Table 1 Body 1</td>
            <td>Table 1 Body 2</td>
        </tr> //---------------------------manually added tr tag before render-helper processing
    </tbody>
</table>

Precautions: not sure how this would respond if there are more than one rows per table without </tr> tag

feruzm commented 2 years ago

@noumantahir As this is user error in content body, I don't think we need to add any workaround yet. Unless it is quite common issue.

noumantahir commented 2 years ago

@feruzm my guess is, the platform user used to create this post content is the one we should check.... perhaps we can reach out to user for understanding more about that platform

feruzm commented 2 years ago

@noumantahir agreed, will write a comment and hope they will respond. Reference: https://ecency.com/hive-163772/@archimax72/villa-deste-in-tivoli-rome-engita