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: renderer.code includes space at beginning of each line of code #1645

Merged
merged 19 commits into from May 2, 2020
Merged

fix: renderer.code includes space at beginning of each line of code #1645

merged 19 commits into from May 2, 2020

Conversation

Scrum
Copy link
Contributor

@Scrum Scrum commented Apr 15, 2020

Description

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR)

Committer

In most cases, this should be a different person than the contributor.

  • Draft GitHub release notes have been updated.
  • CI is green (no forced merge required).
  • Merge PR

@vercel
Copy link

vercel bot commented Apr 15, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/markedjs/markedjs/2i2a4afnt
✅ Preview: https://markedjs-git-fork-scrum-fix-render-code.markedjs.now.sh

@Scrum
Copy link
Contributor Author

Scrum commented Apr 15, 2020

@UziTech @styfle LGTM

@UziTech
Copy link
Member

UziTech commented Apr 15, 2020

It looks like that test passes without the fix.

Our tests use @markedjs/html-differ to compare html and it is probably removing the space before checking. You can try writing a unit test to test the exact output.

@Scrum
Copy link
Contributor Author

Scrum commented Apr 16, 2020

@UziTech Hi

You can try writing a unit test to test the exact output.

done

Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

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

I was thinking of adding an option like that to the spec tests 👍

test/specs/new/code_compensation_indent.md Outdated Show resolved Hide resolved
test/helpers/helpers.js Outdated Show resolved Hide resolved
test/helpers/helpers.js Outdated Show resolved Hide resolved
test/helpers/helpers.js Outdated Show resolved Hide resolved
test/specs/run-spec.js Outdated Show resolved Hide resolved
@UziTech
Copy link
Member

UziTech commented Apr 17, 2020

The text should be fixed when creating the token instead of when rendering. If you merge the latest changes you can change the Tokenizer.fences function to fix token.text before parsing.

marked/src/Tokenizer.js

Lines 77 to 87 in 904c974

fences(src) {
const cap = this.rules.block.fences.exec(src);
if (cap) {
return {
type: 'code',
raw: cap[0],
lang: cap[2] ? cap[2].trim() : cap[2],
text: cap[3] || ''
};
}
}

And you should inline the fix instead of adding a helper since the code is only going to run in one place. No need for the extra function call.

@Scrum
Copy link
Contributor Author

Scrum commented Apr 17, 2020

@UziTech I don’t quite understand, does this relate exactly to my task?

@UziTech
Copy link
Member

UziTech commented Apr 17, 2020

Yes, currently you are taking the text from the token and fixing it before sending it to the renderer.

I'm suggesting that you fix the text before it goes into the token so we can still just take the text from the token and send it to the renderer without changing it.

@Scrum
Copy link
Contributor Author

Scrum commented Apr 17, 2020

ok now understand, to save the contract

@Scrum
Copy link
Contributor Author

Scrum commented Apr 20, 2020

@UziTech done

@UziTech
Copy link
Member

UziTech commented Apr 20, 2020

If you merge the latest changes from master you will see a new file src/Tokenizer.js. This fix should go in that file.

@Scrum
Copy link
Contributor Author

Scrum commented Apr 23, 2020

@UziTech done

src/helpers.js Outdated Show resolved Hide resolved
test/helpers/helpers.js Outdated Show resolved Hide resolved
test/helpers/helpers.js Outdated Show resolved Hide resolved
src/helpers.js Outdated Show resolved Hide resolved
@Scrum
Copy link
Contributor Author

Scrum commented Apr 24, 2020

@UziTech @styfle Thank you for making me wiser and the code cleaner

Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

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

almost ready

src/Tokenizer.js Outdated Show resolved Hide resolved
src/Tokenizer.js Outdated Show resolved Hide resolved
Copy link
Member

@UziTech UziTech left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks for sticking with it. 🎉

@Scrum
Copy link
Contributor Author

Scrum commented Apr 28, 2020

@styfle LGTM

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Thanks!

@styfle styfle merged commit 5c166d4 into markedjs:master May 2, 2020
@UziTech UziTech mentioned this pull request May 16, 2020
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants