shiki.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import assert from 'node:assert/strict';
  2. import { describe, it } from 'node:test';
  3. import { createMarkdownProcessor, createShikiHighlighter } from '../dist/index.js';
  4. describe('shiki syntax highlighting', () => {
  5. it('does not add is:raw to the output', async () => {
  6. const processor = await createMarkdownProcessor();
  7. const { code } = await processor.render('```\ntest\n```');
  8. assert.ok(!code.includes('is:raw'));
  9. });
  10. it('supports light/dark themes', async () => {
  11. const processor = await createMarkdownProcessor({
  12. shikiConfig: {
  13. experimentalThemes: {
  14. light: 'github-light',
  15. dark: 'github-dark',
  16. },
  17. },
  18. });
  19. const { code } = await processor.render('```\ntest\n```');
  20. // light theme is there:
  21. assert.match(code, /background-color:/);
  22. assert.match(code, /github-light/);
  23. // dark theme is there:
  24. assert.match(code, /--shiki-dark-bg:/);
  25. assert.match(code, /github-dark/);
  26. });
  27. it('createShikiHighlighter works', async () => {
  28. const highlighter = await createShikiHighlighter();
  29. const html = highlighter.highlight('const foo = "bar";', 'js');
  30. assert.match(html, /astro-code github-dark/);
  31. assert.match(html, /background-color:#24292e;color:#e1e4e8;/);
  32. });
  33. it('diff +/- text has user-select: none', async () => {
  34. const highlighter = await createShikiHighlighter();
  35. const html = highlighter.highlight(
  36. `\
  37. - const foo = "bar";
  38. + const foo = "world";`,
  39. 'diff'
  40. );
  41. assert.match(html, /user-select: none/);
  42. assert.match(html, />-<\/span>/);
  43. assert.match(html, />+<\/span>/);
  44. });
  45. });