Skip to content

✨ [amp story shopping] newline support in productData#37788

Merged
processprocess merged 6 commits intoampproject:mainfrom
processprocess:newlines
Mar 1, 2022
Merged

✨ [amp story shopping] newline support in productData#37788
processprocess merged 6 commits intoampproject:mainfrom
processprocess:newlines

Conversation

@processprocess
Copy link
Copy Markdown
Contributor

@processprocess processprocess commented Feb 28, 2022

  • Renders \n as a newline by adding white-space: pre-line to the text wrapper.
  • Adds example to html example and visual tests.
  • Limits newlines to maximum of two.

A productDetails string like this:
"One newline after this. \n Two newlines after this. \n\n Four consecutive newlines after this, should become 2 newlines. \n\n\n\n Many consecutive newlines with different spacing and tabs after this, should become 2 newlines. \n \n\n \n \n \n \n \n I hope it works!"
Renders like this:
Screen Shot 2022-02-28 at 1 33 40 PM

Fixes #37787

@processprocess processprocess self-assigned this Feb 28, 2022
@processprocess processprocess marked this pull request as ready for review February 28, 2022 19:45
@amp-owners-bot
Copy link
Copy Markdown

Hey @gmajoulet! These files were changed:

extensions/amp-story-shopping/0.1/amp-story-shopping-attachment.css
extensions/amp-story-shopping/0.1/amp-story-shopping-attachment.js

>
{activeProductData.productDetails}
{activeProductData.productDetails
// Removes spaces after \n.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can replace both with:

    .replace(/\n\s*\n/g, '\n\n')

i.e. Replace two newlines (even if they have 0 or more whitespace characters between them) with just two newlines.
https://jsfiddle.net/o2x45vrj/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧠

@processprocess processprocess merged commit 92cfd7b into ampproject:main Mar 1, 2022
@processprocess processprocess deleted the newlines branch March 1, 2022 15:37
@ampprojectbot
Copy link
Copy Markdown
Member

Warning: disparity between this PR Percy build and its main build

The Percy build for this PR was approved (either manually by a member of the AMP team, or automatically if there were no visual diffs). However, during a continuous integration step we generated another Percy build using the commit on the main branch that this PR was merged into, and there appears to be a mismatch between the two.

This is possibly an indication of an issue with this pull request, but could also be the result of flakiness. Please inspect the two builds < This PR's Percy build / main commit's Percy build > and determine further action:

  • If the disparity appears to be caused by this PR, please create an bug report or send out a new PR to fix
  • If the disparity appears to be a flake, please @-mention ampproject/wg-approvers in a comment
  • If there is no disparity and this comment was created by mistake, please @-mention ampproject/wg-infra
  • If unsure, @-mention ampproject/wg-approvers

@processprocess
Copy link
Copy Markdown
Contributor Author

processprocess commented Mar 1, 2022

@ampproject/wg-approvers This might be a flake, not sure what caused it. Pinging @coreymasanto for context.
The diff on main looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Amp story shopping] Support newlines in productDescription

3 participants