@textmode/docs 0.1.0

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.
Files changed (41) hide show
  1. package/README.md +132 -0
  2. package/index.d.ts +37 -0
  3. package/package.json +60 -0
  4. package/src/cli/textmode-docs.mjs +198 -0
  5. package/src/index.js +23 -0
  6. package/src/internal/config.js +380 -0
  7. package/src/internal/lib/api-doc-checks.mjs +147 -0
  8. package/src/internal/lib/api-doc-routes.mjs +93 -0
  9. package/src/internal/lib/example-checks.mjs +405 -0
  10. package/src/internal/lib/jsdoc-comments.mjs +78 -0
  11. package/src/internal/lib/reflection-policy.mjs +113 -0
  12. package/src/internal/lib/reporting.mjs +23 -0
  13. package/src/internal/operations.js +271 -0
  14. package/src/internal/reflection-kinds.js +21 -0
  15. package/src/internal/typedoc-plugins/accessor-docs-normalizer/README.md +45 -0
  16. package/src/internal/typedoc-plugins/accessor-docs-normalizer/accessor-comments.js +53 -0
  17. package/src/internal/typedoc-plugins/accessor-docs-normalizer/index.js +32 -0
  18. package/src/internal/typedoc-plugins/accessor-docs-normalizer/render-accessor.js +144 -0
  19. package/src/internal/typedoc-plugins/accessor-docs-normalizer/theme-patch.js +28 -0
  20. package/src/internal/typedoc-plugins/all-member-pages-router/README.md +57 -0
  21. package/src/internal/typedoc-plugins/all-member-pages-router/child-pages.js +65 -0
  22. package/src/internal/typedoc-plugins/all-member-pages-router/constants.js +58 -0
  23. package/src/internal/typedoc-plugins/all-member-pages-router/index.js +18 -0
  24. package/src/internal/typedoc-plugins/all-member-pages-router/member-paths.js +48 -0
  25. package/src/internal/typedoc-plugins/all-member-pages-router/member-reflections.js +164 -0
  26. package/src/internal/typedoc-plugins/all-member-pages-router/namespace-paths.js +44 -0
  27. package/src/internal/typedoc-plugins/all-member-pages-router/router.js +58 -0
  28. package/src/internal/typedoc-plugins/api-frontmatter/README.md +66 -0
  29. package/src/internal/typedoc-plugins/api-frontmatter/constants.js +52 -0
  30. package/src/internal/typedoc-plugins/api-frontmatter/descriptions.js +87 -0
  31. package/src/internal/typedoc-plugins/api-frontmatter/frontmatter.js +56 -0
  32. package/src/internal/typedoc-plugins/api-frontmatter/index.js +39 -0
  33. package/src/internal/typedoc-plugins/api-frontmatter/library-context.js +38 -0
  34. package/src/internal/typedoc-plugins/api-frontmatter/reflection-metadata.js +95 -0
  35. package/src/internal/typedoc-plugins/include-code-examples/README.md +40 -0
  36. package/src/internal/typedoc-plugins/include-code-examples/code-fences.js +55 -0
  37. package/src/internal/typedoc-plugins/include-code-examples/example-metadata.js +41 -0
  38. package/src/internal/typedoc-plugins/include-code-examples/index.js +23 -0
  39. package/src/internal/typedoc-plugins/include-code-examples/transform-markdown.js +33 -0
  40. package/src/internal/typedoc-plugins/strip-api-self-links/index.js +117 -0
  41. package/src/internal/typedoc-runner.js +138 -0
@@ -0,0 +1,271 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+
5
+ import { ReflectionKind } from 'typedoc';
6
+
7
+ import { collectApiDocIssues, countApiDocIssues, createApiLinkTargets } from './lib/api-doc-checks.mjs';
8
+ import { readMarkdownRoutes } from './lib/api-doc-routes.mjs';
9
+ import {
10
+ checkSketch,
11
+ getManifestExamples,
12
+ readExamplesIndex,
13
+ readExamplesManifest,
14
+ validateExamplesGallery,
15
+ validateExamplesManifest,
16
+ } from './lib/example-checks.mjs';
17
+ import { findJsdocBeforeLine, getLineStartOffsets, upsertSeeLine } from './lib/jsdoc-comments.mjs';
18
+ import {
19
+ getIncludedReflections,
20
+ shouldProcessEntryPointReflection,
21
+ sourceIsInRoots,
22
+ } from './lib/reflection-policy.mjs';
23
+ import { renderIssueSection, renderList } from './lib/reporting.mjs';
24
+ import { reflectionKindsMask, withAccessorKind } from './reflection-kinds.js';
25
+ import { buildDocs, loadEntryPointProject, watchDocs } from './typedoc-runner.js';
26
+
27
+ async function withTemporaryDocs(config, { strict = false } = {}, callback) {
28
+ const outputDir = fs.mkdtempSync(path.join(os.tmpdir(), 'textmode-docs-'));
29
+ try {
30
+ const result = await buildDocs(config, { outputDir, strict });
31
+ if (!result.ok) {
32
+ return { ok: false, reason: 'typedoc' };
33
+ }
34
+ return await callback({ outputDir });
35
+ } finally {
36
+ fs.rmSync(outputDir, { recursive: true, force: true });
37
+ }
38
+ }
39
+
40
+ function checkKinds(config, includeAccessors) {
41
+ const docstrings = includeAccessors ? withAccessorKind(config.checks.docstrings) : config.checks.docstrings;
42
+ const examples = includeAccessors ? withAccessorKind(config.checks.examples) : config.checks.examples;
43
+ return {
44
+ apiLinks: reflectionKindsMask(config.checks.apiLinks),
45
+ docstrings: reflectionKindsMask(docstrings),
46
+ examples: reflectionKindsMask(examples),
47
+ };
48
+ }
49
+
50
+ function exampleScopeLabel(targetKinds) {
51
+ return targetKinds & ReflectionKind.Accessor
52
+ ? 'exported functions, methods, and accessors'
53
+ : 'exported functions and methods';
54
+ }
55
+
56
+ async function loadPrimaryCheckProject(config) {
57
+ const primaryEntryPoint = config.linkEntryPoints[0] ?? {
58
+ path: config.entryPoints[0],
59
+ tsconfig: config.tsconfig,
60
+ };
61
+ return loadEntryPointProject({
62
+ entryPoint: primaryEntryPoint.path,
63
+ tsconfig: primaryEntryPoint.tsconfig,
64
+ packageName: config.packageName,
65
+ });
66
+ }
67
+
68
+ export async function apiCheck(config, routes, { includeAccessors = false } = {}) {
69
+ const project = await loadPrimaryCheckProject(config);
70
+ const kinds = checkKinds(config, includeAccessors);
71
+ const apiLinkReflections = getIncludedReflections(project, kinds.apiLinks);
72
+ const docstringReflections = getIncludedReflections(project, kinds.docstrings);
73
+ const exampleReflections = getIncludedReflections(project, kinds.examples);
74
+ const issues = collectApiDocIssues({
75
+ apiBaseUrl: config.apiBaseUrl,
76
+ apiLinkReflections,
77
+ docstringReflections,
78
+ exampleReflections,
79
+ routes,
80
+ });
81
+ const issueCount = countApiDocIssues(issues);
82
+ const entryPoint = path.relative(config.projectRoot, config.linkEntryPoints[0].path);
83
+ const scopeLabel = exampleScopeLabel(kinds.examples);
84
+
85
+ if (issueCount === 0) {
86
+ console.log('Public API documentation check passed.');
87
+ console.log(`Scanned ${docstringReflections.length} documented public API reflections from ${entryPoint}.`);
88
+ console.log('Policy: skip private/protected/inherited members and any API path segment starting with "_".');
89
+ console.log('Every included API item has a JSDoc docstring and a valid code.textmode.art API link.');
90
+ console.log(`Every included ${scopeLabel} has at least one @example tag.`);
91
+ if (!includeAccessors && !config.checks.examples.includes('accessor')) {
92
+ console.log('Accessors are excluded by default. Re-run with --include-accessors to check them too.');
93
+ }
94
+ return true;
95
+ }
96
+
97
+ console.error('Public API documentation check failed.');
98
+ console.error(`Scanned ${docstringReflections.length} documented public API reflections from ${entryPoint}.`);
99
+ console.error('Policy: skip private/protected/inherited members and any API path segment starting with "_".');
100
+ console.error(
101
+ `Found ${issueCount} issue(s): ${issues.missingDocstrings.length} missing docstring, ${issues.missingExamples.length} missing @example, ${issues.missingApiLinks.length} missing API link, ${issues.invalidApiLinks.length} invalid API link.`
102
+ );
103
+ if (!includeAccessors && !config.checks.examples.includes('accessor')) {
104
+ console.error('Accessors are excluded by default. Re-run with --include-accessors to check them too.');
105
+ }
106
+ renderIssueSection('Missing JSDoc docstring', issues.missingDocstrings, console.error);
107
+ renderIssueSection('Missing @example tag', issues.missingExamples, console.error);
108
+ renderIssueSection('Missing code.textmode.art API link', issues.missingApiLinks, console.error);
109
+ renderIssueSection('Invalid code.textmode.art API link', issues.invalidApiLinks, console.error);
110
+ return false;
111
+ }
112
+
113
+ export function examplesCheck(config) {
114
+ if (config.examples === false) {
115
+ console.log('Example checks are disabled for this package.');
116
+ return true;
117
+ }
118
+
119
+ console.log(`Checking ${config.packageName} example sketches...`);
120
+ const examplesIndex = path.join(config.projectRoot, 'examples/index.html');
121
+ const examplesManifest = path.join(config.projectRoot, 'examples/manifest.json');
122
+ const sourceDir = path.join(config.projectRoot, 'src');
123
+ const indexContent = readExamplesIndex(examplesIndex);
124
+ const manifest = readExamplesManifest(examplesManifest);
125
+ const galleryIssues = validateExamplesGallery(indexContent, {
126
+ examplesIndex: 'examples/index.html',
127
+ examplesManifest: 'examples/manifest.json',
128
+ forbidGallerySourceBase: config.examples.forbidGallerySourceBase,
129
+ });
130
+ const manifestIssues = validateExamplesManifest(manifest, {
131
+ projectRoot: config.projectRoot,
132
+ examplesDir: 'examples',
133
+ examplesManifest: 'examples/manifest.json',
134
+ sourceDir,
135
+ });
136
+ const validationIssues = [...galleryIssues, ...manifestIssues];
137
+ if (validationIssues.length > 0) {
138
+ renderList('Examples validation failed:', validationIssues);
139
+ return false;
140
+ }
141
+
142
+ const files = getManifestExamples(manifest).map((example) => example.sourceFile);
143
+ console.log(`Found ${files.length} manifest examples from examples/manifest.json.`);
144
+ if (!config.examples.checkSketches) {
145
+ console.log('Sketch convention checks are disabled for this package.');
146
+ return true;
147
+ }
148
+
149
+ let passedCount = 0;
150
+ let failedCount = 0;
151
+ let skippedCount = 0;
152
+ const failures = [];
153
+ for (const file of files) {
154
+ const { skipped, issues } = checkSketch(path.join(config.projectRoot, file));
155
+ if (skipped) {
156
+ skippedCount += 1;
157
+ } else if (issues.length === 0) {
158
+ passedCount += 1;
159
+ } else {
160
+ failedCount += 1;
161
+ failures.push({ file, issues });
162
+ }
163
+ }
164
+
165
+ console.log(`\nResults: ${passedCount} passed, ${failedCount} failed, ${skippedCount} skipped.\n`);
166
+ if (failures.length === 0) {
167
+ console.log('All checked sketches meet the requirements successfully.');
168
+ return true;
169
+ }
170
+
171
+ console.error('Validation failed for the following sketches:');
172
+ for (const failure of failures) {
173
+ console.error(`\n- ${failure.file}:`);
174
+ for (const issue of failure.issues) {
175
+ console.error(` * ${issue}`);
176
+ }
177
+ }
178
+ return false;
179
+ }
180
+
181
+ async function collectPendingEdits(config, routes) {
182
+ const pendingByFile = new Map();
183
+ const targetKinds = reflectionKindsMask(config.checks.apiLinks);
184
+
185
+ for (const entryPoint of config.linkEntryPoints) {
186
+ const project = await loadEntryPointProject({
187
+ entryPoint: entryPoint.path,
188
+ tsconfig: entryPoint.tsconfig,
189
+ packageName: config.packageName,
190
+ });
191
+ const reflections = getIncludedReflections(project, targetKinds);
192
+
193
+ for (const reflection of reflections) {
194
+ if (!shouldProcessEntryPointReflection(entryPoint, reflection)) {
195
+ continue;
196
+ }
197
+ for (const target of createApiLinkTargets(reflection, routes, config.apiBaseUrl)) {
198
+ if (!target.source?.line || !sourceIsInRoots(target.source, config.sourceRoots)) {
199
+ continue;
200
+ }
201
+ const entries = pendingByFile.get(target.source.fullFileName) ?? [];
202
+ entries.push({ line: target.source.line, seeLine: target.seeLine });
203
+ pendingByFile.set(target.source.fullFileName, entries);
204
+ }
205
+ }
206
+ }
207
+ return pendingByFile;
208
+ }
209
+
210
+ function applyPendingEdits(config, pendingByFile) {
211
+ let changedFiles = 0;
212
+ let insertedLinks = 0;
213
+
214
+ for (const [fileName, entries] of pendingByFile) {
215
+ const originalText = fs.readFileSync(fileName, 'utf8');
216
+ let text = originalText;
217
+ const uniqueEntries = Array.from(
218
+ new Map(entries.map((entry) => [`${entry.line}\0${entry.seeLine}`, entry])).values()
219
+ );
220
+ for (const entry of uniqueEntries.sort((left, right) => right.line - left.line)) {
221
+ const before = text;
222
+ const lineStarts = getLineStartOffsets(text);
223
+ const comment = findJsdocBeforeLine(text, lineStarts, entry.line);
224
+ if (!comment) {
225
+ continue;
226
+ }
227
+ text = upsertSeeLine(text, comment, entry.seeLine, config.apiBaseUrl);
228
+ if (text !== before) {
229
+ insertedLinks += 1;
230
+ }
231
+ }
232
+ if (text !== originalText) {
233
+ fs.writeFileSync(fileName, text);
234
+ changedFiles += 1;
235
+ }
236
+ }
237
+ return { changedFiles, insertedLinks };
238
+ }
239
+
240
+ export async function checkDocumentation(config) {
241
+ return withTemporaryDocs(config, { strict: true }, async ({ outputDir }) => {
242
+ const routes = readMarkdownRoutes(outputDir);
243
+ const apiOk = await apiCheck(config, routes);
244
+ const examplesOk = examplesCheck(config);
245
+ return { ok: apiOk && examplesOk };
246
+ });
247
+ }
248
+
249
+ export async function checkApiDocumentation(config, options = {}) {
250
+ return withTemporaryDocs(config, {}, async ({ outputDir }) => ({
251
+ ok: await apiCheck(config, readMarkdownRoutes(outputDir), options),
252
+ }));
253
+ }
254
+
255
+ export async function addApiLinks(config) {
256
+ return withTemporaryDocs(config, {}, async ({ outputDir }) => {
257
+ const routes = readMarkdownRoutes(outputDir);
258
+ const pendingByFile = await collectPendingEdits(config, routes);
259
+ const result = applyPendingEdits(config, pendingByFile);
260
+ console.log(`Inserted ${result.insertedLinks} API reference link(s) in ${result.changedFiles} file(s).`);
261
+ return { ok: true, ...result };
262
+ });
263
+ }
264
+
265
+ export async function generateDocumentation(config) {
266
+ return buildDocs(config, { outputDir: config.outputDir });
267
+ }
268
+
269
+ export async function watchDocumentation(config) {
270
+ return watchDocs(config, { outputDir: config.outputDir });
271
+ }
@@ -0,0 +1,21 @@
1
+ import { ReflectionKind } from 'typedoc';
2
+
3
+ const REFLECTION_KIND_BY_NAME = new Map([
4
+ ['class', ReflectionKind.Class],
5
+ ['interface', ReflectionKind.Interface],
6
+ ['typeAlias', ReflectionKind.TypeAlias],
7
+ ['enum', ReflectionKind.Enum],
8
+ ['variable', ReflectionKind.Variable],
9
+ ['function', ReflectionKind.Function],
10
+ ['method', ReflectionKind.Method],
11
+ ['accessor', ReflectionKind.Accessor],
12
+ ['property', ReflectionKind.Property],
13
+ ]);
14
+
15
+ export function reflectionKindsMask(kindNames) {
16
+ return kindNames.reduce((mask, kindName) => mask | REFLECTION_KIND_BY_NAME.get(kindName), 0);
17
+ }
18
+
19
+ export function withAccessorKind(kindNames) {
20
+ return kindNames.includes('accessor') ? kindNames : [...kindNames, 'accessor'];
21
+ }
@@ -0,0 +1,45 @@
1
+ # Accessor Docs Normalizer
2
+
3
+ ## Purpose
4
+
5
+ TypeDoc stores comments for TypeScript accessors on the getter and setter signatures. `typedoc-plugin-markdown`
6
+ overview tables read descriptions from the accessor reflection itself. When the reflection has no direct comment,
7
+ the generated table falls back to `-` even though the getter or setter is documented in source.
8
+
9
+ This plugin normalizes that shape for the textmode.js API docs:
10
+
11
+ - Copies the first getter or setter signature comment onto an accessor reflection when the accessor has no comment.
12
+ - Tracks copied comments so the accessor page does not render the same summary twice.
13
+ - Replaces the markdown accessor partial so getter documentation appears before setter documentation.
14
+ - Keeps getter return sections, setter parameter sections, inheritance sections, and `disableSources` behavior intact.
15
+
16
+ The plugin does not change runtime library behavior, the public TypeScript API, source JSDoc ownership, or TypeDoc
17
+ reflection conversion. It only adjusts markdown rendering after TypeDoc has built the reflection model.
18
+
19
+ This exists to avoid source-level documentation stubs or declaration-merging boilerplate for accessor descriptions.
20
+ Accessor docs should stay in the source declarations that own the getter and setter behavior.
21
+
22
+ ## Preserved Output Contract
23
+
24
+ - Accessor overview tables show the first available getter or setter summary.
25
+ - Accessor pages do not render copied comments twice.
26
+ - Getter content renders before setter content.
27
+ - Getter return sections, setter parameter sections, inheritance sections, and `disableSources` behavior match
28
+ `typedoc-plugin-markdown`.
29
+
30
+ ## Contributor Notes
31
+
32
+ - Safe to edit: helper names, tests, README wording, and the local comment-normalization traversal.
33
+ - Be careful with: `theme-patch.js`, because it monkey-patches `MarkdownTheme.prototype.getRenderContext`.
34
+ - Do not casually change: accessor partial output order, copied-comment tracking, or source-display conditions.
35
+
36
+ ## Maintenance
37
+
38
+ This plugin depends on `typedoc-plugin-markdown` theme internals, especially `MarkdownTheme.getRenderContext` and the
39
+ `partials.accessor` contract. Re-check this plugin after upgrading `typedoc-plugin-markdown`.
40
+
41
+ Upgrade checklist:
42
+
43
+ - Compare `render-accessor.js` against the current upstream accessor partial.
44
+ - Confirm `MarkdownTheme.getRenderContext` still exists and returns a mutable partials object.
45
+ - Run `npm run test:tooling` and inspect generated accessor pages for duplicate summaries.
@@ -0,0 +1,53 @@
1
+ // @ts-check
2
+
3
+ import { ReflectionKind } from 'typedoc';
4
+
5
+ const syntheticAccessorComments = new WeakSet();
6
+
7
+ /**
8
+ * Get the first signature-level comment available for an accessor reflection.
9
+ * TypeDoc currently keeps getter/setter comments on their signatures, while
10
+ * overview tables read from the accessor declaration itself.
11
+ *
12
+ * @param {import('typedoc').DeclarationReflection} accessor
13
+ * @returns {import('typedoc').Comment | undefined}
14
+ */
15
+ function getAccessorSignatureComment(accessor) {
16
+ return accessor.getSignature?.comment ?? accessor.setSignature?.comment;
17
+ }
18
+
19
+ /**
20
+ * Copy signature comments onto accessor declarations when needed so markdown
21
+ * overview tables can render descriptions instead of falling back to "-".
22
+ *
23
+ * @param {import('typedoc').Reflection | undefined} model
24
+ * @returns {void}
25
+ */
26
+ export function normalizeAccessorComments(model) {
27
+ if (!model) {
28
+ return;
29
+ }
30
+
31
+ if (model.kind === ReflectionKind.Accessor && 'comment' in model && !model.comment) {
32
+ const signatureComment = getAccessorSignatureComment(model);
33
+ if (signatureComment) {
34
+ model.comment = signatureComment;
35
+ syntheticAccessorComments.add(model);
36
+ }
37
+ }
38
+
39
+ model.traverse?.((child) => {
40
+ normalizeAccessorComments(child);
41
+ return true;
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Check whether a comment was copied onto an accessor by this plugin.
47
+ *
48
+ * @param {import('typedoc').DeclarationReflection} accessor
49
+ * @returns {boolean}
50
+ */
51
+ export function hasSyntheticAccessorComment(accessor) {
52
+ return syntheticAccessorComments.has(accessor);
53
+ }
@@ -0,0 +1,32 @@
1
+ // @ts-check
2
+
3
+ import { MarkdownTheme, MarkdownThemeContext } from 'typedoc-plugin-markdown';
4
+
5
+ import { normalizeAccessorComments } from './accessor-comments.js';
6
+ import { renderAccessorDocs } from './render-accessor.js';
7
+ import { patchMarkdownThemeRenderContext } from './theme-patch.js';
8
+
9
+ class AccessorDocsMarkdownThemeContext extends MarkdownThemeContext {
10
+ /**
11
+ * @param {MarkdownTheme} theme
12
+ * @param {import('typedoc-plugin-markdown').MarkdownPageEvent<import('typedoc').Reflection>} page
13
+ * @param {import('typedoc').Options} options
14
+ */
15
+ constructor(theme, page, options) {
16
+ super(theme, page, options);
17
+ normalizeAccessorComments(page.model);
18
+ this.partials.accessor = (accessor, partialOptions) => renderAccessorDocs(this, accessor, partialOptions);
19
+ }
20
+ }
21
+
22
+ /**
23
+ * @param {import('typedoc').Application} app
24
+ * @returns {void}
25
+ */
26
+ export function load(app) {
27
+ patchMarkdownThemeRenderContext(
28
+ (theme, page) => new AccessorDocsMarkdownThemeContext(theme, page, theme.application.options)
29
+ );
30
+
31
+ app.logger.verbose('[typedoc] Registered accessor docs normalizer');
32
+ }
@@ -0,0 +1,144 @@
1
+ // @ts-check
2
+
3
+ import { i18n, ReflectionKind } from 'typedoc';
4
+
5
+ import { hasSyntheticAccessorComment } from './accessor-comments.js';
6
+
7
+ /**
8
+ * @param {number} level
9
+ * @param {string} text
10
+ * @returns {string}
11
+ */
12
+ function heading(level, text) {
13
+ return `${'#'.repeat(level)} ${text}`;
14
+ }
15
+
16
+ /**
17
+ * Render one getter or setter signature.
18
+ *
19
+ * @param {import('typedoc-plugin-markdown').MarkdownThemeContext} context
20
+ * @param {import('typedoc').SignatureReflection} signature
21
+ * @param {{
22
+ * accessor: 'get' | 'set';
23
+ * headingLevel: number;
24
+ * includeParameters: boolean;
25
+ * showSources: boolean;
26
+ * title: string;
27
+ * }} options
28
+ * @returns {string}
29
+ */
30
+ function renderAccessorSignature(context, signature, options) {
31
+ const md = [];
32
+
33
+ md.push(heading(options.headingLevel, options.title));
34
+ md.push(
35
+ context.partials.signatureTitle(signature, {
36
+ accessor: options.accessor,
37
+ })
38
+ );
39
+
40
+ if (options.showSources && !context.options.getValue('disableSources') && signature.sources) {
41
+ md.push(context.partials.sources(signature));
42
+ }
43
+
44
+ if (signature.comment) {
45
+ md.push(
46
+ context.partials.comment(signature.comment, {
47
+ headingLevel: options.headingLevel + 1,
48
+ showTags: false,
49
+ showSummary: true,
50
+ })
51
+ );
52
+ }
53
+
54
+ if (options.includeParameters && signature.parameters?.length) {
55
+ md.push(heading(options.headingLevel + 1, ReflectionKind.pluralString(ReflectionKind.Parameter)));
56
+ if (context.helpers.useTableFormat('parameters')) {
57
+ md.push(context.partials.parametersTable(signature.parameters));
58
+ } else {
59
+ md.push(
60
+ context.partials.parametersList(signature.parameters, {
61
+ headingLevel: options.headingLevel + 1,
62
+ })
63
+ );
64
+ }
65
+ }
66
+
67
+ if (signature.type) {
68
+ md.push(
69
+ context.partials.signatureReturns(signature, {
70
+ headingLevel: options.headingLevel + 1,
71
+ })
72
+ );
73
+ }
74
+
75
+ if (signature.comment) {
76
+ md.push(
77
+ context.partials.comment(signature.comment, {
78
+ headingLevel: options.headingLevel + 1,
79
+ showTags: true,
80
+ showSummary: false,
81
+ })
82
+ );
83
+ }
84
+
85
+ return md.filter(Boolean).join('\n\n');
86
+ }
87
+
88
+ /**
89
+ * Render accessor documentation with getter content before setter content.
90
+ *
91
+ * @param {import('typedoc-plugin-markdown').MarkdownThemeContext} context
92
+ * @param {import('typedoc').DeclarationReflection} accessor
93
+ * @param {{ headingLevel: number }} options
94
+ * @returns {string}
95
+ */
96
+ export function renderAccessorDocs(context, accessor, options) {
97
+ const md = [];
98
+ const showSources = accessor.parent?.kind !== ReflectionKind.TypeLiteral;
99
+
100
+ if (accessor.getSignature) {
101
+ md.push(
102
+ renderAccessorSignature(context, accessor.getSignature, {
103
+ accessor: 'get',
104
+ headingLevel: options.headingLevel,
105
+ includeParameters: false,
106
+ showSources,
107
+ title: i18n.kind_get_signature(),
108
+ })
109
+ );
110
+ }
111
+
112
+ if (accessor.setSignature) {
113
+ md.push(
114
+ renderAccessorSignature(context, accessor.setSignature, {
115
+ accessor: 'set',
116
+ headingLevel: options.headingLevel,
117
+ includeParameters: true,
118
+ showSources,
119
+ title: i18n.kind_set_signature(),
120
+ })
121
+ );
122
+ }
123
+
124
+ if (
125
+ showSources &&
126
+ !context.options.getValue('disableSources') &&
127
+ !accessor.getSignature &&
128
+ !accessor.setSignature
129
+ ) {
130
+ md.push(context.partials.sources(accessor));
131
+ }
132
+
133
+ if (accessor.comment && !hasSyntheticAccessorComment(accessor)) {
134
+ md.push(
135
+ context.partials.comment(accessor.comment, {
136
+ headingLevel: options.headingLevel,
137
+ })
138
+ );
139
+ }
140
+
141
+ md.push(context.partials.inheritance(accessor, { headingLevel: options.headingLevel }));
142
+
143
+ return md.filter(Boolean).join('\n\n');
144
+ }
@@ -0,0 +1,28 @@
1
+ // @ts-check
2
+
3
+ import { MarkdownTheme } from 'typedoc-plugin-markdown';
4
+
5
+ let isPatched = false;
6
+
7
+ /**
8
+ * Patch typedoc-plugin-markdown's theme render-context factory once.
9
+ *
10
+ * This is the only place this plugin reaches into markdown theme internals.
11
+ * Keep the patch idempotent because TypeDoc can load plugins repeatedly in
12
+ * watch mode and tests can import the plugin more than once.
13
+ *
14
+ * @param {(theme: MarkdownTheme, page: import('typedoc-plugin-markdown').MarkdownPageEvent<import('typedoc').Reflection>) => import('typedoc-plugin-markdown').MarkdownThemeContext} createContext
15
+ * @returns {boolean} True when this call installed the patch.
16
+ */
17
+ export function patchMarkdownThemeRenderContext(createContext) {
18
+ if (isPatched) {
19
+ return false;
20
+ }
21
+
22
+ MarkdownTheme.prototype.getRenderContext = function (page) {
23
+ return createContext(this, page);
24
+ };
25
+ isPatched = true;
26
+
27
+ return true;
28
+ }
@@ -0,0 +1,57 @@
1
+ # All Member Pages Router
2
+
3
+ ## Purpose
4
+
5
+ This TypeDoc router makes direct public methods render as focused Markdown pages when an owner page would otherwise
6
+ render too many Sandpack examples.
7
+
8
+ `typedoc-plugin-markdown` can render top-level API structures as pages, but textmode.js also needs compact class and
9
+ interface overview pages that link to individual methods once their inline examples would make the page heavy. This
10
+ router keeps those owner pages small and gives each direct method a stable page.
11
+
12
+ ## Member Pages
13
+
14
+ The router creates pages for direct class/interface methods when rendering the owner page inline would exceed three
15
+ Sandpack examples:
16
+
17
+ - methods
18
+
19
+ Nested type-literal fields intentionally remain inline or anchor-based so structural types do not explode into many
20
+ small pages.
21
+
22
+ ## Paths
23
+
24
+ Examples:
25
+
26
+ - `classes/Textmodifier/methods/background.md`
27
+ - `namespaces/layering/classes/TextmodeLayer/methods/draw.md`
28
+
29
+ ## Preserved Output Contract
30
+
31
+ - The router name remains `all-member-pages`.
32
+ - Direct methods get pages only when their class/interface owner would otherwise exceed three Sandpack examples.
33
+ - Properties, accessors, constructors, variables, type aliases, functions, and nested type-literal members do not get
34
+ extra pages from this router.
35
+ - Existing `MemberRouter` behavior for modules, namespaces, documents, and configured `membersWithOwnFile` kinds is
36
+ preserved.
37
+ - Project-root namespaces use the flattened textmode.js path shape, for example `namespaces/color/classes/TextmodeColor.md`.
38
+ - Sidebar entries include generated member pages under their owners.
39
+
40
+ ## Contributor Notes
41
+
42
+ - Safe to edit: constants, helper names, tests, and README wording.
43
+ - Be careful with: `child-pages.js`, which intentionally mirrors upstream `MemberRouter` traversal.
44
+ - Do not casually change: path segment names, namespace path flattening, example-count thresholds, or direct-method page
45
+ eligibility.
46
+
47
+ ## Maintenance
48
+
49
+ This plugin extends `typedoc-plugin-markdown`'s `MemberRouter` and copies its child-page traversal policy so direct
50
+ members can participate in TypeDoc's `hasOwnDocument` behavior. Re-check this router after upgrading TypeDoc or
51
+ `typedoc-plugin-markdown`, especially around router APIs, `membersWithOwnFile`, and namespace path handling.
52
+
53
+ Upgrade checklist:
54
+
55
+ - Compare `child-pages.js` against the current upstream `MemberRouter.buildChildPages`.
56
+ - Confirm `PageKind.Reflection`, `Slugger`, `fullUrls`, and `sluggers` are still the correct router APIs.
57
+ - Run `npm run build:docs` and verify generated method links still resolve.