@astrojs/markdown-remark 0.8.1 → 0.9.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`53162534`](https://github.com/withastro/astro/commit/53162534450e160f65b95e7ef1523a106347ca28) Thanks [@FredKSchott](https://github.com/FredKSchott)! - - Removed `renderMarkdownWithFrontmatter` because it wasn't being used
8
+ - All options of `renderMarkdown` are now required — see the exported interface `AstroMarkdownOptions`
9
+ - New types: RemarkPlugin, RehypePlugin and ShikiConfig
10
+
11
+ ## 0.8.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [#2970](https://github.com/withastro/astro/pull/2970) [`b835e285`](https://github.com/withastro/astro/commit/b835e285defb4f31fc5ac1039c7f607c07f3c00b) Thanks [@JuanM04](https://github.com/JuanM04)! - Improved type checking
16
+
3
17
  ## 0.8.1
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,21 +1,9 @@
1
- import type { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin } from './types';
2
- export { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin };
3
- /** Internal utility for rendering a full markdown file and extracting Frontmatter data */
4
- export declare function renderMarkdownWithFrontmatter(contents: string, opts?: MarkdownRenderingOptions | null): Promise<{
5
- frontmatter: {
6
- [key: string]: any;
7
- };
8
- metadata: {
9
- headers: any[];
10
- source: string;
11
- html: string;
12
- };
13
- code: string;
14
- }>;
1
+ import type { MarkdownRenderingOptions } from './types';
2
+ export * from './types.js';
15
3
  export declare const DEFAULT_REMARK_PLUGINS: string[];
16
4
  export declare const DEFAULT_REHYPE_PLUGINS: string[];
17
5
  /** Shared utility for rendering markdown */
18
- export declare function renderMarkdown(content: string, opts?: MarkdownRenderingOptions | null): Promise<{
6
+ export declare function renderMarkdown(content: string, opts: MarkdownRenderingOptions): Promise<{
19
7
  metadata: {
20
8
  headers: any[];
21
9
  source: string;
@@ -23,4 +11,3 @@ export declare function renderMarkdown(content: string, opts?: MarkdownRendering
23
11
  };
24
12
  code: string;
25
13
  }>;
26
- export default renderMarkdownWithFrontmatter;
package/dist/index.js CHANGED
@@ -1,22 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
1
  import createCollectHeaders from "./rehype-collect-headers.js";
21
2
  import scopedStyles from "./remark-scoped-styles.js";
22
3
  import { remarkExpressions, loadRemarkExpressions } from "./remark-expressions.js";
@@ -34,21 +15,13 @@ import markdown from "remark-parse";
34
15
  import markdownToHtml from "remark-rehype";
35
16
  import rehypeStringify from "rehype-stringify";
36
17
  import rehypeRaw from "rehype-raw";
37
- import matter from "gray-matter";
38
- async function renderMarkdownWithFrontmatter(contents, opts) {
39
- const { data: frontmatter, content } = matter(contents);
40
- const value = await renderMarkdown(content, opts);
41
- return __spreadProps(__spreadValues({}, value), { frontmatter });
42
- }
18
+ export * from "./types.js";
43
19
  const DEFAULT_REMARK_PLUGINS = ["remark-gfm", "remark-smartypants"];
44
20
  const DEFAULT_REHYPE_PLUGINS = ["rehype-slug"];
45
21
  async function renderMarkdown(content, opts) {
46
22
  var _a;
47
- let { remarkPlugins = [], rehypePlugins = [] } = opts ?? {};
48
- const scopedClassName = (_a = opts == null ? void 0 : opts.$) == null ? void 0 : _a.scopedClassName;
49
- const mode = (opts == null ? void 0 : opts.mode) ?? "mdx";
50
- const syntaxHighlight = (opts == null ? void 0 : opts.syntaxHighlight) ?? "shiki";
51
- const shikiConfig = (opts == null ? void 0 : opts.shikiConfig) ?? {};
23
+ let { mode, syntaxHighlight, shikiConfig, remarkPlugins, rehypePlugins } = opts;
24
+ const scopedClassName = (_a = opts.$) == null ? void 0 : _a.scopedClassName;
52
25
  const isMDX = mode === "mdx";
53
26
  const { headers, rehypeCollectHeaders } = createCollectHeaders();
54
27
  await Promise.all([loadRemarkExpressions(), loadRemarkJsx()]);
@@ -96,11 +69,8 @@ async function renderMarkdown(content, opts) {
96
69
  code: result.toString()
97
70
  };
98
71
  }
99
- var src_default = renderMarkdownWithFrontmatter;
100
72
  export {
101
73
  DEFAULT_REHYPE_PLUGINS,
102
74
  DEFAULT_REMARK_PLUGINS,
103
- src_default as default,
104
- renderMarkdown,
105
- renderMarkdownWithFrontmatter
75
+ renderMarkdown
106
76
  };
@@ -1,3 +1,2 @@
1
1
  import * as unified from 'unified';
2
- import type { Plugin } from './types';
3
- export declare function loadPlugins(items: Plugin[]): Promise<[unified.Plugin, any?]>[];
2
+ export declare function loadPlugins(items: (string | [string, any] | unified.Plugin<any[], any> | [unified.Plugin<any[], any>, any])[]): Promise<[unified.Plugin, any?]>[];
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,30 +1,3 @@
1
- import type * as shiki from 'shiki';
2
- export interface ShikiConfig {
3
- /**
4
- * The languages loaded to Shiki.
5
- * Supports all languages listed here: https://github.com/shikijs/shiki/blob/main/docs/languages.md#all-languages
6
- * Instructions for loading a custom language: https://github.com/shikijs/shiki/blob/main/docs/languages.md#supporting-your-own-languages-with-shiki
7
- *
8
- * @default []
9
- */
10
- langs?: shiki.ILanguageRegistration[];
11
- /**
12
- * The styling theme.
13
- * Supports all themes listed here: https://github.com/shikijs/shiki/blob/main/docs/themes.md#all-themes
14
- * Instructions for loading a custom theme: https://github.com/shikijs/shiki/blob/main/docs/themes.md#loading-theme
15
- *
16
- * @default "github-dark"
17
- */
18
- theme?: shiki.IThemeRegistration;
19
- /**
20
- * Enable word wrapping.
21
- * - true: enabled.
22
- * - false: enabled.
23
- * - null: All overflow styling removed. Code will overflow the element by default.
24
- *
25
- * @default false
26
- */
27
- wrap?: boolean | null;
28
- }
1
+ import type { ShikiConfig } from './types.js';
29
2
  declare const remarkShiki: ({ langs, theme, wrap }: ShikiConfig, scopedClassName?: string | null | undefined) => Promise<() => (tree: any) => void>;
30
3
  export default remarkShiki;
@@ -1,7 +1,7 @@
1
1
  import { getHighlighter } from "shiki";
2
2
  import { visit } from "unist-util-visit";
3
3
  const highlighterCacheAsync = /* @__PURE__ */ new Map();
4
- const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }, scopedClassName) => {
4
+ const remarkShiki = async ({ langs, theme, wrap }, scopedClassName) => {
5
5
  const cacheID = typeof theme === "string" ? theme : theme.name;
6
6
  let highlighterAsync = highlighterCacheAsync.get(cacheID);
7
7
  if (!highlighterAsync) {
File without changes
File without changes
package/dist/types.d.ts CHANGED
@@ -1,15 +1,26 @@
1
1
  import type * as unified from 'unified';
2
- import type { ShikiConfig } from './remark-shiki';
3
- export { ShikiConfig };
4
- export declare type Plugin = string | [string, any] | unified.Plugin | [unified.Plugin, any];
2
+ import type * as mdast from 'mdast';
3
+ import type * as hast from 'hast';
4
+ import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
5
+ export type { Node } from 'unist';
6
+ export declare type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, mdast.Root>;
7
+ export declare type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[];
8
+ export declare type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, hast.Root>;
9
+ export declare type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
10
+ export interface ShikiConfig {
11
+ langs: ILanguageRegistration[];
12
+ theme: Theme | IThemeRegistration;
13
+ wrap: boolean | null;
14
+ }
5
15
  export interface AstroMarkdownOptions {
6
- mode?: 'md' | 'mdx';
7
- syntaxHighlight?: 'shiki' | 'prism' | false;
8
- shikiConfig?: ShikiConfig;
9
- remarkPlugins?: Plugin[];
10
- rehypePlugins?: Plugin[];
16
+ mode: 'md' | 'mdx';
17
+ drafts: boolean;
18
+ syntaxHighlight: 'shiki' | 'prism' | false;
19
+ shikiConfig: ShikiConfig;
20
+ remarkPlugins: RemarkPlugins;
21
+ rehypePlugins: RehypePlugins;
11
22
  }
12
- export interface MarkdownRenderingOptions extends Partial<AstroMarkdownOptions> {
23
+ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
13
24
  /** @internal */
14
25
  $?: {
15
26
  scopedClassName: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -15,11 +15,17 @@
15
15
  "exports": {
16
16
  ".": "./dist/index.js"
17
17
  },
18
+ "scripts": {
19
+ "prepublish": "pnpm build",
20
+ "build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
21
+ "build:ci": "astro-scripts build \"src/**/*.ts\"",
22
+ "postbuild": "astro-scripts copy \"src/**/*.js\"",
23
+ "dev": "astro-scripts dev \"src/**/*.ts\""
24
+ },
18
25
  "dependencies": {
19
26
  "@astrojs/prism": "^0.4.1",
20
27
  "assert": "^2.0.0",
21
28
  "github-slugger": "^1.4.0",
22
- "gray-matter": "^4.0.3",
23
29
  "mdast-util-mdx-expression": "^1.2.0",
24
30
  "mdast-util-mdx-jsx": "^1.2.0",
25
31
  "mdast-util-to-string": "^3.1.0",
@@ -40,14 +46,10 @@
40
46
  },
41
47
  "devDependencies": {
42
48
  "@types/github-slugger": "^1.3.0",
49
+ "@types/hast": "^2.3.4",
50
+ "@types/mdast": "^3.0.10",
43
51
  "@types/prismjs": "^1.26.0",
44
- "astro-scripts": "0.0.2"
45
- },
46
- "scripts": {
47
- "prepublish": "pnpm build",
48
- "build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
49
- "build:ci": "astro-scripts build \"src/**/*.ts\"",
50
- "postbuild": "astro-scripts copy \"src/**/*.js\"",
51
- "dev": "astro-scripts dev \"src/**/*.ts\""
52
+ "@types/unist": "^2.0.6",
53
+ "astro-scripts": "workspace:*"
52
54
  }
53
- }
55
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin } from './types';
1
+ import type { MarkdownRenderingOptions } from './types';
2
2
 
3
3
  import createCollectHeaders from './rehype-collect-headers.js';
4
4
  import scopedStyles from './remark-scoped-styles.js';
@@ -18,31 +18,17 @@ import markdown from 'remark-parse';
18
18
  import markdownToHtml from 'remark-rehype';
19
19
  import rehypeStringify from 'rehype-stringify';
20
20
  import rehypeRaw from 'rehype-raw';
21
- import matter from 'gray-matter';
22
-
23
- export { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin };
24
-
25
- /** Internal utility for rendering a full markdown file and extracting Frontmatter data */
26
- export async function renderMarkdownWithFrontmatter(
27
- contents: string,
28
- opts?: MarkdownRenderingOptions | null
29
- ) {
30
- const { data: frontmatter, content } = matter(contents);
31
- const value = await renderMarkdown(content, opts);
32
- return { ...value, frontmatter };
33
- }
21
+
22
+ export * from './types.js';
34
23
 
35
24
  export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants'];
36
25
 
37
26
  export const DEFAULT_REHYPE_PLUGINS = ['rehype-slug'];
38
27
 
39
28
  /** Shared utility for rendering markdown */
40
- export async function renderMarkdown(content: string, opts?: MarkdownRenderingOptions | null) {
41
- let { remarkPlugins = [], rehypePlugins = [] } = opts ?? {};
42
- const scopedClassName = opts?.$?.scopedClassName;
43
- const mode = opts?.mode ?? 'mdx';
44
- const syntaxHighlight = opts?.syntaxHighlight ?? 'shiki';
45
- const shikiConfig = opts?.shikiConfig ?? {};
29
+ export async function renderMarkdown(content: string, opts: MarkdownRenderingOptions) {
30
+ let { mode, syntaxHighlight, shikiConfig, remarkPlugins, rehypePlugins } = opts;
31
+ const scopedClassName = opts.$?.scopedClassName;
46
32
  const isMDX = mode === 'mdx';
47
33
  const { headers, rehypeCollectHeaders } = createCollectHeaders();
48
34
 
@@ -111,5 +97,3 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
111
97
  code: result.toString(),
112
98
  };
113
99
  }
114
-
115
- export default renderMarkdownWithFrontmatter;
@@ -1,5 +1,4 @@
1
1
  import * as unified from 'unified';
2
- import type { Plugin } from './types';
3
2
 
4
3
  async function importPlugin(p: string | unified.Plugin): Promise<unified.Plugin> {
5
4
  if (typeof p === 'string') {
@@ -10,7 +9,9 @@ async function importPlugin(p: string | unified.Plugin): Promise<unified.Plugin>
10
9
  return p;
11
10
  }
12
11
 
13
- export function loadPlugins(items: Plugin[]): Promise<[unified.Plugin, any?]>[] {
12
+ export function loadPlugins(
13
+ items: (string | [string, any] | unified.Plugin<any[], any> | [unified.Plugin<any[], any>, any])[]
14
+ ): Promise<[unified.Plugin, any?]>[] {
14
15
  return items.map((p) => {
15
16
  return new Promise((resolve, reject) => {
16
17
  if (Array.isArray(p)) {
@@ -1,34 +1,7 @@
1
1
  import type * as shiki from 'shiki';
2
2
  import { getHighlighter } from 'shiki';
3
3
  import { visit } from 'unist-util-visit';
4
-
5
- export interface ShikiConfig {
6
- /**
7
- * The languages loaded to Shiki.
8
- * Supports all languages listed here: https://github.com/shikijs/shiki/blob/main/docs/languages.md#all-languages
9
- * Instructions for loading a custom language: https://github.com/shikijs/shiki/blob/main/docs/languages.md#supporting-your-own-languages-with-shiki
10
- *
11
- * @default []
12
- */
13
- langs?: shiki.ILanguageRegistration[];
14
- /**
15
- * The styling theme.
16
- * Supports all themes listed here: https://github.com/shikijs/shiki/blob/main/docs/themes.md#all-themes
17
- * Instructions for loading a custom theme: https://github.com/shikijs/shiki/blob/main/docs/themes.md#loading-theme
18
- *
19
- * @default "github-dark"
20
- */
21
- theme?: shiki.IThemeRegistration;
22
- /**
23
- * Enable word wrapping.
24
- * - true: enabled.
25
- * - false: enabled.
26
- * - null: All overflow styling removed. Code will overflow the element by default.
27
- *
28
- * @default false
29
- */
30
- wrap?: boolean | null;
31
- }
4
+ import type { ShikiConfig } from './types.js';
32
5
 
33
6
  /**
34
7
  * getHighlighter() is the most expensive step of Shiki. Instead of calling it on every page,
@@ -38,7 +11,7 @@ export interface ShikiConfig {
38
11
  const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();
39
12
 
40
13
  const remarkShiki = async (
41
- { langs = [], theme = 'github-dark', wrap = false }: ShikiConfig,
14
+ { langs, theme, wrap }: ShikiConfig,
42
15
  scopedClassName?: string | null
43
16
  ) => {
44
17
  const cacheID: string = typeof theme === 'string' ? theme : theme.name;
package/src/types.ts CHANGED
@@ -1,18 +1,40 @@
1
1
  import type * as unified from 'unified';
2
- import type { ShikiConfig } from './remark-shiki';
3
- export { ShikiConfig };
2
+ import type * as mdast from 'mdast';
3
+ import type * as hast from 'hast';
4
+ import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
4
5
 
5
- export type Plugin = string | [string, any] | unified.Plugin | [unified.Plugin, any];
6
+ export type { Node } from 'unist';
7
+
8
+ export type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<
9
+ PluginParameters,
10
+ mdast.Root
11
+ >;
12
+
13
+ export type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[];
14
+
15
+ export type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugin<
16
+ PluginParameters,
17
+ hast.Root
18
+ >;
19
+
20
+ export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
21
+
22
+ export interface ShikiConfig {
23
+ langs: ILanguageRegistration[];
24
+ theme: Theme | IThemeRegistration;
25
+ wrap: boolean | null;
26
+ }
6
27
 
7
28
  export interface AstroMarkdownOptions {
8
- mode?: 'md' | 'mdx';
9
- syntaxHighlight?: 'shiki' | 'prism' | false;
10
- shikiConfig?: ShikiConfig;
11
- remarkPlugins?: Plugin[];
12
- rehypePlugins?: Plugin[];
29
+ mode: 'md' | 'mdx';
30
+ drafts: boolean;
31
+ syntaxHighlight: 'shiki' | 'prism' | false;
32
+ shikiConfig: ShikiConfig;
33
+ remarkPlugins: RemarkPlugins;
34
+ rehypePlugins: RehypePlugins;
13
35
  }
14
36
 
15
- export interface MarkdownRenderingOptions extends Partial<AstroMarkdownOptions> {
37
+ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
16
38
  /** @internal */
17
39
  $?: {
18
40
  scopedClassName: string | null;
@@ -1,5 +0,0 @@
1
- @astrojs/markdown-remark:build: cache hit, replaying output 5817ab166c77bc86
2
- @astrojs/markdown-remark:build: 
3
- @astrojs/markdown-remark:build: > @astrojs/markdown-remark@0.8.1 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/LICENSE DELETED
@@ -1,34 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Fred K. Schott
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
23
-
24
- """
25
- This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
26
-
27
- Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
28
-
29
- 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:
30
-
31
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32
-
33
- 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.
34
- """