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

<p> without close tag is added when list has bold text and a previous linebreak #87

Closed
shuedo opened this issue Apr 5, 2024 · 3 comments · Fixed by #88
Closed

<p> without close tag is added when list has bold text and a previous linebreak #87

shuedo opened this issue Apr 5, 2024 · 3 comments · Fixed by #88
Assignees
Labels
bug Something isn't working

Comments

@shuedo
Copy link
Contributor

shuedo commented Apr 5, 2024

Describe the bug
When a list that contains text with attribute bold (it may happen with other kind of inline attributes) has a previous linebreak, the next paragraph after the list breaks.

The delta code which generates the Problem

This is the delta code that fails:

[
  {
    "insert": "This is begin text:\n\n"
  },
  {
    "attributes": {
      "bold": true
    },
    "insert": "Bold text"
  },
  {
    "insert": " and regular text"
  },
  {
    "attributes": {
      "list": "bullet"
    },
    "insert": "\n"
  },
  {
    "insert": "Another bullet"
  },
  {
    "attributes": {
      "list": "bullet"
    },
    "insert": "\n"
  },
  {
    "insert": "Another text after list"
  }
]

The expected html output the delta should produce

It should produce this:

<p>This is begin text:</p><p><br></p><ul><li><strong>Bold text</strong> and regular text</li><li>Another bullet</li></ul><p>Another text after list</p>

But the result is this:

<p>This is begin text:</p><p><br></p><p><ul><li><strong>Bold text</strong> and regular text</li><li>Another bullet</li></ul>Another text after list</p>

Notice the additional <p> tag before the <ul>, which breaks the HTML structure.

Additional context
Upon investigating the Text.render function, it appears that the issue stems from this conditional statement:

} elseif ($pick->line->isEmpty() && $next) {
     $isOpen = $this->output($output, self::CLOSEP.self::OPENP, true);
}

In cases where there is a line break, the variable $next contains the line text <strong>Bold text</strong>, which is inline but also marked as "Done." Consequently, an opening <p> tag is generated due to the fulfillment of the if condition, but it fails to close properly because the line is marked as "Done."

Proposed solution:

Updating the condition to the following resolves the issue:

elseif ($pick->line->isEmpty() && $next && !$next->isDone()) {

This adjustment ensures that the <p> tag is only opened when the next line is not marked as "Done," effectively resolving the problem.

@shuedo shuedo changed the title <p> is added <p> without close tag is added when list has bold text and a previous linebreak Apr 5, 2024
@nadar
Copy link
Owner

nadar commented Apr 5, 2024

thanks for the report. i will create a Pull Request.

@nadar
Copy link
Owner

nadar commented Apr 5, 2024

(@shuedo maybe you like to create a pull request, would be welcome.)

@nadar nadar self-assigned this Apr 5, 2024
@nadar nadar added the bug Something isn't working label Apr 5, 2024
@shuedo
Copy link
Contributor Author

shuedo commented Apr 5, 2024

(@shuedo maybe you like to create a pull request, would be welcome.)

Ok thanks! I will create it.

shuedo added a commit to shuedo/quill-delta-parser that referenced this issue Apr 5, 2024
@shuedo shuedo mentioned this issue Apr 5, 2024
@nadar nadar closed this as completed in #88 Apr 5, 2024
nadar pushed a commit that referenced this issue Apr 5, 2024
* Fix issue #87

* Added changelog

---------

Co-authored-by: Sandra Huedo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants