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

fix: replace all escaped \n with an actual \n character #14454

Merged
merged 2 commits into from
Oct 12, 2022

Conversation

joshuaellis
Copy link
Member

What does it do?

When our objects are stringified they're parsed so the \n becomes \\n, which means when it's parsed, it's no longer recognised as a line-break character, instead it's recognised as a \ and n separately. This PR replaces those string sections, with the line-break character again.

Why is it needed?

IMO it's a little confusing because \n isn't strictly markdown and if people use <br> instead, everything works fine. But this solution does solve the issue brought up by the community.

How to test it?

  • Add richtext content field to a content type
  • Set a default value of something like hello\nthere
  • Create new content entry based on initial type
  • Select preview mode
  • There should be a line break.

This will also work if you type out line breaks in the editor itself.

Related issue(s)/PR(s)

@strapi-cla
Copy link

strapi-cla commented Sep 21, 2022

CLA assistant check
All committers have signed the CLA.

@joshuaellis joshuaellis added source: core:content-manager Source is core/content-manager package pr: fix This PR is fixing a bug labels Sep 21, 2022
@codecov
Copy link

codecov bot commented Sep 21, 2022

Codecov Report

Base: 57.47% // Head: 57.47% // No change to project coverage 👍

Coverage data is based on head (4a15d9f) compared to base (8ebf58d).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14454   +/-   ##
=======================================
  Coverage   57.47%   57.47%           
=======================================
  Files        1263     1263           
  Lines       30775    30775           
  Branches     5772     5772           
=======================================
  Hits        17689    17689           
  Misses      11253    11253           
  Partials     1833     1833           
Flag Coverage Δ
front 61.09% <100.00%> (ø)
unit 49.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...content-manager/components/PreviewWysiwyg/index.js 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@ronronscelestes ronronscelestes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmh so codemirror automatically escaping any \ by replacing it with \\ but then we reverse it for preview with markdown it? 👀
works well though well done!

@joshuaellis
Copy link
Member Author

mmh so codemirror automatically escaping any \ by replacing it with \\ but then we reverse it for preview with markdown it? 👀 works well though well done!

It seems to be when the value is part of an action dispatched that it's serialized along the way & then it's put in the store, but the same is to be said when we get the default value from the API response on initial launch, CodeMirror doesn't really do much in this case I believe.

Copy link
Contributor

@ronronscelestes ronronscelestes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - nice catch 💃

@joshuaellis joshuaellis added this to the 4.4.4 milestone Oct 12, 2022
@joshuaellis joshuaellis merged commit fee711c into main Oct 12, 2022
@joshuaellis joshuaellis deleted the fix/wysiwyg-preview branch October 12, 2022 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:content-manager Source is core/content-manager package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default value field strips newlines
4 participants