Skip to content

Commit 7871ff5

Browse files
committed
Refactor Sätteri plugin support: replace mdast plugin with hast plugin for #end-of-markdown insertion
1 parent 5d768a7 commit 7871ff5

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

.changeset/afraid-toes-fetch.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'astro-vtbot': minor
3+
---
4+
5+
Fixes support for insertion of the #end-of-markdown id for Sätteri builds.
6+
7+
Contrary to my previous assumption, the structure of Sätteri `mdast` plugins differs much from that of `remark` plugins. So I had to replace the `mdast` plugin with a `hast` plugin. See the [ documentation](https://events-3bg.pages.dev/library/StarlightPlugin/#for-sätteri-starlight-041) on how to use it.

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ The bag of tricks provides extensions & support around Astro's view transitions.
1313

1414
A current deployment of tech demos and the documentation can be found at https://events-3bg.pages.dev/
1515

16-
**Do not be put off by the major version bump!** The bump is a SemVer formality, but the chances of encountering the breaking change are very low. See below.
1716

1817
## !!! NEW TRICKS ✨ IN THE BAG 👜 !!!
1918

20-
> If you use the Starlight with Sätteri, you can use `remarkEndOfMarkdown` [as an mdastPlugin](https://events-3bg.pages.dev/library/StarlightPlugin/#for-s%C3%A4tteri-starlight-041). If you prefer a more _mdasty_ name for the plugin: it is now also exported as `mdastEndOfMarkdown`.
19+
> I had to rework the insertion of the `#end-of-markdown` marker used by the automatic `<link rel="expect" ...>` insertion for Sätteri.
20+
>
21+
> I'm sorry that the `mdast` approach did not work. `mdastEndOfMarkdown` isn't supported any more. If you tripped over this, hit me up on Astro's discord.
22+
>
23+
> If you run Starlight with Sätteri, you now have to use `hastMarkEndOfMarkdown` [as a hastPlugin](https://events-3bg.pages.dev/library/StarlightPlugin/#for-s%C3%A4tteri-starlight-041).
24+
2125

2226
## Recently Learned Tricks ##
2327

24-
> This release adds compatibility with Astro v7 while maintaining compatibility with earlier versions of Astro. The only breaking change is the removal of the `CreateAnimationScope.astro` component, which was never officially documented and was rarely, if ever, used. If you were using it, please get in touch on Discord (@martrapp) or Bluesky (@martr.app) and we will find a solution.
28+
> The 3.0.0 release adds compatibility with Astro v7 while maintaining compatibility with earlier versions of Astro. The only breaking change is the removal of the `CreateAnimationScope.astro` component, which was never officially documented and was rarely, if ever, used. If you were using it, please get in touch on Discord (@martrapp) or Bluesky (@martr.app) and we will find a solution.
2529
2630

2731
> Updated dependencies. Especially bumps @vtbag/utensil-drawer to current 1.2.13, where the `declarative-names` script now supports a special `:in-viewport` pseudo-class and `mayStartViewTransition()` supports scoped view transitions, if the browser does. For details see https://vtbag.dev/tools/utensil-drawer/

integration/starlight-view-transitions.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { HookParameters, StarlightPlugin } from '@astrojs/starlight/types';
2+
import { defineHastPlugin } from 'satteri';
23
import { resolve } from 'node:path';
34
import { fileURLToPath } from 'node:url';
45
import vtbot from 'astro-vtbot';
@@ -45,7 +46,30 @@ export function remarkEndOfMarkdown(id = 'end-of-markdown') {
4546
};
4647
}
4748

48-
export const mdastEndOfMarkdown = remarkEndOfMarkdown;
49+
export function hastMarkEndOfMarkdown(id = 'end-of-markdown') {
50+
const seen = new WeakSet();
51+
return defineHastPlugin({
52+
name: 'mark-end-of-markdown',
53+
element: {
54+
filter: ['p'],
55+
visit(node, ctx) {
56+
const parent = ctx.parent(node);
57+
if (parent?.type === 'root') {
58+
if (!seen.has(parent)) {
59+
seen.add(parent);
60+
process.env.vtbotEndOfContentId = id;
61+
ctx.appendChild(parent, {
62+
type: 'element',
63+
tagName: 'a',
64+
properties: { id },
65+
children: [],
66+
});
67+
}
68+
}
69+
}
70+
}
71+
});
72+
}
4973

5074
function set(property: string, value: any) {
5175
if (value === undefined) delete process.env[property];

0 commit comments

Comments
 (0)