@travetto/doc 3.0.2 → 3.0.3

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.
@@ -0,0 +1,254 @@
1
+ export const MOD_MAPPING = {
2
+ App: {
3
+ name: '@travetto/app', folder: '@travetto/app', displayName: 'Application',
4
+ description: 'Application registration/management and run support.'
5
+ },
6
+ Asset: {
7
+ name: '@travetto/asset', folder: '@travetto/asset', displayName: 'Asset',
8
+ description: 'Modular library for storing and retrieving binary assets'
9
+ },
10
+ AssetRest: {
11
+ name: '@travetto/asset-rest', folder: '@travetto/asset-rest', displayName: 'Asset Rest Support',
12
+ description: 'Provides integration between the travetto asset and rest module.'
13
+ },
14
+ Auth: {
15
+ name: '@travetto/auth', folder: '@travetto/auth', displayName: 'Authentication',
16
+ description: 'Authentication scaffolding for the Travetto framework'
17
+ },
18
+ AuthModel: {
19
+ name: '@travetto/auth-model', folder: '@travetto/auth-model', displayName: 'Authentication Model',
20
+ description: 'Authentication model support for the Travetto framework'
21
+ },
22
+ AuthRest: {
23
+ name: '@travetto/auth-rest', folder: '@travetto/auth-rest', displayName: 'Rest Auth',
24
+ description: 'Rest authentication integration support for the Travetto framework'
25
+ },
26
+ AuthRestContext: {
27
+ name: '@travetto/auth-rest-context', folder: '@travetto/auth-rest-context', displayName: 'Rest Auth Context',
28
+ description: 'Rest authentication context integration support for the Travetto framework'
29
+ },
30
+ AuthRestJwt: {
31
+ name: '@travetto/auth-rest-jwt', folder: '@travetto/auth-rest-jwt', displayName: 'Rest Auth JWT',
32
+ description: 'Rest authentication JWT integration support for the Travetto framework'
33
+ },
34
+ AuthRestPassport: {
35
+ name: '@travetto/auth-rest-passport', folder: '@travetto/auth-rest-passport', displayName: 'Rest Auth Passport',
36
+ description: 'Rest authentication integration support for the Travetto framework'
37
+ },
38
+ AuthRestSession: {
39
+ name: '@travetto/auth-rest-session', folder: '@travetto/auth-rest-session', displayName: 'Rest Auth Session',
40
+ description: 'Rest authentication session integration support for the Travetto framework'
41
+ },
42
+ Base: {
43
+ name: '@travetto/base', folder: '@travetto/base', displayName: 'Base',
44
+ description: 'Environment config and common utilities for travetto applications.'
45
+ },
46
+ Cache: {
47
+ name: '@travetto/cache', folder: '@travetto/cache', displayName: 'Caching',
48
+ description: 'Caching functionality with decorators for declarative use.'
49
+ },
50
+ Cli: {
51
+ name: '@travetto/cli', folder: '@travetto/cli', displayName: 'Command Line Interface',
52
+ description: 'CLI infrastructure for Travetto framework'
53
+ },
54
+ Command: {
55
+ name: '@travetto/command', folder: '@travetto/command', displayName: 'Command',
56
+ description: 'Support for executing complex commands at runtime.'
57
+ },
58
+ Compiler: {
59
+ name: '@travetto/compiler', folder: '@travetto/compiler', displayName: 'Compiler',
60
+ description: 'The compiler infrastructure for the Travetto framework'
61
+ },
62
+ Config: {
63
+ name: '@travetto/config', folder: '@travetto/config', displayName: 'Configuration',
64
+ description: 'Configuration support'
65
+ },
66
+ Context: {
67
+ name: '@travetto/context', folder: '@travetto/context', displayName: 'Async Context',
68
+ description: 'Async-aware state management, maintaining context across asynchronous calls.'
69
+ },
70
+ Di: {
71
+ name: '@travetto/di', folder: '@travetto/di', displayName: 'Dependency Injection',
72
+ description: 'Dependency registration/management and injection support.'
73
+ },
74
+ Doc: {
75
+ name: '@travetto/doc', folder: '@travetto/doc', displayName: 'Documentation',
76
+ description: 'Documentation support for the Travetto framework'
77
+ },
78
+ Email: {
79
+ name: '@travetto/email', folder: '@travetto/email', displayName: 'Email',
80
+ description: 'Email transmission module.'
81
+ },
82
+ EmailNodemailer: {
83
+ name: '@travetto/email-nodemailer', folder: '@travetto/email-nodemailer', displayName: 'Email Nodemailer Support',
84
+ description: 'Email transmission module.'
85
+ },
86
+ EmailTemplate: {
87
+ name: '@travetto/email-template', folder: '@travetto/email-template', displayName: 'Email Templating',
88
+ description: 'Email templating module'
89
+ },
90
+ Eslint: {
91
+ name: '@travetto/eslint', folder: '@travetto/eslint', displayName: 'ES Linting Rules',
92
+ description: 'ES Linting Rules'
93
+ },
94
+ Image: {
95
+ name: '@travetto/image', folder: '@travetto/image', displayName: 'Image',
96
+ description: 'Image support, resizing, and optimization'
97
+ },
98
+ Jwt: {
99
+ name: '@travetto/jwt', folder: '@travetto/jwt', displayName: 'JWT',
100
+ description: 'JSON Web Token implementation'
101
+ },
102
+ Log: {
103
+ name: '@travetto/log', folder: '@travetto/log', displayName: 'Logging',
104
+ description: 'Logging framework that integrates at the console.log level.'
105
+ },
106
+ Manifest: {
107
+ name: '@travetto/manifest', folder: '@travetto/manifest', displayName: 'Manifest',
108
+ description: 'Support for project indexing, manifesting, along with file watching'
109
+ },
110
+ Model: {
111
+ name: '@travetto/model', folder: '@travetto/model', displayName: 'Data Modeling Support',
112
+ description: 'Datastore abstraction for core operations.'
113
+ },
114
+ ModelDynamodb: {
115
+ name: '@travetto/model-dynamodb', folder: '@travetto/model-dynamodb', displayName: 'DynamoDB Model Support',
116
+ description: 'DynamoDB backing for the travetto model module.'
117
+ },
118
+ ModelElasticsearch: {
119
+ name: '@travetto/model-elasticsearch', folder: '@travetto/model-elasticsearch', displayName: 'Elasticsearch Model Source',
120
+ description: 'Elasticsearch backing for the travetto model module, with real-time modeling support for Elasticsearch mappings.'
121
+ },
122
+ ModelFirestore: {
123
+ name: '@travetto/model-firestore', folder: '@travetto/model-firestore', displayName: 'Firestore Model Support',
124
+ description: 'Firestore backing for the travetto model module.'
125
+ },
126
+ ModelMongo: {
127
+ name: '@travetto/model-mongo', folder: '@travetto/model-mongo', displayName: 'MongoDB Model Support',
128
+ description: 'Mongo backing for the travetto model module.'
129
+ },
130
+ ModelMysql: {
131
+ name: '@travetto/model-mysql', folder: '@travetto/model-mysql', displayName: 'MySQL Model Service',
132
+ description: 'MySQL backing for the travetto model module, with real-time modeling support for SQL schemas.'
133
+ },
134
+ ModelPostgres: {
135
+ name: '@travetto/model-postgres', folder: '@travetto/model-postgres', displayName: 'PostgreSQL Model Service',
136
+ description: 'PostgreSQL backing for the travetto model module, with real-time modeling support for SQL schemas.'
137
+ },
138
+ ModelQuery: {
139
+ name: '@travetto/model-query', folder: '@travetto/model-query', displayName: 'Data Model Querying',
140
+ description: 'Datastore abstraction for advanced query support.'
141
+ },
142
+ ModelRedis: {
143
+ name: '@travetto/model-redis', folder: '@travetto/model-redis', displayName: 'Redis Model Support',
144
+ description: 'Redis backing for the travetto model module.'
145
+ },
146
+ ModelS3: {
147
+ name: '@travetto/model-s3', folder: '@travetto/model-s3', displayName: 'S3 Model Support',
148
+ description: 'S3 backing for the travetto model module.'
149
+ },
150
+ ModelSql: {
151
+ name: '@travetto/model-sql', folder: '@travetto/model-sql', displayName: 'SQL Model Service',
152
+ description: 'SQL backing for the travetto model module, with real-time modeling support for SQL schemas.'
153
+ },
154
+ ModelSqlite: {
155
+ name: '@travetto/model-sqlite', folder: '@travetto/model-sqlite', displayName: 'SQLite Model Service',
156
+ description: 'SQLite backing for the travetto model module, with real-time modeling support for SQL schemas.'
157
+ },
158
+ Openapi: {
159
+ name: '@travetto/openapi', folder: '@travetto/openapi', displayName: 'OpenAPI Specification',
160
+ description: 'OpenAPI integration support for the Travetto framework'
161
+ },
162
+ Pack: {
163
+ name: '@travetto/pack', folder: '@travetto/pack', displayName: 'Pack',
164
+ description: 'Code packing utilities'
165
+ },
166
+ Registry: {
167
+ name: '@travetto/registry', folder: '@travetto/registry', displayName: 'Registry',
168
+ description: 'Patterns and utilities for handling registration of metadata and functionality for run-time use'
169
+ },
170
+ Repo: {
171
+ name: '@travetto/repo', folder: '@travetto/repo', displayName: 'Repo',
172
+ description: 'Monorepo utilities'
173
+ },
174
+ Rest: {
175
+ name: '@travetto/rest', folder: '@travetto/rest', displayName: 'RESTful API',
176
+ description: 'Declarative api for RESTful APIs with support for the dependency injection module.'
177
+ },
178
+ RestAwsLambda: {
179
+ name: '@travetto/rest-aws-lambda', folder: '@travetto/rest-aws-lambda', displayName: 'RESTful AWS Lambda',
180
+ description: 'RESTful APIs entry point support for AWS Lambdas.'
181
+ },
182
+ RestExpress: {
183
+ name: '@travetto/rest-express', folder: '@travetto/rest-express', displayName: 'Express REST Source',
184
+ description: 'Express provider for the travetto rest module.'
185
+ },
186
+ RestExpressLambda: {
187
+ name: '@travetto/rest-express-lambda', folder: '@travetto/rest-express-lambda', displayName: 'Express REST AWS Lambda Source',
188
+ description: 'Express AWS Lambda provider for the travetto rest module.'
189
+ },
190
+ RestFastify: {
191
+ name: '@travetto/rest-fastify', folder: '@travetto/rest-fastify', displayName: 'Fastify REST Source',
192
+ description: 'Fastify provider for the travetto rest module.'
193
+ },
194
+ RestFastifyLambda: {
195
+ name: '@travetto/rest-fastify-lambda', folder: '@travetto/rest-fastify-lambda', displayName: 'Fastify REST AWS Lambda Source',
196
+ description: 'Fastify AWS Lambda provider for the travetto rest module.'
197
+ },
198
+ RestKoa: {
199
+ name: '@travetto/rest-koa', folder: '@travetto/rest-koa', displayName: 'Koa REST Source',
200
+ description: 'Koa provider for the travetto rest module.'
201
+ },
202
+ RestKoaLambda: {
203
+ name: '@travetto/rest-koa-lambda', folder: '@travetto/rest-koa-lambda', displayName: 'Koa REST AWS Lambda Source',
204
+ description: 'Koa provider for the travetto rest module.'
205
+ },
206
+ RestModel: {
207
+ name: '@travetto/rest-model', folder: '@travetto/rest-model', displayName: 'RESTful Model Routes',
208
+ description: 'RESTful support for generating APIs from Model classes.'
209
+ },
210
+ RestModelQuery: {
211
+ name: '@travetto/rest-model-query', folder: '@travetto/rest-model-query', displayName: 'RESTful Model Query Routes',
212
+ description: 'RESTful support for generating query APIs from Model classes.'
213
+ },
214
+ RestSession: {
215
+ name: '@travetto/rest-session', folder: '@travetto/rest-session', displayName: 'REST Session',
216
+ description: 'Session provider for the travetto rest module.'
217
+ },
218
+ Scaffold: {
219
+ name: '@travetto/scaffold', folder: '@travetto/scaffold', displayName: 'App Scaffold',
220
+ description: 'App Scaffold for the Travetto framework'
221
+ },
222
+ Schema: {
223
+ name: '@travetto/schema', folder: '@travetto/schema', displayName: 'Schema',
224
+ description: 'Data type registry for runtime validation, reflection and binding.'
225
+ },
226
+ SchemaFaker: {
227
+ name: '@travetto/schema-faker', folder: '@travetto/schema-faker', displayName: 'Schema Faker',
228
+ description: 'Data generation for schema-registered objects.'
229
+ },
230
+ Terminal: {
231
+ name: '@travetto/terminal', folder: '@travetto/terminal', displayName: 'Terminal',
232
+ description: 'General terminal support'
233
+ },
234
+ Test: {
235
+ name: '@travetto/test', folder: '@travetto/test', displayName: 'Testing',
236
+ description: 'Declarative test framework'
237
+ },
238
+ TodoApp: {
239
+ name: '@travetto/todo-app', folder: '@travetto/todo-app', displayName: 'Todo Application',
240
+ description: ''
241
+ },
242
+ Transformer: {
243
+ name: '@travetto/transformer', folder: '@travetto/transformer', displayName: 'Transformation',
244
+ description: 'Functionality for AST transformations, with transformer registration, and general utils'
245
+ },
246
+ Worker: {
247
+ name: '@travetto/worker', folder: '@travetto/worker', displayName: 'Worker',
248
+ description: 'Process management utilities, with a focus on inter-process communication'
249
+ },
250
+ Yaml: {
251
+ name: '@travetto/yaml', folder: '@travetto/yaml', displayName: 'YAML',
252
+ description: 'Simple YAML support, provides only clean subset of yaml'
253
+ }
254
+ };
@@ -1,59 +1,129 @@
1
- import { path } from '@travetto/manifest';
1
+ import { createElement, JSXRuntimeTag } from '@travetto/doc/jsx-runtime';
2
2
 
3
- import { AllType, AllTypeMap, node as n } from '../nodes';
4
- import { DocNode, RenderContextShape } from '../types';
3
+ import { PackageUtil, path, RootIndex } from '@travetto/manifest';
5
4
 
6
- export type AllChildren = AllType;
5
+ import { JSXElementByFn, c } from '../jsx';
6
+ import { DocResolveUtil, ResolvedCode, ResolvedRef, ResolvedSnippetLink } from '../util/resolve';
7
+ import { DocRunUtil } from '../util/run';
7
8
 
8
9
  /**
9
- * Render context
10
+ * Render Context
10
11
  */
11
- export class RenderContext implements RenderContextShape {
12
+ export class RenderContext {
12
13
 
14
+ #executeCache: Record<string, string> = {};
15
+
16
+ /**
17
+ * Filename
18
+ */
13
19
  file: string;
20
+
21
+ /**
22
+ * Github root for project
23
+ */
14
24
  baseUrl: string;
25
+
26
+ /**
27
+ * Github root for Travetto framework
28
+ */
15
29
  travettoBaseUrl: string;
30
+
31
+ /**
32
+ * Repository root
33
+ */
16
34
  repoRoot: string;
17
35
 
18
- constructor(file: string, repoRoot: string, baseUrl: string, travettoBaseUrl: string) {
36
+ constructor(file: string, baseUrl: string, repoRoot: string) {
37
+
38
+ const manifestPkg = PackageUtil.readPackage(RootIndex.getModule('@travetto/manifest')!.sourcePath);
39
+
19
40
  this.file = path.toPosix(file);
20
41
  this.baseUrl = baseUrl;
21
42
  this.repoRoot = repoRoot;
22
- this.travettoBaseUrl = travettoBaseUrl;
43
+ this.travettoBaseUrl = repoRoot.includes('travetto.github') ? repoRoot : manifestPkg.travetto!.docBaseUrl!;
23
44
  }
24
45
 
25
- toc(root: DocNode): AllTypeMap['Ordered'] {
26
- return n.Ordered(
27
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
28
- ...(root as AllTypeMap['Group']).nodes
29
- .filter(x => x._type === 'section')
30
- .map(x => {
31
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
32
- const { title } = x as AllTypeMap['Section'];
33
- return n.Anchor(title, title);
34
- })
35
- );
46
+ /**
47
+ * Get generated comment
48
+ */
49
+ get generatedStamp(): string {
50
+ return 'This file was generated by @travetto/doc and should not be modified directly';
36
51
  }
37
52
 
38
- get preamble(): AllTypeMap['Group'] {
39
- return n.Group([
40
- n.Comment('This file was generated by @travetto/doc and should not be modified directly'),
41
- n.Text('\n'),
42
- n.Comment(`Please modify ${this.file.replace(this.repoRoot, this.baseUrl)} and execute "npx trv doc" to rebuild`),
43
- ]);
53
+ /**
54
+ * Get rebuilt comment
55
+ */
56
+ get rebuildStamp(): string {
57
+ return `Please modify ${this.file.replace(this.repoRoot, this.baseUrl)} and execute "npx trv doc" to rebuild`;
44
58
  }
45
59
 
60
+ /**
61
+ * Generate link location
62
+ */
46
63
  link(text: string, line?: number | { [key: string]: unknown, line?: number }): string {
47
64
  const num = typeof line === 'number' ? line : line?.line;
48
65
  return `${text.replace(this.repoRoot, this.baseUrl)
49
66
  .replace(/.*@travetto\//, `${this.travettoBaseUrl}/module/`)}${num ? `#L${num}` : ''}`;
50
67
  }
51
68
 
69
+ /**
70
+ * Clean text
71
+ */
52
72
  cleanText(a?: string): string {
53
73
  return a ? a.replace(/^[\n ]+|[\n ]+$/gs, '') : '';
54
74
  }
55
75
 
76
+ /**
77
+ * Get a consistent anchor id
78
+ */
56
79
  getAnchorId(a: string): string {
57
80
  return a.toLowerCase().replace(/<[^>]+>/g, ' ').replace(/[^a-z0-9]+/g, ' ').trim().replace(/ /g, '-');
58
81
  }
82
+
83
+ /**
84
+ * Execute a node that represents a code invocation
85
+ */
86
+ async execute(node: JSXElementByFn<'Execution'>): Promise<string> {
87
+ const key = node[JSXRuntimeTag]?.id ?? 0;
88
+ if (key && this.#executeCache[key]) {
89
+ return this.#executeCache[key];
90
+ }
91
+
92
+ const { cmd, args = [], config = {} } = node.props;
93
+ const result = await DocRunUtil.run(cmd, args, config);
94
+ return this.#executeCache[key] = result;
95
+ }
96
+
97
+ /**
98
+ * Resolve a reference to a given node
99
+ */
100
+ async resolveRef(node: JSXElementByFn<'Ref'>): Promise<ResolvedRef> {
101
+ return DocResolveUtil.resolveRef(node.props.title, node.props.href);
102
+ }
103
+
104
+ /**
105
+ * Resolve code link
106
+ */
107
+ async resolveCodeLink(node: JSXElementByFn<'CodeLink'>): Promise<ResolvedSnippetLink> {
108
+ const src = typeof node.props.src === 'string' ? node.props.src : RootIndex.getFunctionMetadata(node.props.src)!.source;
109
+ return DocResolveUtil.resolveCodeLink(src, node.props.startRe);
110
+ }
111
+
112
+ /**
113
+ * Resolve code/config
114
+ */
115
+ async resolveCode(node: JSXElementByFn<'Code' | 'Config'>): Promise<ResolvedCode> {
116
+ const src = typeof node.props.src === 'string' ? node.props.src : RootIndex.getFunctionMetadata(node.props.src)!.source;
117
+ return node.props.startRe ?
118
+ DocResolveUtil.resolveSnippet(src, node.props.startRe, node.props.endRe, node.props.outline) :
119
+ DocResolveUtil.resolveCode(src, node.props.language, node.props.outline);
120
+ }
121
+
122
+ /**
123
+ * Create a new element from a given JSX factory
124
+ */
125
+ createElement<K extends keyof typeof c>(name: K, props: JSXElementByFn<K>['props']): JSXElementByFn<K> {
126
+ // @ts-expect-error
127
+ return createElement(c[name], props) as JSXElementByFn<K>;
128
+ }
59
129
  }
@@ -1,81 +1,161 @@
1
- import { node as n } from '../nodes';
2
- import { AllChildren, RenderContext } from './context';
1
+ import fs from 'fs/promises';
2
+
3
+ import { JSXElement } from '@travetto/doc/jsx-runtime';
4
+ import { RootIndex, PackageUtil } from '@travetto/manifest';
5
+
3
6
  import { highlight } from './code-highlight';
4
- import { DocNode, Renderer } from '../types';
7
+ import { RenderProvider, RenderState } from '../types';
8
+ import { c, getComponentName } from '../jsx';
9
+ import { MOD_MAPPING } from '../mapping/mod-mapping';
10
+ import { LIB_MAPPING } from '../mapping/lib-mapping';
11
+ import { RenderContext } from './context';
12
+ import { DocResolveUtil } from '../util/resolve';
5
13
 
6
14
  const ESCAPE_ENTITIES: Record<string, string> = { '<': '&lt;', '>': '&gt;', '&': '&amp;', '{': "{{'{'}}", '}': "{{'}'}}" };
7
15
  const ENTITY_RE = new RegExp(`[${Object.keys(ESCAPE_ENTITIES).join('')}]`, 'gm');
8
16
 
9
- export const Html: Renderer = {
17
+ const stdInline = async ({ recurse, el }: RenderState<JSXElement, RenderContext>): Promise<string> =>
18
+ `<${el.type}>${await recurse()}</${el.type}>`;
19
+
20
+ const std = async ({ recurse, el }: RenderState<JSXElement, RenderContext>): Promise<string> =>
21
+ `<${el.type}>${await recurse()}</${el.type}>\n`;
22
+
23
+ const stdFull = async ({ recurse, el }: RenderState<JSXElement, RenderContext>): Promise<string> =>
24
+ `\n<${el.type}>${await recurse()}</${el.type}>\n`;
25
+
26
+
27
+ export const Html: RenderProvider<RenderContext> = {
10
28
  ext: 'html',
11
- render(c: AllChildren, context: RenderContext, root = c) {
12
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
13
- const recurse = (s: AllChildren | DocNode): string => this.render(s as AllChildren, context, root);
14
- switch (c._type) {
15
- case 'toc': {
16
- const content = recurse(n.Group([n.SubSection(c.title), context.toc(root)]));
17
- return `<div class="toc"><div class="inner">${content}</div></div>`;
18
- }
19
- case 'strong': return `<strong>${recurse(c.content)}</strong>`;
20
- case 'group': return c.nodes.map(cc => recurse(cc)).join('');
21
- case 'comment': return `<!-- ${recurse(c.text)} -->`;
22
- case 'install':
23
- case 'terminal':
24
- case 'config':
25
- case 'code': return `
26
- <figure class="${c._type}">
27
- <figcaption class="${c._type}">${recurse(c.title)}
28
- ${'file' in c && c.file ? `<cite><a target="_blank" href="${context.link(recurse(c.file), c)}">Source</a></cite>` : ''}
29
- </figcaption>
30
- <pre><code class="language-${c.language}">${context.cleanText(highlight(recurse(c.content), c.language))}</code></pre>
31
- </figure>`;
32
- case 'anchor': return `<a class="anchor-link" routerLink="." fragment="${context.getAnchorId(recurse(c.fragment))}">${recurse(c.title)}</a>`;
33
- case 'library':
34
- case 'file':
35
- case 'ref': return `<a target="_blank" class="${c._type === 'library' ? 'external-link' : 'source-link'}" href="${context.link(recurse(c.link), c)}">${recurse(c.title)}</a>`;
36
- case 'mod': return `<a class="module-link" href="${context.link(recurse(c.link), c)}" title="${recurse(c.description)}">${recurse(c.title)}</a>`;
37
- case 'image': return `<img src="${context.link(recurse(c.link), c)}" alt="${recurse(c.title)}">`;
38
- case 'section':
39
- case 'subsection':
40
- case 'subsubsection': {
41
- const tag = c._type === 'section' ? 'h2' : (c._type === 'subsection' ? 'h3' : 'h4');
42
- const title = recurse(c.title);
43
- return `<${tag} id="${context.getAnchorId(title)}">${title}</${tag}>`;
44
- }
45
- case 'command':
46
- case 'method':
47
- case 'path':
48
- case 'class':
49
- case 'field':
50
- case 'input': return `<code class="item ${c._type}">${context.cleanText(recurse(c.content)).replace(ENTITY_RE, k => ESCAPE_ENTITIES[k])}</code>`;
51
- case 'note': return `<p class="note"><strong>Note</strong> ${recurse(c.content)}</p>`;
52
- case 'item': return ` <li>${recurse(c.node)}</li>`;
53
- case 'list': {
54
- const out: string[] = [];
55
- const ordered = c.items.find(x => x._type === 'item' && 'ordered' in x && x.ordered);
56
-
57
- for (const el of c.items) {
58
- out.push(recurse(el));
59
- }
60
- const tag = ordered ? 'ol' : 'ul';
61
- return `<${tag}>${out.join('\n')}</${tag}>`;
29
+ finalize: (text, context) => {
30
+ const brand = `<!-- ${context.generatedStamp} -->\n<!-- ${context.rebuildStamp} -->`;
31
+ const cleaned = text
32
+ .replace(/(<[/](?:a)>)([A-Za-z0-9$])/g, (_, tag, v) => `${tag} ${v}`)
33
+ .replace(/(<[uo]l>)(<li>)/g, (_, a, b) => `${a} ${b}`);
34
+ return `${brand}\n${cleaned}`;
35
+ },
36
+ br: async () => '<br><br>\n',
37
+ hr: async () => '<hr>\n',
38
+ strong: stdInline, em: stdInline,
39
+ h2: stdFull, h3: stdFull, h4: stdFull,
40
+ li: std, ol: stdFull, ul: stdFull,
41
+ table: stdFull, thead: std, tr: std, td: std, tbody: std,
42
+ Execution: async ({ context, el, props, createState }) => {
43
+ const output = await context.execute(el);
44
+ const displayCmd = props.config?.formatCommand?.(props.cmd, props.args ?? []) ??
45
+ `${el.props.cmd} ${(el.props.args ?? []).join(' ')}`;
46
+ const sub = createState('Terminal', {
47
+ language: 'bash',
48
+ title: props.title,
49
+ src: [`$ ${displayCmd}`, '', context.cleanText(output)].join('\n')
50
+ });
51
+ return Html.Terminal(sub);
52
+ },
53
+ Install: async ({ context, el }) => {
54
+ const highlighted = highlight(`
55
+ npm install ${el.props.pkg}
56
+
57
+ # or
58
+
59
+ yarn add ${el.props.pkg}
60
+ `, 'bash');
61
+
62
+ return `\n
63
+ <figure class="install">
64
+ <figcaption class="install">Install ${el.props.title}
65
+
66
+ </figcaption>
67
+ <pre><code class="language-bash">${highlighted}</code></pre>
68
+ </figure>\n\n
69
+ `;
70
+ },
71
+ Terminal: state => Html.Code(state),
72
+ Config: state => Html.Code(state),
73
+ Code: async ({ context, el, props }) => {
74
+ const cls = getComponentName(el.type).replace(/^[A-Z]/g, v => v.toLowerCase());
75
+ const content = await context.resolveCode(el);
76
+ let link: string = '';
77
+ if ('src' in props && content.file) {
78
+ let linkCtx: { file: string, line?: number } = { file: content.file! };
79
+ if (props.startRe) {
80
+ linkCtx = await DocResolveUtil.resolveCodeLink(linkCtx.file, props.startRe);
62
81
  }
63
- case 'table': {
64
- const out: string[] = [
65
- '<table>', '<thead>',
66
- `<tr>${c.headers.map(h => recurse(h)).map(h => `<th>${h}</th>`).join('')}</tr>`,
67
- '</thead>', '<tbody>',
68
- ...c.rows.map(row => `<tr>${row.map(r => `<td>${recurse(r)}</td>`).join('')}</tr>`),
69
- '</tbody>', '</table>'
70
- ];
71
- return out.join('\n');
82
+ link = `<cite><a target="_blank" href="${context.link(content.file!, linkCtx)}">Source</a></cite>`;
83
+ }
84
+ let lang = props.language ?? content.language;
85
+ if (!lang) {
86
+ if (el.type === c.Terminal) {
87
+ lang = 'bash';
88
+ } else if (el.type === c.Code) {
89
+ lang = 'typescript';
72
90
  }
73
- case 'header':
74
- return `<h1>${recurse(c.title)}
75
- ${c.description ? `<small>${recurse(c.description)}</small>\n` : ''}
76
- </h1>\n${('install' in c && c.install) ? recurse(n.Install(`Install ${c.package}`, c.package)) : ''}\n`;
77
- case 'text':
78
- return c.content;
79
91
  }
92
+
93
+ const highlighted = context.cleanText(highlight(content.text, lang));
94
+ return `\n
95
+ <figure class="${cls}">
96
+ <figcaption class="${cls}">${props.title}\n${link}\n\n</figcaption>
97
+ <pre><code class="language-${lang}">${highlighted}</code></pre>
98
+ </figure>\n\n`;
99
+ },
100
+
101
+ Section: async ({ context, recurse, props: { title } }) =>
102
+ `\n<h2 id="${context.getAnchorId(title)}">${title}</h2>\n\n${await recurse()}\n`,
103
+ SubSection: async ({ context, recurse, props: { title } }) =>
104
+ `\n<h3 id="${context.getAnchorId(title)}">${title}</h3>\n\n${await recurse()}\n`,
105
+ SubSubSection: async ({ context, recurse, props: { title } }) =>
106
+ `\n<h4 id="${context.getAnchorId(title)}">${title}</h4>\n\n${await recurse()}\n`,
107
+
108
+ Command: state => Html.Input(state),
109
+ Method: state => Html.Input(state),
110
+ Path: state => Html.Input(state),
111
+ Class: state => Html.Input(state),
112
+ Field: state => Html.Input(state),
113
+ Input: async ({ el, context }) => {
114
+ const cls = getComponentName(el.type).replace(/^[A-Z]/g, v => v.toLowerCase());
115
+ return `<code class="item ${cls}">${context.cleanText(el.props.name.replace(ENTITY_RE, k => ESCAPE_ENTITIES[k]))}</code>`;
116
+ },
117
+ CodeLink: async ({ context, props, el }) => {
118
+ const target = await context.resolveCodeLink(el);
119
+ return `<a target="_blank" class="source-link" href="${context.link(target.file, target)}">${props.title}</a>`;
120
+ },
121
+ Anchor: async ({ context, props }) =>
122
+ `<a class="anchor-link" routerLink="." fragment="${context.getAnchorId(props.href)}">${props.title}</a>`,
123
+
124
+ File: state => Html.Ref(state),
125
+ Ref: async ({ context, props }) =>
126
+ `<a target="_blank" class="source-link" href="${context.link(props.href, props)}">${props.title}</a>`,
127
+ Image: async ({ context, props }) => {
128
+ if (!/^https?:/.test(props.href) && !(await fs.stat(props.href).catch(() => false))) {
129
+ throw new Error(`${props.href} is not a valid location`);
130
+ }
131
+ return `<img src="${context.link(props.href, props)}" alt="${props.title}">`;
132
+ },
133
+
134
+ Mod: async ({ context, props }) => {
135
+ const cfg = MOD_MAPPING[props.name];
136
+ return `<a class="module-link" href="${context.link(cfg.folder, cfg)}" title="${cfg.description}">${cfg.displayName}</a>`;
137
+ },
138
+ Library: async ({ context, props }) => {
139
+ const cfg = LIB_MAPPING[props.name];
140
+ return `<a target="_blank" class="external-link" href="${context.link(cfg.href, cfg)}">${cfg.title}</a>`;
141
+ },
142
+
143
+ Note: async ({ recurse }) => `\n\n<p class="note"><strong>Note</strong> ${await recurse()}</p>\n`,
144
+ Header: async ({ props }) => `<h1>${props.title} ${props.description ? `\n<small>${props.description}</small>\n` : ''}</h1>\n`,
145
+
146
+ StdHeader: async state => {
147
+ const mod = state.el.props.mod ?? RootIndex.mainPackage.name;
148
+ const pkg = PackageUtil.readPackage(RootIndex.getModule(mod)!.sourcePath);
149
+ const title = pkg.travetto?.displayName ?? pkg.name;
150
+ const desc = pkg.description;
151
+ let install = '';
152
+ if (state.el.props.install !== false) {
153
+ const sub = state.createState('Install', {
154
+ title: pkg.name,
155
+ pkg: pkg.name,
156
+ });
157
+ install = await Html.Install(sub);
158
+ }
159
+ return `<h1>${title}${desc ? `\n<small>${desc}</small>\n` : ''}</h1>\n${install}\n`;
80
160
  }
81
- };
161
+ };