@astrojs/markdown-remark 0.11.3 → 0.11.6

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 29cccc2060a2f573
2
+ @astrojs/markdown-remark:build: 
3
+ @astrojs/markdown-remark:build: > @astrojs/markdown-remark@0.11.6 build /home/runner/work/astro/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,27 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 0.11.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3911](https://github.com/withastro/astro/pull/3911) [`ca45c0c27`](https://github.com/withastro/astro/commit/ca45c0c270f5ca3f7d2fb113a235d415cecdb333) Thanks [@JuanM04](https://github.com/JuanM04)! - Don't throw when Shiki doesn't recognize a language
8
+
9
+ - Updated dependencies [[`b48767985`](https://github.com/withastro/astro/commit/b48767985359bd359df8071324952ea5f2bc0d86)]:
10
+ - @astrojs/prism@0.6.0
11
+
12
+ ## 0.11.5
13
+
14
+ ### Patch Changes
15
+
16
+ - [#3669](https://github.com/withastro/astro/pull/3669) [`93e1020b1`](https://github.com/withastro/astro/commit/93e1020b1e8549b08cf5646e1ebc3ae34e14ebc8) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Tooling: reintroduce smoke test across example projects
17
+
18
+ ## 0.11.4
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [[`1cc5b7890`](https://github.com/withastro/astro/commit/1cc5b78905633608e5b07ad291f916f54e67feb1)]:
23
+ - @astrojs/prism@0.5.0
24
+
3
25
  ## 0.11.3
4
26
 
5
27
  ### Patch Changes
package/dist/index.js CHANGED
@@ -41,8 +41,8 @@ async function renderMarkdown(content, opts = {}) {
41
41
  }
42
42
  const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
43
43
  const loadedRehypePlugins = await Promise.all(loadPlugins(rehypePlugins));
44
- loadedRemarkPlugins.forEach(([plugin, opts2]) => {
45
- parser.use([[plugin, opts2]]);
44
+ loadedRemarkPlugins.forEach(([plugin, pluginOpts]) => {
45
+ parser.use([[plugin, pluginOpts]]);
46
46
  });
47
47
  if (scopedClassName) {
48
48
  parser.use([scopedStyles(scopedClassName)]);
@@ -67,8 +67,8 @@ async function renderMarkdown(content, opts = {}) {
67
67
  }
68
68
  ]
69
69
  ]);
70
- loadedRehypePlugins.forEach(([plugin, opts2]) => {
71
- parser.use([[plugin, opts2]]);
70
+ loadedRehypePlugins.forEach(([plugin, pluginOpts]) => {
71
+ parser.use([[plugin, pluginOpts]]);
72
72
  });
73
73
  parser.use(isMDX ? [rehypeJsx, rehypeExpressions] : [rehypeRaw]).use(rehypeEscape).use(rehypeIslands).use([rehypeCollectHeaders]).use(rehypeStringify, { allowDangerousHtml: true });
74
74
  let result;
@@ -18,7 +18,7 @@ function createCollectHeaders() {
18
18
  const depth = Number.parseInt(level);
19
19
  let text = "";
20
20
  let isJSX = false;
21
- visit(node, (child, _2, parent) => {
21
+ visit(node, (child, __, parent) => {
22
22
  if (child.type === "element" || parent == null) {
23
23
  return;
24
24
  }
@@ -1,28 +1,9 @@
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 { map } from "unist-util-map";
21
2
  function rehypeExpressions() {
22
3
  return function(node) {
23
4
  return map(node, (child) => {
24
5
  if (child.type === "text") {
25
- return __spreadProps(__spreadValues({}, child), { type: "raw" });
6
+ return { ...child, type: "raw" };
26
7
  }
27
8
  if (child.type === "mdxTextExpression") {
28
9
  return { type: "raw", value: `{${child.value}}` };
@@ -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 { SKIP, visit as _visit } from "unist-util-visit";
21
2
  const visit = _visit;
22
3
  function rehypeIslands() {
@@ -26,10 +7,11 @@ function rehypeIslands() {
26
7
  visit(el, "text", (child, index, parent) => {
27
8
  if (child.type === "text") {
28
9
  if (parent && child.value.indexOf("<!--") > -1 && index != null) {
29
- parent.children.splice(index, 1, __spreadProps(__spreadValues({}, child), {
10
+ parent.children.splice(index, 1, {
11
+ ...child,
30
12
  type: "comment",
31
13
  value: child.value.replace("<!--", "").replace("-->", "").trim()
32
- }));
14
+ });
33
15
  return [SKIP, index];
34
16
  }
35
17
  child.value = child.value.replace(/\n+/g, "");
@@ -9,9 +9,9 @@ function runHighlighter(lang, code) {
9
9
  if (lang == null) {
10
10
  lang = "plaintext";
11
11
  }
12
- const ensureLoaded = (lang2) => {
13
- if (lang2 && !Prism.languages[lang2]) {
14
- loadLanguages([lang2]);
12
+ const ensureLoaded = (language) => {
13
+ if (language && !Prism.languages[language]) {
14
+ loadLanguages([language]);
15
15
  }
16
16
  };
17
17
  if (languageMap.has(lang)) {
@@ -14,7 +14,19 @@ const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false },
14
14
  }
15
15
  return () => (tree) => {
16
16
  visit(tree, "code", (node) => {
17
- let html = highlighter.codeToHtml(node.value, { lang: node.lang ?? "plaintext" });
17
+ let lang;
18
+ if (typeof node.lang === "string") {
19
+ const langExists = highlighter.getLoadedLanguages().includes(node.lang);
20
+ if (langExists) {
21
+ lang = node.lang;
22
+ } else {
23
+ console.warn(`The language "${node.lang}" doesn't exist, falling back to plaintext.`);
24
+ lang = "plaintext";
25
+ }
26
+ } else {
27
+ lang = "plaintext";
28
+ }
29
+ let html = highlighter.codeToHtml(node.value, { lang });
18
30
  html = html.replace('<pre class="shiki"', `<pre is:raw class="astro-code${scopedClassName ? " " + scopedClassName : ""}"`);
19
31
  html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
20
32
  if (node.lang === "diff") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "0.11.3",
3
+ "version": "0.11.6",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -13,17 +13,16 @@
13
13
  "homepage": "https://astro.build",
14
14
  "main": "./dist/index.js",
15
15
  "exports": {
16
- ".": "./dist/index.js",
17
- "./ssr-utils": "./dist/ssr-utils.js"
16
+ ".": "./dist/index.js"
18
17
  },
19
18
  "dependencies": {
20
19
  "@astrojs/micromark-extension-mdx-jsx": "^1.0.3",
21
- "@astrojs/prism": "^0.4.1",
20
+ "@astrojs/prism": "^0.6.0",
22
21
  "acorn": "^8.7.1",
23
22
  "acorn-jsx": "^5.3.2",
24
23
  "assert": "^2.0.0",
25
24
  "github-slugger": "^1.4.0",
26
- "mdast-util-mdx-expression": "^1.2.0",
25
+ "mdast-util-mdx-expression": "^1.2.1",
27
26
  "mdast-util-mdx-jsx": "^1.2.0",
28
27
  "mdast-util-to-string": "^3.1.0",
29
28
  "micromark-extension-mdx-expression": "^1.0.3",
@@ -50,7 +49,7 @@
50
49
  "@types/mocha": "^9.1.1",
51
50
  "@types/prismjs": "^1.26.0",
52
51
  "@types/unist": "^2.0.6",
53
- "astro-scripts": "0.0.4",
52
+ "astro-scripts": "0.0.6",
54
53
  "chai": "^4.3.6",
55
54
  "micromark-util-types": "^1.0.2",
56
55
  "mocha": "^9.2.2"
package/src/index.ts CHANGED
@@ -57,8 +57,8 @@ export async function renderMarkdown(
57
57
  const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
58
58
  const loadedRehypePlugins = await Promise.all(loadPlugins(rehypePlugins));
59
59
 
60
- loadedRemarkPlugins.forEach(([plugin, opts]) => {
61
- parser.use([[plugin, opts]]);
60
+ loadedRemarkPlugins.forEach(([plugin, pluginOpts]) => {
61
+ parser.use([[plugin, pluginOpts]]);
62
62
  });
63
63
 
64
64
  if (scopedClassName) {
@@ -87,8 +87,8 @@ export async function renderMarkdown(
87
87
  ],
88
88
  ]);
89
89
 
90
- loadedRehypePlugins.forEach(([plugin, opts]) => {
91
- parser.use([[plugin, opts]]);
90
+ loadedRehypePlugins.forEach(([plugin, pluginOpts]) => {
91
+ parser.use([[plugin, pluginOpts]]);
92
92
  });
93
93
 
94
94
  parser
@@ -106,6 +106,7 @@ export async function renderMarkdown(
106
106
  // Ensure that the error message contains the input filename
107
107
  // to make it easier for the user to fix the issue
108
108
  err = prefixError(err, `Failed to parse Markdown file "${input.path}"`);
109
+ // eslint-disable-next-line no-console
109
110
  console.error(err);
110
111
  throw err;
111
112
  }
@@ -20,7 +20,7 @@ export default function createCollectHeaders() {
20
20
 
21
21
  let text = '';
22
22
  let isJSX = false;
23
- visit(node, (child, _, parent) => {
23
+ visit(node, (child, __, parent) => {
24
24
  if (child.type === 'element' || parent == null) {
25
25
  return;
26
26
  }
@@ -13,9 +13,9 @@ function runHighlighter(lang: string, code: string) {
13
13
  lang = 'plaintext';
14
14
  }
15
15
 
16
- const ensureLoaded = (lang: string) => {
17
- if (lang && !Prism.languages[lang]) {
18
- loadLanguages([lang]);
16
+ const ensureLoaded = (language: string) => {
17
+ if (language && !Prism.languages[language]) {
18
+ loadLanguages([language]);
19
19
  }
20
20
  };
21
21
 
@@ -30,6 +30,7 @@ function runHighlighter(lang: string, code: string) {
30
30
  }
31
31
 
32
32
  if (lang && !Prism.languages[lang]) {
33
+ // eslint-disable-next-line no-console
33
34
  console.warn(`Unable to load the language: ${lang}`);
34
35
  }
35
36
 
@@ -30,7 +30,21 @@ const remarkShiki = async (
30
30
 
31
31
  return () => (tree: any) => {
32
32
  visit(tree, 'code', (node) => {
33
- let html = highlighter!.codeToHtml(node.value, { lang: node.lang ?? 'plaintext' });
33
+ let lang: string;
34
+
35
+ if (typeof node.lang === 'string') {
36
+ const langExists = highlighter.getLoadedLanguages().includes(node.lang);
37
+ if (langExists) {
38
+ lang = node.lang;
39
+ } else {
40
+ console.warn(`The language "${node.lang}" doesn't exist, falling back to plaintext.`);
41
+ lang = 'plaintext';
42
+ }
43
+ } else {
44
+ lang = 'plaintext';
45
+ }
46
+
47
+ let html = highlighter!.codeToHtml(node.value, { lang });
34
48
 
35
49
  // Q: Couldn't these regexes match on a user's inputted code blocks?
36
50
  // A: Nope! All rendered HTML is properly escaped.
@@ -1,2 +0,0 @@
1
- /** @see {@link "/packages/astro/vite-plugin-markdown"} */
2
- export declare function slug(value: string): string;
package/dist/ssr-utils.js DELETED
@@ -1,8 +0,0 @@
1
- import Slugger from "github-slugger";
2
- const slugger = new Slugger();
3
- function slug(value) {
4
- return slugger.slug(value);
5
- }
6
- export {
7
- slug
8
- };
package/src/ssr-utils.ts DELETED
@@ -1,8 +0,0 @@
1
- /** Utilities used in deployment-ready SSR bundles */
2
- import Slugger from 'github-slugger';
3
-
4
- const slugger = new Slugger();
5
- /** @see {@link "/packages/astro/vite-plugin-markdown"} */
6
- export function slug(value: string): string {
7
- return slugger.slug(value);
8
- }