arve0 / markdown-it-attrs

Add classes, identifiers and attributes to your markdown with {} curly brackets, similar to pandoc's header attributes
MIT License
300 stars 58 forks source link

Unable to apply attributes to the last column of tables. #150

Closed RedSparr0w closed 3 months ago

RedSparr0w commented 1 year ago

Unable to apply attributes to the last column of tables, if there is an attribute in the last <td> it will apply it to the parent <tr>.

Markdown-it versions:

markdown-it@13.0.1
markdown-it-attrs@4.1.6

Example input:

| title | title |
| :----: | :----: |
| text | text {.text-primary} | 
| text {.text-primary} | text |

Current output:

<table>
  <thead>
    <tr>
      <th style="text-align:center">title</th>
      <th style="text-align:center">title</th>
    </tr>
  </thead>
  <tbody>
    <tr class="text-primary">
      <td style="text-align:center">text</td>
      <td style="text-align:center">text</td>
    </tr>
    <tr>
      <td style="text-align:center" class="text-primary">text</td>
      <td style="text-align:center">text</td>
    </tr>
  </tbody>
</table>

Expected output:

<table>
  <thead>
    <tr>
      <th style="text-align:center">title</th>
      <th style="text-align:center">title</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="text-align:center">text</td>
      <td style="text-align:center" class="text-primary">text</td>
    </tr>
    <tr>
      <td style="text-align:center" class="text-primary">text</td>
      <td style="text-align:center">text</td>
    </tr>
  </tbody>
</table>

Diff:

<table>
  <thead>
    <tr>
      <th style="text-align:center">title</th>
      <th style="text-align:center">title</th>
    </tr>
  </thead>
  <tbody>
-    <tr class="text-primary">
+    <tr>
      <td style="text-align:center">text</td>
-      <td style="text-align:center">text</td>
+      <td style="text-align:center" class="text-primary">text</td>
    </tr>
    <tr>
      <td style="text-align:center" class="text-primary">text</td>
      <td style="text-align:center">text</td>
    </tr>
  </tbody>
</table>
arve0 commented 3 months ago

Fixed in v4.2.0, thanks to @TheNorthMemory :octocat: