@astrojs/mdx 0.14.0 → 0.15.0-beta.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.
@@ -36,6 +36,19 @@ describe('MDX plugins', () => {
36
36
  expect(selectGfmLink(document)).to.not.be.null;
37
37
  });
38
38
 
39
+ it('Applies SmartyPants by default', async () => {
40
+ const fixture = await buildFixture({
41
+ integrations: [mdx()],
42
+ });
43
+
44
+ const html = await fixture.readFile(FILE);
45
+ const { document } = parseHTML(html);
46
+
47
+ const quote = selectSmartypantsQuote(document);
48
+ expect(quote).to.not.be.null;
49
+ expect(quote.textContent).to.contain('“Smartypants” is — awesome');
50
+ });
51
+
39
52
  it('supports custom rehype plugins', async () => {
40
53
  const fixture = await buildFixture({
41
54
  integrations: [
@@ -80,91 +93,75 @@ describe('MDX plugins', () => {
80
93
  expect(selectTocLink(document)).to.be.null;
81
94
  });
82
95
 
83
- it('respects "extendDefaultPlugins" when extending markdown', async () => {
84
- const fixture = await buildFixture({
85
- markdown: {
86
- remarkPlugins: [remarkExamplePlugin],
87
- rehypePlugins: [rehypeExamplePlugin],
88
- extendDefaultPlugins: true,
89
- },
90
- integrations: [mdx()],
91
- });
92
-
93
- const html = await fixture.readFile(FILE);
94
- const { document } = parseHTML(html);
95
-
96
- expect(selectRemarkExample(document)).to.not.be.null;
97
- expect(selectRehypeExample(document)).to.not.be.null;
98
- expect(selectGfmLink(document)).to.not.be.null;
99
- });
100
-
101
- it('extends markdown config with extendPlugins: "markdown"', async () => {
102
- const fixture = await buildFixture({
103
- markdown: {
104
- remarkPlugins: [remarkExamplePlugin],
105
- rehypePlugins: [rehypeExamplePlugin],
106
- },
107
- integrations: [
108
- mdx({
109
- extendPlugins: 'markdown',
110
- remarkPlugins: [remarkToc],
111
- }),
112
- ],
96
+ for (const extendMarkdownConfig of [true, false]) {
97
+ describe(`extendMarkdownConfig = ${extendMarkdownConfig}`, () => {
98
+ let fixture;
99
+ before(async () => {
100
+ fixture = await buildFixture({
101
+ markdown: {
102
+ remarkPlugins: [remarkToc],
103
+ gfm: false,
104
+ smartypants: false,
105
+ },
106
+ integrations: [
107
+ mdx({
108
+ extendMarkdownConfig,
109
+ remarkPlugins: [remarkExamplePlugin],
110
+ rehypePlugins: [rehypeExamplePlugin],
111
+ }),
112
+ ],
113
+ });
114
+ });
115
+
116
+ it('Handles MDX plugins', async () => {
117
+ const html = await fixture.readFile(FILE);
118
+ const { document } = parseHTML(html);
119
+
120
+ expect(selectRemarkExample(document, 'MDX remark plugins not applied.')).to.not.be.null;
121
+ expect(selectRehypeExample(document, 'MDX rehype plugins not applied.')).to.not.be.null;
122
+ });
123
+
124
+ it('Handles Markdown plugins', async () => {
125
+ const html = await fixture.readFile(FILE);
126
+ const { document } = parseHTML(html);
127
+
128
+ expect(
129
+ selectTocLink(
130
+ document,
131
+ '`remarkToc` plugin applied unexpectedly. Should override Markdown config.'
132
+ )
133
+ ).to.be.null;
134
+ });
135
+
136
+ it('Handles gfm', async () => {
137
+ const html = await fixture.readFile(FILE);
138
+ const { document } = parseHTML(html);
139
+
140
+ if (extendMarkdownConfig === true) {
141
+ expect(selectGfmLink(document), 'Does not respect `markdown.gfm` option.').to.be.null;
142
+ } else {
143
+ expect(selectGfmLink(document), 'Respects `markdown.gfm` unexpectedly.').to.not.be.null;
144
+ }
145
+ });
146
+
147
+ it('Handles smartypants', async () => {
148
+ const html = await fixture.readFile(FILE);
149
+ const { document } = parseHTML(html);
150
+
151
+ const quote = selectSmartypantsQuote(document);
152
+
153
+ if (extendMarkdownConfig === true) {
154
+ expect(quote.textContent, 'Does not respect `markdown.smartypants` option.').to.contain(
155
+ '"Smartypants" is -- awesome'
156
+ );
157
+ } else {
158
+ expect(quote.textContent, 'Respects `markdown.smartypants` unexpectedly.').to.contain(
159
+ '“Smartypants” is — awesome'
160
+ );
161
+ }
162
+ });
113
163
  });
114
-
115
- const html = await fixture.readFile(FILE);
116
- const { document } = parseHTML(html);
117
-
118
- expect(selectRemarkExample(document)).to.not.be.null;
119
- expect(selectRehypeExample(document)).to.not.be.null;
120
- expect(selectTocLink(document)).to.not.be.null;
121
- });
122
-
123
- it('extends default plugins with extendPlugins: "astroDefaults"', async () => {
124
- const fixture = await buildFixture({
125
- markdown: {
126
- // should NOT be applied to MDX
127
- remarkPlugins: [remarkToc],
128
- },
129
- integrations: [
130
- mdx({
131
- remarkPlugins: [remarkExamplePlugin],
132
- rehypePlugins: [rehypeExamplePlugin],
133
- extendPlugins: 'astroDefaults',
134
- }),
135
- ],
136
- });
137
-
138
- const html = await fixture.readFile(FILE);
139
- const { document } = parseHTML(html);
140
-
141
- expect(selectGfmLink(document)).to.not.be.null;
142
- // remark and rehype plugins still respected
143
- expect(selectRemarkExample(document)).to.not.be.null;
144
- expect(selectRehypeExample(document)).to.not.be.null;
145
- // Does NOT inherit TOC from markdown config
146
- expect(selectTocLink(document)).to.be.null;
147
- });
148
-
149
- it('does not extend default plugins with extendPlugins: false', async () => {
150
- const fixture = await buildFixture({
151
- markdown: {
152
- remarkPlugins: [remarkExamplePlugin],
153
- },
154
- integrations: [
155
- mdx({
156
- remarkPlugins: [],
157
- extendPlugins: false,
158
- }),
159
- ],
160
- });
161
-
162
- const html = await fixture.readFile(FILE);
163
- const { document } = parseHTML(html);
164
-
165
- expect(selectGfmLink(document)).to.be.null;
166
- expect(selectRemarkExample(document)).to.be.null;
167
- });
164
+ }
168
165
 
169
166
  it('supports custom recma plugins', async () => {
170
167
  const fixture = await buildFixture({
@@ -236,6 +233,10 @@ function selectGfmLink(document) {
236
233
  return document.querySelector('a[href="https://handle-me-gfm.com"]');
237
234
  }
238
235
 
236
+ function selectSmartypantsQuote(document) {
237
+ return document.querySelector('blockquote');
238
+ }
239
+
239
240
  function selectRemarkExample(document) {
240
241
  return document.querySelector('div[data-remark-plugin-works]');
241
242
  }
@@ -67,6 +67,32 @@ describe('MDX syntax highlighting', () => {
67
67
  const prismCodeBlock = document.querySelector('pre.language-astro');
68
68
  expect(prismCodeBlock).to.not.be.null;
69
69
  });
70
+
71
+ for (const extendMarkdownConfig of [true, false]) {
72
+ it(`respects syntaxHighlight when extendMarkdownConfig = ${extendMarkdownConfig}`, async () => {
73
+ const fixture = await loadFixture({
74
+ root: FIXTURE_ROOT,
75
+ markdown: {
76
+ syntaxHighlight: 'shiki',
77
+ },
78
+ integrations: [
79
+ mdx({
80
+ extendMarkdownConfig,
81
+ syntaxHighlight: 'prism',
82
+ }),
83
+ ],
84
+ });
85
+ await fixture.build();
86
+
87
+ const html = await fixture.readFile('/index.html');
88
+ const { document } = parseHTML(html);
89
+
90
+ const shikiCodeBlock = document.querySelector('pre.astro-code');
91
+ expect(shikiCodeBlock, 'Markdown config syntaxHighlight used unexpectedly').to.be.null;
92
+ const prismCodeBlock = document.querySelector('pre.language-astro');
93
+ expect(prismCodeBlock).to.not.be.null;
94
+ });
95
+ }
70
96
  });
71
97
 
72
98
  it('supports custom highlighter - shiki-twoslash', async () => {
@@ -1,7 +0,0 @@
1
- ---
2
- title: 'Overridden title'
3
- injectedReadingTime:
4
- text: '1000 min read'
5
- ---
6
-
7
- # Working!