Skip to content

Empty text syntax tree node added when using two md text styles #374

@ffolkes1911

Description

@ffolkes1911

Describe the bug

context
When I parse markdown:

new _li**ne**_  
a  

expectation
I expected to get output:

<root>
  <paragraph>
    <text>
      new 
    <em>
      <text>
        li
      <strong>
        <text>
          ne
    <hardbreak>
    <text>
      a

bug
But instead I get:

<root>
  <paragraph>
    <text>
      new 
    <em>
      <text>
        li
      <strong>
        <text>
          ne
      <text>
    <hardbreak>
    <text>
      a

There's an additional <text> empty node being inserted at the end. Problem seems to occur when there are nested styles and both end at the same time.

Reproduce the bug

Code:

from markdown_it import MarkdownIt
from markdown_it.tree import SyntaxTreeNode

md = MarkdownIt('gfm-like').disable(['linkify'])
text = ("""
new _li**ne**_  
new _l**i**ne_  
new _**line**_  
""")
tokens = md.parse(text)
node = SyntaxTreeNode(tokens)
print("------\n" + node.pretty(indent=2, show_text=True) + "------\n")

output:

------
<root>
  <paragraph>
    <inline>
      <text>
        new 
      <em>
        <text>
          li
        <strong>
          <text>
            ne
        <text>
      <hardbreak>
      <text>
        new 
      <em>
        <text>
          l
        <strong>
          <text>
            i
        <text>
          ne
      <hardbreak>
      <text>
        new 
      <em>
        <text>
        <strong>
          <text>
            line
        <text>------

List your environment

Version of markdown-it-py - 4.0.0
Versions of mdit-py-plugins - none
The version of Python you're using. - 3.10.6
Your operating system - Ubuntu 20.04.6 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions