astro 2.3.4 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/client-base.d.ts +6 -0
  2. package/components/Code.astro +46 -21
  3. package/components/shiki-languages.js +172 -2016
  4. package/components/shiki-themes.js +41 -31
  5. package/config.d.ts +12 -0
  6. package/config.mjs +14 -0
  7. package/dist/@types/app.d.js +0 -0
  8. package/dist/@types/astro.d.ts +108 -1
  9. package/dist/assets/index.d.ts +0 -3
  10. package/dist/assets/index.js +1 -15
  11. package/dist/assets/internal.d.ts +6 -1
  12. package/dist/assets/internal.js +37 -4
  13. package/dist/content/runtime.js +8 -3
  14. package/dist/content/vite-plugin-content-assets.js +14 -4
  15. package/dist/core/app/index.js +50 -10
  16. package/dist/core/app/types.d.ts +10 -1
  17. package/dist/core/build/generate.js +62 -23
  18. package/dist/core/build/internal.d.ts +10 -4
  19. package/dist/core/build/internal.js +29 -18
  20. package/dist/core/build/page-data.js +2 -2
  21. package/dist/core/build/plugins/plugin-css.d.ts +1 -8
  22. package/dist/core/build/plugins/plugin-css.js +185 -150
  23. package/dist/core/build/plugins/plugin-pages.d.ts +1 -1
  24. package/dist/core/build/plugins/plugin-pages.js +13 -2
  25. package/dist/core/build/plugins/plugin-ssr.d.ts +2 -2
  26. package/dist/core/build/plugins/plugin-ssr.js +14 -5
  27. package/dist/core/build/types.d.ts +15 -6
  28. package/dist/core/compile/compile.js +1 -0
  29. package/dist/core/config/config.js +5 -1
  30. package/dist/core/config/schema.d.ts +40 -0
  31. package/dist/core/config/schema.js +10 -2
  32. package/dist/core/constants.d.ts +1 -0
  33. package/dist/core/constants.js +3 -1
  34. package/dist/core/dev/dev.js +1 -1
  35. package/dist/core/endpoint/dev/index.js +7 -4
  36. package/dist/core/endpoint/index.d.ts +9 -2
  37. package/dist/core/endpoint/index.js +42 -24
  38. package/dist/core/errors/errors-data.d.ts +81 -0
  39. package/dist/core/errors/errors-data.js +84 -0
  40. package/dist/core/messages.js +2 -2
  41. package/dist/core/middleware/callMiddleware.d.ts +36 -0
  42. package/dist/core/middleware/callMiddleware.js +38 -0
  43. package/dist/core/middleware/index.d.ts +4 -0
  44. package/dist/core/middleware/index.js +8 -0
  45. package/dist/core/middleware/loadMiddleware.d.ts +8 -0
  46. package/dist/core/middleware/loadMiddleware.js +13 -0
  47. package/dist/core/middleware/sequence.d.ts +6 -0
  48. package/dist/core/middleware/sequence.js +27 -0
  49. package/dist/core/render/context.d.ts +7 -2
  50. package/dist/core/render/context.js +13 -2
  51. package/dist/core/render/core.d.ts +22 -2
  52. package/dist/core/render/core.js +68 -32
  53. package/dist/core/render/dev/index.d.ts +5 -1
  54. package/dist/core/render/dev/index.js +23 -3
  55. package/dist/core/render/index.d.ts +1 -1
  56. package/dist/core/render/index.js +7 -1
  57. package/dist/core/render/result.d.ts +1 -0
  58. package/dist/core/render/result.js +2 -1
  59. package/dist/core/render/ssr-element.d.ts +3 -2
  60. package/dist/core/render/ssr-element.js +22 -15
  61. package/dist/core/request.js +2 -0
  62. package/dist/integrations/index.js +1 -1
  63. package/dist/runtime/server/endpoint.js +1 -1
  64. package/dist/runtime/server/index.d.ts +1 -1
  65. package/dist/runtime/server/index.js +0 -2
  66. package/dist/runtime/server/render/head.js +3 -1
  67. package/dist/runtime/server/render/index.d.ts +1 -1
  68. package/dist/runtime/server/render/index.js +1 -2
  69. package/dist/runtime/server/render/tags.d.ts +2 -7
  70. package/dist/runtime/server/render/tags.js +9 -27
  71. package/dist/vite-plugin-astro-server/response.js +3 -3
  72. package/dist/vite-plugin-astro-server/route.js +7 -0
  73. package/package.json +10 -6
package/client-base.d.ts CHANGED
@@ -387,3 +387,9 @@ declare module '*?inline' {
387
387
  const src: string;
388
388
  export default src;
389
389
  }
390
+
391
+ // eslint-disable-next-line @typescript-eslint/no-namespace
392
+ export namespace App {
393
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
394
+ export interface Locals {}
395
+ }
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  import type * as shiki from 'shiki';
3
+ import { renderToHtml } from 'shiki';
3
4
  import { getHighlighter } from './Shiki.js';
4
5
 
5
6
  export interface Props {
@@ -30,36 +31,60 @@ export interface Props {
30
31
  * @default false
31
32
  */
32
33
  wrap?: boolean | null;
34
+ /**
35
+ * Generate inline code element only, without the pre element wrapper.
36
+ *
37
+ * @default false
38
+ */
39
+ inline?: boolean;
33
40
  }
34
41
 
35
- const { code, lang = 'plaintext', theme = 'github-dark', wrap = false } = Astro.props;
36
-
37
- /** Replace the shiki class name with a custom astro class name. */
38
- function repairShikiTheme(html: string): string {
39
- // Replace "shiki" class naming with "astro"
40
- html = html.replace(/<pre class="(.*?)shiki(.*?)"/, '<pre class="$1astro-code$2"');
41
- // Handle code wrapping
42
- // if wrap=null, do nothing.
43
- if (wrap === false) {
44
- html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto;"');
45
- } else if (wrap === true) {
46
- html = html.replace(
47
- /style="(.*?)"/,
48
- 'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"'
49
- );
50
- }
51
- return html;
52
- }
42
+ const {
43
+ code,
44
+ lang = 'plaintext',
45
+ theme = 'github-dark',
46
+ wrap = false,
47
+ inline = false,
48
+ } = Astro.props;
53
49
 
50
+ // 1. Get the shiki syntax highlighter
54
51
  const highlighter = await getHighlighter({
55
52
  theme,
56
53
  // Load custom lang if passed an object, otherwise load the default
57
54
  langs: typeof lang !== 'string' ? [lang] : undefined,
58
55
  });
59
- const _html = highlighter.codeToHtml(code, {
60
- lang: typeof lang === 'string' ? lang : lang.id,
56
+
57
+ // 2. Turn code into shiki theme tokens
58
+ const tokens = highlighter.codeToThemedTokens(code, typeof lang === 'string' ? lang : lang.id);
59
+
60
+ // 3. Get shiki theme object
61
+ const _theme = highlighter.getTheme();
62
+
63
+ // 4. Render the theme tokens as html
64
+ const html = renderToHtml(tokens, {
65
+ themeName: _theme.name,
66
+ fg: _theme.fg,
67
+ bg: _theme.bg,
68
+ elements: {
69
+ pre({ className, style, children }) {
70
+ // Swap to `code` tag if inline
71
+ const tag = inline ? 'code' : 'pre';
72
+ // Replace "shiki" class naming with "astro-code"
73
+ className = className.replace(/shiki/g, 'astro-code');
74
+ // Handle code wrapping
75
+ // if wrap=null, do nothing.
76
+ if (wrap === false) {
77
+ style += '; overflow-x: auto;"';
78
+ } else if (wrap === true) {
79
+ style += '; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"';
80
+ }
81
+ return `<${tag} class="${className}" style="${style}" tabindex="0">${children}</${tag}>`;
82
+ },
83
+ code({ children }) {
84
+ return inline ? children : `<code>${children}</code>`;
85
+ },
86
+ },
61
87
  });
62
- const html = repairShikiTheme(_html);
63
88
  ---
64
89
 
65
90
  <Fragment set:html={html} />