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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug in TextDelta.lines(document) for a particular edge case #5

Open
achedeuzot opened this issue Jun 25, 2022 · 0 comments
Open

Comments

@achedeuzot
Copy link

achedeuzot commented Jun 25, 2022

Hello 馃憢

I'm currently using your awesome library to do a TextDelta to HTML converter on the backend side.

When converting a particular document to lines, I noticed some attributes were lost in translation.

Sample unexpected output

input_textdelta = %TextDelta{
  ops: [
    %{insert: "\nTitle 1"},
    %{attributes: %{header: 1}, insert: "\n"},
    %{insert: "\nTitle 2"},
    %{attributes: %{header: 1}, insert: "\n\n"},
    %{insert: "\n"}
  ]
}

TextDelta.lines(input_textdelta)
# Outputs:
{:ok,
 [
   {%TextDelta{ops: []}, %{}},
   {%TextDelta{ops: [%{insert: " Title 1"}]}, %{header: 1}},
   {%TextDelta{ops: []}, %{}},
   {%TextDelta{ops: [%{insert: " Title 2"}]}, %{}}, # <=== Here, we're missing the attribute `header: 1`
   {%TextDelta{ops: []}, %{}}, # <=== Here as well. 馃 
   {%TextDelta{ops: []}, %{}}
 ]}

As you can see, the %{header: 1} attribute has been lost on Title 2 and the subsequent line. This only seems to happen on the last lines of the document. The rest of the document is properly separated into lines.

What makes me say it's a potential bug is that when comparing with the HTML output of QuillJS, this generates the following HTML:

<p><br><p>
<h1>Title 1</h1>
<p><br><p>
<h1>Title 2</h1>
<h1><br></h1>
<p><br><p>

I'll see if I can provide a pull request fixing the issue and thanks again for this awesome library 馃樆

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

1 participant