-
Notifications
You must be signed in to change notification settings - Fork 6
feat: support langalias #68
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,5 @@ | |
"changesets-changelog-clean": "^1.3.0", | ||
"typescript": "^5.8.2" | ||
}, | ||
"packageManager": "pnpm@10.4.0", | ||
"pnpm": { | ||
"onlyBuiltDependencies": [ | ||
"@biomejs/biome", | ||
"esbuild" | ||
] | ||
} | ||
Comment on lines
-28
to
-33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these options can now live in pnpm-workspace in case you're wondering where they went 😅 |
||
"packageManager": "pnpm@10.12.1" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,19 @@ interface TestComponentProps { | |
theme: Theme; | ||
transformers?: ShikiTransformer[]; | ||
tabindex?: string; | ||
langAlias?: Record<string, string>; | ||
} | ||
|
||
const TestComponent = ({ | ||
code, | ||
language, | ||
theme, | ||
transformers, | ||
langAlias, | ||
}: TestComponentProps) => { | ||
const highlighted = useShikiHighlighter(code, language, theme, { | ||
transformers, | ||
langAlias, | ||
}); | ||
return <div data-testid="highlighted">{highlighted}</div>; | ||
}; | ||
|
@@ -132,4 +135,26 @@ describe('useShikiHighlighter Hook', () => { | |
expect(container).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
test('applies highlighting on aliased language', async () => { | ||
const code = 'package main'; | ||
const { getByTestId } = renderComponent({ | ||
code, | ||
language: 'golang', | ||
langAlias: { | ||
golang: 'go', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn’t go recognized as an alias for golang by default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it looks like go is the primary identifier for golang in shiki - https://shiki.style/languages. Does golang work as an identifier for go? I don't think it would judging by go.json in shiki-textmate-themes-grammars repo, but can't test at the moment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our usecase for this was that LLMs sometimes output |
||
}, | ||
}); | ||
|
||
await waitFor(() => { | ||
const container = getByTestId('highlighted'); | ||
const preElement = container.querySelector('pre'); | ||
const spanElement = preElement?.querySelector( | ||
'code>span>span' | ||
) as HTMLSpanElement | null; | ||
|
||
expect(spanElement).toBeInTheDocument(); | ||
expect(spanElement).toHaveStyle('color: #D73A49'); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,8 +96,13 @@ export const useShikiHighlighter = ( | |
const [stableOpts, optsRev] = useStableOptions(options); | ||
|
||
const { languageId, langsToLoad } = useMemo( | ||
() => resolveLanguage(stableLang, stableOpts.customLanguages), | ||
[stableLang, stableOpts.customLanguages] | ||
() => | ||
resolveLanguage( | ||
stableLang, | ||
stableOpts.customLanguages as never, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why cast as never? |
||
stableOpts.langAlias | ||
), | ||
[stableLang, stableOpts.customLanguages, stableOpts.langAlias] | ||
); | ||
|
||
const { isMultiTheme, themeId, multiTheme, singleTheme, themesToLoad } = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
packages: | ||
- package | ||
- playground | ||
- playground | ||
onlyBuiltDependencies: | ||
- "@biomejs/biome" | ||
- esbuild |
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.
got some errors trying to install this version with checksums so updated it