@open-agent-toolkit/docs-transforms 0.0.10 → 0.0.18
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/remark-links.d.ts +7 -5
- package/dist/remark-links.d.ts.map +1 -1
- package/dist/remark-links.js +58 -16
- package/package.json +15 -15
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thomas Stang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -29,3 +29,8 @@ export const customRemarkPlugins = [remarkLinks, remarkTabs, remarkMermaid];
|
|
|
29
29
|
- `remarkLinks`
|
|
30
30
|
- `remarkMermaid`
|
|
31
31
|
- `remarkTabs`
|
|
32
|
+
|
|
33
|
+
## Docs
|
|
34
|
+
|
|
35
|
+
- [Docs Tooling](https://voxmedia.github.io/open-agent-toolkit/docs-tooling)
|
|
36
|
+
- [Repository](https://github.com/voxmedia/open-agent-toolkit)
|
package/dist/remark-links.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Root } from 'mdast';
|
|
2
2
|
import type { Plugin } from 'unified';
|
|
3
3
|
/**
|
|
4
|
-
* Remark plugin that rewrites relative
|
|
5
|
-
*
|
|
4
|
+
* Remark plugin that rewrites source-relative markdown links to routed,
|
|
5
|
+
* extensionless URLs that still work once pages are emitted with trailing
|
|
6
|
+
* slashes.
|
|
6
7
|
*
|
|
7
8
|
* URL rewriting:
|
|
8
|
-
* - `quickstart.md` → `./quickstart`
|
|
9
|
-
* - `
|
|
10
|
-
*
|
|
9
|
+
* - `quickstart.md` from `docs/index.md` → `./quickstart`
|
|
10
|
+
* - `documentation/commands.md` from `docs/guide/cli-reference.md`
|
|
11
|
+
* → `../documentation/commands`
|
|
12
|
+
* - `../reference/index.md` from `docs/guide/concepts.md` → `../../reference`
|
|
11
13
|
* - Absolute URLs and anchors are left unchanged.
|
|
12
14
|
*
|
|
13
15
|
* Display text cleanup:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-links.d.ts","sourceRoot":"","sources":["../src/remark-links.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remark-links.d.ts","sourceRoot":"","sources":["../src/remark-links.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,IAAI,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAmEtC;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,CAyCxC,CAAC"}
|
package/dist/remark-links.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
import { posix as path } from 'node:path';
|
|
1
2
|
import { visit } from 'unist-util-visit';
|
|
2
3
|
/**
|
|
3
|
-
* Strip
|
|
4
|
-
* Returns null if the path is not a
|
|
4
|
+
* Strip markdown extension and collapse `/index` from a relative path.
|
|
5
|
+
* Returns null if the path is not a markdown link that should be rewritten.
|
|
5
6
|
*/
|
|
6
7
|
function cleanMdPath(raw) {
|
|
7
|
-
|
|
8
|
+
const extension = raw.endsWith('.mdx')
|
|
9
|
+
? '.mdx'
|
|
10
|
+
: raw.endsWith('.md')
|
|
11
|
+
? '.md'
|
|
12
|
+
: null;
|
|
13
|
+
if (!extension)
|
|
8
14
|
return null;
|
|
9
|
-
let cleaned = raw.slice(0, -
|
|
15
|
+
let cleaned = raw.slice(0, -extension.length);
|
|
10
16
|
if (cleaned.endsWith('/index')) {
|
|
11
17
|
cleaned = cleaned.slice(0, -'/index'.length) || '.';
|
|
12
18
|
}
|
|
@@ -15,14 +21,49 @@ function cleanMdPath(raw) {
|
|
|
15
21
|
}
|
|
16
22
|
return cleaned;
|
|
17
23
|
}
|
|
24
|
+
function normalizeFsPath(raw) {
|
|
25
|
+
return raw.replaceAll('\\', '/');
|
|
26
|
+
}
|
|
27
|
+
function docsRelativeFilePath(filePath) {
|
|
28
|
+
const normalized = normalizeFsPath(filePath);
|
|
29
|
+
const marker = '/docs/';
|
|
30
|
+
const index = normalized.lastIndexOf(marker);
|
|
31
|
+
if (index === -1)
|
|
32
|
+
return null;
|
|
33
|
+
return normalized.slice(index + marker.length);
|
|
34
|
+
}
|
|
35
|
+
function routePathFromDocsFile(filePath) {
|
|
36
|
+
const cleaned = cleanMdPath(filePath);
|
|
37
|
+
if (cleaned === null)
|
|
38
|
+
return null;
|
|
39
|
+
if (cleaned === '.')
|
|
40
|
+
return '/';
|
|
41
|
+
return path.normalize(`/${cleaned}`);
|
|
42
|
+
}
|
|
43
|
+
function resolveRelativeDocsLink(sourceFilePath, targetPath) {
|
|
44
|
+
const sourceDocsFile = docsRelativeFilePath(sourceFilePath);
|
|
45
|
+
if (!sourceDocsFile)
|
|
46
|
+
return null;
|
|
47
|
+
const targetDocsFile = path
|
|
48
|
+
.normalize(path.join('/', path.dirname(sourceDocsFile), targetPath))
|
|
49
|
+
.slice(1);
|
|
50
|
+
const currentRoute = routePathFromDocsFile(sourceDocsFile);
|
|
51
|
+
const targetRoute = routePathFromDocsFile(targetDocsFile);
|
|
52
|
+
if (!currentRoute || !targetRoute)
|
|
53
|
+
return null;
|
|
54
|
+
const relativeRoute = path.relative(currentRoute, targetRoute) || '.';
|
|
55
|
+
return relativeRoute.startsWith('.') ? relativeRoute : `./${relativeRoute}`;
|
|
56
|
+
}
|
|
18
57
|
/**
|
|
19
|
-
* Remark plugin that rewrites relative
|
|
20
|
-
*
|
|
58
|
+
* Remark plugin that rewrites source-relative markdown links to routed,
|
|
59
|
+
* extensionless URLs that still work once pages are emitted with trailing
|
|
60
|
+
* slashes.
|
|
21
61
|
*
|
|
22
62
|
* URL rewriting:
|
|
23
|
-
* - `quickstart.md` → `./quickstart`
|
|
24
|
-
* - `
|
|
25
|
-
*
|
|
63
|
+
* - `quickstart.md` from `docs/index.md` → `./quickstart`
|
|
64
|
+
* - `documentation/commands.md` from `docs/guide/cli-reference.md`
|
|
65
|
+
* → `../documentation/commands`
|
|
66
|
+
* - `../reference/index.md` from `docs/guide/concepts.md` → `../../reference`
|
|
26
67
|
* - Absolute URLs and anchors are left unchanged.
|
|
27
68
|
*
|
|
28
69
|
* Display text cleanup:
|
|
@@ -32,7 +73,7 @@ function cleanMdPath(raw) {
|
|
|
32
73
|
* while rendering clean labels on the web.
|
|
33
74
|
*/
|
|
34
75
|
export const remarkLinks = function remarkLinks() {
|
|
35
|
-
return (tree) => {
|
|
76
|
+
return (tree, file) => {
|
|
36
77
|
visit(tree, 'link', (node) => {
|
|
37
78
|
const { url } = node;
|
|
38
79
|
// Skip absolute URLs, protocol links, and pure anchors
|
|
@@ -46,13 +87,14 @@ export const remarkLinks = function remarkLinks() {
|
|
|
46
87
|
const cleaned = cleanMdPath(path);
|
|
47
88
|
if (cleaned === null)
|
|
48
89
|
return;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const adjusted = cleaned.startsWith('..') ? `../${cleaned}` : cleaned;
|
|
90
|
+
const rewrittenPath = typeof file?.path === 'string'
|
|
91
|
+
? (resolveRelativeDocsLink(file.path, path) ?? cleaned)
|
|
92
|
+
: cleaned;
|
|
53
93
|
// Rewrite URL
|
|
54
|
-
const prefix =
|
|
55
|
-
|
|
94
|
+
const prefix = rewrittenPath.startsWith('.') || rewrittenPath.startsWith('/')
|
|
95
|
+
? ''
|
|
96
|
+
: './';
|
|
97
|
+
node.url = prefix + rewrittenPath + fragment;
|
|
56
98
|
// Clean display text when it's a single inlineCode child with a .md path
|
|
57
99
|
const firstChild = node.children[0];
|
|
58
100
|
if (node.children.length === 1 && firstChild?.type === 'inlineCode') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-agent-toolkit/docs-transforms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Remark/unified transforms for OAT documentation",
|
|
6
6
|
"homepage": "https://github.com/voxmedia/open-agent-toolkit/tree/main/packages/docs-transforms",
|
|
@@ -29,19 +29,6 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"build": "tsc",
|
|
34
|
-
"clean": "rm -rf dist",
|
|
35
|
-
"check": "oxlint . && oxfmt --check .",
|
|
36
|
-
"check:fix": "oxlint --fix . && oxfmt .",
|
|
37
|
-
"format": "oxfmt --check .",
|
|
38
|
-
"format:fix": "oxfmt .",
|
|
39
|
-
"lint": "oxlint .",
|
|
40
|
-
"lint:fix": "oxlint --fix .",
|
|
41
|
-
"test": "vitest run",
|
|
42
|
-
"test:watch": "vitest",
|
|
43
|
-
"type-check": "tsc --noEmit"
|
|
44
|
-
},
|
|
45
32
|
"dependencies": {
|
|
46
33
|
"remark-parse": "^11.0.0",
|
|
47
34
|
"unified": "^11.0.5",
|
|
@@ -55,5 +42,18 @@
|
|
|
55
42
|
},
|
|
56
43
|
"engines": {
|
|
57
44
|
"node": ">=22.17.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"clean": "rm -rf dist",
|
|
49
|
+
"check": "oxlint . && oxfmt --check .",
|
|
50
|
+
"check:fix": "oxlint --fix . && oxfmt .",
|
|
51
|
+
"format": "oxfmt --check .",
|
|
52
|
+
"format:fix": "oxfmt .",
|
|
53
|
+
"lint": "oxlint .",
|
|
54
|
+
"lint:fix": "oxlint --fix .",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"test:watch": "vitest",
|
|
57
|
+
"type-check": "tsc --noEmit"
|
|
58
58
|
}
|
|
59
|
-
}
|
|
59
|
+
}
|