@astrojs/starlight 0.41.6 → 0.41.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/integrations/satteri.ts +41 -47
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.41.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4114](https://github.com/withastro/starlight/pull/4114) [`3e486fb`](https://github.com/withastro/starlight/commit/3e486fba2015589c55aa452746eb17b407a4716e) Thanks [@delucis](https://github.com/delucis)! - Fixes processing of code examples in RTL languages when using Astro’s Sätteri Markdown processor
|
|
8
|
+
|
|
3
9
|
## 0.41.6
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/integrations/satteri.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
2
|
import { satteriHeadingIdsPlugin } from '@astrojs/markdown-satteri';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Parents, Properties } from 'hast';
|
|
4
4
|
import type { Paragraph } from 'mdast';
|
|
5
5
|
import { directiveToMarkdown } from 'mdast-util-directive';
|
|
6
6
|
import { toMarkdown } from 'mdast-util-to-markdown';
|
|
7
7
|
import type {
|
|
8
8
|
HastPluginDefinition,
|
|
9
9
|
HastPluginInput,
|
|
10
|
+
HastVisitorContext,
|
|
10
11
|
MdastPluginInput,
|
|
11
12
|
MdastPluginDefinition,
|
|
12
13
|
} from 'satteri';
|
|
@@ -136,59 +137,52 @@ function serializeDirective(node: Parameters<typeof toMarkdown>[0]): string {
|
|
|
136
137
|
return md.at(-1) === '\n' ? md.slice(0, -1) : md;
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
function satteriRtlCodeSupportPlugin(allowedPaths: string[]):
|
|
140
|
-
return
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
element: [
|
|
150
|
-
{
|
|
151
|
-
filter: ['pre'],
|
|
152
|
-
visit(node, ctx) {
|
|
153
|
-
if (!shouldTransformPath(ctx.fileURL, allowedPaths)) return;
|
|
154
|
-
const span = nodeSpan(node);
|
|
155
|
-
if (span) preSpans.push(span);
|
|
156
|
-
if (node.properties && 'dir' in node.properties) return;
|
|
157
|
-
ctx.setProperty(node, 'dir', 'ltr');
|
|
158
|
-
},
|
|
140
|
+
function satteriRtlCodeSupportPlugin(allowedPaths: string[]): HastPluginDefinition {
|
|
141
|
+
return {
|
|
142
|
+
name: 'starlight-rtl-code-support',
|
|
143
|
+
element: [
|
|
144
|
+
{
|
|
145
|
+
filter: ['pre'],
|
|
146
|
+
visit(node, ctx) {
|
|
147
|
+
if (!shouldTransformPath(ctx.fileURL, allowedPaths)) return;
|
|
148
|
+
if (node.properties && 'dir' in node.properties) return;
|
|
149
|
+
ctx.setProperty(node, 'dir', 'ltr');
|
|
159
150
|
},
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
filter: ['code'],
|
|
154
|
+
visit(node, ctx) {
|
|
155
|
+
if (
|
|
156
|
+
shouldTransformPath(ctx.fileURL, allowedPaths) &&
|
|
157
|
+
!(node.properties && 'dir' in node.properties) &&
|
|
158
|
+
!hasPreParent(node, ctx)
|
|
159
|
+
) {
|
|
166
160
|
ctx.setProperty(node, 'dir', 'auto');
|
|
167
|
-
}
|
|
161
|
+
}
|
|
168
162
|
},
|
|
169
|
-
],
|
|
170
|
-
// Shiki runs ahead of us and replaces the highlighted `<pre>` element with a raw HTML
|
|
171
|
-
// node, so the `pre` element visitor above never sees it. Patch the raw markup instead.
|
|
172
|
-
raw(node, ctx) {
|
|
173
|
-
if (!shouldTransformPath(ctx.fileURL, allowedPaths)) return undefined;
|
|
174
|
-
const value = ltrRawPre(node.value);
|
|
175
|
-
if (value === null) return undefined;
|
|
176
|
-
return { type: 'raw', value };
|
|
177
163
|
},
|
|
178
|
-
|
|
164
|
+
],
|
|
165
|
+
// Shiki runs ahead of us and replaces the highlighted `<pre>` element with a raw HTML
|
|
166
|
+
// node, so the `pre` element visitor above never sees it. Patch the raw markup instead.
|
|
167
|
+
raw(node, ctx) {
|
|
168
|
+
if (!shouldTransformPath(ctx.fileURL, allowedPaths)) return undefined;
|
|
169
|
+
const value = ltrRawPre(node.value);
|
|
170
|
+
if (value === null) return undefined;
|
|
171
|
+
return { type: 'raw', value };
|
|
172
|
+
},
|
|
179
173
|
};
|
|
180
174
|
}
|
|
181
175
|
|
|
182
|
-
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return
|
|
176
|
+
/**
|
|
177
|
+
* Check if any parent of `child` is a `<pre>` element by walking up the tree.
|
|
178
|
+
*/
|
|
179
|
+
function hasPreParent(child: Readonly<Parents> | undefined, ctx: HastVisitorContext): boolean {
|
|
180
|
+
while (child) {
|
|
181
|
+
const parent: Readonly<Parents> | undefined = ctx.parent(child);
|
|
182
|
+
if (parent?.type === 'element' && parent.tagName === 'pre') return true;
|
|
183
|
+
child = parent;
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
192
186
|
}
|
|
193
187
|
|
|
194
188
|
const rawPreOpenTag = /<pre(?=[\s>])[^>]*>/;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/starlight",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.7",
|
|
4
4
|
"description": "Build beautiful, high-performance documentation websites with Astro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -51,18 +51,18 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@astrojs/markdown-remark": "^7.2.
|
|
54
|
+
"@astrojs/markdown-remark": "^7.2.2",
|
|
55
55
|
"@playwright/test": "^1.61.1",
|
|
56
56
|
"@types/node": "^22.19.17",
|
|
57
57
|
"@vitest/coverage-v8": "^4.1.5",
|
|
58
|
-
"astro": "^7.
|
|
58
|
+
"astro": "^7.1.6",
|
|
59
59
|
"linkedom": "^0.18.12",
|
|
60
60
|
"vitest": "^4.1.5"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@astrojs/markdown-satteri": "^0.3.
|
|
64
|
-
"@astrojs/mdx": "^7.0.
|
|
65
|
-
"@astrojs/sitemap": "^3.7.
|
|
63
|
+
"@astrojs/markdown-satteri": "^0.3.5",
|
|
64
|
+
"@astrojs/mdx": "^7.0.5",
|
|
65
|
+
"@astrojs/sitemap": "^3.7.3",
|
|
66
66
|
"@pagefind/default-ui": "^1.3.0",
|
|
67
67
|
"@types/hast": "^3.0.4",
|
|
68
68
|
"@types/js-yaml": "^4.0.9",
|