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

set correct nesting when adding container #29

Closed
arve0 opened this issue Apr 22, 2019 · 1 comment
Closed

set correct nesting when adding container #29

arve0 opened this issue Apr 22, 2019 · 1 comment

Comments

@arve0
Copy link

arve0 commented Apr 22, 2019

To reproduce:

let md = require('markdown-it')();
let container = require('markdown-it-container');

md.use(container, 'column');

let src = `
::: column
Lorem ipsum
:::
`;

console.log(md.render(src));

gives tokens:

[
  Token {type: "container_column_open", tag: "div", attrs: null, map: Array(2), nesting: 1, …},
  Token {type: "paragraph_open", tag: "p", attrs: null, map: Array(2), nesting: 1, …}
  ...
]

Note that div and p both have nesting === 1, which is incorrect, as p is inside div.

This results in arve0/markdown-it-attrs#72, attributes on the wrong opening tag.

@rlidwka
Copy link
Member

rlidwka commented Jul 5, 2019

Note that div and p both have nesting === 1, which is incorrect, as p is inside div.

It is correct. Nesting does not represent a level of nesting, it represent a change of level of nesting.

See here for more details.

I believe what you are looking for is level property which is hidden behind in your dump.

Full dump of tokens:

[ Token {
    type: 'container_column_open',
    tag: 'div',
    attrs: null,
    map: [ 1, 3 ],
    nesting: 1,
    level: 0,
    children: null,
    content: '',
    markup: ':::',
    info: ' column',
    meta: null,
    block: true,
    hidden: false },
  Token {
    type: 'paragraph_open',
    tag: 'p',
    attrs: null,
    map: [ 2, 3 ],
    nesting: 1,
    level: 1,
    children: null,
    content: '',
    markup: '',
    info: '',
    meta: null,
    block: true,
    hidden: false },
  Token {
    type: 'inline',
    tag: '',
    attrs: null,
    map: [ 2, 3 ],
    nesting: 0,
    level: 2,
    children: [ [Token] ],
    content: 'Lorem ipsum',
    markup: '',
    info: '',
    meta: null,
    block: true,
    hidden: false },
  Token {
    type: 'paragraph_close',
    tag: 'p',
    attrs: null,
    map: null,
    nesting: -1,
    level: 1,
    children: null,
    content: '',
    markup: '',
    info: '',
    meta: null,
    block: true,
    hidden: false },
  Token {
    type: 'container_column_close',
    tag: 'div',
    attrs: null,
    map: null,
    nesting: -1,
    level: 0,
    children: null,
    content: '',
    markup: ':::',
    info: '',
    meta: null,
    block: true,
    hidden: false } ]

@puzrin puzrin closed this as completed Jul 5, 2019
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