@travetto/doc 5.0.0-rc.7 → 5.0.0-rc.9
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/package.json +3 -3
- package/src/jsx.ts +4 -4
- package/src/render/code-highlight.ts +9 -9
- package/src/render/context.ts +2 -2
- package/src/render/renderer.ts +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/doc",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.9",
|
|
4
4
|
"description": "Documentation support for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"directory": "module/doc"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@travetto/runtime": "^5.0.0-rc.
|
|
27
|
+
"@travetto/runtime": "^5.0.0-rc.9",
|
|
28
28
|
"@types/prismjs": "^1.26.4",
|
|
29
29
|
"prismjs": "^1.29.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@travetto/cli": "^5.0.0-rc.
|
|
32
|
+
"@travetto/cli": "^5.0.0-rc.9"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|
|
35
35
|
"@travetto/cli": {
|
package/src/jsx.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createElement, JSXElement, JSXComponentFunction as CompFn } from '@travetto/doc/jsx-runtime';
|
|
2
|
-
import { TypedObject } from '@travetto/runtime';
|
|
2
|
+
import { castTo, TypedObject } from '@travetto/runtime';
|
|
3
3
|
|
|
4
4
|
import { LIB_MAPPING } from './mapping/lib-mapping';
|
|
5
5
|
import { MOD_MAPPING } from './mapping/mod-mapping';
|
|
@@ -65,7 +65,7 @@ export type JSXElements = { [K in keyof C]: JSXElementByFn<K>; };
|
|
|
65
65
|
|
|
66
66
|
export const EMPTY_ELEMENT = EMPTY;
|
|
67
67
|
|
|
68
|
-
const invertedC = new Map<Function, string>(TypedObject.entries(c).map(p => [p[1], p[0]]
|
|
68
|
+
const invertedC = new Map<Function, string>(TypedObject.entries(c).map<[Function, string]>(p => [p[1], p[0]]));
|
|
69
69
|
|
|
70
70
|
export function getComponentName(fn: Function | string): string {
|
|
71
71
|
if (typeof fn === 'string') {
|
|
@@ -81,7 +81,7 @@ function CodeLinker(titleOrNode: string | JSXElement, src?: string, startRe?: Re
|
|
|
81
81
|
if (typeof titleOrNode === 'string') {
|
|
82
82
|
props = { title: titleOrNode, src: src!, startRe: startRe! };
|
|
83
83
|
} else if (titleOrNode.type === Code) {
|
|
84
|
-
const node
|
|
84
|
+
const node: JSXElementByFn<'Code'> = castTo(titleOrNode);
|
|
85
85
|
props = {
|
|
86
86
|
title: node.props.title,
|
|
87
87
|
src: node.props.src,
|
|
@@ -90,7 +90,7 @@ function CodeLinker(titleOrNode: string | JSXElement, src?: string, startRe?: Re
|
|
|
90
90
|
} else {
|
|
91
91
|
throw new Error(`Unsupported element type: ${titleOrNode.type}`);
|
|
92
92
|
}
|
|
93
|
-
return createElement(c.CodeLink, props)
|
|
93
|
+
return createElement(c.CodeLink, props);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export const d = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { default as
|
|
1
|
+
import { default as prismJs } from 'prismjs';
|
|
2
2
|
|
|
3
3
|
import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.js';
|
|
4
4
|
import 'prismjs/components/prism-typescript.js';
|
|
@@ -12,20 +12,20 @@ import 'prismjs/components/prism-sql.js';
|
|
|
12
12
|
import 'prismjs/components/prism-properties.js';
|
|
13
13
|
import 'prismjs/components/prism-bash.js';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
prismJs.plugins.NormalizeWhitespace.setDefaults({
|
|
16
16
|
'remove-trailing': true,
|
|
17
17
|
'remove-indent': true,
|
|
18
18
|
'left-trim': true,
|
|
19
19
|
'right-trim': true
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
const nw =
|
|
22
|
+
const nw = prismJs.plugins.NormalizeWhitespace;
|
|
23
23
|
|
|
24
24
|
const tokenMapping: { [key: string]: string } = {
|
|
25
|
-
gt: '>',
|
|
26
|
-
lt: '<',
|
|
27
|
-
quot: '"',
|
|
28
|
-
apos: "'"
|
|
25
|
+
'>': '>',
|
|
26
|
+
'<': '<',
|
|
27
|
+
'"': '"',
|
|
28
|
+
''': "'"
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export function highlight(text: string, lang: string): string | undefined {
|
|
@@ -35,10 +35,10 @@ export function highlight(text: string, lang: string): string | undefined {
|
|
|
35
35
|
|
|
36
36
|
text = text
|
|
37
37
|
.replace(/&#(\d+);/g, (x, code) => String.fromCharCode(code))
|
|
38
|
-
.replace(/&
|
|
38
|
+
.replace(/&[a-z][^;]*;/g, a => tokenMapping[a] || a);
|
|
39
39
|
|
|
40
40
|
try {
|
|
41
|
-
return
|
|
41
|
+
return prismJs.highlight(text, prismJs.languages[lang], lang)
|
|
42
42
|
.replace(/(@\s*<span[^>]*)function("\s*>)/g, (a, pre, post) => `${pre}meta${post}`)
|
|
43
43
|
.replace(/[{}]/g, a => `{{'${a}'}}`);
|
|
44
44
|
} catch (err) {
|
package/src/render/context.ts
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { createElement, JSXRuntimeTag } from '@travetto/doc/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
import { PackageUtil } from '@travetto/manifest';
|
|
6
|
-
import { RuntimeIndex } from '@travetto/runtime';
|
|
6
|
+
import { castTo, RuntimeIndex } from '@travetto/runtime';
|
|
7
7
|
|
|
8
8
|
import { JSXElementByFn, c } from '../jsx';
|
|
9
9
|
import { DocResolveUtil, ResolvedCode, ResolvedRef, ResolvedSnippetLink } from '../util/resolve';
|
|
@@ -125,6 +125,6 @@ export class RenderContext {
|
|
|
125
125
|
*/
|
|
126
126
|
createElement<K extends keyof typeof c>(name: K, props: JSXElementByFn<K>['props']): JSXElementByFn<K> {
|
|
127
127
|
// @ts-expect-error
|
|
128
|
-
return createElement(c[name], props)
|
|
128
|
+
return castTo(createElement(c[name], props));
|
|
129
129
|
}
|
|
130
130
|
}
|
package/src/render/renderer.ts
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
|
|
3
3
|
import { type ManifestContext, PackageUtil } from '@travetto/manifest';
|
|
4
4
|
import { isJSXElement, JSXElement, JSXFragmentType } from '@travetto/doc/jsx-runtime';
|
|
5
|
-
import { Runtime } from '@travetto/runtime';
|
|
5
|
+
import { castTo, Runtime } from '@travetto/runtime';
|
|
6
6
|
|
|
7
7
|
import { EMPTY_ELEMENT, getComponentName, JSXElementByFn, c } from '../jsx';
|
|
8
8
|
import { DocumentShape, RenderProvider, RenderState } from '../types';
|
|
@@ -55,8 +55,7 @@ export class DocRenderer {
|
|
|
55
55
|
let final: JSXElement = node;
|
|
56
56
|
// Render simple element if needed
|
|
57
57
|
if (typeof node.type === 'function' && node.type !== JSXFragmentType) {
|
|
58
|
-
|
|
59
|
-
const out = node.type(node.props);
|
|
58
|
+
const out = castTo<Function>(node.type)(node.props);
|
|
60
59
|
final = out !== EMPTY_ELEMENT ? out : final;
|
|
61
60
|
}
|
|
62
61
|
|