Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

fix(project): image link, update CSS, add code highlighter #1259

Merged
merged 2 commits into from Jun 11, 2021
Merged

fix(project): image link, update CSS, add code highlighter #1259

merged 2 commits into from Jun 11, 2021

Conversation

lasjorg
Copy link
Contributor

@lasjorg lasjorg commented May 28, 2021

Pre-Submission Checklist

  • Your pull request targets the master branch of freeCodeCamp/testable-projects-fcc
  • Branch starts with either fix/, feature/, or translate/ (e.g. fix/signin-issue)
  • You have only one commit (if not, squash them into one commit).
  • Your changes have been tested either locally or using a newly created CDN based on your fork's testable-projects-fcc/build/bundle.js file

Type of Change

  • Small bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds new functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Add new translation (feature adding new translations)

Checklist:

  • Tested changes locally.

Description

So I was going to just update the broken image link but then I noticed some issues with the responsiveness and started to change a few things. Before you know it it's a bit of a "refresh". I have updated the CSS and added a code highlighter as well just for good measure. The code highlighter implementation is likely not super well optimized (runs on componentDidUpdate) but I think it's fine.

Here is a Codepen fork for preview as well
https://codepen.io/lasjorg/pen/jOBGzgP


@scissorsneedfoodtoo When you update the Codepen (I assume it will be you) can you also set the HTML Preprocessor to none (click the cog on the left of the HTML box > set HTML Preprocessor from Haml to none). Not sure why it's there but it shouldn't be needed.

There is also a CSS file linked to in the Codepen Settings (Settings > CSS) which I don't believe is being used for anything.

https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.css

It looks like some styles for mocha but the file isn't in any of the other projects and I can't see where its style would be used. It might just be some old CSS for an older version of the test script, not sure.

@lasjorg lasjorg requested a review from a team May 28, 2021 20:25
@scissorsneedfoodtoo
Copy link
Contributor

scissorsneedfoodtoo commented Jun 1, 2021

Hi @lasjorg, thanks for your hard work on this and for taking the time to write such helpful instructions.

I took a look at this and noticed a few of things, one which may need some discussion. I'll leave them as review comments.

return `<a target="_blank" href="${href}">${text}` + '</a>';
};
// Use Prism for code highlighting
renderer.code = function (code) {
return `<pre><code class="language-javascript">${code}` + `</code></pre>\n`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor nitpick, but this could probably be simplified to:

Suggested change
return `<pre><code class="language-javascript">${code}` + `</code></pre>\n`;
return `<pre><code class="language-javascript">${code}</code></pre>\n`;

const renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
renderer.link = function (href, title, text) {
return `<a target="_blank" href="${href}">${text}` + '</a>';
Copy link
Contributor

Choose a reason for hiding this comment

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

If you agree with the change below, would you mind also simplifying this line a bit?:

Suggested change
return `<a target="_blank" href="${href}">${text}` + '</a>';
return `<a target="_blank" href="${href}">${text}</a>`;

@scissorsneedfoodtoo
Copy link
Contributor

Also, since you're making a lot of improvements to this project, let's also update the link on line 141 to point to https://www.freecodecamp.org/.

@scissorsneedfoodtoo
Copy link
Contributor

The last thing I noticed is a weird bug where Prism seems to add some extra whitespace to the class attribute, which throws off one of the tests in certain situations.

To reproduce this, expand either the editor or the preview, then run the test. Then test 6 which reads "When my markdown previewer first loads, the default markdown in the #editor field should be rendered as HTML in the #preview element" will fail.

This seems to be because Prism adds an extra space after rendering the code highlights.

Our test suite gets the innerHTML of the preview pane before the tests are run, then compares it again with the preview pane's innerHTML when it gets to test 6.

Sometime between those two points, if either the preview or editor pane are maximized, Prism renders class=\" language-javascript\"> with two spaces, not class=\" language-javascript\"> with a single space like the test expects. It would be better if it didn't render extra spaces at all, but it seems to be a known issue.

It's a pretty minor thing, and I'm not sure how many people will actually run into this. And if you press the "Run Tests" button again, everything passes, at least until the editor or preview pane are resized again.

It might be possible to strip off the extra whitespace introduced by Prism in test itself, but I can see that possibly introducing some edge cases.

Then again, I'm thinking we might just leave this as-is since resizing the panes isn't a requirement. I don't think learners will run into this in their own projects if they don't add that feature.

What do think @lasjorg? Is there a simple way to prevent Prism from adding that extra whitespace? Or should we just leave this the way it is for now?

@lasjorg
Copy link
Contributor Author

lasjorg commented Jun 1, 2021

@scissorsneedfoodtoo Totally agree with everything. I was paying too much attention to the CSS, and at the last minute just threw in the code highlighter. Your thorough review is much appreciated.

I think I came up with a solution that fixes the class name issue.

I also just realized that the version of React and Marked we are using are pretty old. I updated them and everything still seems to work just fine. But I can revert them back if needed.


Here is an updated Codepen as well
https://codepen.io/lasjorg/pen/VwpygEo

@scissorsneedfoodtoo
Copy link
Contributor

@lasjorg, no worries. I like the addition of the code highlights, even if it's not a requirement. If anything it's another cool feature that learners can choose to implement themselves if they want.

Also, I checked your updated pen and locally and no longer run into that issue where resizing the editor or preview pane causes the tests to fail. Thanks for diving back in and fixing that.

Everything LGTM 👍 👍. Will just wait for another review before merging this and deploying your changes to CodePen with your helpful instructions above.

@raisedadead raisedadead requested a review from moT01 June 2, 2021 14:38
@moT01
Copy link
Member

moT01 commented Jun 10, 2021

Hey, sorry I missed this one - I'll try and give it a look in the next day or two.

Copy link
Member

@moT01 moT01 left a comment

Choose a reason for hiding this comment

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

LGTM @lasjorg 🎉 Thanks for fixing this up - it looks a lot better 👍

Want to take a quick look at the pen and make sure it's good?

@moT01 moT01 merged commit 2b5bdb0 into freeCodeCamp:main Jun 11, 2021
@lasjorg
Copy link
Contributor Author

lasjorg commented Jun 11, 2021

Want to take a quick look at the pen and make sure it's good?

@moT01 Looks good.

@lasjorg lasjorg deleted the fix/update-project branch June 11, 2021 19:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants