Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant