Repository: arve0/markdown-it-attrs (js)

Issue:
Unable to apply attributes to the last column of tables.
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:**

```md
| title | title |
| :----: | :----: |
| text | text {.text-primary} | 
| text {.text-primary} | text |
```

**Current output:**

```html
<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:**

```html
<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:**

```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>
```

Pull request:
fix: apply attributes to the last column of tables
fixed #150, ref the `should apply attributes to the last column of tables` test case.

Patch:
diff --git a/patterns.js b/patterns.js
index 3f8f2e5..be68fe3 100644
--- a/patterns.js
+++ b/patterns.js
@@ -324,7 +324,7 @@ module.exports = options => {
         const content = token.content;
         const attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), options);
         let ii = i + 1;
-        while (tokens[ii + 1] && tokens[ii + 1].nesting === -1) { ii++; }
+        do if (tokens[ii] && tokens[ii].nesting === -1) { break; } while (ii++ < tokens.length);
         const openingToken = utils.getMatchingOpeningToken(tokens, ii);
         utils.addAttrs(attrs, openingToken);
         const trimmed = content.slice(0, content.lastIndexOf(options.leftDelimiter));


Test patch:
diff --git a/test.js b/test.js
index da9e9a5..88d47f7 100644
--- a/test.js
+++ b/test.js
@@ -292,6 +292,34 @@ function describeTestsWithOptions(options, postText) {
       assert.equal(md.render(replaceDelimiters(src, options)), expected);
     });
 
+    it(replaceDelimiters('should apply attributes to the last column of tables', options), () => {
+      src = '| title | title {.title-primar} |\n';
+      src += '| :---: | :---: |\n';
+      src += '| text | text {.text-primar} |\n';
+      src += '| text {.text-primary} | text |\n';
+      src += '\n';
+      src += '{.c}';
+      expected = '<table class="c">\n';
+      expected += '<thead>\n';
+      expected += '<tr>\n';
+      expected += '<th style="text-align:center">title</th>\n';
+      expected += '<th style="text-align:center" class="title-primar">title</th>\n';
+      expected += '</tr>\n';
+      expected += '</thead>\n';
+      expected += '<tbody>\n';
+      expected += '<tr>\n';
+      expected += '<td style="text-align:center">text</td>\n';
+      expected += '<td style="text-align:center" class="text-primar">text</td>\n';
+      expected += '</tr>\n';
+      expected += '<tr>\n';
+      expected += '<td style="text-align:center" class="text-primary">text</td>\n';
+      expected += '<td style="text-align:center">text</td>\n';
+      expected += '</tr>\n';
+      expected += '</tbody>\n';
+      expected += '</table>\n';
+      assert.equal(md.render(replaceDelimiters(src, options)), expected);
+    });
+
     it(replaceDelimiters('should support nested lists', options), () => {
       src =  '- item\n';
       src += '  - nested\n';