Skip to content

Commit

Permalink
remove empty inline tokens (#31)
Browse files Browse the repository at this point in the history
```md
![](img.png) {.asdf}
```

will give

```js
Token {
  type: 'inline',
  tag: '',
  attrs: null,
  map: [ 0, 1 ],
  nesting: 0,
  level: 1,
  children:
   [ Token {
       type: 'image',
       tag: 'img',
       attrs: [Object],
       map: null,
       nesting: 0,
       level: 0,
       children: [],
       content: '',
       markup: '',
       info: '',
       meta: null,
       block: false,
       hidden: false },
     Token {
       type: 'text',
       tag: '',
       attrs: null,
       map: null,
       nesting: 0,
       level: 0,
       children: null,
       content: '',
       markup: '',
       info: '',
       meta: null,
       block: false,
       hidden: false } ],
  content: '![](img.png)',
  markup: '',
  info: '',
  meta: null,
  block: true,
  hidden: false }
```

This removes last child with empty text. Fixes markdown-it-implicit-figures#13.
  • Loading branch information
arve0 authored Sep 22, 2016
1 parent 7406dcf commit 55d0f58
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ module.exports = function attributes(md) {
}

// attributes for blocks
var lastInlineToken;
if (hasCurly(tokens[i].content)) {
var content = last(inlineTokens).content;
lastInlineToken = last(inlineTokens);
var content = lastInlineToken.content;
var curlyStart = content.lastIndexOf('{');
var attrs = utils.getAttrs(content, curlyStart + 1, content.length - 1);
// if list and `\n{#c}` -> apply to bullet list open:
Expand Down Expand Up @@ -126,7 +128,11 @@ module.exports = function attributes(md) {
}
} else {
utils.addAttrs(attrs, correspondingBlock);
last(inlineTokens).content = removeCurly(content);
lastInlineToken.content = removeCurly(content);
if (lastInlineToken.content === '') {
// remove empty inline token
inlineTokens.pop();
}
tokens[i].content = removeCurly(tokens[i].content);
}
}
Expand Down

0 comments on commit 55d0f58

Please sign in to comment.