Skip to content

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

Merged
styfle merged 19 commits into
markedjs:masterfrom
Scrum:fix/render-code
May 2, 2020
Merged

fix: renderer.code includes space at beginning of each line of code#1645
styfle merged 19 commits into
markedjs:masterfrom
Scrum:fix/render-code

Conversation

@Scrum

@Scrum Scrum commented Apr 15, 2020

Copy link
Copy Markdown
Contributor

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

vercel Bot commented Apr 15, 2020

Copy link
Copy Markdown

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

Scrum commented Apr 15, 2020

Copy link
Copy Markdown
Contributor Author

@UziTech @styfle LGTM

@UziTech

UziTech commented Apr 15, 2020

Copy link
Copy Markdown
Member

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

Scrum commented Apr 16, 2020

Copy link
Copy Markdown
Contributor Author

@UziTech Hi

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

done

@UziTech UziTech left a comment

Copy link
Copy Markdown
Member

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 👍

Comment thread test/specs/new/code_compensation_indent.md Outdated
Comment thread test/helpers/helpers.js Outdated
Comment thread test/helpers/helpers.js Outdated
Comment thread test/helpers/helpers.js Outdated
Comment thread test/specs/run-spec.js Outdated
@UziTech

UziTech commented Apr 17, 2020

Copy link
Copy Markdown
Member

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

Scrum commented Apr 17, 2020

Copy link
Copy Markdown
Contributor Author

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

@UziTech

UziTech commented Apr 17, 2020

Copy link
Copy Markdown
Member

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

Scrum commented Apr 17, 2020

Copy link
Copy Markdown
Contributor Author

ok now understand, to save the contract

@Scrum

Scrum commented Apr 20, 2020

Copy link
Copy Markdown
Contributor Author

@UziTech done

@UziTech

UziTech commented Apr 20, 2020

Copy link
Copy Markdown
Member

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

Scrum commented Apr 23, 2020

Copy link
Copy Markdown
Contributor Author

@UziTech done

Comment thread src/helpers.js Outdated
Comment thread test/helpers/helpers.js Outdated
Comment thread test/helpers/helpers.js Outdated
Comment thread src/helpers.js Outdated
@Scrum

Scrum commented Apr 24, 2020

Copy link
Copy Markdown
Contributor Author

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

@UziTech UziTech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

almost ready

Comment thread src/Tokenizer.js Outdated
Comment thread src/Tokenizer.js Outdated

@UziTech UziTech left a comment

Copy link
Copy Markdown
Member

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

Scrum commented Apr 28, 2020

Copy link
Copy Markdown
Contributor Author

@styfle LGTM

@styfle styfle left a comment

Copy link
Copy Markdown
Member

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.

4 participants