Skip to content

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>

ee7 added 7 commits February 21, 2024 12:37
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.

2 participants