@astrojs/markdown-remark 0.10.1 → 0.11.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 0.11.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3564](https://github.com/withastro/astro/pull/3564) [`76fb01cf`](https://github.com/withastro/astro/commit/76fb01cff1002f2a37e93869378802156c4eca7c) Thanks [@hippotastic](https://github.com/hippotastic)! - Fix autolinking of URLs inside links
8
+
9
+ * [#3554](https://github.com/withastro/astro/pull/3554) [`c549f161`](https://github.com/withastro/astro/commit/c549f161cadd76a666672556f2c2d63b5f97f00d) Thanks [@hippotastic](https://github.com/hippotastic)! - Allow AlpineJS syntax extensions in Markdown
10
+
11
+ ## 0.11.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#3502](https://github.com/withastro/astro/pull/3502) [`939fe159`](https://github.com/withastro/astro/commit/939fe159255cecf1cab5c1b3da2670d30ac8e4a7) Thanks [@nokazn](https://github.com/nokazn)! - Fix cases for JSX-like expressions in code blocks of headings
16
+
17
+ ### Patch Changes
18
+
19
+ - [#3514](https://github.com/withastro/astro/pull/3514) [`6c955ca6`](https://github.com/withastro/astro/commit/6c955ca643a7a071609ce8a5258cc7faf5a636b2) Thanks [@hippotastic](https://github.com/hippotastic)! - Fix Markdown errors missing source filename
20
+
21
+ * [#3516](https://github.com/withastro/astro/pull/3516) [`30578015`](https://github.com/withastro/astro/commit/30578015919e019cd8dd354288a45c1fc63bd01f) Thanks [@hippotastic](https://github.com/hippotastic)! - Fix: Allow self-closing tags in Markdown
22
+
23
+ ## 0.10.2
24
+
25
+ ### Patch Changes
26
+
27
+ - [#3486](https://github.com/withastro/astro/pull/3486) [`119ecf8d`](https://github.com/withastro/astro/commit/119ecf8d469f034eaf1b1217523954d29f492cb6) Thanks [@hippotastic](https://github.com/hippotastic)! - Fix components in markdown regressions
28
+
3
29
  ## 0.10.1
4
30
 
5
31
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
+ import { loadPlugins } from "./load-plugins.js";
1
2
  import createCollectHeaders from "./rehype-collect-headers.js";
2
- import scopedStyles from "./remark-scoped-styles.js";
3
+ import rehypeEscape from "./rehype-escape.js";
3
4
  import rehypeExpressions from "./rehype-expressions.js";
4
5
  import rehypeIslands from "./rehype-islands.js";
5
- import remarkMdxish from "./remark-mdxish.js";
6
- import remarkMarkAndUnravel from "./remark-mark-and-unravel.js";
7
6
  import rehypeJsx from "./rehype-jsx.js";
8
- import rehypeEscape from "./rehype-escape.js";
7
+ import remarkMarkAndUnravel from "./remark-mark-and-unravel.js";
8
+ import remarkMdxish from "./remark-mdxish.js";
9
9
  import remarkPrism from "./remark-prism.js";
10
+ import scopedStyles from "./remark-scoped-styles.js";
10
11
  import remarkShiki from "./remark-shiki.js";
11
12
  import remarkUnwrap from "./remark-unwrap.js";
12
- import { loadPlugins } from "./load-plugins.js";
13
- import { unified } from "unified";
13
+ import Slugger from "github-slugger";
14
+ import rehypeRaw from "rehype-raw";
15
+ import rehypeStringify from "rehype-stringify";
14
16
  import markdown from "remark-parse";
15
17
  import markdownToHtml from "remark-rehype";
16
- import rehypeStringify from "rehype-stringify";
17
- import rehypeRaw from "rehype-raw";
18
- import Slugger from "github-slugger";
18
+ import { unified } from "unified";
19
19
  import { VFile } from "vfile";
20
20
  export * from "./types.js";
21
21
  const DEFAULT_REMARK_PLUGINS = ["remark-gfm", "remark-smartypants"];
@@ -74,12 +74,13 @@ async function renderMarkdown(content, opts = {}) {
74
74
  loadedRehypePlugins.forEach(([plugin, opts2]) => {
75
75
  parser.use([[plugin, opts2]]);
76
76
  });
77
- parser.use(isMDX ? [rehypeJsx, rehypeExpressions] : [rehypeRaw]).use(rehypeEscape).use(rehypeIslands);
77
+ parser.use(isMDX ? [rehypeJsx, rehypeExpressions] : [rehypeRaw]).use(rehypeEscape).use(rehypeIslands).use([rehypeCollectHeaders]).use(rehypeStringify, { allowDangerousHtml: true });
78
78
  let result;
79
79
  try {
80
- const vfile = await parser.use([rehypeCollectHeaders]).use(rehypeStringify, { allowDangerousHtml: true }).process(input);
80
+ const vfile = await parser.process(input);
81
81
  result = vfile.toString();
82
82
  } catch (err) {
83
+ err = prefixError(err, `Failed to parse Markdown file "${input.path}"`);
83
84
  console.error(err);
84
85
  throw err;
85
86
  }
@@ -88,6 +89,23 @@ async function renderMarkdown(content, opts = {}) {
88
89
  code: result.toString()
89
90
  };
90
91
  }
92
+ function prefixError(err, prefix) {
93
+ if (err && err.message) {
94
+ try {
95
+ err.message = `${prefix}:
96
+ ${err.message}`;
97
+ return err;
98
+ } catch (error) {
99
+ }
100
+ }
101
+ const wrappedError = new Error(`${prefix}${err ? `: ${err}` : ""}`);
102
+ try {
103
+ wrappedError.stack = err.stack;
104
+ wrappedError.cause = err;
105
+ } catch (error) {
106
+ }
107
+ return wrappedError;
108
+ }
91
109
  export {
92
110
  DEFAULT_REHYPE_PLUGINS,
93
111
  DEFAULT_REMARK_PLUGINS,
@@ -0,0 +1,3 @@
1
+ import type { Options } from 'micromark-extension-mdx-expression';
2
+ import type { Extension } from 'micromark-util-types';
3
+ export declare function mdxjs(options: Options): Extension;
package/dist/mdxjs.js ADDED
@@ -0,0 +1,17 @@
1
+ import { mdxJsx } from "@astrojs/micromark-extension-mdx-jsx";
2
+ import { Parser } from "acorn";
3
+ import acornJsx from "acorn-jsx";
4
+ import { mdxExpression } from "micromark-extension-mdx-expression";
5
+ import { mdxMd } from "micromark-extension-mdx-md";
6
+ import { combineExtensions } from "micromark-util-combine-extensions";
7
+ function mdxjs(options) {
8
+ const settings = Object.assign({
9
+ acorn: Parser.extend(acornJsx()),
10
+ acornOptions: { ecmaVersion: 2020, sourceType: "module" },
11
+ addResult: true
12
+ }, options);
13
+ return combineExtensions([mdxExpression(settings), mdxJsx(settings), mdxMd]);
14
+ }
15
+ export {
16
+ mdxjs
17
+ };
@@ -1,5 +1,6 @@
1
- import { visit } from "unist-util-visit";
2
1
  import Slugger from "github-slugger";
2
+ import { toHtml } from "hast-util-to-html";
3
+ import { visit } from "unist-util-visit";
3
4
  function createCollectHeaders() {
4
5
  const headers = [];
5
6
  const slugger = new Slugger();
@@ -15,29 +16,31 @@ function createCollectHeaders() {
15
16
  if (!level)
16
17
  return;
17
18
  const depth = Number.parseInt(level);
18
- let raw = "";
19
19
  let text = "";
20
20
  let isJSX = false;
21
- visit(node, (child) => {
22
- if (child.type === "element") {
21
+ visit(node, (child, _2, parent) => {
22
+ if (child.type === "element" || parent == null) {
23
23
  return;
24
24
  }
25
25
  if (child.type === "raw") {
26
26
  if (child.value.startsWith("\n<") || child.value.endsWith(">\n")) {
27
- raw += child.value.replace(/^\n|\n$/g, "");
28
27
  return;
29
28
  }
30
29
  }
31
30
  if (child.type === "text" || child.type === "raw") {
32
- raw += child.value;
33
- text += child.value;
34
- isJSX = isJSX || child.value.includes("{");
31
+ if ((/* @__PURE__ */ new Set(["code", "pre"])).has(parent.tagName)) {
32
+ text += child.value;
33
+ } else {
34
+ text += child.value.replace(/\{/g, "${");
35
+ isJSX = isJSX || child.value.includes("{");
36
+ }
35
37
  }
36
38
  });
37
39
  node.properties = node.properties || {};
38
40
  if (typeof node.properties.id !== "string") {
39
41
  if (isJSX) {
40
- node.properties.id = `$$slug(\`${text.replace(/\{/g, "${")}\`)`;
42
+ const raw = toHtml(node.children, { allowDangerousHtml: true }).replace(/\n(<)/g, "<").replace(/(>)\n/g, ">");
43
+ node.properties.id = `$$slug(\`${text}\`)`;
41
44
  node.type = "raw";
42
45
  node.value = `<${node.tagName} id={${node.properties.id}}>${raw}</${node.tagName}>`;
43
46
  } else {
@@ -4,6 +4,9 @@ function rehypeEscape() {
4
4
  return visit(node, "element", (el) => {
5
5
  if (el.tagName === "code" || el.tagName === "pre") {
6
6
  el.properties["is:raw"] = true;
7
+ visit(el, "raw", (raw) => {
8
+ raw.value = raw.value.replace(/</g, "&lt;").replace(/>/g, "&gt;");
9
+ });
7
10
  }
8
11
  return el;
9
12
  });
@@ -1 +1,2 @@
1
- export default function rehypeJsx(): any;
1
+ import type { RehypePlugin } from './types.js';
2
+ export default function rehypeJsx(): ReturnType<RehypePlugin>;
@@ -1,69 +1,50 @@
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
- import { map } from "unist-util-map";
21
- const MDX_ELEMENTS = /* @__PURE__ */ new Set(["mdxJsxFlowElement", "mdxJsxTextElement"]);
1
+ import { visit } from "unist-util-visit";
2
+ const MDX_ELEMENTS = ["mdxJsxFlowElement", "mdxJsxTextElement"];
22
3
  function rehypeJsx() {
23
- return function(node) {
24
- return map(node, (child) => {
25
- if (child.type === "element") {
26
- return __spreadProps(__spreadValues({}, child), { tagName: `${child.tagName}` });
4
+ return function(tree) {
5
+ visit(tree, MDX_ELEMENTS, (node, index, parent) => {
6
+ if (index === null || !Boolean(parent))
7
+ return;
8
+ const attrs = node.attributes.reduce((acc, entry) => {
9
+ let attr = entry.value;
10
+ if (attr && typeof attr === "object") {
11
+ attr = `{${attr.value}}`;
12
+ } else if (attr && entry.type === "mdxJsxExpressionAttribute") {
13
+ attr = `{${attr}}`;
14
+ } else if (attr === null) {
15
+ attr = "";
16
+ } else if (typeof attr === "string") {
17
+ attr = `"${attr}"`;
18
+ }
19
+ if (!entry.name) {
20
+ return acc + ` ${attr}`;
21
+ }
22
+ return acc + ` ${entry.name}${attr ? "=" : ""}${attr}`;
23
+ }, "");
24
+ if (node.children.length === 0) {
25
+ node.type = "raw";
26
+ node.value = `<${node.name}${attrs} />`;
27
+ return;
27
28
  }
28
- if (MDX_ELEMENTS.has(child.type)) {
29
- const attrs = child.attributes.reduce((acc, entry) => {
30
- let attr = entry.value;
31
- if (attr && typeof attr === "object") {
32
- attr = `{${attr.value}}`;
33
- } else if (attr && entry.type === "mdxJsxExpressionAttribute") {
34
- attr = `{${attr}}`;
35
- } else if (attr === null) {
36
- attr = "";
37
- } else if (typeof attr === "string") {
38
- attr = `"${attr}"`;
29
+ if (node.name === "a") {
30
+ visit(node, "element", (el, elIndex, elParent) => {
31
+ const isAutolink = el.tagName === "a" && el.children.length === 1 && el.children[0].type === "text" && el.children[0].value.match(/^(https?:\/\/|www\.)/i);
32
+ if (isAutolink) {
33
+ elParent.children.splice(elIndex, 1, el.children[0]);
39
34
  }
40
- if (!entry.name) {
41
- return acc + ` ${attr}`;
42
- }
43
- return acc + ` ${entry.name}${attr ? "=" : ""}${attr}`;
44
- }, "");
45
- if (child.children.length === 0) {
46
- return {
47
- type: "raw",
48
- value: `<${child.name}${attrs} />`
49
- };
50
- }
51
- child.children.splice(0, 0, {
52
- type: "raw",
53
- value: `
54
- <${child.name}${attrs}>`
55
- });
56
- child.children.push({
57
- type: "raw",
58
- value: `</${child.name}>
59
- `
60
- });
61
- return __spreadProps(__spreadValues({}, child), {
62
- type: "element",
63
- tagName: `Fragment`
64
35
  });
65
36
  }
66
- return child;
37
+ const openingTag = {
38
+ type: "raw",
39
+ value: `
40
+ <${node.name}${attrs}>`
41
+ };
42
+ const closingTag = {
43
+ type: "raw",
44
+ value: `</${node.name}>
45
+ `
46
+ };
47
+ parent.children.splice(index, 1, openingTag, ...node.children, closingTag);
67
48
  });
68
49
  };
69
50
  }
@@ -1,15 +1,50 @@
1
- import { mdxjs } from "micromark-extension-mdxjs";
2
1
  import { mdxFromMarkdown, mdxToMarkdown } from "./mdast-util-mdxish.js";
2
+ import { mdxjs } from "./mdxjs.js";
3
3
  function remarkMdxish(options = {}) {
4
4
  const data = this.data();
5
5
  add("micromarkExtensions", mdxjs(options));
6
- add("fromMarkdownExtensions", mdxFromMarkdown());
6
+ add("fromMarkdownExtensions", makeFromMarkdownLessStrict(mdxFromMarkdown()));
7
7
  add("toMarkdownExtensions", mdxToMarkdown());
8
8
  function add(field, value) {
9
9
  const list = data[field] ? data[field] : data[field] = [];
10
10
  list.push(value);
11
11
  }
12
12
  }
13
+ function makeFromMarkdownLessStrict(extensions) {
14
+ extensions.forEach((extension) => {
15
+ ["mdxJsxFlowTag", "mdxJsxTextTag"].forEach((exitHandler) => {
16
+ if (!extension.exit || !extension.exit[exitHandler])
17
+ return;
18
+ extension.exit[exitHandler] = chainHandlers(fixSelfClosing, extension.exit[exitHandler]);
19
+ });
20
+ });
21
+ return extensions;
22
+ }
23
+ const selfClosingTags = /* @__PURE__ */ new Set([
24
+ "area",
25
+ "base",
26
+ "br",
27
+ "col",
28
+ "embed",
29
+ "hr",
30
+ "img",
31
+ "input",
32
+ "link",
33
+ "meta",
34
+ "source",
35
+ "track",
36
+ "wbr"
37
+ ]);
38
+ function fixSelfClosing() {
39
+ const tag = this.getData("mdxJsxTag");
40
+ if (tag.name && selfClosingTags.has(tag.name))
41
+ tag.selfClosing = true;
42
+ }
43
+ function chainHandlers(...handlers) {
44
+ return function handlerChain(token) {
45
+ handlers.forEach((handler) => handler.call(this, token));
46
+ };
47
+ }
13
48
  export {
14
49
  remarkMdxish as default
15
50
  };
@@ -1,7 +1,7 @@
1
- import { visit } from "unist-util-visit";
2
- import Prism from "prismjs";
3
1
  import { addAstro } from "@astrojs/prism/internal";
2
+ import Prism from "prismjs";
4
3
  import loadLanguages from "prismjs/components/index.js";
4
+ import { visit } from "unist-util-visit";
5
5
  const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
6
6
  const languageMap = /* @__PURE__ */ new Map([["ts", "typescript"]]);
7
7
  function runHighlighter(lang, code) {
@@ -1,3 +1,3 @@
1
1
  import type { ShikiConfig } from './types.js';
2
- declare const remarkShiki: ({ langs, theme, wrap }: ShikiConfig, scopedClassName?: string | null | undefined) => Promise<() => (tree: any) => void>;
2
+ declare const remarkShiki: ({ langs, theme, wrap }: ShikiConfig, scopedClassName?: string | null) => Promise<() => (tree: any) => void>;
3
3
  export default remarkShiki;
@@ -1,4 +1,4 @@
1
- import { visit as _visit, SKIP } from "unist-util-visit";
1
+ import { SKIP, visit as _visit } from "unist-util-visit";
2
2
  const visit = _visit;
3
3
  function remarkUnwrap() {
4
4
  const astroRootNodes = /* @__PURE__ */ new Set();
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type * as unified from 'unified';
2
- import type * as mdast from 'mdast';
3
1
  import type * as hast from 'hast';
2
+ import type * as mdast from 'mdast';
4
3
  import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
4
+ import type * as unified from 'unified';
5
5
  export type { Node } from 'unist';
6
6
  export declare type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, mdast.Root>;
7
7
  export declare type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "0.10.1",
3
+ "version": "0.11.1",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -16,14 +16,18 @@
16
16
  ".": "./dist/index.js"
17
17
  },
18
18
  "dependencies": {
19
+ "@astrojs/micromark-extension-mdx-jsx": "^1.0.3",
19
20
  "@astrojs/prism": "^0.4.1",
21
+ "acorn": "^8.7.1",
22
+ "acorn-jsx": "^5.3.2",
20
23
  "assert": "^2.0.0",
21
24
  "github-slugger": "^1.4.0",
22
25
  "mdast-util-mdx-expression": "^1.2.0",
23
26
  "mdast-util-mdx-jsx": "^1.2.0",
24
27
  "mdast-util-to-string": "^3.1.0",
25
- "micromark-extension-mdx-jsx": "^1.0.3",
26
- "micromark-extension-mdxjs": "^1.0.0",
28
+ "micromark-extension-mdx-expression": "^1.0.3",
29
+ "micromark-extension-mdx-md": "^1.0.0",
30
+ "micromark-util-combine-extensions": "^1.0.0",
27
31
  "prismjs": "^1.28.0",
28
32
  "rehype-raw": "^6.1.1",
29
33
  "rehype-stringify": "^9.0.3",
@@ -47,6 +51,7 @@
47
51
  "@types/unist": "^2.0.6",
48
52
  "astro-scripts": "0.0.4",
49
53
  "chai": "^4.3.6",
54
+ "micromark-util-types": "^1.0.2",
50
55
  "mocha": "^9.2.2"
51
56
  },
52
57
  "scripts": {
package/src/index.ts CHANGED
@@ -1,24 +1,24 @@
1
1
  import type { MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
2
2
 
3
+ import { loadPlugins } from './load-plugins.js';
3
4
  import createCollectHeaders from './rehype-collect-headers.js';
4
- import scopedStyles from './remark-scoped-styles.js';
5
+ import rehypeEscape from './rehype-escape.js';
5
6
  import rehypeExpressions from './rehype-expressions.js';
6
7
  import rehypeIslands from './rehype-islands.js';
7
- import remarkMdxish from './remark-mdxish.js';
8
- import remarkMarkAndUnravel from './remark-mark-and-unravel.js';
9
8
  import rehypeJsx from './rehype-jsx.js';
10
- import rehypeEscape from './rehype-escape.js';
9
+ import remarkMarkAndUnravel from './remark-mark-and-unravel.js';
10
+ import remarkMdxish from './remark-mdxish.js';
11
11
  import remarkPrism from './remark-prism.js';
12
+ import scopedStyles from './remark-scoped-styles.js';
12
13
  import remarkShiki from './remark-shiki.js';
13
14
  import remarkUnwrap from './remark-unwrap.js';
14
- import { loadPlugins } from './load-plugins.js';
15
15
 
16
- import { unified } from 'unified';
16
+ import Slugger from 'github-slugger';
17
+ import rehypeRaw from 'rehype-raw';
18
+ import rehypeStringify from 'rehype-stringify';
17
19
  import markdown from 'remark-parse';
18
20
  import markdownToHtml from 'remark-rehype';
19
- import rehypeStringify from 'rehype-stringify';
20
- import rehypeRaw from 'rehype-raw';
21
- import Slugger from 'github-slugger';
21
+ import { unified } from 'unified';
22
22
  import { VFile } from 'vfile';
23
23
 
24
24
  export * from './types.js';
@@ -99,16 +99,18 @@ export async function renderMarkdown(
99
99
  parser
100
100
  .use(isMDX ? [rehypeJsx, rehypeExpressions] : [rehypeRaw])
101
101
  .use(rehypeEscape)
102
- .use(rehypeIslands);
102
+ .use(rehypeIslands)
103
+ .use([rehypeCollectHeaders])
104
+ .use(rehypeStringify, { allowDangerousHtml: true });
103
105
 
104
106
  let result: string;
105
107
  try {
106
- const vfile = await parser
107
- .use([rehypeCollectHeaders])
108
- .use(rehypeStringify, { allowDangerousHtml: true })
109
- .process(input);
108
+ const vfile = await parser.process(input);
110
109
  result = vfile.toString();
111
110
  } catch (err) {
111
+ // Ensure that the error message contains the input filename
112
+ // to make it easier for the user to fix the issue
113
+ err = prefixError(err, `Failed to parse Markdown file "${input.path}"`);
112
114
  console.error(err);
113
115
  throw err;
114
116
  }
@@ -118,3 +120,27 @@ export async function renderMarkdown(
118
120
  code: result.toString(),
119
121
  };
120
122
  }
123
+
124
+ function prefixError(err: any, prefix: string) {
125
+ // If the error is an object with a `message` property, attempt to prefix the message
126
+ if (err && err.message) {
127
+ try {
128
+ err.message = `${prefix}:\n${err.message}`;
129
+ return err;
130
+ } catch (error) {
131
+ // Any errors here are ok, there's fallback code below
132
+ }
133
+ }
134
+
135
+ // If that failed, create a new error with the desired message and attempt to keep the stack
136
+ const wrappedError = new Error(`${prefix}${err ? `: ${err}` : ''}`);
137
+ try {
138
+ wrappedError.stack = err.stack;
139
+ // @ts-ignore
140
+ wrappedError.cause = err;
141
+ } catch (error) {
142
+ // It's ok if we could not set the stack or cause - the message is the most important part
143
+ }
144
+
145
+ return wrappedError;
146
+ }
package/src/mdxjs.ts ADDED
@@ -0,0 +1,27 @@
1
+ // Note: The code in this file is based on `micromark-extension-mdxjs`
2
+ // and was adapted to use our fork `@astrojs/micromark-extension-mdx-jsx`
3
+ // instead of `micromark-extension-mdx-jsx` to allow some extended syntax.
4
+ // See `@astrojs/micromark-extension-mdx-jsx` on NPM for more details.
5
+ // Also, support for ESM imports & exports in Markdown content was removed.
6
+
7
+ import { mdxJsx } from '@astrojs/micromark-extension-mdx-jsx';
8
+ import { Parser } from 'acorn';
9
+ import acornJsx from 'acorn-jsx';
10
+ import type { Options } from 'micromark-extension-mdx-expression';
11
+ import { mdxExpression } from 'micromark-extension-mdx-expression';
12
+ import { mdxMd } from 'micromark-extension-mdx-md';
13
+ import { combineExtensions } from 'micromark-util-combine-extensions';
14
+ import type { Extension } from 'micromark-util-types';
15
+
16
+ export function mdxjs(options: Options): Extension {
17
+ const settings: any = Object.assign(
18
+ {
19
+ acorn: Parser.extend(acornJsx()),
20
+ acornOptions: { ecmaVersion: 2020, sourceType: 'module' },
21
+ addResult: true,
22
+ },
23
+ options
24
+ );
25
+
26
+ return combineExtensions([mdxExpression(settings), mdxJsx(settings), mdxMd]);
27
+ }
@@ -1,5 +1,6 @@
1
- import { visit } from 'unist-util-visit';
2
1
  import Slugger from 'github-slugger';
2
+ import { toHtml } from 'hast-util-to-html';
3
+ import { visit } from 'unist-util-visit';
3
4
 
4
5
  import type { MarkdownHeader, RehypePlugin } from './types.js';
5
6
 
@@ -17,32 +18,36 @@ export default function createCollectHeaders() {
17
18
  if (!level) return;
18
19
  const depth = Number.parseInt(level);
19
20
 
20
- let raw = '';
21
21
  let text = '';
22
22
  let isJSX = false;
23
- visit(node, (child) => {
24
- if (child.type === 'element') {
23
+ visit(node, (child, _, parent) => {
24
+ if (child.type === 'element' || parent == null) {
25
25
  return;
26
26
  }
27
27
  if (child.type === 'raw') {
28
- // HACK: serialized JSX from internal plugins, ignore these for slug
29
28
  if (child.value.startsWith('\n<') || child.value.endsWith('>\n')) {
30
- raw += child.value.replace(/^\n|\n$/g, '');
31
29
  return;
32
30
  }
33
31
  }
34
32
  if (child.type === 'text' || child.type === 'raw') {
35
- raw += child.value;
36
- text += child.value;
37
- isJSX = isJSX || child.value.includes('{');
33
+ if (new Set(['code', 'pre']).has(parent.tagName)) {
34
+ text += child.value;
35
+ } else {
36
+ text += child.value.replace(/\{/g, '${');
37
+ isJSX = isJSX || child.value.includes('{');
38
+ }
38
39
  }
39
40
  });
40
41
 
41
42
  node.properties = node.properties || {};
42
43
  if (typeof node.properties.id !== 'string') {
43
44
  if (isJSX) {
45
+ // HACK: serialized JSX from internal plugins, ignore these for slug
46
+ const raw = toHtml(node.children, { allowDangerousHtml: true })
47
+ .replace(/\n(<)/g, '<')
48
+ .replace(/(>)\n/g, '>');
44
49
  // HACK: for ids that have JSX content, use $$slug helper to generate slug at runtime
45
- node.properties.id = `$$slug(\`${text.replace(/\{/g, '${')}\`)`;
50
+ node.properties.id = `$$slug(\`${text}\`)`;
46
51
  (node as any).type = 'raw';
47
52
  (
48
53
  node as any
@@ -1,10 +1,15 @@
1
- import { SKIP, visit } from 'unist-util-visit';
1
+ import { visit } from 'unist-util-visit';
2
2
 
3
3
  export default function rehypeEscape(): any {
4
4
  return function (node: any): any {
5
5
  return visit(node, 'element', (el) => {
6
6
  if (el.tagName === 'code' || el.tagName === 'pre') {
7
7
  el.properties['is:raw'] = true;
8
+ // Visit all raw children and escape HTML tags to prevent Markdown code
9
+ // like "This is a `<script>` tag" from actually opening a script tag
10
+ visit(el, 'raw', (raw) => {
11
+ raw.value = raw.value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
12
+ });
8
13
  }
9
14
  return el;
10
15
  });
package/src/rehype-jsx.ts CHANGED
@@ -1,51 +1,65 @@
1
- import { map } from 'unist-util-map';
1
+ import { visit } from 'unist-util-visit';
2
+ import type { RehypePlugin } from './types.js';
2
3
 
3
- const MDX_ELEMENTS = new Set(['mdxJsxFlowElement', 'mdxJsxTextElement']);
4
- export default function rehypeJsx(): any {
5
- return function (node: any): any {
6
- return map(node, (child: any) => {
7
- if (child.type === 'element') {
8
- return { ...child, tagName: `${child.tagName}` };
9
- }
10
- if (MDX_ELEMENTS.has(child.type)) {
11
- const attrs = child.attributes.reduce((acc: any[], entry: any) => {
12
- let attr = entry.value;
13
- if (attr && typeof attr === 'object') {
14
- attr = `{${attr.value}}`;
15
- } else if (attr && entry.type === 'mdxJsxExpressionAttribute') {
16
- attr = `{${attr}}`;
17
- } else if (attr === null) {
18
- attr = '';
19
- } else if (typeof attr === 'string') {
20
- attr = `"${attr}"`;
21
- }
22
- if (!entry.name) {
23
- return acc + ` ${attr}`;
24
- }
25
- return acc + ` ${entry.name}${attr ? '=' : ''}${attr}`;
26
- }, '');
4
+ const MDX_ELEMENTS = ['mdxJsxFlowElement', 'mdxJsxTextElement'];
27
5
 
28
- if (child.children.length === 0) {
29
- return {
30
- type: 'raw',
31
- value: `<${child.name}${attrs} />`,
32
- };
6
+ export default function rehypeJsx(): ReturnType<RehypePlugin> {
7
+ return function (tree) {
8
+ visit(tree, MDX_ELEMENTS, (node: any, index: number | null, parent: any) => {
9
+ if (index === null || !Boolean(parent)) return;
10
+
11
+ const attrs = node.attributes.reduce((acc: any[], entry: any) => {
12
+ let attr = entry.value;
13
+ if (attr && typeof attr === 'object') {
14
+ attr = `{${attr.value}}`;
15
+ } else if (attr && entry.type === 'mdxJsxExpressionAttribute') {
16
+ attr = `{${attr}}`;
17
+ } else if (attr === null) {
18
+ attr = '';
19
+ } else if (typeof attr === 'string') {
20
+ attr = `"${attr}"`;
33
21
  }
34
- child.children.splice(0, 0, {
35
- type: 'raw',
36
- value: `\n<${child.name}${attrs}>`,
37
- });
38
- child.children.push({
39
- type: 'raw',
40
- value: `</${child.name}>\n`,
22
+ if (!entry.name) {
23
+ return acc + ` ${attr}`;
24
+ }
25
+ return acc + ` ${entry.name}${attr ? '=' : ''}${attr}`;
26
+ }, '');
27
+
28
+ if (node.children.length === 0) {
29
+ node.type = 'raw';
30
+ node.value = `<${node.name}${attrs} />`;
31
+ return;
32
+ }
33
+
34
+ // If the current node is a JSX <a> element, remove autolinks from its children
35
+ // to prevent Markdown code like `<a href="/">**Go to www.example.com now!**</a>`
36
+ // from creating a nested link to `www.example.com`
37
+ if (node.name === 'a') {
38
+ visit(node, 'element', (el, elIndex, elParent) => {
39
+ const isAutolink =
40
+ el.tagName === 'a' &&
41
+ el.children.length === 1 &&
42
+ el.children[0].type === 'text' &&
43
+ el.children[0].value.match(/^(https?:\/\/|www\.)/i);
44
+
45
+ // If we found an autolink, remove it by replacing it with its text-only child
46
+ if (isAutolink) {
47
+ elParent.children.splice(elIndex, 1, el.children[0]);
48
+ }
41
49
  });
42
- return {
43
- ...child,
44
- type: 'element',
45
- tagName: `Fragment`,
46
- };
47
50
  }
48
- return child;
51
+
52
+ // Replace the current node with its children
53
+ // wrapped by raw opening and closing tags
54
+ const openingTag = {
55
+ type: 'raw',
56
+ value: `\n<${node.name}${attrs}>`,
57
+ };
58
+ const closingTag = {
59
+ type: 'raw',
60
+ value: `</${node.name}>\n`,
61
+ };
62
+ parent.children.splice(index, 1, openingTag, ...node.children, closingTag);
49
63
  });
50
64
  };
51
65
  }
@@ -1,11 +1,13 @@
1
- import { mdxjs } from 'micromark-extension-mdxjs';
1
+ import type * as fromMarkdown from 'mdast-util-from-markdown';
2
+ import type { Tag } from 'mdast-util-mdx-jsx';
2
3
  import { mdxFromMarkdown, mdxToMarkdown } from './mdast-util-mdxish.js';
4
+ import { mdxjs } from './mdxjs.js';
3
5
 
4
6
  export default function remarkMdxish(this: any, options = {}) {
5
7
  const data = this.data();
6
8
 
7
9
  add('micromarkExtensions', mdxjs(options));
8
- add('fromMarkdownExtensions', mdxFromMarkdown());
10
+ add('fromMarkdownExtensions', makeFromMarkdownLessStrict(mdxFromMarkdown()));
9
11
  add('toMarkdownExtensions', mdxToMarkdown());
10
12
 
11
13
  function add(field: string, value: unknown) {
@@ -13,3 +15,42 @@ export default function remarkMdxish(this: any, options = {}) {
13
15
  list.push(value);
14
16
  }
15
17
  }
18
+
19
+ function makeFromMarkdownLessStrict(extensions: fromMarkdown.Extension[]) {
20
+ extensions.forEach((extension) => {
21
+ // Fix exit handlers that are too strict
22
+ ['mdxJsxFlowTag', 'mdxJsxTextTag'].forEach((exitHandler) => {
23
+ if (!extension.exit || !extension.exit[exitHandler]) return;
24
+ extension.exit[exitHandler] = chainHandlers(fixSelfClosing, extension.exit[exitHandler]);
25
+ });
26
+ });
27
+
28
+ return extensions;
29
+ }
30
+
31
+ const selfClosingTags = new Set([
32
+ 'area',
33
+ 'base',
34
+ 'br',
35
+ 'col',
36
+ 'embed',
37
+ 'hr',
38
+ 'img',
39
+ 'input',
40
+ 'link',
41
+ 'meta',
42
+ 'source',
43
+ 'track',
44
+ 'wbr',
45
+ ]);
46
+
47
+ function fixSelfClosing(this: fromMarkdown.CompileContext) {
48
+ const tag = this.getData('mdxJsxTag') as Tag;
49
+ if (tag.name && selfClosingTags.has(tag.name)) tag.selfClosing = true;
50
+ }
51
+
52
+ function chainHandlers(...handlers: fromMarkdown.Handle[]) {
53
+ return function handlerChain(this: fromMarkdown.CompileContext, token: fromMarkdown.Token) {
54
+ handlers.forEach((handler) => handler.call(this, token));
55
+ };
56
+ }
@@ -1,7 +1,7 @@
1
- import { visit } from 'unist-util-visit';
2
- import Prism from 'prismjs';
3
1
  import { addAstro } from '@astrojs/prism/internal';
2
+ import Prism from 'prismjs';
4
3
  import loadLanguages from 'prismjs/components/index.js';
4
+ import { visit } from 'unist-util-visit';
5
5
  const noVisit = new Set(['root', 'html', 'text']);
6
6
 
7
7
  const languageMap = new Map([['ts', 'typescript']]);
@@ -1,4 +1,4 @@
1
- import { visit as _visit, SKIP } from 'unist-util-visit';
1
+ import { SKIP, visit as _visit } from 'unist-util-visit';
2
2
 
3
3
  // This is a workaround.
4
4
  // It fixes a compatibility issue between different, incompatible ASTs given by plugins to Unist
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type * as unified from 'unified';
2
- import type * as mdast from 'mdast';
3
1
  import type * as hast from 'hast';
2
+ import type * as mdast from 'mdast';
4
3
  import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
4
+ import type * as unified from 'unified';
5
5
 
6
6
  export type { Node } from 'unist';
7
7
 
@@ -0,0 +1,92 @@
1
+ import { renderMarkdown } from '../dist/index.js';
2
+ import chai from 'chai';
3
+
4
+ describe('autolinking', () => {
5
+ it('autolinks URLs starting with a protocol in plain text', async () => {
6
+ const { code } = await renderMarkdown(`See https://example.com for more.`, {});
7
+
8
+ chai
9
+ .expect(code.replace(/\n/g, ''))
10
+ .to.equal(`<p>See <a href="https://example.com">https://example.com</a> for more.</p>`);
11
+ });
12
+
13
+ it('autolinks URLs starting with "www." in plain text', async () => {
14
+ const { code } = await renderMarkdown(`See www.example.com for more.`, {});
15
+
16
+ chai
17
+ .expect(code.trim())
18
+ .to.equal(`<p>See <a href="http://www.example.com">www.example.com</a> for more.</p>`);
19
+ });
20
+
21
+ it('does not autolink URLs in code blocks', async () => {
22
+ const { code } = await renderMarkdown(
23
+ 'See `https://example.com` or `www.example.com` for more.',
24
+ {}
25
+ );
26
+
27
+ chai
28
+ .expect(code.trim())
29
+ .to.equal(
30
+ `<p>See <code is:raw>https://example.com</code> or ` +
31
+ `<code is:raw>www.example.com</code> for more.</p>`
32
+ );
33
+ });
34
+
35
+ it('does not autolink URLs in fenced code blocks', async () => {
36
+ const { code } = await renderMarkdown(
37
+ 'Example:\n```\nGo to https://example.com or www.example.com now.\n```',
38
+ {}
39
+ );
40
+
41
+ chai
42
+ .expect(code)
43
+ .to.contain(`<pre is:raw`)
44
+ .to.contain(`Go to https://example.com or www.example.com now.`);
45
+ });
46
+
47
+ it('does not autolink URLs starting with a protocol when nested inside links', async () => {
48
+ const { code } = await renderMarkdown(
49
+ `See [http://example.com](http://example.com) or ` +
50
+ `<a test href="https://example.com">https://example.com</a>`,
51
+ {}
52
+ );
53
+
54
+ chai
55
+ .expect(code.replace(/\n/g, ''))
56
+ .to.equal(
57
+ `<p>See <a href="http://example.com">http://example.com</a> or ` +
58
+ `<a test href="https://example.com">https://example.com</a></p>`
59
+ );
60
+ });
61
+
62
+ it('does not autolink URLs starting with "www." when nested inside links', async () => {
63
+ const { code } = await renderMarkdown(
64
+ `See [www.example.com](https://www.example.com) or ` +
65
+ `<a test href="https://www.example.com">www.example.com</a>`,
66
+ {}
67
+ );
68
+
69
+ chai
70
+ .expect(code.replace(/\n/g, ''))
71
+ .to.equal(
72
+ `<p>See <a href="https://www.example.com">www.example.com</a> or ` +
73
+ `<a test href="https://www.example.com">www.example.com</a></p>`
74
+ );
75
+ });
76
+
77
+ it('does not autolink URLs when nested several layers deep inside links', async () => {
78
+ const { code } = await renderMarkdown(
79
+ `<a href="https://www.example.com">**Visit _our www.example.com or ` +
80
+ `http://localhost pages_ for more!**</a>`,
81
+ {}
82
+ );
83
+
84
+ chai
85
+ .expect(code.replace(/\n/g, ''))
86
+ .to.equal(
87
+ `<a href="https://www.example.com"><strong>` +
88
+ `Visit <em>our www.example.com or http://localhost pages</em> for more!` +
89
+ `</strong></a>`
90
+ );
91
+ });
92
+ });
@@ -49,9 +49,18 @@ describe('components', () => {
49
49
  it('should normalize children', async () => {
50
50
  const { code } = await renderMarkdown(`<Component bool={true}>Hello world!</Component>`, {});
51
51
 
52
+ chai.expect(code).to.equal(`\n<Component bool={true}>Hello world!</Component>\n`);
53
+ });
54
+
55
+ it('should be able to nest components', async () => {
56
+ const { code } = await renderMarkdown(
57
+ `<Component bool={true}><Component>Hello world!</Component></Component>`,
58
+ {}
59
+ );
60
+
52
61
  chai
53
62
  .expect(code)
54
- .to.equal(`<Fragment>\n<Component bool={true}>Hello world!</Component>\n</Fragment>`);
63
+ .to.equal(`\n<Component bool={true}>\n<Component>Hello world!</Component>\n</Component>\n`);
55
64
  });
56
65
 
57
66
  it('should allow markdown without many spaces', async () => {
@@ -62,10 +71,6 @@ describe('components', () => {
62
71
  {}
63
72
  );
64
73
 
65
- chai
66
- .expect(code)
67
- .to.equal(
68
- `<Fragment>\n<Component><h1 id="hello-world">Hello world!</h1></Component>\n</Fragment>`
69
- );
74
+ chai.expect(code).to.equal(`\n<Component><h1 id="hello-world">Hello world!</h1></Component>\n`);
70
75
  });
71
76
  });
@@ -2,7 +2,7 @@ import { renderMarkdown } from '../dist/index.js';
2
2
  import chai from 'chai';
3
3
 
4
4
  describe('expressions', () => {
5
- it('should be able to serialize bare expession', async () => {
5
+ it('should be able to serialize bare expression', async () => {
6
6
  const { code } = await renderMarkdown(`{a}`, {});
7
7
 
8
8
  chai.expect(code).to.equal(`{a}`);
@@ -11,7 +11,7 @@ describe('expressions', () => {
11
11
  it('should be able to serialize expression inside component', async () => {
12
12
  const { code } = await renderMarkdown(`<Component>{a}</Component>`, {});
13
13
 
14
- chai.expect(code).to.equal(`<Fragment>\n<Component>{a}</Component>\n</Fragment>`);
14
+ chai.expect(code).to.equal(`\n<Component>{a}</Component>\n`);
15
15
  });
16
16
 
17
17
  it('should be able to serialize expression inside markdown', async () => {
@@ -40,6 +40,37 @@ describe('expressions', () => {
40
40
  );
41
41
  });
42
42
 
43
+ it('should be able to avoid evaluating JSX-like expressions in an inline code & generate a slug for id', async () => {
44
+ const { code } = await renderMarkdown(`# \`{frontmatter.title}\``, {});
45
+
46
+ chai
47
+ .expect(code)
48
+ .to.equal('<h1 id="frontmattertitle"><code is:raw>{frontmatter.title}</code></h1>');
49
+ });
50
+
51
+ it('should be able to avoid evaluating JSX-like expressions in inline codes', async () => {
52
+ const { code } = await renderMarkdown(`# \`{ foo }\` is a shorthand for \`{ foo: foo }\``, {});
53
+
54
+ chai
55
+ .expect(code)
56
+ .to.equal(
57
+ '<h1 id="-foo--is-a-shorthand-for--foo-foo-"><code is:raw>{ foo }</code> is a shorthand for <code is:raw>{ foo: foo }</code></h1>'
58
+ );
59
+ });
60
+
61
+ it('should be able to avoid evaluating JSX-like expressions & escape HTML tag characters in inline codes', async () => {
62
+ const { code } = await renderMarkdown(
63
+ `###### \`{}\` is equivalent to \`Record<never, never>\` <small>(at TypeScript v{frontmatter.version})</small>`,
64
+ {}
65
+ );
66
+
67
+ chai
68
+ .expect(code)
69
+ .to.equal(
70
+ `<h6 id={$$slug(\`{} is equivalent to Record&lt;never, never&gt; (at TypeScript v\${frontmatter.version})\`)}><code is:raw>{}</code> is equivalent to <code is:raw>Record&lt;never, never&gt;</code> <small>(at TypeScript v{frontmatter.version})</small></h6>`
71
+ );
72
+ });
73
+
43
74
  it('should be able to serialize function expression', async () => {
44
75
  const { code } = await renderMarkdown(
45
76
  `{frontmatter.list.map(item => <p id={item}>{item}</p>)}`,
@@ -0,0 +1,99 @@
1
+ import { renderMarkdown } from '../dist/index.js';
2
+ import chai from 'chai';
3
+
4
+ describe('strictness', () => {
5
+ it('should allow self-closing HTML tags (void elements)', async () => {
6
+ const { code } = await renderMarkdown(
7
+ `Use self-closing void elements<br>like word<wbr>break and images: <img src="hi.jpg">`,
8
+ {}
9
+ );
10
+
11
+ chai
12
+ .expect(code)
13
+ .to.equal(
14
+ `<p>Use self-closing void elements<br />like word<wbr />break and images: ` +
15
+ `<img src="hi.jpg" /></p>`
16
+ );
17
+ });
18
+
19
+ it('should allow attribute names starting with ":" after element names', async () => {
20
+ const { code } = await renderMarkdown(`<div :class="open ? '' : 'hidden'">Test</div>`, {});
21
+
22
+ chai.expect(code.trim()).to.equal(`<div :class="open ? '' : 'hidden'">Test</div>`);
23
+ });
24
+
25
+ it('should allow attribute names starting with ":" after local element names', async () => {
26
+ const { code } = await renderMarkdown(`<div.abc :class="open ? '' : 'hidden'">x</div.abc>`, {});
27
+
28
+ chai.expect(code.trim()).to.equal(`<div.abc :class="open ? '' : 'hidden'">x</div.abc>`);
29
+ });
30
+
31
+ it('should allow attribute names starting with ":" after attribute names', async () => {
32
+ const { code } = await renderMarkdown(`<input type="text" disabled :placeholder="hi">`, {});
33
+
34
+ chai.expect(code.trim()).to.equal(`<input type="text" disabled :placeholder="hi" />`);
35
+ });
36
+
37
+ it('should allow attribute names starting with ":" after local attribute names', async () => {
38
+ const { code } = await renderMarkdown(
39
+ `<input type="text" x-test:disabled :placeholder="hi">`,
40
+ {}
41
+ );
42
+
43
+ chai.expect(code.trim()).to.equal(`<input type="text" x-test:disabled :placeholder="hi" />`);
44
+ });
45
+
46
+ it('should allow attribute names starting with ":" after attribute values', async () => {
47
+ const { code } = await renderMarkdown(`<input type="text" :placeholder="placeholder">`, {});
48
+
49
+ chai.expect(code.trim()).to.equal(`<input type="text" :placeholder="placeholder" />`);
50
+ });
51
+
52
+ it('should allow attribute names starting with "@" after element names', async () => {
53
+ const { code } = await renderMarkdown(`<button @click="handleClick">Test</button>`, {});
54
+
55
+ chai.expect(code.trim()).to.equal(`<button @click="handleClick">Test</button>`);
56
+ });
57
+
58
+ it('should allow attribute names starting with "@" after local element names', async () => {
59
+ const { code } = await renderMarkdown(
60
+ `<button.local @click="handleClick">Test</button.local>`,
61
+ {}
62
+ );
63
+
64
+ chai.expect(code.trim()).to.equal(`<button.local @click="handleClick">Test</button.local>`);
65
+ });
66
+
67
+ it('should allow attribute names starting with "@" after attribute names', async () => {
68
+ const { code } = await renderMarkdown(
69
+ `<button disabled @click="handleClick">Test</button>`,
70
+ {}
71
+ );
72
+
73
+ chai.expect(code.trim()).to.equal(`<button disabled @click="handleClick">Test</button>`);
74
+ });
75
+
76
+ it('should allow attribute names starting with "@" after local attribute names', async () => {
77
+ const { code } = await renderMarkdown(
78
+ `<button x-test:disabled @click="handleClick">Test</button>`,
79
+ {}
80
+ );
81
+
82
+ chai.expect(code.trim()).to.equal(`<button x-test:disabled @click="handleClick">Test</button>`);
83
+ });
84
+
85
+ it('should allow attribute names starting with "@" after attribute values', async () => {
86
+ const { code } = await renderMarkdown(
87
+ `<button type="submit" @click="handleClick">Test</button>`,
88
+ {}
89
+ );
90
+
91
+ chai.expect(code.trim()).to.equal(`<button type="submit" @click="handleClick">Test</button>`);
92
+ });
93
+
94
+ it('should allow attribute names containing dots', async () => {
95
+ const { code } = await renderMarkdown(`<input x-on:input.debounce.500ms="fetchResults">`, {});
96
+
97
+ chai.expect(code.trim()).to.equal(`<input x-on:input.debounce.500ms="fetchResults" />`);
98
+ });
99
+ });