-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
normalize class property #9723
normalize class property #9723
Conversation
🦋 Changeset detectedLatest commit: 528b57a The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -129,6 +131,10 @@ export async function createShikiHighlighter({ | |||
}; | |||
} | |||
|
|||
function normalizeMaybeArray(value: Properties[string]): string | null { | |||
return Array.isArray(value) ? value.join(' ') : (value as string); |
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.
If value
is cast to string
, when does the function return null
?
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.
Updated @ematipico
What does this fix? Is there an issue or code example? |
I gave a description with the PR; to elaborate, if you added a codeblock like the following to an // &mut means mutable reference
fn next_question(&mut self) -> &Question {
let count = self.questions.len() - 1; // [!code --]
if self.current_question().is_answered() && self.current_index < count {
self.current_index += 1;
}
self.current_question()
} Notice on line 3, we do This PR converts it back to a string by just concatenating them. Here's a screenshot of the error |
This is a |
const classValue = normalizeMaybeArray(node.properties.class) ?? ''; | ||
|
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 the fix! This makes sense to me. Could we also handle this for style
? I assume transformers could also change that to a non-string now.
Maybe we can rename and generalize the function as normalizePropAsString
ready |
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
@florian-lefebvre @bluwy @ematipico Can we get this merged soon? |
Changes
Attempting to use some of the common transformers raises an exception:
This is because
addClassToHast
returns an array of strings. ButArray
s don't have a.replace
. See: https://github.com/antfu/shikiji/blob/31241ba4dc47c2d4d7809ee08c6573b26b07b812/packages/shikiji-core/src/utils.ts#L44Testing
I couldn't figure out how to write a unit test for this. But I edited a build version with this logic and it works.
Docs