Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/starlight-codeblocks/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Split diff: a **Unified** and **Split** switch in the title bar of each block that removes and adds lines. **Split** shows the old code on the left and the new code on the right, as a GitHub pull request does. `splitDiff.view`, `splitDiff.switch` and `splitDiff.sync` set the start view, remove the switch and stop it syncing across the page (#37)
- Untitled blocks with title bar controls use the tab bar colours of titled blocks (#37)
- Skipped code: `[!code skip]` on its own line shows a marker in place of code that a block leaves out, at the indentation of its line. The text after the directive goes in the marker, else it reads "Code not shown". The line keeps its line number, and copies as a comment with the text, such as `// Not shown: Imports`. A comment that holds only `...`, such as `// ...`, and `...` alone on a line in JSON, also show as markers and copy as written. `skippedCode.commentAliases` and `skippedCode.bareAliases` change these aliases for each language. `skippedCode: false` turns the feature off (#28)
- API links: a starlight-pydocs registry left over from an `astro dev` restart that removed starlight-pydocs from the config is dropped, so Python names no longer link to its old pages

## 1.4.1

Expand Down
7 changes: 7 additions & 0 deletions packages/starlight-codeblocks/src/adapters/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export interface PydocsSymbol {

const PYDOCS = Symbol.for('starlight-pydocs');

/** Drops the starlight-pydocs registry when the config has no starlight-pydocs: as a global, it outlives a dev restart. */
export function dropStalePydocsRegistry(integrations: readonly { name: string }[]) {
if (!integrations.some((integration) => integration.name === 'starlight-pydocs')) {
delete (globalThis as { [PYDOCS]?: PydocsRegistry })[PYDOCS];
}
}

const pydocsRegistry = () => {
const registry = (globalThis as { [PYDOCS]?: PydocsRegistry })[PYDOCS];
return registry?.version === 1 ? registry : undefined;
Expand Down
2 changes: 2 additions & 0 deletions packages/starlight-codeblocks/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ExpressiveCodePlugin } from '@expressive-code/core';
import type { AstroIntegration } from 'astro';
import { AstroError } from 'astro/errors';
import type { MdastPluginEntry } from 'satteri';
import { dropStalePydocsRegistry } from './adapters/python.ts';
import { apiCardPageStyles, CARD_CSS_ID } from './api-card-page.ts';
import { readClientModules } from './client-modules.ts';
import { PLUGIN_PREFIX } from './expressive-code/core.ts';
Expand Down Expand Up @@ -59,6 +60,7 @@ export function codeblocksIntegration({
options?: { mdastPlugins?: unknown[]; remarkPlugins?: unknown[]; starlightCodeblocks?: string };
}
| undefined;
dropStalePydocsRegistry(config.integrations);
const registry = getRegistry();
if (registry?.cacheDir) registry.readFiles = loadReadFiles(registry.cacheDir);
const unified = processor?.name === 'unified';
Expand Down
11 changes: 10 additions & 1 deletion packages/starlight-codeblocks/test/python-adapter.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from 'node:fs';
import { deflateSync } from 'node:zlib';
import { afterEach, expect, test, vi } from 'vitest';
import { type PydocsRegistry, type PydocsSymbol, python } from '../src/adapters/python.ts';
import { dropStalePydocsRegistry, type PydocsRegistry, type PydocsSymbol, python } from '../src/adapters/python.ts';
import { readInventory } from '../src/adapters/python-index.ts';
import { type CodeblocksOptions, resolveOptions } from '../src/options.ts';
import { setRegistry } from '../src/registry.ts';
Expand Down Expand Up @@ -179,6 +179,15 @@ const myproject = () =>
],
]);

test('drops a starlight-pydocs registry left by a config that no longer has starlight-pydocs', () => {
const registry: PydocsRegistry = { version: 1, packages: [] };
pydocs(registry);
dropStalePydocsRegistry([{ name: 'starlight-pydocs' }]);
expect((globalThis as { [PYDOCS]?: PydocsRegistry })[PYDOCS]).toBe(registry);
dropStalePydocsRegistry([{ name: 'starlight-codeblocks' }]);
expect((globalThis as { [PYDOCS]?: PydocsRegistry })[PYDOCS]).toBeUndefined();
});

test('links the objects of a starlight-pydocs package through its registry, with the site base', async () => {
pydocs({ version: 1, packages: [{ name: 'myproject', base: 'api/myproject', symbols: myproject() }] });
setRegistry({ options: resolveOptions(), plugins: [], base: '/docs' });
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight-codeblocks/test/remark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const setup = (processor: Processor, options = {}) => {
p: unknown,
) => void;
hook({
config: { markdown: { processor }, base: '/', build: { assets: '_astro' } },
config: { markdown: { processor }, base: '/', build: { assets: '_astro' }, integrations: [] },
updateConfig() {},
injectScript() {},
logger: { warn() {} },
Expand Down
8 changes: 7 additions & 1 deletion packages/starlight-codeblocks/test/runnable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,13 @@ test('in astro dev, a change to a read file refreshes the content layer and relo
const noop = () => {};
await integration.hooks['astro:config:setup']?.({
command: 'dev',
config: { markdown: { processor }, build: { assets: '_astro' }, base: '/', root: new URL('file:///site/') },
config: {
markdown: { processor },
build: { assets: '_astro' },
base: '/',
root: new URL('file:///site/'),
integrations: [],
},
updateConfig: noop,
injectScript: noop,
logger: { warn: noop },
Expand Down
Loading