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

token.attrJoin is not a function #144

Open
zim32 opened this issue Sep 7, 2022 · 8 comments
Open

token.attrJoin is not a function #144

zim32 opened this issue Sep 7, 2022 · 8 comments

Comments

@zim32
Copy link

zim32 commented Sep 7, 2022

Versions:

+-- [email protected]
+-- [email protected]
`-- [email protected]

Example input:

There are two *ways*{.red} to install

Current output:

Uncaught (in promise) Error: Module build failed (from ./node_modules/@vuepress/markdown-loader/index.js):
TypeError: token.attrJoin is not a function

@zim32
Copy link
Author

zim32 commented Sep 7, 2022

Problem is somewhere in utils.getMatchingOpeningToken(tokens[i].children, j - 1);

This function returns false, and then there is no check of false value, it is just passed to utils.addAttrs(attrs, openingToken);
Here is token that causes getMatchingOpeningToken to return false

Token {
  type: 'em_close',
  tag: 'em',
  attrs: null,
  map: null,
  nesting: -1,
  level: 0,
  children: null,
  content: '',
  markup: '*',
  info: '',
  meta: null,
  block: false,
  hidden: false
}

@zim32
Copy link
Author

zim32 commented Sep 7, 2022

After more debugging I found that level is not correct

I have this text

There are two *ways*{.red} to install

and here is token stream. I don't know why on Earth em_open and em_close have different level property and why nesting is -1

Token {
  type: 'em_close',
  tag: 'em',
  attrs: null,
  map: null,
  nesting: -1,
  level: 0,
  children: null,
  content: '',
  markup: '*',
  info: '',
  meta: null,
  block: false,
  hidden: false
}
Token {
  type: 'text',
  tag: '',
  attrs: null,
  map: null,
  nesting: 0,
  level: 1,
  children: null,
  content: 'ways',
  markup: '',
  info: '',
  meta: null,
  block: false,
  hidden: false
}
Token {
  type: 'em_open',
  tag: 'em',
  attrs: null,
  map: null,
  nesting: 1,
  level: 1,
  children: null,
  content: '',
  markup: '*',
  info: '',
  meta: null,
  block: false,
  hidden: false
}
Token {
  type: 'text',
  tag: '',
  attrs: null,
  map: null,
  nesting: 0,
  level: 0,
  children: null,
  content: 'There are two ',
  markup: '',
  info: '',
  meta: null,
  block: false,
  hidden: false
}

@zim32
Copy link
Author

zim32 commented Sep 7, 2022

Right now if I remove tokens[i].level === level check from this code

for (; i >= 0; --i) {
    if (tokens[i].type === type && tokens[i].level === level) {
      return tokens[i];
    }
  }

in getMatchingOpeningToken function it works. But this is wrong

@arve0
Copy link
Owner

arve0 commented Sep 8, 2022

Hi👋 Thanks for the detailed description. What version of markdown-it do you use?

@zim32
Copy link
Author

zim32 commented Sep 8, 2022

Actually I don't know. Im using vuepress. You can see version in issue

@zim32
Copy link
Author

zim32 commented Sep 8, 2022

Maybe this will help you

@aufdenpunkt
Copy link

I have the same issue when using markdown-it-bracketed-spans. Is this may more be related to https://github.com/mb21/markdown-it-bracketed-spans?

@zim32
Copy link
Author

zim32 commented Sep 11, 2022

I think the problem is not with this plugin but with markdown-it itself. Or maybe vuepress. Very hard to tell

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

3 participants