Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: link_open and link_close Have Different Levels #466

Closed
ilyaigpetrov opened this issue Jun 13, 2018 · 1 comment
Closed

Bug: link_open and link_close Have Different Levels #466

ilyaigpetrov opened this issue Jun 13, 2018 · 1 comment

Comments

@ilyaigpetrov
Copy link

For input [AA homer.j.simpson@example.com BB](mailto:homer.j.simpson@example.com) link_open and link_close tokens have different levels. I think it may be a bug, otherwise, please, explain it to me why they have different levels.
Markdown-it version: 8.4.1.

'use strict';

const md = require('markdown-it')();

md.core.ruler.push('buggy_levels', (state) => {

  const blockTokens = state.tokens;
  for (let j = 0, l = blockTokens.length; j < l; j++) {
    if (
      !(blockTokens[j].type === 'inline' && blockTokens[j].content.includes('@'))
    ) {
      continue;
    }
    const tokens = blockTokens[j].children;
    console.log('LOOK AT LEVELS:', tokens.map((t) => [t.type, t.level]));

    for (let i = tokens.length - 1; i >= 0; --i) {

      if (tokens[i].type !== 'link_close') {
        continue;
      }
      const linkCloseToken = tokens[i];
      const linkCloseIndex = i;

      do {
        --i;
      } while (!(tokens[i].level === linkCloseToken.level && tokens[i].type === 'link_open'));
      if (!tokens[i].attrGet('href').startsWith('mailto:')) {
        continue;
      }
      console.log('NO BUG ANYMORE!');
    }
  }
});

const input = '[AA homer.j.simpson@example.com BB](mailto:homer.j.simpson@example.com)';
console.log(md.render(input));

Online demo on RunKit

@rlidwka
Copy link
Member

rlidwka commented Jul 12, 2019

It was a bug due to oversight when these levels were re-calculated.

Fixed, thanks for reporting.

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

No branches or pull requests

2 participants