Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rope_htmlrender: fix some HTML rendering bugs #57

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft

rope_htmlrender: fix some HTML rendering bugs #57

wants to merge 7 commits into from

Conversation

ee7
Copy link

@ee7 ee7 commented Feb 21, 2024

Fixes crashappsec/chalk#178.

Consider this HTML:

<table>
  <caption>Commands</caption>
  <tbody>
    <tr>
      <th>Command Name</th>
      <th>Description</th>
    </tr>
    <tr>
      <td>insert</td>
      <td>Add chalk marks to artifacts</td>
    </tr>
    <tr>
      <td>docgen</td>
      <td>Generate technical documentation</td>
    </tr>
  </tbody>
</table>

Before this PR, if we converted that to a Rope then called toHtml, we'd get invalid HTML:

<div>

<table>

<tbody>

<td>

<th>
Command Name</th>
</td>


<td>

<th>
Description</th>
</td>


<td>

<td>
insert</td>
</td>


<td>

<td>
Add chalk marks to artifacts</td>
</td>


<td>

<td>
docgen</td>
</td>


<td>

<td>
Generate technical documentation</td>
</td>
</tbody>

<caption>

<caption>
Commands</caption>
</caption>
</table>

<div>
</div>
</div>

The errors:

  • an extra <td> pair around each cell
  • no <tr> anywhere
  • <caption> at the bottom, but <caption> must be the first child of <table>

See the errors when pasting into https://validator.w3.org/#validate_by_input.

With this PR, toHtml produces valid HTML for that input:

<div>
<table>
<caption>
Commands
</caption>

<tbody>

<tr>

<th>
Command Name
</th>

<th>
Description
</th>

</tr>

<tr>

<td>
insert
</td>

<td>
Add chalk marks to artifacts
</td>

</tr>

<tr>

<td>
docgen
</td>

<td>
Generate technical documentation
</td>

</tr>

</tbody>
</table>
<div>

</div>

</div>

which prettifies to something that's the same as the input, except:

+<div>
   <table>
     <caption>Commands</caption>
     <tbody>
       <tr>
         <th>Command Name</th>
         <th>Description</th>
       </tr>
       <tr>
         <td>insert</td>
         <td>Add chalk marks to artifacts</td>
       </tr>
       <tr>
         <td>docgen</td>
         <td>Generate technical documentation</td>
       </tr>
     </tbody>
   </table>
+  <div></div>
+</div>

Remove invalid <td> and </td>, and add missing <tr> and </tr>.
This rendering isn't great, but at least it's valid HTML now.
Before this commit:

    <caption>

    <caption>
    Commands
    </caption>

    </caption>

With this commit:

    <caption>
    Commands
    </caption>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant