summaryrefslogtreecommitdiff
path: root/packages/markdown
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2023-01-11 12:51:31 -0500
committerGravatar GitHub <noreply@github.com> 2023-01-11 12:51:31 -0500
commit52209ca2ad72a30854947dcb3a90ab4db0ac0a6f (patch)
tree707b90eee0464eedfa2dbc10d01500c73d6661c7 /packages/markdown
parent665a2c2225e42881f5a9550599e8f3fc1deea0b4 (diff)
downloadastro-52209ca2ad72a30854947dcb3a90ab4db0ac0a6f.tar.gz
astro-52209ca2ad72a30854947dcb3a90ab4db0ac0a6f.tar.zst
astro-52209ca2ad72a30854947dcb3a90ab4db0ac0a6f.zip
[Content collections] Remove experimental flag (#5825)
* refactor: remove experimental.cc from core * chore: remove experimental flag from tests * fix: mock contentDir in remark tests * fix: check vfile.path in rel-image-error plugin * fix: move .astro/ excludes to all test/fixtures * fix: include test/**/fixtures in ignore * chore: changeset
Diffstat (limited to 'packages/markdown')
-rw-r--r--packages/markdown/remark/src/index.ts5
-rw-r--r--packages/markdown/remark/src/remark-content-rel-image-error.ts2
-rw-r--r--packages/markdown/remark/src/types.ts2
-rw-r--r--packages/markdown/remark/test/autolinking.test.js13
-rw-r--r--packages/markdown/remark/test/entities.test.js6
-rw-r--r--packages/markdown/remark/test/plugins.test.js2
-rw-r--r--packages/markdown/remark/test/test-utils.js3
7 files changed, 23 insertions, 10 deletions
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index 91680f3fd..fdd669280 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -53,7 +53,6 @@ export async function renderMarkdown(
remarkRehype = markdownConfigDefaults.remarkRehype,
gfm = markdownConfigDefaults.gfm,
smartypants = markdownConfigDefaults.smartypants,
- isExperimentalContentCollections = false,
contentDir,
frontmatter: userFrontmatter = {},
} = opts;
@@ -91,9 +90,7 @@ export async function renderMarkdown(
}
// Apply later in case user plugins resolve relative image paths
- if (isExperimentalContentCollections) {
- parser.use([toRemarkContentRelImageError({ contentDir })]);
- }
+ parser.use([toRemarkContentRelImageError({ contentDir })]);
parser.use([
[
diff --git a/packages/markdown/remark/src/remark-content-rel-image-error.ts b/packages/markdown/remark/src/remark-content-rel-image-error.ts
index 1a0870c22..3e3664b20 100644
--- a/packages/markdown/remark/src/remark-content-rel-image-error.ts
+++ b/packages/markdown/remark/src/remark-content-rel-image-error.ts
@@ -10,6 +10,8 @@ import type { VFile } from 'vfile';
export default function toRemarkContentRelImageError({ contentDir }: { contentDir: URL }) {
return function remarkContentRelImageError() {
return (tree: any, vfile: VFile) => {
+ if (typeof vfile?.path !== 'string') return;
+
const isContentFile = pathToFileURL(vfile.path).href.startsWith(contentDir.href);
if (!isContentFile) return;
diff --git a/packages/markdown/remark/src/types.ts b/packages/markdown/remark/src/types.ts
index 40b2ac841..ff3060704 100644
--- a/packages/markdown/remark/src/types.ts
+++ b/packages/markdown/remark/src/types.ts
@@ -59,8 +59,6 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
scopedClassName: string | null;
};
/** Used to prevent relative image imports from `src/content/` */
- isExperimentalContentCollections?: boolean;
- /** Used to prevent relative image imports from `src/content/` */
contentDir: URL;
/** Used for frontmatter injection plugins */
frontmatter?: Record<string, any>;
diff --git a/packages/markdown/remark/test/autolinking.test.js b/packages/markdown/remark/test/autolinking.test.js
index 48bf894be..b1e567bb4 100644
--- a/packages/markdown/remark/test/autolinking.test.js
+++ b/packages/markdown/remark/test/autolinking.test.js
@@ -1,10 +1,14 @@
import { renderMarkdown } from '../dist/index.js';
import chai from 'chai';
+import { mockRenderMarkdownParams } from './test-utils.js';
describe('autolinking', () => {
describe('plain md', () => {
it('autolinks URLs starting with a protocol in plain text', async () => {
- const { code } = await renderMarkdown(`See https://example.com for more.`, {});
+ const { code } = await renderMarkdown(
+ `See https://example.com for more.`,
+ mockRenderMarkdownParams
+ );
chai
.expect(code.replace(/\n/g, ''))
@@ -12,7 +16,10 @@ describe('autolinking', () => {
});
it('autolinks URLs starting with "www." in plain text', async () => {
- const { code } = await renderMarkdown(`See www.example.com for more.`, {});
+ const { code } = await renderMarkdown(
+ `See www.example.com for more.`,
+ mockRenderMarkdownParams
+ );
chai
.expect(code.trim())
@@ -22,7 +29,7 @@ describe('autolinking', () => {
it('does not autolink URLs in code blocks', async () => {
const { code } = await renderMarkdown(
'See `https://example.com` or `www.example.com` for more.',
- {}
+ mockRenderMarkdownParams
);
chai
diff --git a/packages/markdown/remark/test/entities.test.js b/packages/markdown/remark/test/entities.test.js
index d35ed3a89..acaf71be1 100644
--- a/packages/markdown/remark/test/entities.test.js
+++ b/packages/markdown/remark/test/entities.test.js
@@ -1,9 +1,13 @@
import { renderMarkdown } from '../dist/index.js';
import { expect } from 'chai';
+import { mockRenderMarkdownParams } from './test-utils.js';
describe('entities', () => {
it('should not unescape entities in regular Markdown', async () => {
- const { code } = await renderMarkdown(`&lt;i&gt;This should NOT be italic&lt;/i&gt;`, {});
+ const { code } = await renderMarkdown(
+ `&lt;i&gt;This should NOT be italic&lt;/i&gt;`,
+ mockRenderMarkdownParams
+ );
expect(code).to.equal(`<p>&#x3C;i>This should NOT be italic&#x3C;/i></p>`);
});
diff --git a/packages/markdown/remark/test/plugins.test.js b/packages/markdown/remark/test/plugins.test.js
index a1abeb2ed..35e5dcaf8 100644
--- a/packages/markdown/remark/test/plugins.test.js
+++ b/packages/markdown/remark/test/plugins.test.js
@@ -1,4 +1,5 @@
import { renderMarkdown } from '../dist/index.js';
+import { mockRenderMarkdownParams } from './test-utils.js';
import chai from 'chai';
import { fileURLToPath } from 'node:url';
@@ -8,6 +9,7 @@ describe('plugins', () => {
it('should be able to get file path when passing fileURL', async () => {
let context;
await renderMarkdown(`test`, {
+ ...mockRenderMarkdownParams,
fileURL: new URL('virtual.md', import.meta.url),
remarkPlugins: [
function () {
diff --git a/packages/markdown/remark/test/test-utils.js b/packages/markdown/remark/test/test-utils.js
new file mode 100644
index 000000000..10b779a7d
--- /dev/null
+++ b/packages/markdown/remark/test/test-utils.js
@@ -0,0 +1,3 @@
+export const mockRenderMarkdownParams = {
+ contentDir: new URL('file:///src/content/'),
+};