-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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 anchors erroring when heading is empty #772
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Deploy preview for docusaurus-preview ready! Built with commit d60a99e |
@Rendez Thank you for the pull request. Can you please sign the CLA so that we can review/merge it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this. Just have a small question regarding the test.
@@ -109,3 +112,8 @@ test('Anchor index resets on each render', () => { | |||
'id="almost-unique-heading-1"' | |||
); | |||
}); | |||
|
|||
test('Anchor uses default renderer when empty', () => { | |||
expect(render([{hLevel: 1}, {content: null}], 0, {}, {})).toEqual('<h1>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it equal <h1>
instead of <h1></h1>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the render method references the rules.heading_open
alone const render = md.renderer.rules.heading_open;
. We do not run the remarkable parser, but simply invoke this one function. Am I right?
Until now, the tests' expectations though checked to see if the opening header tag contained an id
attribute, etc., so the new test's expectation looks unusual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified that the test results are intended. Thanks @Rendez!
Motivation
Found a bug because one of our Markdown docs contained an empty heading
Here's part of the stacktrace:
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
I added a test to specifically check for these cases.