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

Issue:
Incorrect attribute assignment for bracketed text within code within items
I came across this bug while writing a README for a javascript package.

This test fails (see https://github.com/rivy/js.markdown-it-attrs/commit/795a537a53b54ec2a877e2d710c3cc66c0eede9e in [rivy/js.markdown-it-attrs/fix.item+code](https://github.com/rivy/js.markdown-it-attrs/tree/fix.item+code))...

```
    it(replaceDelimiters('should not apply inside item lists with `code{.red}`', options), () => {
      src = '- item with `code = {.red}`';
      expected = '<ul>\n<li>item with <code>code = {.red}</code></li>\n</ul>\n';
      assert.equal(md.render(replaceDelimiters(src, options)), replaceDelimiters(expected, options));
    });
```

The bracketed text is being removed from the code section and applied as an attribute to the item. It should, I believe, stay within the code section, untouched.

Example input:
```md
- item with `code = {.red}`
```

Current output:
```html
<ul>
<li class="red">item with <code>code =</code></li>
</ul>
```

Expected output:
```html
<ul>
<li>item with <code>code = {.red}</code></li>
</ul>
```


Pull request:
Fix ~ correct application of trailing 'attr-like' strings within items
* fixes #94 

Patch:
diff --git a/patterns.js b/patterns.js
index bb147db..6fad938 100644
--- a/patterns.js
+++ b/patterns.js
@@ -150,6 +150,7 @@ module.exports = options => {
               type: 'softbreak'
             }, {
               position: -1,
+              type: 'text',
               content: utils.hasDelimiters('only', options)
             }
           ]
@@ -219,6 +220,7 @@ module.exports = options => {
           children: [
             {
               position: -1,
+              type: 'text',
               content: utils.hasDelimiters('end', options)
             }
           ]
@@ -334,4 +336,4 @@ module.exports = options => {
 // get last element of array or string
 function last(arr) {
   return arr.slice(-1)[0];
-}
\ No newline at end of file
+}


Test patch:
diff --git a/test.js b/test.js
index cad860b..5935b1c 100644
--- a/test.js
+++ b/test.js
@@ -219,6 +219,22 @@ function describeTestsWithOptions(options, postText) {
       assert.equal(md.render(replaceDelimiters(src, options)), expected);
     });
 
+    it(replaceDelimiters('should add class ul after a "softbreak"', options), () => {
+      src = '- item\n{.blue}';
+      expected = '<ul class="blue">\n';
+      expected += '<li>item</li>\n';
+      expected += '</ul>\n';
+      assert.equal(md.render(replaceDelimiters(src, options)), expected);
+    });
+
+    it(replaceDelimiters('should ignore non-text "attr-like" text after a "softbreak"', options), () => {
+      src = '- item\n*{.blue}*';
+      expected = '<ul>\n';
+      expected += '<li>item\n<em>{.blue}</em></li>\n';
+      expected += '</ul>\n';
+      assert.equal(md.render(src), expected);
+    });
+
     it(replaceDelimiters('should work with ordered lists', options), () => {
       src = '1. item\n{.blue}';
       expected = '<ol class="blue">\n';
@@ -309,6 +325,18 @@ function describeTestsWithOptions(options, postText) {
       assert.equal(md.render(replaceDelimiters(src, options)), replaceDelimiters(expected, options));
     });
 
+    it(replaceDelimiters('should not apply inside item lists with trailing `code{.red}`', options), () => {
+      src = '- item with trailing `code = {.red}`';
+      expected = '<ul>\n<li>item with trailing <code>code = {.red}</code></li>\n</ul>\n';
+      assert.equal(md.render(replaceDelimiters(src, options)), replaceDelimiters(expected, options));
+    });
+
+    it(replaceDelimiters('should not apply inside item lists with trailing non-text, eg *{.red}*', options), () => {
+      src = '- item with trailing *{.red}*';
+      expected = '<ul>\n<li>item with trailing <em>{.red}</em></li>\n</ul>\n';
+      assert.equal(md.render(replaceDelimiters(src, options)), replaceDelimiters(expected, options));
+    });
+
     it(replaceDelimiters('should work with multiple inline code blocks in same paragraph', options), () => {
       src = 'bla `click()`{.c} blah `release()`{.cpp}';
       expected = '<p>bla <code class="c">click()</code> blah <code class="cpp">release()</code></p>\n';