-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Markdown + Components usage (#3410)
* feat: use internal MDX tooling for markdown + components * fix: improve MD + component tests * chore: add changeset * fix: make tsc happy * fix(#3319): add regression test for component children * fix(markdown): support HTML comments in markdown * fix(#2474): ensure namespaced components are properly handled in markdown pages * fix(#3220): ensure html in markdown pages does not have extra surrounding space * fix(#3264): ensure that remark files pass in file information * fix(#3254): enable experimentalStaticExtraction for `.md` pages * fix: revert parsing change * fix: remove `markdown.mode` option
- Loading branch information
1 parent
78e962f
commit cfae976
Showing
31 changed files
with
542 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'astro': patch | ||
'@astrojs/markdown-remark': minor | ||
--- | ||
|
||
Significantally more stable behavior for "Markdown + Components" usage, which now handles component serialization much more similarly to MDX. Also supports switching between Components and Markdown without extra newlines, removes wrapping `<p>` tags from standalone components, and improves JSX expression handling. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/astro/test/fixtures/astro-markdown/src/components/TextBlock.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { h } from 'preact'; | ||
|
||
const TextBlock = ({ | ||
title, | ||
children, | ||
noPadding = false, | ||
}) => { | ||
return ( | ||
<div | ||
className={`${ | ||
noPadding ? "" : "md:px-2 lg:px-4" | ||
} flex-1 prose prose-headings:font-grotesk`} | ||
> | ||
<h3>{title}</h3> | ||
<p>{children}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TextBlock; |
5 changes: 5 additions & 0 deletions
5
packages/astro/test/fixtures/astro-markdown/src/components/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Counter from './Counter'; | ||
|
||
export default { | ||
Counter | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/astro-markdown/src/content/code-element.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This should have `nospace` around it. | ||
|
||
This should have <code class="custom-class">nospace</code> around it. |
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/astro-markdown/src/pages/children.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
setup: import TextBlock from '../components/TextBlock' | ||
--- | ||
{/* https://github.com/withastro/astro/issues/3319 */} | ||
|
||
<TextBlock title="Hello world!" noPadding> | ||
<ul class="not-prose"> | ||
<li>A</li> | ||
<li>B</li> | ||
<li>C</li> | ||
</ul> | ||
</TextBlock> |
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/astro-markdown/src/pages/code-element.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
const content = await Astro.glob('../content/*.md'); | ||
--- | ||
|
||
<div> | ||
{content.map(({ Content }) => <Content />)} | ||
</div> |
2 changes: 2 additions & 0 deletions
2
packages/astro/test/fixtures/astro-markdown/src/pages/comment.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!-- HTML comments! --> | ||
# It works! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/astro-markdown/src/pages/namespace.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
setup: import ns from '../components/index.js'; | ||
--- | ||
|
||
# Hello Namespace! | ||
|
||
<ns.Counter>Click me!</ns.Counter> |
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/astro-markdown/src/pages/script.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Test | ||
|
||
## Let's try a script... | ||
|
||
This should work! | ||
|
||
<script src="/src/scripts/test.js" /> |
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/astro-markdown/src/pages/slug.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: My Blog Post | ||
--- | ||
|
||
# {frontmatter.title} | ||
|
||
Hello world |
1 change: 1 addition & 0 deletions
1
packages/astro/test/fixtures/astro-markdown/src/scripts/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hello world"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
mdxExpressionFromMarkdown, | ||
mdxExpressionToMarkdown | ||
} from 'mdast-util-mdx-expression' | ||
import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'mdast-util-mdx-jsx' | ||
|
||
export function mdxFromMarkdown(): any { | ||
return [mdxExpressionFromMarkdown, mdxJsxFromMarkdown] | ||
} | ||
|
||
export function mdxToMarkdown(): any { | ||
return { | ||
extensions: [ | ||
mdxExpressionToMarkdown, | ||
mdxJsxToMarkdown, | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.