@astrojs/markdown-remark 0.7.0-next.0 → 0.8.0

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.
@@ -0,0 +1,5 @@
1
+ @astrojs/markdown-remark:build: cache hit, replaying output 6e22a141f5baff6f
2
+ @astrojs/markdown-remark:build: 
3
+ @astrojs/markdown-remark:build: > @astrojs/markdown-remark@0.8.0 build /Users/fks/Code/astro/packages/markdown/remark
4
+ @astrojs/markdown-remark:build: > astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
5
+ @astrojs/markdown-remark:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`e425f896`](https://github.com/withastro/astro/commit/e425f896b668d98033ad3b998b50c1f28bc7f6ee) Thanks [@FredKSchott](https://github.com/FredKSchott)! - Update config options to resepect [RFC0019](https://github.com/withastro/rfcs/blob/main/proposals/0019-config-finalization.md)
8
+
9
+ ## 0.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#2824](https://github.com/withastro/astro/pull/2824) [`0a3d3e51`](https://github.com/withastro/astro/commit/0a3d3e51a66af80fa949ba0f5e2104439d2be634) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Change shiki to our default markdown syntax highlighter. This includes updates to all relevant starter projects that used Prism-specific styles.
14
+
15
+ ### Patch Changes
16
+
17
+ - [#2870](https://github.com/withastro/astro/pull/2870) [`d763ec18`](https://github.com/withastro/astro/commit/d763ec183ea391ad79ca16bf2b2e76848fc1180c) Thanks [@FredKSchott](https://github.com/FredKSchott)! - Fix a shiki performance issue affecting large sites
18
+
19
+ - Updated dependencies [[`2db97f10`](https://github.com/withastro/astro/commit/2db97f10dc50f9498413181b78c477fe8833895b)]:
20
+ - @astrojs/prism@0.4.1
21
+
22
+ ## 0.7.0-next.1
23
+
24
+ ### Patch Changes
25
+
26
+ - [#2870](https://github.com/withastro/astro/pull/2870) [`d763ec18`](https://github.com/withastro/astro/commit/d763ec183ea391ad79ca16bf2b2e76848fc1180c) Thanks [@FredKSchott](https://github.com/FredKSchott)! - Fix a shiki performance issue affecting large sites
27
+
28
+ - Updated dependencies [[`2db97f10`](https://github.com/withastro/astro/commit/2db97f10dc50f9498413181b78c477fe8833895b)]:
29
+ - @astrojs/prism@0.4.1-next.0
30
+
3
31
  ## 0.7.0-next.0
4
32
 
5
33
  ### Minor Changes
@@ -165,10 +193,10 @@
165
193
 
166
194
  ```js
167
195
  export default {
168
- markdownOptions: {
169
- remarkPlugins: ['remark-slug', ['remark-autolink-headings', { behavior: 'prepend' }]],
170
- rehypePlugins: ['rehype-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]],
171
- },
196
+ markdownOptions: {
197
+ remarkPlugins: ['remark-slug', ['remark-autolink-headings', { behavior: 'prepend' }]],
198
+ rehypePlugins: ['rehype-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]],
199
+ },
172
200
  };
173
201
  ```
174
202
 
package/LICENSE CHANGED
@@ -21,21 +21,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
 
23
23
 
24
- """
25
- This license applies to parts of the `packages/astro-parser` subdirectory originating from the
26
- https://github.com/sveltejs/svelte repository:
27
-
28
-
29
- Copyright (c) 2016-21 [these people](https://github.com/sveltejs/svelte/graphs/contributors)
30
-
31
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
32
-
33
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
34
-
35
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
- """
37
-
38
-
39
24
  """
40
25
  This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
41
26
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AstroMarkdownOptions, MarkdownRenderingOptions } from './types';
2
- export { AstroMarkdownOptions, MarkdownRenderingOptions };
1
+ import type { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin } from './types';
2
+ export { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin };
3
3
  /** Internal utility for rendering a full markdown file and extracting Frontmatter data */
4
4
  export declare function renderMarkdownWithFrontmatter(contents: string, opts?: MarkdownRenderingOptions | null): Promise<{
5
5
  frontmatter: {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  import { visit } from "unist-util-visit";
2
2
  import Prism from "prismjs";
3
- import { addAstro } from "@astrojs/prism";
3
+ import { addAstro } from "@astrojs/prism/internal";
4
4
  import loadLanguages from "prismjs/components/index.js";
5
5
  const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
6
6
  const languageMap = /* @__PURE__ */ new Map([["ts", "typescript"]]);
File without changes
File without changes
@@ -1,13 +1,14 @@
1
1
  import { getHighlighter } from "shiki";
2
2
  import { visit } from "unist-util-visit";
3
- const highlighterCache = /* @__PURE__ */ new Map();
3
+ const highlighterCacheAsync = /* @__PURE__ */ new Map();
4
4
  const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }, scopedClassName) => {
5
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);
6
+ let highlighterAsync = highlighterCacheAsync.get(cacheID);
7
+ if (!highlighterAsync) {
8
+ highlighterAsync = getHighlighter({ theme });
9
+ highlighterCacheAsync.set(cacheID, highlighterAsync);
10
10
  }
11
+ const highlighter = await highlighterAsync;
11
12
  for (const lang of langs) {
12
13
  await highlighter.loadLanguage(lang);
13
14
  }
File without changes
File without changes
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type * as unified from 'unified';
2
2
  import type { ShikiConfig } from './remark-shiki';
3
+ export { ShikiConfig };
3
4
  export declare type Plugin = string | [string, any] | unified.Plugin | [unified.Plugin, any];
4
5
  export interface AstroMarkdownOptions {
5
6
  mode?: 'md' | 'mdx';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "0.7.0-next.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  ".": "./dist/index.js"
17
17
  },
18
18
  "dependencies": {
19
- "@astrojs/prism": "^0.4.0",
19
+ "@astrojs/prism": "^0.4.1",
20
20
  "assert": "^2.0.0",
21
21
  "github-slugger": "^1.4.0",
22
22
  "gray-matter": "^4.0.3",
@@ -35,7 +35,7 @@
35
35
  "remark-smartypants": "^2.0.0",
36
36
  "shiki": "^0.10.1",
37
37
  "unified": "^10.1.2",
38
- "unist-util-map": "^3.0.0",
38
+ "unist-util-map": "^3.0.1",
39
39
  "unist-util-visit": "^4.1.0"
40
40
  },
41
41
  "devDependencies": {
@@ -46,6 +46,7 @@
46
46
  "scripts": {
47
47
  "prepublish": "pnpm build",
48
48
  "build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
49
+ "build:ci": "astro-scripts build \"src/**/*.ts\"",
49
50
  "postbuild": "astro-scripts copy \"src/**/*.js\"",
50
51
  "dev": "astro-scripts dev \"src/**/*.ts\""
51
52
  }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AstroMarkdownOptions, MarkdownRenderingOptions } from './types';
1
+ import type { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin } from './types';
2
2
 
3
3
  import createCollectHeaders from './rehype-collect-headers.js';
4
4
  import scopedStyles from './remark-scoped-styles.js';
@@ -20,7 +20,7 @@ import rehypeStringify from 'rehype-stringify';
20
20
  import rehypeRaw from 'rehype-raw';
21
21
  import matter from 'gray-matter';
22
22
 
23
- export { AstroMarkdownOptions, MarkdownRenderingOptions };
23
+ export { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin };
24
24
 
25
25
  /** Internal utility for rendering a full markdown file and extracting Frontmatter data */
26
26
  export async function renderMarkdownWithFrontmatter(contents: string, opts?: MarkdownRenderingOptions | null) {
@@ -1,6 +1,6 @@
1
1
  import { visit } from 'unist-util-visit';
2
2
  import Prism from 'prismjs';
3
- import { addAstro } from '@astrojs/prism';
3
+ import { addAstro } from '@astrojs/prism/internal';
4
4
  import loadLanguages from 'prismjs/components/index.js';
5
5
  const noVisit = new Set(['root', 'html', 'text']);
6
6
 
@@ -33,19 +33,25 @@ export interface ShikiConfig {
33
33
  /**
34
34
  * getHighlighter() is the most expensive step of Shiki. Instead of calling it on every page,
35
35
  * cache it here as much as possible. Make sure that your highlighters can be cached, state-free.
36
+ * We make this async, so that multiple calls to parse markdown still share the same highlighter.
36
37
  */
37
- const highlighterCache = new Map<string, shiki.Highlighter>();
38
+ const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();
38
39
 
39
40
  const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig, scopedClassName?: string | null) => {
40
41
  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);
42
+ let highlighterAsync = highlighterCacheAsync.get(cacheID);
43
+ if (!highlighterAsync) {
44
+ highlighterAsync = getHighlighter({ theme });
45
+ highlighterCacheAsync.set(cacheID, highlighterAsync);
45
46
  }
47
+ const highlighter = await highlighterAsync;
48
+
49
+ // NOTE: There may be a performance issue here for large sites that use `lang`.
50
+ // Since this will be called on every page load. Unclear how to fix this.
46
51
  for (const lang of langs) {
47
52
  await highlighter.loadLanguage(lang);
48
53
  }
54
+
49
55
  return () => (tree: any) => {
50
56
  visit(tree, 'code', (node) => {
51
57
  let html = highlighter!.codeToHtml(node.value, { lang: node.lang ?? 'plaintext' });
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type * as unified from 'unified';
2
2
  import type { ShikiConfig } from './remark-shiki';
3
+ export { ShikiConfig };
3
4
 
4
5
  export type Plugin = string | [string, any] | unified.Plugin | [unified.Plugin, any];
5
6