feat: add addThemeNameToClass option, fixes #373#376
Closed
sesgoe wants to merge 2 commits into
Closed
Conversation
❌ Deploy Preview for shiki-matsu failed.
|
Collaborator
|
I believe it would be more flexible to expose the return renderToHtml(tokens, {
fg: _theme.fg,
bg: _theme.bg,
lineOptions: options?.lineOptions,
elements: options?.elements. // Adding this
})
And then you can just create your custom const out = highlighter.codeToHtml(`console.log('shiki');`, {
lang: 'js',
elements: {
pre({ className, style, children }) {
return `<pre class="${className} from muenzpraeger" style="${style}">${children}</pre>`
}
}
}) |
Author
|
I agree with you that this would be more flexible. I feel like the API is much less intuitive/simple, but I can work on implementing this version instead and see how it looks! Thanks for the feedback. |
3 tasks
Contributor
|
Hey folks, good PR! I think we don't need an option for this, it's just a generally good idea IMO, so I've taken this PR and reduced it down to always add the theme name with 961cd9e |
This was referenced Jan 11, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a test if possible
Format all commit messages with Conventional Commits
Did my best here, unsure if this is proper formatting, happy to fix with a squash commit if necessary.
Added a new
addThemeNameToClassoption forHtmlOptionsto enable adding the theme name to the generated HTML class. This leaves the current functionality as-is and makes this new feature opt-in for anyone that wants it.Previous behavior (and with the option disabled by default):
New Behavior (with the option enabled):
I'm unsure about testing conventions here, so I added a test to both
simple.test.tsandcomprehensive.test.tsthat should exercise the functionality. All tests continue to pass with these changes.There is still a failing test in
styleAttributes.test.tsbut it's also failing inside themainbranch. I don't have the full context to feel comfortable changing it to pass, but I would be happy to add changes necessary to fix it if it's simple and doesn't muddy the understanding of this PR.