@plebeiantech/lat.md 0.12.3-fork.1
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 +97 -0
- package/dist/src/cli/check-frontmatter.d.ts +12 -0
- package/dist/src/cli/check-frontmatter.js +44 -0
- package/dist/src/cli/check-mode.d.ts +6 -0
- package/dist/src/cli/check-mode.js +303 -0
- package/dist/src/cli/check-status.d.ts +74 -0
- package/dist/src/cli/check-status.js +217 -0
- package/dist/src/cli/check.d.ts +45 -0
- package/dist/src/cli/check.js +777 -0
- package/dist/src/cli/checklist-menu.d.ts +12 -0
- package/dist/src/cli/checklist-menu.js +111 -0
- package/dist/src/cli/comment-guard.d.ts +16 -0
- package/dist/src/cli/comment-guard.js +111 -0
- package/dist/src/cli/comment-reminder.d.ts +62 -0
- package/dist/src/cli/comment-reminder.js +210 -0
- package/dist/src/cli/context.d.ts +11 -0
- package/dist/src/cli/context.js +58 -0
- package/dist/src/cli/expand.d.ts +8 -0
- package/dist/src/cli/expand.js +94 -0
- package/dist/src/cli/gen-index.d.ts +45 -0
- package/dist/src/cli/gen-index.js +235 -0
- package/dist/src/cli/gen.d.ts +6 -0
- package/dist/src/cli/gen.js +42 -0
- package/dist/src/cli/graph.d.ts +7 -0
- package/dist/src/cli/graph.js +47 -0
- package/dist/src/cli/hook.d.ts +1 -0
- package/dist/src/cli/hook.js +432 -0
- package/dist/src/cli/index.d.ts +2 -0
- package/dist/src/cli/index.js +307 -0
- package/dist/src/cli/init.d.ts +9 -0
- package/dist/src/cli/init.js +1031 -0
- package/dist/src/cli/link-scheme.d.ts +54 -0
- package/dist/src/cli/link-scheme.js +101 -0
- package/dist/src/cli/locate.d.ts +2 -0
- package/dist/src/cli/locate.js +17 -0
- package/dist/src/cli/refs.d.ts +22 -0
- package/dist/src/cli/refs.js +229 -0
- package/dist/src/cli/reindex.d.ts +13 -0
- package/dist/src/cli/reindex.js +136 -0
- package/dist/src/cli/search.d.ts +36 -0
- package/dist/src/cli/search.js +217 -0
- package/dist/src/cli/section.d.ts +43 -0
- package/dist/src/cli/section.js +252 -0
- package/dist/src/cli/select-menu.d.ts +13 -0
- package/dist/src/cli/select-menu.js +100 -0
- package/dist/src/cli/templates.d.ts +1 -0
- package/dist/src/cli/templates.js +15 -0
- package/dist/src/cli/ui.d.ts +11 -0
- package/dist/src/cli/ui.js +34 -0
- package/dist/src/code-refs.d.ts +17 -0
- package/dist/src/code-refs.js +277 -0
- package/dist/src/config.d.ts +29 -0
- package/dist/src/config.js +83 -0
- package/dist/src/context.d.ts +23 -0
- package/dist/src/context.js +11 -0
- package/dist/src/extensions/wiki-link/from-markdown.d.ts +5 -0
- package/dist/src/extensions/wiki-link/from-markdown.js +34 -0
- package/dist/src/extensions/wiki-link/index.d.ts +4 -0
- package/dist/src/extensions/wiki-link/index.js +3 -0
- package/dist/src/extensions/wiki-link/syntax.d.ts +14 -0
- package/dist/src/extensions/wiki-link/syntax.js +121 -0
- package/dist/src/extensions/wiki-link/to-markdown.d.ts +5 -0
- package/dist/src/extensions/wiki-link/to-markdown.js +28 -0
- package/dist/src/extensions/wiki-link/types.d.ts +34 -0
- package/dist/src/extensions/wiki-link/types.js +1 -0
- package/dist/src/format.d.ts +8 -0
- package/dist/src/format.js +43 -0
- package/dist/src/graph-export.d.ts +60 -0
- package/dist/src/graph-export.js +309 -0
- package/dist/src/init-version.d.ts +10 -0
- package/dist/src/init-version.js +49 -0
- package/dist/src/knowledge/bd.d.ts +2 -0
- package/dist/src/knowledge/bd.js +107 -0
- package/dist/src/knowledge/claude-memory.d.ts +13 -0
- package/dist/src/knowledge/claude-memory.js +204 -0
- package/dist/src/knowledge/cq.d.ts +2 -0
- package/dist/src/knowledge/cq.js +74 -0
- package/dist/src/knowledge/index.d.ts +49 -0
- package/dist/src/knowledge/index.js +271 -0
- package/dist/src/knowledge/ranking.d.ts +17 -0
- package/dist/src/knowledge/ranking.js +62 -0
- package/dist/src/knowledge/session.d.ts +46 -0
- package/dist/src/knowledge/session.js +203 -0
- package/dist/src/knowledge/types.d.ts +47 -0
- package/dist/src/knowledge/types.js +10 -0
- package/dist/src/lattice.d.ts +108 -0
- package/dist/src/lattice.js +816 -0
- package/dist/src/mcp/server.d.ts +1 -0
- package/dist/src/mcp/server.js +58 -0
- package/dist/src/parser.d.ts +3 -0
- package/dist/src/parser.js +18 -0
- package/dist/src/search/db.d.ts +16 -0
- package/dist/src/search/db.js +54 -0
- package/dist/src/search/embedder.d.ts +25 -0
- package/dist/src/search/embedder.js +58 -0
- package/dist/src/search/index.d.ts +9 -0
- package/dist/src/search/index.js +66 -0
- package/dist/src/search/search.d.ts +9 -0
- package/dist/src/search/search.js +16 -0
- package/dist/src/source-parser.d.ts +27 -0
- package/dist/src/source-parser.js +916 -0
- package/dist/src/untrusted.d.ts +24 -0
- package/dist/src/untrusted.js +97 -0
- package/dist/src/version.d.ts +7 -0
- package/dist/src/version.js +39 -0
- package/dist/src/view/client/assets/index-B0n0u03y.css +1 -0
- package/dist/src/view/client/assets/index-xm2_px4q.js +23 -0
- package/dist/src/view/client/index.html +14 -0
- package/dist/src/view/diagnostics.d.ts +5 -0
- package/dist/src/view/diagnostics.js +171 -0
- package/dist/src/view/git-diff.d.ts +3 -0
- package/dist/src/view/git-diff.js +255 -0
- package/dist/src/view/git.d.ts +22 -0
- package/dist/src/view/git.js +193 -0
- package/dist/src/view/highlight.d.ts +2 -0
- package/dist/src/view/highlight.js +3767 -0
- package/dist/src/view/markdown.d.ts +22 -0
- package/dist/src/view/markdown.js +322 -0
- package/dist/src/view/protocol.d.ts +89 -0
- package/dist/src/view/protocol.js +1 -0
- package/dist/src/view/references.d.ts +62 -0
- package/dist/src/view/references.js +345 -0
- package/dist/src/view/repository.d.ts +12 -0
- package/dist/src/view/repository.js +167 -0
- package/dist/src/view/search.d.ts +14 -0
- package/dist/src/view/search.js +64 -0
- package/dist/src/view/server.d.ts +20 -0
- package/dist/src/view/server.js +233 -0
- package/dist/src/view/store.d.ts +57 -0
- package/dist/src/view/store.js +404 -0
- package/dist/src/walk.d.ts +18 -0
- package/dist/src/walk.js +27 -0
- package/package.json +85 -0
- package/templates/AGENTS.md +118 -0
- package/templates/README +1 -0
- package/templates/cursor-rules.md +77 -0
- package/templates/init/lat.md +1 -0
- package/templates/logo-dark.svg +182 -0
- package/templates/logo-light.svg +182 -0
- package/templates/logo.txt +7 -0
- package/templates/opencode-plugin.ts +180 -0
- package/templates/pi-extension.ts +364 -0
- package/templates/skill/SKILL.md +189 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export type WikiLinkContext = {
|
|
3
|
+
line: number;
|
|
4
|
+
};
|
|
5
|
+
export type WikiLinkResolver = (target: string, context: WikiLinkContext) => string | null | Promise<string | null>;
|
|
6
|
+
export type MarkdownRenderOptions = {
|
|
7
|
+
activeMarkdownLink?: string;
|
|
8
|
+
activeWikiLink?: string;
|
|
9
|
+
errors?: {
|
|
10
|
+
anchor: string;
|
|
11
|
+
line: number;
|
|
12
|
+
marker: 'heading' | 'line' | 'target';
|
|
13
|
+
target: string;
|
|
14
|
+
}[];
|
|
15
|
+
lineOffset?: number;
|
|
16
|
+
rewriteMarkdownLink?: (url: string) => string;
|
|
17
|
+
};
|
|
18
|
+
/** Render a lat.md file as safe HTML with resolved wiki links. */
|
|
19
|
+
export declare function renderMarkdown(markdown: string, filePath: string, resolveWikiLink?: WikiLinkResolver, options?: MarkdownRenderOptions, parsedTree?: Root): Promise<{
|
|
20
|
+
html: string;
|
|
21
|
+
title: string;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { basename, extname } from 'node:path';
|
|
2
|
+
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
|
|
3
|
+
import rehypeSlug from 'rehype-slug';
|
|
4
|
+
import rehypeStringify from 'rehype-stringify';
|
|
5
|
+
import remarkRehype from 'remark-rehype';
|
|
6
|
+
import { unified } from 'unified';
|
|
7
|
+
import { visit } from 'unist-util-visit';
|
|
8
|
+
import { parse } from '../parser.js';
|
|
9
|
+
const CODE_LINK_CLASSES = [
|
|
10
|
+
'wiki-link-code',
|
|
11
|
+
'wiki-link-active',
|
|
12
|
+
'code-link-language',
|
|
13
|
+
'code-language-ts',
|
|
14
|
+
'code-language-js',
|
|
15
|
+
'code-language-py',
|
|
16
|
+
'code-language-rs',
|
|
17
|
+
'code-language-go',
|
|
18
|
+
'code-language-c',
|
|
19
|
+
];
|
|
20
|
+
const ERROR_CLASS = 'markdown-error';
|
|
21
|
+
const GIT_CLASSES = ['git-added', 'git-removed'];
|
|
22
|
+
function classAttributes(tag) {
|
|
23
|
+
return [
|
|
24
|
+
...(defaultSchema.attributes?.[tag] ?? []),
|
|
25
|
+
['className', ERROR_CLASS, ...GIT_CLASSES],
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
const sanitizeSchema = {
|
|
29
|
+
...defaultSchema,
|
|
30
|
+
tagNames: [...(defaultSchema.tagNames ?? []), 'ins'],
|
|
31
|
+
attributes: {
|
|
32
|
+
...defaultSchema.attributes,
|
|
33
|
+
a: [
|
|
34
|
+
...(defaultSchema.attributes?.a ?? []).filter((attribute) => !(Array.isArray(attribute) && attribute[0] === 'className')),
|
|
35
|
+
[
|
|
36
|
+
'className',
|
|
37
|
+
'data-footnote-backref',
|
|
38
|
+
'wiki-link-segmented',
|
|
39
|
+
'wiki-link-code',
|
|
40
|
+
'wiki-link-active',
|
|
41
|
+
ERROR_CLASS,
|
|
42
|
+
...GIT_CLASSES,
|
|
43
|
+
],
|
|
44
|
+
],
|
|
45
|
+
blockquote: classAttributes('blockquote'),
|
|
46
|
+
code: classAttributes('code'),
|
|
47
|
+
del: classAttributes('del'),
|
|
48
|
+
div: classAttributes('div'),
|
|
49
|
+
h1: classAttributes('h1'),
|
|
50
|
+
h2: classAttributes('h2'),
|
|
51
|
+
h3: classAttributes('h3'),
|
|
52
|
+
h4: classAttributes('h4'),
|
|
53
|
+
h5: classAttributes('h5'),
|
|
54
|
+
h6: classAttributes('h6'),
|
|
55
|
+
img: classAttributes('img'),
|
|
56
|
+
ins: classAttributes('ins'),
|
|
57
|
+
li: classAttributes('li'),
|
|
58
|
+
p: classAttributes('p'),
|
|
59
|
+
pre: classAttributes('pre'),
|
|
60
|
+
span: [
|
|
61
|
+
...(defaultSchema.attributes?.span ?? []),
|
|
62
|
+
'ariaHidden',
|
|
63
|
+
[
|
|
64
|
+
'className',
|
|
65
|
+
'wiki-link-context',
|
|
66
|
+
'wiki-link-leaf',
|
|
67
|
+
...CODE_LINK_CLASSES.slice(2),
|
|
68
|
+
ERROR_CLASS,
|
|
69
|
+
...GIT_CLASSES,
|
|
70
|
+
],
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const htmlProcessor = unified()
|
|
75
|
+
.use(remarkRehype)
|
|
76
|
+
.use(rehypeSanitize, sanitizeSchema)
|
|
77
|
+
.use(rehypeSlug)
|
|
78
|
+
.use(rehypeStringify);
|
|
79
|
+
function nodeText(node) {
|
|
80
|
+
if (typeof node.value === 'string')
|
|
81
|
+
return node.value;
|
|
82
|
+
if (!Array.isArray(node.children))
|
|
83
|
+
return '';
|
|
84
|
+
return node.children
|
|
85
|
+
.map((child) => nodeText(child))
|
|
86
|
+
.join('');
|
|
87
|
+
}
|
|
88
|
+
function wikiLinkContent(node) {
|
|
89
|
+
if (node.data.alias) {
|
|
90
|
+
return {
|
|
91
|
+
children: [{ type: 'text', value: node.data.alias }],
|
|
92
|
+
segmented: false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const hash = node.value.lastIndexOf('#');
|
|
96
|
+
if (hash <= 0 || hash === node.value.length - 1) {
|
|
97
|
+
return {
|
|
98
|
+
children: [{ type: 'text', value: node.value }],
|
|
99
|
+
segmented: false,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
children: [
|
|
104
|
+
{
|
|
105
|
+
type: 'emphasis',
|
|
106
|
+
data: {
|
|
107
|
+
hName: 'span',
|
|
108
|
+
hProperties: { className: ['wiki-link-context'] },
|
|
109
|
+
},
|
|
110
|
+
children: [{ type: 'text', value: node.value.slice(0, hash + 1) }],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: 'emphasis',
|
|
114
|
+
data: {
|
|
115
|
+
hName: 'span',
|
|
116
|
+
hProperties: { className: ['wiki-link-leaf'] },
|
|
117
|
+
},
|
|
118
|
+
children: [{ type: 'text', value: node.value.slice(hash + 1) }],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
segmented: true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function codeLanguage(target) {
|
|
125
|
+
switch (extname(target.split('#', 1)[0]).toLowerCase()) {
|
|
126
|
+
case '.ts':
|
|
127
|
+
case '.tsx':
|
|
128
|
+
return { className: 'code-language-ts', label: 'TS' };
|
|
129
|
+
case '.js':
|
|
130
|
+
case '.jsx':
|
|
131
|
+
return { className: 'code-language-js', label: 'JS' };
|
|
132
|
+
case '.py':
|
|
133
|
+
return { className: 'code-language-py', label: 'PY' };
|
|
134
|
+
case '.rs':
|
|
135
|
+
return { className: 'code-language-rs', label: 'RS' };
|
|
136
|
+
case '.go':
|
|
137
|
+
return { className: 'code-language-go', label: 'GO' };
|
|
138
|
+
case '.c':
|
|
139
|
+
case '.h':
|
|
140
|
+
return { className: 'code-language-c', label: 'C' };
|
|
141
|
+
default:
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function languageIcon(language) {
|
|
146
|
+
return {
|
|
147
|
+
type: 'emphasis',
|
|
148
|
+
data: {
|
|
149
|
+
hName: 'span',
|
|
150
|
+
hProperties: {
|
|
151
|
+
ariaHidden: 'true',
|
|
152
|
+
className: ['code-link-language', language.className],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
children: [{ type: 'text', value: language.label }],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function targetMatches(node, target) {
|
|
159
|
+
if (node.type === 'wikiLink') {
|
|
160
|
+
return node.value.toLowerCase() === target.toLowerCase();
|
|
161
|
+
}
|
|
162
|
+
if (node.type === 'link' || node.type === 'image') {
|
|
163
|
+
return node.url === target;
|
|
164
|
+
}
|
|
165
|
+
if (node.type === 'linkReference' || node.type === 'imageReference') {
|
|
166
|
+
return node.identifier.toLowerCase() === target.toLowerCase();
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
function errorNodeScore(node, error) {
|
|
171
|
+
const { line, marker, target } = error;
|
|
172
|
+
const start = node.position?.start.line;
|
|
173
|
+
const end = node.position?.end.line;
|
|
174
|
+
if (!start || !end || line < start || line > end)
|
|
175
|
+
return null;
|
|
176
|
+
if (marker === 'heading') {
|
|
177
|
+
return start === line && node.type === 'heading' ? 0 : null;
|
|
178
|
+
}
|
|
179
|
+
if (marker === 'target' && targetMatches(node, target))
|
|
180
|
+
return 0;
|
|
181
|
+
if (node.type === 'paragraph')
|
|
182
|
+
return marker === 'line' ? 1 : 3;
|
|
183
|
+
if (start === line)
|
|
184
|
+
return 4;
|
|
185
|
+
return 5 + (end - start);
|
|
186
|
+
}
|
|
187
|
+
function markMarkdownErrors(tree, errors) {
|
|
188
|
+
for (const error of errors) {
|
|
189
|
+
let selected = null;
|
|
190
|
+
let selectedScore = Number.POSITIVE_INFINITY;
|
|
191
|
+
visit(tree, (candidate) => {
|
|
192
|
+
if (candidate.type === 'root' || candidate.type === 'text')
|
|
193
|
+
return;
|
|
194
|
+
const node = candidate;
|
|
195
|
+
const score = errorNodeScore(node, error);
|
|
196
|
+
if (score === null || score >= selectedScore)
|
|
197
|
+
return;
|
|
198
|
+
selected = node;
|
|
199
|
+
selectedScore = score;
|
|
200
|
+
});
|
|
201
|
+
if (!selected)
|
|
202
|
+
continue;
|
|
203
|
+
const node = selected;
|
|
204
|
+
const properties = node.data?.hProperties ?? {};
|
|
205
|
+
const currentClasses = properties.className;
|
|
206
|
+
const classes = Array.isArray(currentClasses)
|
|
207
|
+
? currentClasses.map(String)
|
|
208
|
+
: currentClasses
|
|
209
|
+
? [String(currentClasses)]
|
|
210
|
+
: [];
|
|
211
|
+
if (!classes.includes(ERROR_CLASS))
|
|
212
|
+
classes.push(ERROR_CLASS);
|
|
213
|
+
const generatedAnchor = error.anchor.startsWith('user-content-');
|
|
214
|
+
node.data = {
|
|
215
|
+
...node.data,
|
|
216
|
+
hProperties: {
|
|
217
|
+
...properties,
|
|
218
|
+
className: classes,
|
|
219
|
+
...(node.type === 'heading' && !generatedAnchor
|
|
220
|
+
? {}
|
|
221
|
+
: { id: error.anchor.replace(/^user-content-/, '') }),
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/** Render a lat.md file as safe HTML with resolved wiki links. */
|
|
227
|
+
export async function renderMarkdown(markdown, filePath, resolveWikiLink, options = {}, parsedTree) {
|
|
228
|
+
const tree = parsedTree ? structuredClone(parsedTree) : parse(markdown);
|
|
229
|
+
tree.children = tree.children.filter((node) => node.type !== 'yaml');
|
|
230
|
+
if (options.errors)
|
|
231
|
+
markMarkdownErrors(tree, options.errors);
|
|
232
|
+
if (options.rewriteMarkdownLink || options.activeMarkdownLink) {
|
|
233
|
+
visit(tree, 'link', (node) => {
|
|
234
|
+
const authoredUrl = node.url;
|
|
235
|
+
if (options.activeMarkdownLink &&
|
|
236
|
+
authoredUrl === options.activeMarkdownLink) {
|
|
237
|
+
node.data = {
|
|
238
|
+
...node.data,
|
|
239
|
+
hProperties: {
|
|
240
|
+
...(node.data?.hProperties ?? {}),
|
|
241
|
+
className: ['wiki-link-active'],
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
if (options.rewriteMarkdownLink) {
|
|
246
|
+
node.url = options.rewriteMarkdownLink(authoredUrl);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
const firstHeading = tree.children.find((node) => node.type === 'heading');
|
|
251
|
+
const title = firstHeading
|
|
252
|
+
? nodeText(firstHeading)
|
|
253
|
+
: basename(filePath, '.md');
|
|
254
|
+
const resolvedLinks = new Map();
|
|
255
|
+
if (resolveWikiLink) {
|
|
256
|
+
const wikiLinks = [];
|
|
257
|
+
visit(tree, 'wikiLink', (node) => {
|
|
258
|
+
wikiLinks.push(node);
|
|
259
|
+
});
|
|
260
|
+
for (const node of wikiLinks) {
|
|
261
|
+
resolvedLinks.set(node, await resolveWikiLink(node.value, {
|
|
262
|
+
line: (node.position?.start.line ?? 0) + (options.lineOffset ?? 0),
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
visit(tree, 'wikiLink', (node, index, parent) => {
|
|
267
|
+
if (index === undefined || !parent || !('children' in parent))
|
|
268
|
+
return;
|
|
269
|
+
const href = resolvedLinks.get(node);
|
|
270
|
+
const markedProperties = node.data?.hProperties;
|
|
271
|
+
if (href) {
|
|
272
|
+
const content = wikiLinkContent(node);
|
|
273
|
+
const language = href.startsWith('/code/')
|
|
274
|
+
? codeLanguage(node.value)
|
|
275
|
+
: null;
|
|
276
|
+
const classes = content.segmented ? ['wiki-link-segmented'] : [];
|
|
277
|
+
if (language)
|
|
278
|
+
classes.push('wiki-link-code');
|
|
279
|
+
if (options.activeWikiLink &&
|
|
280
|
+
node.value.toLowerCase() === options.activeWikiLink.toLowerCase()) {
|
|
281
|
+
classes.push('wiki-link-active');
|
|
282
|
+
}
|
|
283
|
+
parent.children[index] = {
|
|
284
|
+
type: 'link',
|
|
285
|
+
url: href,
|
|
286
|
+
data: classes.length > 0 || markedProperties
|
|
287
|
+
? {
|
|
288
|
+
hProperties: {
|
|
289
|
+
...markedProperties,
|
|
290
|
+
className: [
|
|
291
|
+
...classes,
|
|
292
|
+
...(Array.isArray(markedProperties?.className)
|
|
293
|
+
? markedProperties.className.map(String)
|
|
294
|
+
: []),
|
|
295
|
+
],
|
|
296
|
+
},
|
|
297
|
+
}
|
|
298
|
+
: undefined,
|
|
299
|
+
children: language
|
|
300
|
+
? [languageIcon(language), ...content.children]
|
|
301
|
+
: content.children,
|
|
302
|
+
};
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const alias = node.data.alias ? `|${node.data.alias}` : '';
|
|
306
|
+
parent.children[index] = markedProperties
|
|
307
|
+
? {
|
|
308
|
+
type: 'emphasis',
|
|
309
|
+
data: {
|
|
310
|
+
hName: 'span',
|
|
311
|
+
hProperties: markedProperties,
|
|
312
|
+
},
|
|
313
|
+
children: [{ type: 'text', value: `[[${node.value}${alias}]]` }],
|
|
314
|
+
}
|
|
315
|
+
: {
|
|
316
|
+
type: 'text',
|
|
317
|
+
value: `[[${node.value}${alias}]]`,
|
|
318
|
+
};
|
|
319
|
+
});
|
|
320
|
+
const hast = await htmlProcessor.run(tree);
|
|
321
|
+
return { html: htmlProcessor.stringify(hast), title };
|
|
322
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export type ViewGitFileStatus = 'modified' | 'new';
|
|
2
|
+
export type ViewGitState = {
|
|
3
|
+
files: Record<string, ViewGitFileStatus>;
|
|
4
|
+
};
|
|
5
|
+
export type ViewIndex = {
|
|
6
|
+
files: string[];
|
|
7
|
+
entry: string;
|
|
8
|
+
errorCounts: Record<string, number>;
|
|
9
|
+
git: ViewGitState | null;
|
|
10
|
+
};
|
|
11
|
+
export type ViewDocumentError = {
|
|
12
|
+
anchor: string;
|
|
13
|
+
line: number;
|
|
14
|
+
marker: 'heading' | 'line' | 'target';
|
|
15
|
+
message: string;
|
|
16
|
+
target: string;
|
|
17
|
+
};
|
|
18
|
+
export type ViewSearchResult = {
|
|
19
|
+
sectionId: string;
|
|
20
|
+
title: string;
|
|
21
|
+
path: string;
|
|
22
|
+
breadcrumbs: string[];
|
|
23
|
+
description: string;
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
26
|
+
export type ViewSearchResponse = {
|
|
27
|
+
query: string;
|
|
28
|
+
results: ViewSearchResult[];
|
|
29
|
+
};
|
|
30
|
+
export type ViewProjectChange = {
|
|
31
|
+
generation: number;
|
|
32
|
+
markdownGeneration: number;
|
|
33
|
+
};
|
|
34
|
+
export type ViewDocument = {
|
|
35
|
+
path: string;
|
|
36
|
+
title: string;
|
|
37
|
+
html: string;
|
|
38
|
+
gitHtml: string | null;
|
|
39
|
+
errors: ViewDocumentError[];
|
|
40
|
+
backReferences: ViewSectionBackReferences[];
|
|
41
|
+
frontmatter: {
|
|
42
|
+
requireCodeMention: boolean;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type ViewMarkdownBackReference = {
|
|
46
|
+
kind: 'markdown';
|
|
47
|
+
sectionId: string;
|
|
48
|
+
breadcrumbs: string[];
|
|
49
|
+
paragraph: string;
|
|
50
|
+
paragraphHtml: string;
|
|
51
|
+
url: string;
|
|
52
|
+
};
|
|
53
|
+
export type ViewCodeBackReference = {
|
|
54
|
+
kind: 'code';
|
|
55
|
+
path: string;
|
|
56
|
+
line: number;
|
|
57
|
+
snippet: string;
|
|
58
|
+
url: string;
|
|
59
|
+
};
|
|
60
|
+
export type ViewSectionBackReference = ViewMarkdownBackReference | ViewCodeBackReference;
|
|
61
|
+
export type ViewSectionBackReferences = {
|
|
62
|
+
sectionId: string;
|
|
63
|
+
headingId: string;
|
|
64
|
+
references: ViewSectionBackReference[];
|
|
65
|
+
};
|
|
66
|
+
export type ViewSourceReference = {
|
|
67
|
+
sectionId: string;
|
|
68
|
+
breadcrumbs: string[];
|
|
69
|
+
paragraph: string;
|
|
70
|
+
paragraphHtml: string;
|
|
71
|
+
url: string;
|
|
72
|
+
};
|
|
73
|
+
export type ViewSourceDocument = {
|
|
74
|
+
path: string;
|
|
75
|
+
content: string;
|
|
76
|
+
highlightedHtmlLines: string[];
|
|
77
|
+
focus: {
|
|
78
|
+
symbol: string;
|
|
79
|
+
kind: string;
|
|
80
|
+
signature: string;
|
|
81
|
+
startLine: number;
|
|
82
|
+
endLine: number;
|
|
83
|
+
} | null;
|
|
84
|
+
context: ViewSourceReference | null;
|
|
85
|
+
otherReferences: ViewSourceReference[];
|
|
86
|
+
};
|
|
87
|
+
export type ViewError = {
|
|
88
|
+
error: string;
|
|
89
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import type { CodeRef } from '../code-refs.js';
|
|
3
|
+
import { type Ref, type MdLink, type Section } from '../lattice.js';
|
|
4
|
+
import { type WikiLinkResolver } from './markdown.js';
|
|
5
|
+
import type { ViewCodeBackReference, ViewSectionBackReferences, ViewSourceReference } from './protocol.js';
|
|
6
|
+
export type SourceReferenceOrigin = {
|
|
7
|
+
sectionId: string;
|
|
8
|
+
line: number;
|
|
9
|
+
};
|
|
10
|
+
type ParagraphContent = {
|
|
11
|
+
markdown: string;
|
|
12
|
+
startLine: number;
|
|
13
|
+
text: string;
|
|
14
|
+
};
|
|
15
|
+
type MarkdownLink = {
|
|
16
|
+
kind: 'image' | 'link';
|
|
17
|
+
line: number;
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
20
|
+
export type ViewParsedMarkdownFile = {
|
|
21
|
+
absolutePath: string;
|
|
22
|
+
content: string;
|
|
23
|
+
path: string;
|
|
24
|
+
projectPath: string;
|
|
25
|
+
tree: Root;
|
|
26
|
+
sections: Section[];
|
|
27
|
+
wikiRefs: Ref[];
|
|
28
|
+
paragraphs: Map<number, ParagraphContent>;
|
|
29
|
+
markdownLinks: MarkdownLink[];
|
|
30
|
+
validationLinks: MdLink[];
|
|
31
|
+
};
|
|
32
|
+
export type ViewCodeReferenceFile = {
|
|
33
|
+
path: string;
|
|
34
|
+
lines: string[];
|
|
35
|
+
refs: CodeRef[];
|
|
36
|
+
};
|
|
37
|
+
type IndexedMarkdownReference = {
|
|
38
|
+
kind: 'markdown';
|
|
39
|
+
section: Section;
|
|
40
|
+
sourcePath: string;
|
|
41
|
+
line: number;
|
|
42
|
+
paragraph: ParagraphContent;
|
|
43
|
+
activeWikiLink?: string;
|
|
44
|
+
activeMarkdownLink?: string;
|
|
45
|
+
};
|
|
46
|
+
type IndexedBackReference = IndexedMarkdownReference | ViewCodeBackReference;
|
|
47
|
+
export type ViewReferenceIndex = {
|
|
48
|
+
incomingBySection: ReadonlyMap<string, readonly IndexedBackReference[]>;
|
|
49
|
+
sourceByTarget: ReadonlyMap<string, readonly IndexedMarkdownReference[]>;
|
|
50
|
+
};
|
|
51
|
+
/** Parse one Markdown file once into every structure needed by the view store. */
|
|
52
|
+
export declare function parseViewMarkdownFile(absolutePath: string, content: string, latDir: string, projectRoot: string): ViewParsedMarkdownFile;
|
|
53
|
+
/** Resolve cached outgoing occurrences into direct section and source indexes. */
|
|
54
|
+
export declare function buildViewReferenceIndex(markdownFiles: Iterable<ViewParsedMarkdownFile>, codeFiles: Iterable<ViewCodeReferenceFile>, allSections: Section[]): ViewReferenceIndex;
|
|
55
|
+
/** Render direct reverse-index entries for the sections visible in one file. */
|
|
56
|
+
export declare function renderSectionBackReferences(index: ViewReferenceIndex, visibleSections: Section[], latDir: string, projectRoot: string, createWikiLinkResolver?: (requestedPath: string) => Promise<WikiLinkResolver>): Promise<ViewSectionBackReferences[]>;
|
|
57
|
+
/** Render cached Markdown occurrences that point to one source target. */
|
|
58
|
+
export declare function renderSourceReferenceContext(index: ViewReferenceIndex, target: string, origin: SourceReferenceOrigin | undefined, latDir: string, projectRoot: string, createWikiLinkResolver?: (requestedPath: string) => Promise<WikiLinkResolver>): Promise<{
|
|
59
|
+
context: ViewSourceReference | null;
|
|
60
|
+
otherReferences: ViewSourceReference[];
|
|
61
|
+
}>;
|
|
62
|
+
export {};
|