-
-
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.
* wip: serverside render dynamic Markdown content * docs: update Markdown.astro comments * Use existing markdown infrastructure to render external MD * Update Markdown docs * Add a changeset Co-authored-by: Matthew Phillips <matthew@skypack.dev>
- Loading branch information
1 parent
d2330a5
commit ffb6380
Showing
11 changed files
with
93 additions
and
7 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,5 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Support for dynamic Markdown through the content attribute. |
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,6 @@ | ||
--- | ||
import Markdown from 'astro/components/Markdown.astro'; | ||
const content = await fetch('https://raw.githubusercontent.com/snowpackjs/snowpack/main/README.md').then(res => res.text()); | ||
--- | ||
|
||
<Markdown content={content} /> |
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 |
---|---|---|
@@ -1,3 +1,24 @@ | ||
<!-- Probably not what you're looking for! --> | ||
<!-- Check `astro-parser` or /frontend/markdown.ts --> | ||
<slot /> | ||
--- | ||
import { renderMarkdown } from 'astro/dist/frontend/markdown.js'; | ||
export let content: string; | ||
export let $scope: string; | ||
let html = null; | ||
// This flow is only triggered if a user passes `<Markdown content={content} />` | ||
if (content) { | ||
const { content: htmlContent } = await renderMarkdown(content, { | ||
mode: 'md', | ||
$: { | ||
scopedClassName: $scope | ||
} | ||
}); | ||
html = htmlContent; | ||
} | ||
/* | ||
If we have rendered `html` for `content`, render that | ||
Otherwise, just render the slotted content | ||
*/ | ||
--- | ||
{html ? html : <slot />} |
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
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 @@ | ||
export { renderMarkdown } from '../compiler/utils'; |
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
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/astro-markdown/src/pages/external.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,15 @@ | ||
--- | ||
import Markdown from 'astro/components/Markdown.astro'; | ||
import Hello from '../components/Hello.jsx'; | ||
const outer = `# Outer`; | ||
const inner = `## Inner`; | ||
--- | ||
|
||
<Markdown content={outer} /> | ||
|
||
<Markdown> | ||
# Nested | ||
|
||
<Markdown content={inner} /> | ||
</Markdown> |