@vibe-agent-toolkit/resources 0.1.39-rc.1 → 0.1.39-rc.2
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/dist/frontmatter-link-validator.d.ts +4 -4
- package/dist/frontmatter-link-validator.d.ts.map +1 -1
- package/dist/frontmatter-link-validator.js +3 -3
- package/dist/frontmatter-link-validator.js.map +1 -1
- package/dist/html-link-parser.d.ts +47 -0
- package/dist/html-link-parser.d.ts.map +1 -0
- package/dist/html-link-parser.js +111 -0
- package/dist/html-link-parser.js.map +1 -0
- package/dist/html-transform.d.ts +45 -0
- package/dist/html-transform.d.ts.map +1 -0
- package/dist/html-transform.js +116 -0
- package/dist/html-transform.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/link-parser.d.ts +26 -2
- package/dist/link-parser.d.ts.map +1 -1
- package/dist/link-parser.js +28 -1
- package/dist/link-parser.js.map +1 -1
- package/dist/link-validator.d.ts +50 -3
- package/dist/link-validator.d.ts.map +1 -1
- package/dist/link-validator.js +72 -55
- package/dist/link-validator.js.map +1 -1
- package/dist/resource-registry.d.ts +46 -11
- package/dist/resource-registry.d.ts.map +1 -1
- package/dist/resource-registry.js +140 -34
- package/dist/resource-registry.js.map +1 -1
- package/dist/schemas/link-auth.d.ts +382 -0
- package/dist/schemas/link-auth.d.ts.map +1 -0
- package/dist/schemas/link-auth.js +124 -0
- package/dist/schemas/link-auth.js.map +1 -0
- package/dist/schemas/project-config.d.ts +642 -98
- package/dist/schemas/project-config.d.ts.map +1 -1
- package/dist/schemas/project-config.js +3 -0
- package/dist/schemas/project-config.js.map +1 -1
- package/dist/schemas/resource-metadata.d.ts +46 -10
- package/dist/schemas/resource-metadata.d.ts.map +1 -1
- package/dist/schemas/resource-metadata.js +14 -1
- package/dist/schemas/resource-metadata.js.map +1 -1
- package/package.json +4 -3
- package/src/frontmatter-link-validator.ts +5 -5
- package/src/html-link-parser.ts +140 -0
- package/src/html-transform.ts +157 -0
- package/src/index.ts +6 -1
- package/src/link-parser.ts +35 -2
- package/src/link-validator.ts +102 -82
- package/src/resource-registry.ts +157 -39
- package/src/schemas/link-auth.ts +146 -0
- package/src/schemas/project-config.ts +4 -0
- package/src/schemas/resource-metadata.ts +17 -1
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
* email (mailto:)
|
|
18
18
|
* anchor-only (validated as anchor in current file via validateLink)
|
|
19
19
|
*/
|
|
20
|
-
import { type ValidateLinkOptions } from './link-validator.js';
|
|
21
|
-
import type {
|
|
20
|
+
import { type FragmentIndex, type ValidateLinkOptions } from './link-validator.js';
|
|
21
|
+
import type { ValidationIssue } from './types.js';
|
|
22
22
|
/** A frontmatter-sourced external URL captured for downstream health checking. */
|
|
23
23
|
export interface FrontmatterExternalUrl {
|
|
24
24
|
url: string;
|
|
@@ -35,8 +35,8 @@ export interface FrontmatterLinkValidationResult {
|
|
|
35
35
|
* @param frontmatter - Parsed frontmatter (or undefined)
|
|
36
36
|
* @param schema - JSON Schema for the collection
|
|
37
37
|
* @param sourceFilePath - Absolute path to the source file
|
|
38
|
-
* @param
|
|
38
|
+
* @param fragmentsByFile - Fragment index (file path → set of valid fragments) for anchor validation
|
|
39
39
|
* @param options - Same shape as validateLink (projectRoot, gitTracker, ...)
|
|
40
40
|
*/
|
|
41
|
-
export declare function validateFrontmatterLinks(frontmatter: Record<string, unknown> | undefined, schema: object, sourceFilePath: string,
|
|
41
|
+
export declare function validateFrontmatterLinks(frontmatter: Record<string, unknown> | undefined, schema: object, sourceFilePath: string, fragmentsByFile: FragmentIndex, options?: ValidateLinkOptions): Promise<FrontmatterLinkValidationResult>;
|
|
42
42
|
//# sourceMappingURL=frontmatter-link-validator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter-link-validator.d.ts","sourceRoot":"","sources":["../src/frontmatter-link-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"frontmatter-link-validator.d.ts","sourceRoot":"","sources":["../src/frontmatter-link-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEjG,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,YAAY,CAAC;AAUhE,kFAAkF;AAClF,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,YAAY,EAAE,sBAAsB,EAAE,CAAC;CACxC;AAED;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAChD,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,aAAa,EAC9B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,+BAA+B,CAAC,CAoC1C"}
|
|
@@ -34,10 +34,10 @@ const LINK_CODE_TO_FRONTMATTER_CODE = {
|
|
|
34
34
|
* @param frontmatter - Parsed frontmatter (or undefined)
|
|
35
35
|
* @param schema - JSON Schema for the collection
|
|
36
36
|
* @param sourceFilePath - Absolute path to the source file
|
|
37
|
-
* @param
|
|
37
|
+
* @param fragmentsByFile - Fragment index (file path → set of valid fragments) for anchor validation
|
|
38
38
|
* @param options - Same shape as validateLink (projectRoot, gitTracker, ...)
|
|
39
39
|
*/
|
|
40
|
-
export async function validateFrontmatterLinks(frontmatter, schema, sourceFilePath,
|
|
40
|
+
export async function validateFrontmatterLinks(frontmatter, schema, sourceFilePath, fragmentsByFile, options) {
|
|
41
41
|
if (!frontmatter)
|
|
42
42
|
return { issues: [], externalUrls: [] };
|
|
43
43
|
const captures = walkFrontmatterUriReferences(frontmatter, schema);
|
|
@@ -63,7 +63,7 @@ export async function validateFrontmatterLinks(frontmatter, schema, sourceFilePa
|
|
|
63
63
|
type: linkType,
|
|
64
64
|
line: 1, // Frontmatter per-field line numbers are post-v1.
|
|
65
65
|
};
|
|
66
|
-
const issue = await validateLink(syntheticLink, sourceFilePath,
|
|
66
|
+
const issue = await validateLink(syntheticLink, sourceFilePath, fragmentsByFile, options);
|
|
67
67
|
if (!issue)
|
|
68
68
|
continue;
|
|
69
69
|
issues.push(rewriteIssue(issue, capture.dottedPath));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter-link-validator.js","sourceRoot":"","sources":["../src/frontmatter-link-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,mBAAmB,EAAkB,MAAM,kCAAkC,CAAC;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"frontmatter-link-validator.js","sourceRoot":"","sources":["../src/frontmatter-link-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,mBAAmB,EAAkB,MAAM,kCAAkC,CAAC;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAgD,MAAM,qBAAqB,CAAC;AACjG,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAGtE,sFAAsF;AACtF,MAAM,6BAA6B,GAA0C;IAC3E,gBAAgB,EAAE,yBAAyB;IAC3C,kBAAkB,EAAE,4BAA4B;IAChD,kBAAkB,EAAE,gCAA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AI,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,YAAY,CAAC,KAAsB,EAAE,UAAkB;IAC9D,MAAM,UAAU,GAAG,6BAA6B,CAAC,KAAK,CAAC,IAAiB,CAAC,IAAK,KAAK,CAAC,IAAkB,CAAC;IACvG,MAAM,OAAO,GAAG,WAAW,UAAU,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IAC5D,MAAM,MAAM,GAAgF,EAAE,CAAC;IAC/F,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS;QAAE,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;IACnE,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACvD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACvD,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;QAAE,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IACzE,OAAO,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML resource parser.
|
|
3
|
+
*
|
|
4
|
+
* Parses local HTML files into the shared `ParseResult` shape:
|
|
5
|
+
* - `<a href>` and `<img src>` links (classified by `classifyLink`)
|
|
6
|
+
* - `id` / `name` attributes as fragment anchors
|
|
7
|
+
* - well-formedness diagnostics from parse5's `onParseError`
|
|
8
|
+
*
|
|
9
|
+
* Uses parse5 (WHATWG-conformant). The parse5 document + element walker are
|
|
10
|
+
* exported so the link rewriter (html-transform.ts) shares one parser path.
|
|
11
|
+
*
|
|
12
|
+
* Non-goal: `<base href>` is not honored — relative links are resolved against
|
|
13
|
+
* the file's own directory, not a document base.
|
|
14
|
+
*/
|
|
15
|
+
import { type DefaultTreeAdapterMap } from 'parse5';
|
|
16
|
+
import { type ParseResult } from './link-parser.js';
|
|
17
|
+
import type { HtmlParseError } from './schemas/resource-metadata.js';
|
|
18
|
+
type P5Node = DefaultTreeAdapterMap['node'];
|
|
19
|
+
type P5Element = DefaultTreeAdapterMap['element'];
|
|
20
|
+
/** A parsed parse5 document together with any well-formedness diagnostics. */
|
|
21
|
+
export interface HtmlDocument {
|
|
22
|
+
document: DefaultTreeAdapterMap['document'];
|
|
23
|
+
parseErrors: HtmlParseError[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse an HTML source string with source-location info and collect parser
|
|
27
|
+
* errors. Shared by `parseHtml` (link/anchor extraction) and `rewriteHtmlLinks`
|
|
28
|
+
* (attribute offset splicing).
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseHtmlDocument(source: string): HtmlDocument;
|
|
31
|
+
/**
|
|
32
|
+
* Depth-first walk yielding every element node in the tree.
|
|
33
|
+
*
|
|
34
|
+
* Deliberate gap: a `<template>` element's content lives in its separate
|
|
35
|
+
* `content` fragment (not `childNodes`), so links inside `<template>` are not
|
|
36
|
+
* walked, and foreign-content (SVG/MathML) subtrees are not special-cased.
|
|
37
|
+
* Both are rare in the content link graph we rewrite.
|
|
38
|
+
*/
|
|
39
|
+
export declare function walkElements(node: P5Node): Generator<P5Element>;
|
|
40
|
+
/**
|
|
41
|
+
* Parse an HTML file into a `ParseResult`.
|
|
42
|
+
*
|
|
43
|
+
* @param filePath - Absolute path to the HTML file.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseHtml(filePath: string): Promise<ParseResult>;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=html-link-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-link-parser.d.ts","sourceRoot":"","sources":["../src/html-link-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAS,KAAK,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAE3D,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGrE,KAAK,MAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC5C,KAAK,SAAS,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAGlD,8EAA8E;AAC9E,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAC5C,WAAW,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAW9D;AAED;;;;;;;GAOG;AACH,wBAAiB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,CAShE;AAuCD;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CA2BtE"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML resource parser.
|
|
3
|
+
*
|
|
4
|
+
* Parses local HTML files into the shared `ParseResult` shape:
|
|
5
|
+
* - `<a href>` and `<img src>` links (classified by `classifyLink`)
|
|
6
|
+
* - `id` / `name` attributes as fragment anchors
|
|
7
|
+
* - well-formedness diagnostics from parse5's `onParseError`
|
|
8
|
+
*
|
|
9
|
+
* Uses parse5 (WHATWG-conformant). The parse5 document + element walker are
|
|
10
|
+
* exported so the link rewriter (html-transform.ts) shares one parser path.
|
|
11
|
+
*
|
|
12
|
+
* Non-goal: `<base href>` is not honored — relative links are resolved against
|
|
13
|
+
* the file's own directory, not a document base.
|
|
14
|
+
*/
|
|
15
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
16
|
+
import { parse } from 'parse5';
|
|
17
|
+
import { classifyLink } from './link-parser.js';
|
|
18
|
+
/**
|
|
19
|
+
* Parse an HTML source string with source-location info and collect parser
|
|
20
|
+
* errors. Shared by `parseHtml` (link/anchor extraction) and `rewriteHtmlLinks`
|
|
21
|
+
* (attribute offset splicing).
|
|
22
|
+
*/
|
|
23
|
+
export function parseHtmlDocument(source) {
|
|
24
|
+
const parseErrors = [];
|
|
25
|
+
const document = parse(source, {
|
|
26
|
+
sourceCodeLocationInfo: true,
|
|
27
|
+
onParseError: (err) => {
|
|
28
|
+
// parse5's ParserError extends Location which always has startLine: number.
|
|
29
|
+
// We always include line since it is always present.
|
|
30
|
+
parseErrors.push({ message: err.code, line: err.startLine });
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return { document, parseErrors };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Depth-first walk yielding every element node in the tree.
|
|
37
|
+
*
|
|
38
|
+
* Deliberate gap: a `<template>` element's content lives in its separate
|
|
39
|
+
* `content` fragment (not `childNodes`), so links inside `<template>` are not
|
|
40
|
+
* walked, and foreign-content (SVG/MathML) subtrees are not special-cased.
|
|
41
|
+
* Both are rare in the content link graph we rewrite.
|
|
42
|
+
*/
|
|
43
|
+
export function* walkElements(node) {
|
|
44
|
+
if ('tagName' in node) {
|
|
45
|
+
yield node;
|
|
46
|
+
}
|
|
47
|
+
if ('childNodes' in node) {
|
|
48
|
+
for (const child of node.childNodes) {
|
|
49
|
+
yield* walkElements(child);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function getAttr(element, name) {
|
|
54
|
+
return element.attrs.find((a) => a.name === name)?.value;
|
|
55
|
+
}
|
|
56
|
+
function makeLink(href, line) {
|
|
57
|
+
return { text: '', href, type: classifyLink(href), ...(line !== undefined && { line }) };
|
|
58
|
+
}
|
|
59
|
+
function visitElement(element, links, anchors) {
|
|
60
|
+
const line = element.sourceCodeLocation?.startLine;
|
|
61
|
+
if (element.tagName === 'a') {
|
|
62
|
+
const href = getAttr(element, 'href');
|
|
63
|
+
if (href !== undefined) {
|
|
64
|
+
links.push(makeLink(href, line));
|
|
65
|
+
}
|
|
66
|
+
const name = getAttr(element, 'name');
|
|
67
|
+
if (name !== undefined && name !== '') {
|
|
68
|
+
anchors.add(name);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (element.tagName === 'img') {
|
|
72
|
+
const src = getAttr(element, 'src');
|
|
73
|
+
if (src !== undefined) {
|
|
74
|
+
links.push(makeLink(src, line));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const id = getAttr(element, 'id');
|
|
78
|
+
if (id !== undefined && id !== '') {
|
|
79
|
+
anchors.add(id);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Parse an HTML file into a `ParseResult`.
|
|
84
|
+
*
|
|
85
|
+
* @param filePath - Absolute path to the HTML file.
|
|
86
|
+
*/
|
|
87
|
+
export async function parseHtml(filePath) {
|
|
88
|
+
const [content, stats] = await Promise.all([
|
|
89
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- filePath is a user-provided path parameter
|
|
90
|
+
readFile(filePath, 'utf-8'),
|
|
91
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- filePath is a user-provided path parameter
|
|
92
|
+
stat(filePath),
|
|
93
|
+
]);
|
|
94
|
+
const { document, parseErrors } = parseHtmlDocument(content);
|
|
95
|
+
const links = [];
|
|
96
|
+
const anchors = new Set();
|
|
97
|
+
for (const element of walkElements(document)) {
|
|
98
|
+
visitElement(element, links, anchors);
|
|
99
|
+
}
|
|
100
|
+
const anchorList = [...anchors];
|
|
101
|
+
return {
|
|
102
|
+
links,
|
|
103
|
+
headings: [],
|
|
104
|
+
content,
|
|
105
|
+
sizeBytes: stats.size,
|
|
106
|
+
estimatedTokenCount: Math.ceil(content.length / 4),
|
|
107
|
+
...(anchorList.length > 0 && { anchors: anchorList }),
|
|
108
|
+
...(parseErrors.length > 0 && { parseErrors }),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=html-link-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-link-parser.js","sourceRoot":"","sources":["../src/html-link-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,KAAK,EAA8B,MAAM,QAAQ,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAoB,MAAM,kBAAkB,CAAC;AAclE;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,WAAW,GAAqB,EAAE,CAAC;IACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE;QAC7B,sBAAsB,EAAE,IAAI;QAC5B,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE;YACpB,4EAA4E;YAC5E,qDAAqD;YACrD,WAAW,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;QAC/D,CAAC;KACF,CAAC,CAAC;IACH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACnC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,YAAY,CAAC,IAAY;IACxC,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,MAAM,IAAI,CAAC;IACb,CAAC;IACD,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAA2B,EAAE,CAAC;YACrD,KAAK,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CA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
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structure-preserving HTML link rewriter.
|
|
3
|
+
*
|
|
4
|
+
* Rewrites `<a href>` and `<img src>` attribute VALUES in place by splicing the
|
|
5
|
+
* original source string at parse5-reported offsets. The document is never
|
|
6
|
+
* re-serialized (parse5's serializer normalizes whitespace, quotes, void
|
|
7
|
+
* elements, and the doctype), so unchanged input round-trips byte-for-byte.
|
|
8
|
+
*
|
|
9
|
+
* Uses the same `RewriteHref` callback model as `rewriteBodyLinks` — callers
|
|
10
|
+
* supply per-href target resolution; this module owns only the splice mechanics.
|
|
11
|
+
*
|
|
12
|
+
* Non-goal: `<base href>` is not honored. Relative hrefs are resolved by the
|
|
13
|
+
* caller against the file's own directory; a `<base>` element that would
|
|
14
|
+
* override that in a browser is ignored.
|
|
15
|
+
*/
|
|
16
|
+
import type { RewriteHref } from './rewriter-helpers.js';
|
|
17
|
+
/** A wanted link rewrite that could not be spliced back into the source. */
|
|
18
|
+
export interface UnappliedRewrite {
|
|
19
|
+
tagName: string;
|
|
20
|
+
attr: string;
|
|
21
|
+
/** The original attribute value the rewrite targeted. */
|
|
22
|
+
from: string;
|
|
23
|
+
/** The value the rewrite wanted to write. */
|
|
24
|
+
to: string;
|
|
25
|
+
/**
|
|
26
|
+
* Why the splice could not be located:
|
|
27
|
+
* - `no-source-location` — parse5 omitted the attribute's offsets (synthesized
|
|
28
|
+
* during error recovery on malformed input).
|
|
29
|
+
* - `unparseable-attribute` — the attribute's source span had no locatable
|
|
30
|
+
* value (e.g. an unterminated quote).
|
|
31
|
+
*/
|
|
32
|
+
reason: 'no-source-location' | 'unparseable-attribute';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Rewrite `<a href>` / `<img src>` values in `source` using `rewriteHref`.
|
|
36
|
+
* Returns `source` unchanged (byte-for-byte) when no value changes.
|
|
37
|
+
*
|
|
38
|
+
* A rewrite that is wanted (the href resolves to a new value) but cannot be
|
|
39
|
+
* spliced back — because parse5 omitted the source location or the attribute
|
|
40
|
+
* span is unparseable — is reported via `onUnapplied` rather than dropped
|
|
41
|
+
* silently. Malformed pages are exactly the ones that hit this path, so the
|
|
42
|
+
* caller can surface it instead of shipping a stale link.
|
|
43
|
+
*/
|
|
44
|
+
export declare function rewriteHtmlLinks(source: string, rewriteHref: RewriteHref, onUnapplied?: (info: UnappliedRewrite) => void): string;
|
|
45
|
+
//# sourceMappingURL=html-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-transform.d.ts","sourceRoot":"","sources":["../src/html-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAqEzD,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;OAMG;IACH,MAAM,EAAE,oBAAoB,GAAG,uBAAuB,CAAC;CACxD;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,GAC7C,MAAM,CAsCR"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structure-preserving HTML link rewriter.
|
|
3
|
+
*
|
|
4
|
+
* Rewrites `<a href>` and `<img src>` attribute VALUES in place by splicing the
|
|
5
|
+
* original source string at parse5-reported offsets. The document is never
|
|
6
|
+
* re-serialized (parse5's serializer normalizes whitespace, quotes, void
|
|
7
|
+
* elements, and the doctype), so unchanged input round-trips byte-for-byte.
|
|
8
|
+
*
|
|
9
|
+
* Uses the same `RewriteHref` callback model as `rewriteBodyLinks` — callers
|
|
10
|
+
* supply per-href target resolution; this module owns only the splice mechanics.
|
|
11
|
+
*
|
|
12
|
+
* Non-goal: `<base href>` is not honored. Relative hrefs are resolved by the
|
|
13
|
+
* caller against the file's own directory; a `<base>` element that would
|
|
14
|
+
* override that in a browser is ignored.
|
|
15
|
+
*/
|
|
16
|
+
import { parseHtmlDocument, walkElements } from './html-link-parser.js';
|
|
17
|
+
/** Tag name → the single link-bearing attribute we rewrite. */
|
|
18
|
+
const LINK_ATTR_BY_TAG = { a: 'href', img: 'src' };
|
|
19
|
+
/**
|
|
20
|
+
* Chars that force an unquoted HTML attribute value to be quoted. Follows the
|
|
21
|
+
* WHATWG unquoted-attribute-value rules: whitespace, quotes, `<`, `>`, plus
|
|
22
|
+
* backtick and `=` (a superset of paths we expect, kept strict for safety).
|
|
23
|
+
*/
|
|
24
|
+
const UNQUOTED_UNSAFE = /[\s"'`<>=]/;
|
|
25
|
+
/**
|
|
26
|
+
* Locate the value sub-range within an attribute's full source span.
|
|
27
|
+
*
|
|
28
|
+
* parse5 reports the whole-attribute span (`href="value"`); this finds the
|
|
29
|
+
* value's absolute offsets and the quote char. Returns undefined for boolean
|
|
30
|
+
* attributes (no `=`).
|
|
31
|
+
*/
|
|
32
|
+
function valueSpan(attrSource, base) {
|
|
33
|
+
const eq = attrSource.indexOf('=');
|
|
34
|
+
if (eq === -1) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
let i = eq + 1;
|
|
38
|
+
while (i < attrSource.length && /\s/.test(attrSource.charAt(i))) {
|
|
39
|
+
i += 1;
|
|
40
|
+
}
|
|
41
|
+
if (i >= attrSource.length) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const ch = attrSource.charAt(i);
|
|
45
|
+
if (ch === '"' || ch === "'") {
|
|
46
|
+
const close = attrSource.indexOf(ch, i + 1);
|
|
47
|
+
const end = close === -1 ? attrSource.length : close;
|
|
48
|
+
return { valueStart: base + i + 1, valueEnd: base + end, quote: ch };
|
|
49
|
+
}
|
|
50
|
+
return { valueStart: base + i, valueEnd: base + attrSource.length, quote: '' };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Encode a new value for writing. For quoted attributes the surrounding quotes
|
|
54
|
+
* stay in the source (we only replace the inner value), so we escape `&` and the
|
|
55
|
+
* active quote. For originally-unquoted values we keep them bare when safe, else
|
|
56
|
+
* wrap in double quotes.
|
|
57
|
+
*/
|
|
58
|
+
function encodeValue(newValue, quote) {
|
|
59
|
+
if (quote === '"' || quote === "'") {
|
|
60
|
+
const amp = newValue.replaceAll('&', '&');
|
|
61
|
+
return quote === '"' ? amp.replaceAll('"', '"') : amp.replaceAll("'", ''');
|
|
62
|
+
}
|
|
63
|
+
if (newValue.length > 0 && !UNQUOTED_UNSAFE.test(newValue)) {
|
|
64
|
+
return newValue.replaceAll('&', '&');
|
|
65
|
+
}
|
|
66
|
+
const escaped = newValue.replaceAll('&', '&').replaceAll('"', '"');
|
|
67
|
+
return `"${escaped}"`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Rewrite `<a href>` / `<img src>` values in `source` using `rewriteHref`.
|
|
71
|
+
* Returns `source` unchanged (byte-for-byte) when no value changes.
|
|
72
|
+
*
|
|
73
|
+
* A rewrite that is wanted (the href resolves to a new value) but cannot be
|
|
74
|
+
* spliced back — because parse5 omitted the source location or the attribute
|
|
75
|
+
* span is unparseable — is reported via `onUnapplied` rather than dropped
|
|
76
|
+
* silently. Malformed pages are exactly the ones that hit this path, so the
|
|
77
|
+
* caller can surface it instead of shipping a stale link.
|
|
78
|
+
*/
|
|
79
|
+
export function rewriteHtmlLinks(source, rewriteHref, onUnapplied) {
|
|
80
|
+
const { document } = parseHtmlDocument(source);
|
|
81
|
+
const edits = [];
|
|
82
|
+
for (const element of walkElements(document)) {
|
|
83
|
+
const attrName = LINK_ATTR_BY_TAG[element.tagName];
|
|
84
|
+
if (attrName === undefined) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const attr = element.attrs.find((a) => a.name === attrName);
|
|
88
|
+
if (attr === undefined) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// Resolve first so we only record drops that actually lose a wanted edit.
|
|
92
|
+
const newValue = rewriteHref(attr.value);
|
|
93
|
+
if (newValue === attr.value) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const location = element.sourceCodeLocation?.attrs?.[attrName];
|
|
97
|
+
if (location === undefined) {
|
|
98
|
+
onUnapplied?.({ tagName: element.tagName, attr: attrName, from: attr.value, to: newValue, reason: 'no-source-location' });
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const span = valueSpan(source.slice(location.startOffset, location.endOffset), location.startOffset);
|
|
102
|
+
if (span === undefined) {
|
|
103
|
+
onUnapplied?.({ tagName: element.tagName, attr: attrName, from: attr.value, to: newValue, reason: 'unparseable-attribute' });
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
edits.push({ ...span, newValue });
|
|
107
|
+
}
|
|
108
|
+
// Apply descending by start offset so earlier edits don't shift later ones.
|
|
109
|
+
edits.sort((a, b) => b.valueStart - a.valueStart);
|
|
110
|
+
let result = source;
|
|
111
|
+
for (const edit of edits) {
|
|
112
|
+
result = result.slice(0, edit.valueStart) + encodeValue(edit.newValue, edit.quote) + result.slice(edit.valueEnd);
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=html-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-transform.js","sourceRoot":"","sources":["../src/html-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGxE,+DAA+D;AAC/D,MAAM,gBAAgB,GAAuC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,K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AClD,IAAI,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,10 @@ export type { ResourceCollectionInterface } from './resource-collection-interfac
|
|
|
32
32
|
export type { LinkNodeType, LinkType, HeadingNode, ResourceLink, ResourceMetadata, ValidationIssue, ValidationResult, ProjectConfig, ResourcesConfig, CollectionConfig, CollectionValidation, ValidationMode, SkillFileEntry, SkillPackagingConfig, SkillsConfig, ClaudeConfig, ClaudeMarketplaceConfig, ClaudeMarketplacePluginEntry, } from './types.js';
|
|
33
33
|
export { LinkNodeTypeSchema, LinkTypeSchema, HeadingNodeSchema, ResourceLinkSchema, ResourceMetadataSchema, } from './schemas/resource-metadata.js';
|
|
34
34
|
export { ValidationIssueSchema, ValidationResultSchema, } from './schemas/validation-result.js';
|
|
35
|
-
export { parseMarkdown, type ParseResult } from './link-parser.js';
|
|
35
|
+
export { parseMarkdown, classifyLink, isLocalFileLink, type ParseResult } from './link-parser.js';
|
|
36
|
+
export { parseHtml } from './html-link-parser.js';
|
|
37
|
+
export type { HtmlParseError } from './schemas/resource-metadata.js';
|
|
38
|
+
export { rewriteHtmlLinks, type UnappliedRewrite } from './html-transform.js';
|
|
36
39
|
export { validateFrontmatter } from './frontmatter-validator.js';
|
|
37
40
|
export { createAjvWithUriFormats } from './ajv-factory.js';
|
|
38
41
|
export { transformContent, type ContentTransformOptions, type LinkRewriteMatch, type LinkRewriteRule, type ResourceLookup, } from './content-transform.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,YAAY,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAGtF,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,wB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KAAK,iBAAiB,GACvB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,yCAAyC,EACzC,+BAA+B,EAC/B,gBAAgB,EAChB,KAAK,WAAW,GACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,eAAe,EACf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,9 @@ export { ResourceCollection } from './resource-collection.js';
|
|
|
35
35
|
export { LinkNodeTypeSchema, LinkTypeSchema, HeadingNodeSchema, ResourceLinkSchema, ResourceMetadataSchema, } from './schemas/resource-metadata.js';
|
|
36
36
|
export { ValidationIssueSchema, ValidationResultSchema, } from './schemas/validation-result.js';
|
|
37
37
|
// Export parser interface for advanced use cases
|
|
38
|
-
export { parseMarkdown } from './link-parser.js';
|
|
38
|
+
export { parseMarkdown, classifyLink, isLocalFileLink } from './link-parser.js';
|
|
39
|
+
export { parseHtml } from './html-link-parser.js';
|
|
40
|
+
export { rewriteHtmlLinks } from './html-transform.js';
|
|
39
41
|
// Export frontmatter validation
|
|
40
42
|
export { validateFrontmatter } from './frontmatter-validator.js';
|
|
41
43
|
// Public Ajv factory for adopters consuming VAT-generated schemas. Registers
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,+DAA+D;AAC/D,OAAO,EACL,gBAAgB,EAChB,kBAAkB,GAMnB,MAAM,wBAAwB,CAAC;AAEhC,yDAAyD;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,oFAAoF;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AA2B9D,qFAAq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EAA2E;AAC3E,OAAO,EAAE,gBAAgB,EAA+B,MAAM,YAAY,CAAC;AAE3E,sEAAsE;AACtE,OAAO,EACL,eAAe,EACf,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AAEjC,+EAA+E;AAC/E,OAAO,EACL,yCAAyC,EACzC,+BAA+B,EAC/B,gBAAgB,GAEjB,MAAM,uBAAuB,CAAC;AAE/B,gCAAgC;AAChC,OAAO,EACL,eAAe,EACf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC"}
|
package/dist/link-parser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Markdown link parser and
|
|
2
|
+
* Markdown link parser and shared resource-parsing types.
|
|
3
3
|
*
|
|
4
4
|
* Parses markdown files to extract:
|
|
5
5
|
* - Links (regular, reference-style, autolinks)
|
|
@@ -7,10 +7,15 @@
|
|
|
7
7
|
* - File size and token estimates
|
|
8
8
|
*
|
|
9
9
|
* Uses unified/remark for robust markdown parsing with GFM support.
|
|
10
|
+
*
|
|
11
|
+
* Also defines the format-neutral `ParseResult` contract shared with the HTML
|
|
12
|
+
* parser (`html-link-parser.ts`). The `HtmlParseError` shape is Zod-sourced
|
|
13
|
+
* from `schemas/resource-metadata.ts` (single source of truth).
|
|
10
14
|
*/
|
|
15
|
+
import type { HtmlParseError } from './schemas/resource-metadata.js';
|
|
11
16
|
import type { HeadingNode, LinkType, ResourceLink } from './types.js';
|
|
12
17
|
/**
|
|
13
|
-
* Result of parsing a markdown
|
|
18
|
+
* Result of parsing a resource file (markdown or HTML).
|
|
14
19
|
*/
|
|
15
20
|
export interface ParseResult {
|
|
16
21
|
links: ResourceLink[];
|
|
@@ -20,6 +25,10 @@ export interface ParseResult {
|
|
|
20
25
|
content: string;
|
|
21
26
|
sizeBytes: number;
|
|
22
27
|
estimatedTokenCount: number;
|
|
28
|
+
/** Fragment targets (HTML `id`/`name` attributes). Markdown leaves this undefined. */
|
|
29
|
+
anchors?: string[];
|
|
30
|
+
/** HTML well-formedness diagnostics. Markdown leaves this undefined. */
|
|
31
|
+
parseErrors?: HtmlParseError[];
|
|
23
32
|
}
|
|
24
33
|
/**
|
|
25
34
|
* Parse a markdown file and extract all links, headings, and metadata.
|
|
@@ -53,7 +62,22 @@ export declare function parseMarkdown(filePath: string): Promise<ParseResult>;
|
|
|
53
62
|
* classifyLink('#heading') // 'anchor'
|
|
54
63
|
* classifyLink('./file.md') // 'local_file'
|
|
55
64
|
* classifyLink('./file.md#anchor') // 'local_file'
|
|
65
|
+
* classifyLink('docs/') // 'local_directory'
|
|
66
|
+
* classifyLink('./docs/') // 'local_directory'
|
|
67
|
+
* classifyLink('../docs/') // 'local_directory'
|
|
68
|
+
* classifyLink('/docs/') // 'local_directory'
|
|
69
|
+
* classifyLink('https://x.com/docs/') // 'external' (not a local ref)
|
|
56
70
|
* ```
|
|
57
71
|
*/
|
|
58
72
|
export declare function classifyLink(href: string): LinkType;
|
|
73
|
+
/**
|
|
74
|
+
* Returns true for link types that represent local filesystem targets — both
|
|
75
|
+
* regular files and directories. Other packages (e.g. agent-skills walker)
|
|
76
|
+
* import this predicate as the single source of truth for "should we treat
|
|
77
|
+
* this link like a file link during validation/traversal?"
|
|
78
|
+
*
|
|
79
|
+
* @param type - The classified link type
|
|
80
|
+
* @returns `true` for `'local_file'` and `'local_directory'`
|
|
81
|
+
*/
|
|
82
|
+
export declare function isLocalFileLink(type: LinkType): boolean;
|
|
59
83
|
//# sourceMappingURL=link-parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-parser.d.ts","sourceRoot":"","sources":["../src/link-parser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"link-parser.d.ts","sourceRoot":"","sources":["../src/link-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,sFAAsF;IACtF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,wEAAwE;IACxE,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;CAChC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAwC1E;AA+ED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CA2DnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEvD"}
|
package/dist/link-parser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Markdown link parser and
|
|
2
|
+
* Markdown link parser and shared resource-parsing types.
|
|
3
3
|
*
|
|
4
4
|
* Parses markdown files to extract:
|
|
5
5
|
* - Links (regular, reference-style, autolinks)
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* - File size and token estimates
|
|
8
8
|
*
|
|
9
9
|
* Uses unified/remark for robust markdown parsing with GFM support.
|
|
10
|
+
*
|
|
11
|
+
* Also defines the format-neutral `ParseResult` contract shared with the HTML
|
|
12
|
+
* parser (`html-link-parser.ts`). The `HtmlParseError` shape is Zod-sourced
|
|
13
|
+
* from `schemas/resource-metadata.ts` (single source of truth).
|
|
10
14
|
*/
|
|
11
15
|
import { readFile, stat } from 'node:fs/promises';
|
|
12
16
|
import GithubSlugger from 'github-slugger';
|
|
@@ -151,6 +155,11 @@ function extractLinkText(node) {
|
|
|
151
155
|
* classifyLink('#heading') // 'anchor'
|
|
152
156
|
* classifyLink('./file.md') // 'local_file'
|
|
153
157
|
* classifyLink('./file.md#anchor') // 'local_file'
|
|
158
|
+
* classifyLink('docs/') // 'local_directory'
|
|
159
|
+
* classifyLink('./docs/') // 'local_directory'
|
|
160
|
+
* classifyLink('../docs/') // 'local_directory'
|
|
161
|
+
* classifyLink('/docs/') // 'local_directory'
|
|
162
|
+
* classifyLink('https://x.com/docs/') // 'external' (not a local ref)
|
|
154
163
|
* ```
|
|
155
164
|
*/
|
|
156
165
|
export function classifyLink(href) {
|
|
@@ -168,6 +177,12 @@ export function classifyLink(href) {
|
|
|
168
177
|
if (href.includes(':')) {
|
|
169
178
|
return 'unknown';
|
|
170
179
|
}
|
|
180
|
+
// Local directory: path component (before any # or ?) ends in '/'.
|
|
181
|
+
// Must come after all protocol guards so external URLs are never reclassified.
|
|
182
|
+
const pathPart = href.split(/[#?]/u)[0] ?? href;
|
|
183
|
+
if (pathPart.endsWith('/')) {
|
|
184
|
+
return 'local_directory';
|
|
185
|
+
}
|
|
171
186
|
// Links with anchors are still local file links
|
|
172
187
|
if (href.includes('#')) {
|
|
173
188
|
return 'local_file';
|
|
@@ -208,6 +223,18 @@ export function classifyLink(href) {
|
|
|
208
223
|
}
|
|
209
224
|
return 'unknown';
|
|
210
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Returns true for link types that represent local filesystem targets — both
|
|
228
|
+
* regular files and directories. Other packages (e.g. agent-skills walker)
|
|
229
|
+
* import this predicate as the single source of truth for "should we treat
|
|
230
|
+
* this link like a file link during validation/traversal?"
|
|
231
|
+
*
|
|
232
|
+
* @param type - The classified link type
|
|
233
|
+
* @returns `true` for `'local_file'` and `'local_directory'`
|
|
234
|
+
*/
|
|
235
|
+
export function isLocalFileLink(type) {
|
|
236
|
+
return type === 'local_file' || type === 'local_directory';
|
|
237
|
+
}
|
|
211
238
|
/**
|
|
212
239
|
* Extract headings from the markdown AST and build a nested tree structure.
|
|
213
240
|
*
|
package/dist/link-parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-parser.js","sourceRoot":"","sources":["../src/link-parser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"link-parser.js","sourceRoot":"","sources":["../src/link-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,aAAa,MAAM,gBAAgB,CAAC;AAE3C,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAsB7B;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,QAAgB;IAClD,8BAA8B;IAC9B,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACzC,+GAA+G;QAC/G,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;QAC3B,+GAA+G;QAC/G,IAAI,CAAC,QAAQ,CAAC;KACf,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;IAC7B,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAA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