Skip to content

Commit d634a6e

Browse files
authored
feat: disclosure directive (#250)
1 parent da4e6af commit d634a6e

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

workspace/aubade/src/artisan/example.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ describe('libretto', ({ concurrent: it }) => {
778778
],
779779

780780
'directive#video': [
781-
'@video{src="./video.mp4" caption="local video"}',
781+
'@video{src=./video.mp4 caption="local video"}',
782782
[
783783
'<figure>',
784784
'<div data-aubade="video">',
@@ -792,26 +792,26 @@ describe('libretto', ({ concurrent: it }) => {
792792
].join('\n'),
793793
],
794794
'directive#video/disclosure': [
795-
'@video{disclosure src="./video.mp4" caption="local video"}',
795+
'@video{disclosure src=<http://127.0.0.1/video.mp4> caption="local video"}',
796796
[
797797
'<details>',
798798
'<summary>local video</summary>',
799799
'<div data-aubade="video">',
800800
'<video controls preload="metadata">',
801-
'<source src="./video.mp4" type="video/mp4" />',
801+
'<source src="http://127.0.0.1/video.mp4" type="video/mp4" />',
802802
'Your browser does not support HTML5 video.',
803803
'</video>',
804804
'</div>',
805805
'</details>',
806806
].join('\n'),
807807
],
808808
'directive#video/no-caption': [
809-
'@video{src="./video.mp4"}',
809+
'@video{src=[http://127.0.0.1/video.mp4]}',
810810
[
811811
'<figure>',
812812
'<div data-aubade="video">',
813813
'<video controls preload="metadata">',
814-
'<source src="./video.mp4" type="video/mp4" />',
814+
'<source src="http://127.0.0.1/video.mp4" type="video/mp4" />',
815815
'Your browser does not support HTML5 video.',
816816
'</video>',
817817
'</div>',

workspace/aubade/src/artisan/registry.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ export function directive({ cursor }: Context): null | {
130130
if (text[0] !== '"' && text[0] !== "'") return text;
131131
return last === text[0] ? text.slice(1, -1) : text;
132132
}
133-
134-
// 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 68 48"><path d="M66.52 7.74c-.78-2.93-2.49-5.41-5.42-6.19C55.79.13 34 0 34 0S12.21.13 6.9 1.55c-2.93.78-4.63 3.26-5.42 6.19C.06 13.05 0 24 0 24s.06 10.95 1.48 16.26c.78 2.93 2.49 5.41 5.42 6.19C12.21 47.87 34 48 34 48s21.79-.13 27.1-1.55c2.93-.78 4.64-3.26 5.42-6.19C67.94 34.95 68 24 68 24s-.06-10.95-1.48-16.26z" fill="red"/><path d="M45 24 27 14v20" fill="white"/></svg>'
135133
}
136134

137135
export function markup({ compose, cursor }: Context): null | {

workspace/aubade/src/artisan/resolver.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import type { Options } from './index.js';
22

33
export const base = {
4+
disclosure({ data, annotate, print }) {
5+
return print(
6+
`<details${data.open === 'true' ? ' open' : ''}>`,
7+
`<summary>${annotate(data.summary || 'more')}</summary>`,
8+
'<div data-aubade="disclosure">',
9+
annotate(data.body || ''),
10+
'</div>',
11+
'</details>',
12+
);
13+
},
414
youtube({ data, annotate, print, sanitize }) {
515
const id = sanitize(data.series || data.id || '');
616
const prefix = data.series ? 'videoseries?list=' : '';
@@ -25,15 +35,20 @@ export const base = {
2535
);
2636
},
2737
video({ data, annotate, print, sanitize }) {
28-
const src = sanitize(data.src || '');
38+
let source = data.src || '';
39+
const pairs: Record<string, string> = { '<': '>', '[': ']' };
40+
if (pairs[data.src[0]] === data.src[data.src.length - 1]) {
41+
source = data.src.slice(1, -1);
42+
}
43+
2944
const type = sanitize(data.type || 'video/mp4').toLowerCase();
3045
const text = annotate(data.caption || 'video');
3146
return print(
3247
data.disclosure ? '<details>' : '<figure>',
3348
data.disclosure && `<summary>${text}</summary>`,
3449
'<div data-aubade="video">',
3550
'<video controls preload="metadata">',
36-
`<source src="${src}" type="${type}" />`,
51+
`<source src="${sanitize(source)}" type="${type}" />`,
3752
sanitize(data.fallback || 'Your browser does not support HTML5 video.'),
3853
'</video>',
3954
'</div>',

workspace/content/libretto/+article.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ Directives extend Markdown with inline metadata. They begin with `@`, followed b
6464
- **Separation**: properties are separated by spaces or newlines.
6565
- **End**: the directive closes with `}`.
6666

67+
### `@disclosure`
68+
69+
| Attribute | Type | Description |
70+
| --------- | ------- | -------------------------------------- |
71+
| `summary` | string | Text for `<summary>` (default: "more") |
72+
| `body` | string | Content inside the disclosure |
73+
| `open` | boolean | If `true`, the disclosure is expanded |
74+
6775
### `@youtube`
6876

6977
| Attribute | Type | Description |

workspace/website/src/routes/content/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const DATA = {
2727
doc.tokens = doc.visit({
2828
'aubade:directive'(token) {
2929
if (token.meta.type !== 'video') return token;
30-
const { source } = token.meta.data;
31-
token.meta.data.source = materialize(source);
30+
const { src } = token.meta.data;
31+
token.meta.data.src = materialize(src);
3232
return token;
3333
},
3434
'block:image'(token) {

0 commit comments

Comments
 (0)