@astrojs/mdx 0.18.0 → 0.18.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.
@@ -1,5 +1,5 @@
1
- @astrojs/mdx:build: cache hit, replaying output 61e81c86fa4b4798
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.18.0 build /home/runner/work/astro/astro/packages/integrations/mdx
4
- @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
- @astrojs/mdx:build: 
1
+ @astrojs/mdx:build: cache hit, replaying output 6863c2b0a0d736f6
2
+ @astrojs/mdx:build: 
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.18.1 build /home/runner/work/astro/astro/packages/integrations/mdx
4
+ @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
+ @astrojs/mdx:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#6494](https://github.com/withastro/astro/pull/6494) [`a13e9d7e3`](https://github.com/withastro/astro/commit/a13e9d7e33baccf51e7d4815f99b481ad174bc57) Thanks [@Yan-Thomas](https://github.com/Yan-Thomas)! - Consistency improvements to several package descriptions
8
+
9
+ - Updated dependencies [[`a13e9d7e3`](https://github.com/withastro/astro/commit/a13e9d7e33baccf51e7d4815f99b481ad174bc57)]:
10
+ - @astrojs/prism@2.1.1
11
+
3
12
  ## 0.18.0
4
13
 
5
14
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { markdownConfigDefaults } from '@astrojs/markdown-remark';
2
- import { PluggableList } from '@mdx-js/mdx/lib/core.js';
2
+ import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
3
3
  import type { AstroIntegration, ContentEntryType, HookParameters } from 'astro';
4
4
  import type { Options as RemarkRehypeOptions } from 'remark-rehype';
5
5
  export declare type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | 'rehypePlugins'> & {
package/dist/plugins.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
2
2
  import type { AstroConfig } from 'astro';
3
3
  import type { VFile } from 'vfile';
4
- import { MdxOptions } from './index.js';
4
+ import type { MdxOptions } from './index.js';
5
5
  export declare function recmaInjectImportMetaEnvPlugin({ importMetaEnv, }: {
6
6
  importMetaEnv: Record<string, any>;
7
7
  }): (tree: any) => void;
@@ -1,2 +1,2 @@
1
- import { MarkdownVFile } from '@astrojs/markdown-remark';
1
+ import type { MarkdownVFile } from '@astrojs/markdown-remark';
2
2
  export declare function rehypeInjectHeadingsExport(): (tree: any, file: MarkdownVFile) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/mdx",
3
- "description": "Use MDX within Astro",
4
- "version": "0.18.0",
3
+ "description": "Add support for MDX pages in your Astro site",
4
+ "version": "0.18.1",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@astrojs/markdown-remark": "^2.1.0",
27
- "@astrojs/prism": "^2.1.0",
27
+ "@astrojs/prism": "^2.1.1",
28
28
  "@mdx-js/mdx": "^2.3.0",
29
29
  "@mdx-js/rollup": "^2.3.0",
30
30
  "acorn": "^8.8.0",
@@ -48,7 +48,7 @@
48
48
  "@types/mdast": "^3.0.10",
49
49
  "@types/mocha": "^9.1.1",
50
50
  "@types/yargs-parser": "^21.0.0",
51
- "astro": "2.1.0",
51
+ "astro": "2.1.3",
52
52
  "astro-scripts": "0.0.14",
53
53
  "chai": "^4.3.6",
54
54
  "cheerio": "^1.0.0-rc.11",
@@ -57,7 +57,9 @@
57
57
  "mdast-util-to-string": "^3.1.0",
58
58
  "mocha": "^9.2.2",
59
59
  "reading-time": "^1.5.0",
60
+ "rehype-mathjax": "^4.0.2",
60
61
  "rehype-pretty-code": "^0.4.0",
62
+ "remark-math": "^5.1.1",
61
63
  "remark-rehype": "^10.1.0",
62
64
  "remark-shiki-twoslash": "^3.1.0",
63
65
  "remark-toc": "^8.0.1",
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { markdownConfigDefaults } from '@astrojs/markdown-remark';
2
2
  import { toRemarkInitializeAstroData } from '@astrojs/markdown-remark/dist/internal.js';
3
3
  import { compile as mdxCompile } from '@mdx-js/mdx';
4
- import { PluggableList } from '@mdx-js/mdx/lib/core.js';
4
+ import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
5
5
  import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
6
6
  import type { AstroIntegration, ContentEntryType, HookParameters } from 'astro';
7
7
  import { parse as parseESM } from 'es-module-lexer';
package/src/plugins.ts CHANGED
@@ -13,7 +13,7 @@ import rehypeRaw from 'rehype-raw';
13
13
  import remarkGfm from 'remark-gfm';
14
14
  import remarkSmartypants from 'remark-smartypants';
15
15
  import type { VFile } from 'vfile';
16
- import { MdxOptions } from './index.js';
16
+ import type { MdxOptions } from './index.js';
17
17
  import { rehypeInjectHeadingsExport } from './rehype-collect-headings.js';
18
18
  import rehypeMetaString from './rehype-meta-string.js';
19
19
  import remarkPrism from './remark-prism.js';
@@ -1,4 +1,4 @@
1
- import { MarkdownHeading, MarkdownVFile } from '@astrojs/markdown-remark';
1
+ import type { MarkdownHeading, MarkdownVFile } from '@astrojs/markdown-remark';
2
2
  import { jsToTreeNode } from './utils.js';
3
3
 
4
4
  export function rehypeInjectHeadingsExport() {
@@ -0,0 +1,5 @@
1
+ # Mathjax
2
+
3
+ $$
4
+ \left(\frac{\sqrt{x+2}}{y^{2}}\right)
5
+ $$
@@ -0,0 +1,13 @@
1
+ # Script style raw
2
+
3
+ <script id="test-script">
4
+ {`console.log('raw script')`}
5
+ </script>
6
+
7
+ <style id="test-style">
8
+ {`
9
+ h1[id="script-style-raw"] {
10
+ color: red;
11
+ }
12
+ `}
13
+ </style>
@@ -0,0 +1,64 @@
1
+ import mdx from '@astrojs/mdx';
2
+ import { expect } from 'chai';
3
+ import { parseHTML } from 'linkedom';
4
+ import { loadFixture } from '../../../astro/test/test-utils.js';
5
+ import remarkMath from 'remark-math';
6
+ import rehypeMathjaxSvg from 'rehype-mathjax';
7
+ import rehypeMathjaxChtml from 'rehype-mathjax/chtml.js';
8
+
9
+ const FIXTURE_ROOT = new URL('./fixtures/mdx-math/', import.meta.url);
10
+
11
+ describe('MDX math', () => {
12
+ describe('mathjax', () => {
13
+ it('works with svg', async () => {
14
+ const fixture = await loadFixture({
15
+ root: FIXTURE_ROOT,
16
+ markdown: {
17
+ remarkPlugins: [remarkMath],
18
+ rehypePlugins: [rehypeMathjaxSvg],
19
+ },
20
+ integrations: [mdx()],
21
+ });
22
+ await fixture.build();
23
+
24
+ const html = await fixture.readFile('/mathjax/index.html');
25
+ const { document } = parseHTML(html);
26
+
27
+ const mjxContainer = document.querySelector('mjx-container[jax="SVG"]');
28
+ expect(mjxContainer).to.not.be.null;
29
+
30
+ const mjxStyle = document.querySelector('style').innerHTML;
31
+ expect(mjxStyle).to.include('mjx-container[jax="SVG"]', 'style should not be html-escaped');
32
+ });
33
+
34
+ it('works with chtml', async () => {
35
+ const fixture = await loadFixture({
36
+ root: FIXTURE_ROOT,
37
+ markdown: {
38
+ remarkPlugins: [remarkMath],
39
+ rehypePlugins: [
40
+ [
41
+ rehypeMathjaxChtml,
42
+ {
43
+ chtml: {
44
+ fontURL: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/output/chtml/fonts/woff-v2',
45
+ },
46
+ },
47
+ ],
48
+ ],
49
+ },
50
+ integrations: [mdx()],
51
+ });
52
+ await fixture.build();
53
+
54
+ const html = await fixture.readFile('/mathjax/index.html');
55
+ const { document } = parseHTML(html);
56
+
57
+ const mjxContainer = document.querySelector('mjx-container[jax="CHTML"]');
58
+ expect(mjxContainer).to.not.be.null;
59
+
60
+ const mjxStyle = document.querySelector('style').innerHTML;
61
+ expect(mjxStyle).to.include('mjx-container[jax="CHTML"]', 'style should not be html-escaped');
62
+ });
63
+ });
64
+ });
@@ -0,0 +1,70 @@
1
+ import mdx from '@astrojs/mdx';
2
+ import { expect } from 'chai';
3
+ import { parseHTML } from 'linkedom';
4
+ import { loadFixture } from '../../../astro/test/test-utils.js';
5
+
6
+ const FIXTURE_ROOT = new URL('./fixtures/mdx-script-style-raw/', import.meta.url);
7
+
8
+ describe('MDX script style raw', () => {
9
+ describe('dev', () => {
10
+ let fixture;
11
+ let devServer;
12
+
13
+ before(async () => {
14
+ fixture = await loadFixture({
15
+ root: FIXTURE_ROOT,
16
+ integrations: [mdx()],
17
+ });
18
+ devServer = await fixture.startDevServer();
19
+ });
20
+
21
+ after(async () => {
22
+ await devServer.stop();
23
+ });
24
+
25
+ it('works with with raw script and style strings', async () => {
26
+ const res = await fixture.fetch('/index.html');
27
+ expect(res.status).to.equal(200);
28
+
29
+ const html = await res.text();
30
+ const { document } = parseHTML(html);
31
+
32
+ const scriptContent = document.getElementById('test-script').innerHTML;
33
+ expect(scriptContent).to.include(
34
+ "console.log('raw script')",
35
+ 'script should not be html-escaped'
36
+ );
37
+
38
+ const styleContent = document.getElementById('test-style').innerHTML;
39
+ expect(styleContent).to.include(
40
+ 'h1[id="script-style-raw"]',
41
+ 'style should not be html-escaped'
42
+ );
43
+ });
44
+ });
45
+
46
+ describe('build', () => {
47
+ it('works with with raw script and style strings', async () => {
48
+ const fixture = await loadFixture({
49
+ root: FIXTURE_ROOT,
50
+ integrations: [mdx()],
51
+ });
52
+ await fixture.build();
53
+
54
+ const html = await fixture.readFile('/index.html');
55
+ const { document } = parseHTML(html);
56
+
57
+ const scriptContent = document.getElementById('test-script').innerHTML;
58
+ expect(scriptContent).to.include(
59
+ "console.log('raw script')",
60
+ 'script should not be html-escaped'
61
+ );
62
+
63
+ const styleContent = document.getElementById('test-style').innerHTML;
64
+ expect(styleContent).to.include(
65
+ 'h1[id="script-style-raw"]',
66
+ 'style should not be html-escaped'
67
+ );
68
+ });
69
+ });
70
+ });