Spaces:
Running
Running
thibaud frere
commited on
Commit
·
6fab523
1
Parent(s):
d35f5b3
update
Browse files
app/src/components/HtmlEmbed.astro
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
interface Props { src: string; title?: string; desc?: string; frameless?: boolean; align?: 'left' | 'center' | 'right' }
|
| 3 |
-
const { src, title, desc, frameless = false, align = 'left' } = Astro.props as Props;
|
| 4 |
|
| 5 |
// Load all .html embeds under src/content/embeds/** as strings (dev & build)
|
| 6 |
const embeds = (import.meta as any).glob('../content/embeds/**/*.html', { query: '?raw', import: 'default', eager: true }) as Record<string, string>;
|
|
@@ -20,7 +20,7 @@ const html = resolveFragment(src);
|
|
| 20 |
const mountId = `frag-${Math.random().toString(36).slice(2)}`;
|
| 21 |
---
|
| 22 |
{ html ? (
|
| 23 |
-
<figure class="html-embed">
|
| 24 |
{title && <figcaption class="html-embed__title" style={`text-align:${align}`}>{title}</figcaption>}
|
| 25 |
<div class={`html-embed__card${frameless ? ' is-frameless' : ''}`}>
|
| 26 |
<div id={mountId} set:html={html} />
|
|
|
|
| 1 |
---
|
| 2 |
+
interface Props { src: string; title?: string; desc?: string; frameless?: boolean; align?: 'left' | 'center' | 'right'; id?: string }
|
| 3 |
+
const { src, title, desc, frameless = false, align = 'left', id } = Astro.props as Props;
|
| 4 |
|
| 5 |
// Load all .html embeds under src/content/embeds/** as strings (dev & build)
|
| 6 |
const embeds = (import.meta as any).glob('../content/embeds/**/*.html', { query: '?raw', import: 'default', eager: true }) as Record<string, string>;
|
|
|
|
| 20 |
const mountId = `frag-${Math.random().toString(36).slice(2)}`;
|
| 21 |
---
|
| 22 |
{ html ? (
|
| 23 |
+
<figure class="html-embed" id={id}>
|
| 24 |
{title && <figcaption class="html-embed__title" style={`text-align:${align}`}>{title}</figcaption>}
|
| 25 |
<div class={`html-embed__card${frameless ? ' is-frameless' : ''}`}>
|
| 26 |
<div id={mountId} set:html={html} />
|
app/src/content/chapters/components.mdx
CHANGED
|
@@ -224,6 +224,7 @@ For researchers who want to stay in **Python** while targeting **D3**, the [d3bl
|
|
| 224 |
| `desc` | No | Short description displayed below the card. Supports inline HTML (e.g., links).
|
| 225 |
| `frameless` | No | Removes the card background and border for seamless embeds.
|
| 226 |
| `align` | No | Aligns the title/description text. One of `left` (default), `center`, `right`.
|
|
|
|
| 227 |
|
| 228 |
<Accordion title="Code example">
|
| 229 |
```mdx
|
|
@@ -231,6 +232,7 @@ import HtmlEmbed from '../components/HtmlEmbed.astro'
|
|
| 231 |
|
| 232 |
<HtmlEmbed src="plotly-line.html" title="Plotly Line" desc="Some chart description" />
|
| 233 |
<HtmlEmbed src="d3-line-example.html" title="D3 Line" desc="Some chart description" />
|
|
|
|
| 234 |
```
|
| 235 |
</Accordion>
|
| 236 |
|
|
|
|
| 224 |
| `desc` | No | Short description displayed below the card. Supports inline HTML (e.g., links).
|
| 225 |
| `frameless` | No | Removes the card background and border for seamless embeds.
|
| 226 |
| `align` | No | Aligns the title/description text. One of `left` (default), `center`, `right`.
|
| 227 |
+
| `id` | No | Adds an `id` to the outer figure for deep-linking and cross-references.
|
| 228 |
|
| 229 |
<Accordion title="Code example">
|
| 230 |
```mdx
|
|
|
|
| 232 |
|
| 233 |
<HtmlEmbed src="plotly-line.html" title="Plotly Line" desc="Some chart description" />
|
| 234 |
<HtmlEmbed src="d3-line-example.html" title="D3 Line" desc="Some chart description" />
|
| 235 |
+
<HtmlEmbed src="d3-line-example.html" id="real-world-examples" title="D3 Line (with id)" desc="Linkable example via #real-world-examples" />
|
| 236 |
```
|
| 237 |
</Accordion>
|
| 238 |
|