-
Notifications
You must be signed in to change notification settings - Fork 7
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
Preserve whitespace in text nodes #26
Conversation
- Don't remove whitespace from text when converting nodes to_h
lib/tip_tap/nodes/text.rb
Outdated
@@ -22,7 +22,7 @@ def self.from_json(json) | |||
end | |||
|
|||
def to_h | |||
data = {type: type_name, text: text.presence || ""} | |||
data = {type: type_name, text: text} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC I did the presence || ""
bit because text
was nil
sometimes and TipTap JS wouldn't render the document stating that text can't be null
. It turns out that text can't be an empty string either so my fix didn't actually work. I'm actually surprised that this is removing your " "
string since that isn't empty?
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah but it is blank?
I guess so that is why it's falling back to this. I think your fix should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also do text || ""
to split the difference — though I guess it doesn't matter if empty strings are also problematic — but yeah presence
is being too aggressive here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea that's a nice middle ground I think.
@cwhitehouse can you fix the standard lint errors? |
Description
Pass the
text
from a text node directly to the JSON created viato_h
instead of stripping out whitespace only strings.Reason/Reference
Text nodes that just contain whitespace have a valid use case, such as separating out two text nodes with marks. This currently prevents you from having a space between two link nodes, for example.
Example
The message...
Should have four JSON text nodes that look like...
...but the current implementation returns...
... which would mean if we pass the JSON to an editor we would get:
... instead of what we expected.