Skip to content

Escape quotes #98

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

Merged
merged 8 commits into from
Sep 23, 2021
Merged

Escape quotes #98

merged 8 commits into from
Sep 23, 2021

Conversation

greym0uth
Copy link
Contributor

@greym0uth greym0uth commented Sep 10, 2021

This aims to fix #34.

Prettier, in some cases, is annoyingly opinionated and doesnt seem to want to preserve escaped quotes and instead just switch to use double quotes or single quotes if the string contains one or the other (this seems like its going to be the case forever (prettier/prettier#973). In order for prettier to correctly decide this we need to escape them inside strings.

In contentful an array of strings that contain apostrophe's will break the output:

  tags: (
    | 'Something'
    | 'Banana'
    | 'Apples'
    | 'Someone's pear' // This line here breaks as the quote isnt escaped so prettier doesnt reformat this to correct code.
    | 'Grape'
  )[];

Where as if the quote is escaped it properly reformats to:

  tags: (
    | 'Something'
    | 'Banana'
    | 'Apples'
    | "Someone's pear" // Switches to double quotes
    | 'Grape'
  )[];

This PR specifically adds the escapeSingleQuote function to a utils.ts in the renderer directory. It then uses this function to escape apostrophes used in contentful data (specifically text) that we drop in.

@greym0uth
Copy link
Contributor Author

@lorcan Bumping this for a review.

Copy link
Contributor

@GabrielAnca GabrielAnca left a comment

Choose a reason for hiding this comment

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

Thanks for this PR @Jaden-Giordano! It looks great to me! I have a couple of questions there, mainly if we need to do this for locales and sys.contentType.sys.id 😃 Let me know what you think!

@GabrielAnca
Copy link
Contributor

I'm also investigating why the CircleCI build didn't kick off 😅

Copy link
Contributor

@GabrielAnca GabrielAnca left a comment

Choose a reason for hiding this comment

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

Looks perfect, just one tiny unused import! I'm still actively working on the CircleCI issue. Hope to get it fixed during this week.

Co-authored-by: Gabriel Anca Corral <GabrielAnca@users.noreply.github.com>
Copy link
Contributor

@GabrielAnca GabrielAnca left a comment

Choose a reason for hiding this comment

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

Looking great! The CircleCI support said the issue should be sorted so if you make an empty push (or a rebase) it should kick off the CI build

@GabrielAnca
Copy link
Contributor

GabrielAnca commented Sep 23, 2021

Rebased the PR myself and now the build is not passing 😬 It seems it's a small thing.

I'm working on a change in our NPM config and I'm happy to approve and merge this PR as soon as that's ready, hopefully before the end of the week.

Copy link
Contributor

@GabrielAnca GabrielAnca left a comment

Choose a reason for hiding this comment

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

All green, looks perfect 👌🏻 Thanks a lot for the contribution @Jaden-Giordano

@intercom-mr-updater
Copy link
Member

🎉 This PR is included in version 3.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add apostrophe support
3 participants