@astrojs/markdown-remark 0.6.1-next.2 → 0.6.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 0.6.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2697](https://github.com/withastro/astro/pull/2697) [`91765d79`](https://github.com/withastro/astro/commit/91765d79b1ec1181417fb6a4604a9e20564bb10e) Thanks [@FredKSchott](https://github.com/FredKSchott)! - Improve performance by optimizing calls to `getHighlighter`
8
+
9
+ ## 0.6.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2628](https://github.com/withastro/astro/pull/2628) [`9b7e2ab2`](https://github.com/withastro/astro/commit/9b7e2ab2516cd36520364490df8e3482008292e3) Thanks [@JuanM04](https://github.com/JuanM04)! - Fixed shiki to work with `{ "type": "module" }`
14
+
15
+ ## 0.6.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#2534](https://github.com/withastro/astro/pull/2534) [`cfeaa941`](https://github.com/withastro/astro/commit/cfeaa9414acdecec6f5d66ee0e33fe4fde574eee) Thanks [@JuanM04](https://github.com/JuanM04)! - Now you can use local plugins by passing a function instead of an `import`
20
+
21
+ * [#2518](https://github.com/withastro/astro/pull/2518) [`2bc91543`](https://github.com/withastro/astro/commit/2bc91543ceeb5f3dd45e201bf75d79f186e85141) Thanks [@JuanM04](https://github.com/JuanM04)! - Added the ability to use custom themes and langs with Shiki (`<Code />` and `@astrojs/markdown-remark`)
22
+
23
+ - [#2497](https://github.com/withastro/astro/pull/2497) [`6fe1b027`](https://github.com/withastro/astro/commit/6fe1b0279fce5a7a0e90ff79746ea0b641da3e21) Thanks [@JuanM04](https://github.com/JuanM04)! - Add Shiki as an alternative to Prism
24
+
25
+ * [#2518](https://github.com/withastro/astro/pull/2518) [`2bc91543`](https://github.com/withastro/astro/commit/2bc91543ceeb5f3dd45e201bf75d79f186e85141) Thanks [@JuanM04](https://github.com/JuanM04)! - Added `wrap` to Shiki config
26
+
27
+ - [#2564](https://github.com/withastro/astro/pull/2564) [`d71c4620`](https://github.com/withastro/astro/commit/d71c46207af40de6811596ca4f5e10aa9006377b) Thanks [@JuanM04](https://github.com/JuanM04)! - Fixed curly braces inside Shiki codeblocks
28
+
3
29
  ## 0.6.1-next.2
4
30
 
5
31
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import shiki from 'shiki';
1
+ import type * as shiki from 'shiki';
2
2
  export interface ShikiConfig {
3
3
  /**
4
4
  * The languages loaded to Shiki.
@@ -1,7 +1,13 @@
1
- import shiki from "shiki";
1
+ import { getHighlighter } from "shiki";
2
2
  import { visit } from "unist-util-visit";
3
+ const highlighterCache = new Map();
3
4
  const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }) => {
4
- const highlighter = await shiki.getHighlighter({ theme });
5
+ const cacheID = typeof theme === "string" ? theme : theme.name;
6
+ let highlighter = highlighterCache.get(cacheID);
7
+ if (!highlighter) {
8
+ highlighter = await getHighlighter({ theme });
9
+ highlighterCache.set(cacheID, highlighter);
10
+ }
5
11
  for (const lang of langs) {
6
12
  await highlighter.loadLanguage(lang);
7
13
  }
@@ -26,4 +32,4 @@ var remark_shiki_default = remarkShiki;
26
32
  export {
27
33
  remark_shiki_default as default
28
34
  };
29
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3JlbWFyay1zaGlraS50cyJdLAogICJtYXBwaW5ncyI6ICJBQUFBO0FBQ0E7QUE4QkEsTUFBTSxjQUFjLE9BQU8sRUFBRSxRQUFRLElBQUksUUFBUSxlQUFlLE9BQU8sWUFBeUI7QUFDL0YsUUFBTSxjQUFjLE1BQU0sTUFBTSxlQUFlLEVBQUU7QUFFakQsYUFBVyxRQUFRLE9BQU87QUFDekIsVUFBTSxZQUFZLGFBQWE7QUFBQTtBQUdoQyxTQUFPLE1B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DQUFDLFNBQVM7QUFqRGhDO0FBa0RHLFVBQUksT0FBTyxZQUFhLFdBQVcsS0FBSyxPQUFPLEVBQUUsTUFBTSxXQUFLLFNBQUwsWUFBYTtBQUdwRSxhQUFPLEtBQUssUUFBUSxzQkFBc0I7QUFFMUMsYUFBTyxLQUFLLFFBQVEsOENBQThDO0FBR2xFLFVBQUksU0FBUyxPQUFPO0FBQ25CLGVBQU8sS0FBSyxRQUFRLGlCQUFpQjtBQUFBLGlCQUMzQixTQUFTLE1BQU07QUFDekIsZUFBTyxLQUFLLFFBQVEsaUJBQWlCO0FBQUE7QUFHdEMsV0FBSyxPQUFPO0FBQ1osV0FBSyxRQUFRO0FBQ2IsV0FBSyxXQUFXO0FBQUE7QUFBQTtBQUFBO0FBS25CLElBQU8sdUJBQVE7IiwKICAibmFtZXMiOiBbXQp9Cg==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "0.6.1-next.2",
3
+ "version": "0.6.3",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -1,4 +1,5 @@
1
- import shiki from 'shiki';
1
+ import type * as shiki from 'shiki';
2
+ import { getHighlighter } from 'shiki';
2
3
  import { visit } from 'unist-util-visit';
3
4
 
4
5
  export interface ShikiConfig {
@@ -29,16 +30,25 @@ export interface ShikiConfig {
29
30
  wrap?: boolean | null;
30
31
  }
31
32
 
32
- const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig) => {
33
- const highlighter = await shiki.getHighlighter({ theme });
33
+ /**
34
+ * getHighlighter() is the most expensive step of Shiki. Instead of calling it on every page,
35
+ * cache it here as much as possible. Make sure that your highlighters can be cached, state-free.
36
+ */
37
+ const highlighterCache = new Map<string, shiki.Highlighter>();
34
38
 
39
+ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig) => {
40
+ const cacheID: string = typeof theme === 'string' ? theme : theme.name;
41
+ let highlighter = highlighterCache.get(cacheID);
42
+ if (!highlighter) {
43
+ highlighter = await getHighlighter({ theme });
44
+ highlighterCache.set(cacheID, highlighter);
45
+ }
35
46
  for (const lang of langs) {
36
47
  await highlighter.loadLanguage(lang);
37
48
  }
38
-
39
49
  return () => (tree: any) => {
40
50
  visit(tree, 'code', (node) => {
41
- let html = highlighter.codeToHtml(node.value, { lang: node.lang ?? 'plaintext' });
51
+ let html = highlighter!.codeToHtml(node.value, { lang: node.lang ?? 'plaintext' });
42
52
 
43
53
  // Replace "shiki" class naming with "astro" and add "data-astro-raw".
44
54
  html = html.replace('<pre class="shiki"', '<pre data-astro-raw class="astro-code"');