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

Added Codepen Support #17

Merged
merged 29 commits into from
Oct 10, 2019
Merged

Conversation

anuraghazra
Copy link
Contributor

@anuraghazra anuraghazra commented Oct 4, 2019

What:
Added Codepen support
closes #16

How:
created a new /src/codepen.js file which utilizes shouldTransform getHTML to detect codepen links and embed them into markdown.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged

here's how it looks: (feel free to change the codepen link in the docs because i used one of my own pen)
My Second Post    Gatsby Starter Blog

Copy link
Owner

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

Hi @anuraghazra!

Thanks for taking your time to implement the CodePen transformer! 🙂
Really awesome work.

I've added some small improvements and better default-values (imo) before this one can be merged.

Could you please add some tests too?

Let me know if you need some further help. 🙂

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/codepen.js Outdated Show resolved Hide resolved
@anuraghazra
Copy link
Contributor Author

I hope i'm doing everything correctly, it's my 1st time someone requested a change in my PR. ❤️

@anuraghazra
Copy link
Contributor Author

And for the tests, i really don't know how to write tests effectively i thought i will find the tests for CodeSandBox and get some understanding how it works and write it similarly for CodePen.js but couldn't find it.

@anuraghazra
Copy link
Contributor Author

@MichaelDeBoey, added tests. please check if everything is ok. 😃

Copy link
Owner

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

Hi @anuraghazra!

I've rebased your branch onto upstream (my repo) and updated the tests.

If the tests are passing, I think this one can be merged 🙂

@anuraghazra
Copy link
Contributor Author

Okay something is wrong here, i will try to fix the tests and let you know.

@anuraghazra
Copy link
Contributor Author

@MichaelDeBoey hopefully everything is all right now? ❤️

@MichaelDeBoey
Copy link
Owner

I think something went wrong when merging on your end.

I’ll rebase again and ping you afterwards 😉

@MichaelDeBoey
Copy link
Owner

@anuraghazra I've rebased your master onto upstream (my repo) and added some extra tests for you to take into account.

If you need some help, I can give you a clue on how shouldTransform should change, but don't want to ruin the learning-experience for you. 🙂

@anuraghazra
Copy link
Contributor Author

Opps, yes i see what happed there, i'm learning a lot from this one PR. yes if you can give some clues that would be great! Thank you very much for this.

@MichaelDeBoey
Copy link
Owner

There should be 2 things (3 actually 😛) you need to adjust and then all tests will pass.

  • shouldTransform should check if the host is a valid CodePen host and if the pathName includes '/pen/'
  • getHTML should replace '/pen/' by '/embed/preview/' instead of with '/embed/' so the Pen isn't run directly on the page.
    • Also change the style attribute on the iframe.

If you need any further help, I'm glad to help you get through this one. 🙂

Copy link
Owner

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

@anuraghazra Added some tiny nitpicks that I would like to have changed before merging this one.

src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/CodePen.js Outdated Show resolved Hide resolved
src/CodePen.js Outdated Show resolved Hide resolved
@MichaelDeBoey
Copy link
Owner

No problem, just some miscommunication I get it 🙂

@anuraghazra
Copy link
Contributor Author

well i'm really confused with the snapshot stuff.

test:

  expect(html).toMatchInlineSnapshot(
    `"<iframe src=\\"https://codepen.io/team/codepen/embed/preview/PNaGbb\\" style=\\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\\"></iframe>"`
  );

codepen.js

return `<iframe src="${iframeUrl}" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"></iframe>`;

this this ok?

Copy link
Owner

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

@anuraghazra Like I already said: you don't have to update the snapshot. You have to update the code so the snapshot is correct even tho you're not changing it.

src/CodePen.js Outdated Show resolved Hide resolved
Co-Authored-By: Michaël De Boey <info@michaeldeboey.be>
@MichaelDeBoey
Copy link
Owner

I also added extra tests for shouldTransform, so if you could fix shouldTransform so the tests pass, this PR is ready to merge 🙂

@anuraghazra
Copy link
Contributor Author

okay i think i got the snapshot stuff. okay working on the new tests.

Copy link
Owner

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

Just 2 small things and this one's good to be merged 🙂

src/CodePen.js Outdated Show resolved Hide resolved
Co-Authored-By: Michaël De Boey <info@michaeldeboey.be>
@anuraghazra
Copy link
Contributor Author

anuraghazra commented Oct 10, 2019

my bad! fixing

(haha silly me, just commited your suggetion directly)

Copy link
Owner

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

This looks good to me now 🙂

Thanks for all your hard work @anuraghazra! 👊

@MichaelDeBoey MichaelDeBoey merged commit a331ef5 into MichaelDeBoey:master Oct 10, 2019
@anuraghazra
Copy link
Contributor Author

Yey! THANK YOU VERY MUCH for your patience with this. ❤️

Learned soo much stuff.

@MichaelDeBoey
Copy link
Owner

@all-contributors Please add @anuraghazra for code and tests

@allcontributors
Copy link
Contributor

@MichaelDeBoey

I've put up a pull request to add @anuraghazra! 🎉

@MichaelDeBoey
Copy link
Owner

@anuraghazra It was a pleasure to help you get through this one!

Glad you learned some things when doing so. 🙂

@MichaelDeBoey
Copy link
Owner

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@MichaelDeBoey MichaelDeBoey added released ⚙️ CodePen Issue or pull request regarding CodePen labels Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ CodePen Issue or pull request regarding CodePen released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support For CodePen
2 participants