Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding language ID to the class attribute #166

Open
hasparus opened this issue Oct 13, 2022 · 1 comment
Open

Adding language ID to the class attribute #166

hasparus opened this issue Oct 13, 2022 · 1 comment
Labels
Enhancement New feature or request You can do this The idea is well specified and good for a PR

Comments

@hasparus
Copy link

馃憢 Hello. Firstly, thank you for shiki-twoslash. It's amazing.

I'd like to post this as a humble feature request.


Problem

Knowing the language of the code snippet in CSS may be quite useful in a few cases.

AFAIK it's not possible right now with remark-shiki-twoslash without a second pass with a rehype plugin?

Possible Solution

The remark plugin could accept a configuration option to set attributes of the pre element at the root of the code block.
This would later be used in preOpenerFromRenderingOptsWithExtras in shiki-twoslash.

Workaround

I used pnpm patch to quickly add opts.langId to the classList in preOpenerFromRenderingOptsWithExtras.

export const preOpenerFromRenderingOptsWithExtras = (opts: HtmlRendererOptions, meta: Meta, classes?: string[]) => {
const bg = opts.bg || "#fff"
const fg = opts.fg || "black"
const theme = opts.themeName || ""
// shiki + `class` from fence + with-title if title exists + classes
const classList = ["shiki", theme, meta.class, meta.title ? "with-title" : "", ...(classes || [])]

@orta
Copy link
Contributor

orta commented Oct 13, 2022

Yep, I think this is totally reasonable 馃憤馃徎

@orta orta added Enhancement New feature or request You can do this The idea is well specified and good for a PR labels Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request You can do this The idea is well specified and good for a PR
Projects
None yet
Development

No branches or pull requests

2 participants