-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
"Shift" option doesn't accept zero #2
Comments
As to why we would want this, there are times our HTML headings might be on the right level already, and other times where it is not. We could pass in a variable shift value instead of setting it at zero as I did in the ticket above. (IE |
Yeah that was my next question lol. Open to a PR for this, I understand the use case :) |
Yeah! No problem and thanks for the fast response. Its not a big deal and can be worked around by setting the options object to const processHTML = async (
html: string,
options?: Options,
) => {
// ...
// Bypass zeroes not being accepted in this method.
let shiftHeadingOptions
if (options?.shift == null || options.shift === 0) shiftHeadingOptions = false
else shiftHeadingOptions = {shift: options.shift}
// ...
const vFile = await rehype( )
.use(rehypeShiftHeading, shiftHeadingOptions)
.use( // ...etc
} |
For the PR: you should add a test, and then: don't walk the tree on 0, that would be useless! |
This comment has been minimized.
This comment has been minimized.
done! |
Initial checklist
Affected packages and versions
v1.02
Link to runnable example
No response
Steps to reproduce
Use {shift: 0} as an option in the this module.
IE,
Expected behavior
It shouldn't throw an error, even though technically the function shouldn't do anything to the tree either, with a shift value of zero.
Actual behavior
There is an error thrown:
Error: Missing required `shift` in options
.You can see why this behavior is happening:
rehype-shift-heading/index.js
Line 18 in 5bab36b
Zero is falsey, so it isn't an accepted value.
Runtime
No response
Package manager
No response
OS
No response
Build and bundle tools
No response
The text was updated successfully, but these errors were encountered: