@tnotesjs/core 0.5.0 → 0.6.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.
Files changed (36) hide show
  1. package/dist/chunk-3R7QSABB.cjs +502 -0
  2. package/dist/chunk-56PKXCOX.js +176 -0
  3. package/dist/chunk-5F5RJ2HV.cjs +176 -0
  4. package/dist/chunk-CZXRQPFJ.js +11 -0
  5. package/dist/{chunk-XCWFZLER.js → chunk-DUTS75WQ.js} +27 -493
  6. package/dist/chunk-HXED7KVT.cjs +11 -0
  7. package/dist/chunk-MZIXIY2Y.cjs +216 -0
  8. package/dist/chunk-TJ4527KA.cjs +5264 -0
  9. package/dist/chunk-U6IBLREL.js +502 -0
  10. package/dist/cli/index.cjs +936 -0
  11. package/dist/cli/index.d.cts +2 -0
  12. package/dist/cli/index.d.ts +2 -0
  13. package/dist/cli/index.js +9 -6
  14. package/dist/index.cjs +8 -0
  15. package/dist/index.d.cts +56 -0
  16. package/dist/index.d.ts +56 -0
  17. package/dist/markdown/index.cjs +82 -0
  18. package/dist/markdown/index.d.cts +36 -0
  19. package/dist/markdown/index.d.ts +36 -0
  20. package/dist/markdown/index.js +82 -0
  21. package/dist/note-oGm44Rw8.d.cts +84 -0
  22. package/dist/note-oGm44Rw8.d.ts +84 -0
  23. package/dist/types-CpsEy8lA.d.cts +221 -0
  24. package/dist/types-CwBWwNVv.d.ts +221 -0
  25. package/dist/vitepress/config/index.cjs +1669 -0
  26. package/dist/vitepress/config/index.d.cts +12 -0
  27. package/dist/vitepress/config/index.d.ts +12 -0
  28. package/dist/vitepress/config/index.js +10 -4
  29. package/dist/workspace/index.cjs +1207 -0
  30. package/dist/workspace/index.d.cts +14 -0
  31. package/dist/workspace/index.d.ts +14 -0
  32. package/dist/workspace/index.js +1207 -0
  33. package/package.json +15 -2
  34. package/vitepress/components/Settings/Settings.vue +3 -3
  35. package/vitepress/components/SidebarCard/SidebarCard.vue +3 -3
  36. package/vitepress/plugins/localSearchReindexLogic.ts +11 -3
@@ -0,0 +1,176 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkHXED7KVTcjs = require('./chunk-HXED7KVT.cjs');
4
+
5
+ // markdown/noteFormatter.ts
6
+ var _prettier = require('prettier');
7
+ var NOTE_TOC_START_TAG = "<!-- region:toc -->";
8
+ var NOTE_TOC_END_TAG = "<!-- endregion:toc -->";
9
+ function generatedNoteTitle(input) {
10
+ const dirName = `${input.noteIndex}. ${input.title}`;
11
+ const encodedDirName = encodeURIComponent(dirName);
12
+ const repositoryUrl = `https://github.com/${input.repoOwner}/${input.repoName}/tree/main/notes`;
13
+ return `# [${dirName}](${repositoryUrl}/${encodedDirName})`;
14
+ }
15
+ function ensureGeneratedTitle(lines, generatedTitle) {
16
+ if (lines.length === 0) {
17
+ lines.push(generatedTitle);
18
+ return;
19
+ }
20
+ lines[0] = lines[0].replace(/^\uFEFF/, "");
21
+ if (lines[0].trimStart().startsWith("# ")) {
22
+ lines[0] = generatedTitle;
23
+ return;
24
+ }
25
+ lines.unshift(generatedTitle, "");
26
+ }
27
+ function ensureTocRegion(lines) {
28
+ let start = lines.findIndex((line) => line.trim() === NOTE_TOC_START_TAG);
29
+ let end = lines.findIndex(
30
+ (line, index) => index > start && line.trim() === NOTE_TOC_END_TAG
31
+ );
32
+ if (start >= 0 && end > start) return { start, end };
33
+ if (start >= 0) lines.splice(start, 1);
34
+ if (end >= 0) lines.splice(end > start ? end - 1 : end, 1);
35
+ let insertAt = 1;
36
+ while (insertAt < lines.length && lines[insertAt].trim() === "") insertAt++;
37
+ lines.splice(
38
+ insertAt,
39
+ 0,
40
+ "",
41
+ NOTE_TOC_START_TAG,
42
+ "",
43
+ NOTE_TOC_END_TAG,
44
+ ""
45
+ );
46
+ start = insertAt + 1;
47
+ end = insertAt + 3;
48
+ return { start, end };
49
+ }
50
+ function normalizeHeadings(lines) {
51
+ const headings = [];
52
+ const counters = { h2: 0, h3: 0 };
53
+ let fence = null;
54
+ let inHtmlComment = false;
55
+ for (let index = 0; index < lines.length; index++) {
56
+ const line = lines[index];
57
+ const fenceMatch = line.match(/^\s{0,3}(`{3,}|~{3,})/);
58
+ if (fenceMatch) {
59
+ const marker = fenceMatch[1][0];
60
+ if (!fence) {
61
+ fence = { marker, length: fenceMatch[1].length };
62
+ } else if (fence.marker === marker && fenceMatch[1].length >= fence.length) {
63
+ fence = null;
64
+ }
65
+ continue;
66
+ }
67
+ if (fence) continue;
68
+ if (inHtmlComment) {
69
+ if (line.includes("-->")) inHtmlComment = false;
70
+ continue;
71
+ }
72
+ const commentStart = line.indexOf("<!--");
73
+ if (commentStart >= 0) {
74
+ const commentEnd = line.indexOf("-->", commentStart + 4);
75
+ if (commentEnd < 0) inHtmlComment = true;
76
+ if (line.trimStart().startsWith("<!--")) continue;
77
+ }
78
+ const match = line.match(/^(#{2,6})\s+(.+?)\s*#*\s*$/);
79
+ if (!match) continue;
80
+ const level = match[1].length;
81
+ const plainText = match[2].replace(/^\d+(?:\.\d+)+\.?\s+|^\d+\.\s+/, "").trim();
82
+ let text = plainText;
83
+ if (level === 2) {
84
+ counters.h2 += 1;
85
+ counters.h3 = 0;
86
+ text = `${counters.h2}. ${plainText}`;
87
+ } else if (level === 3) {
88
+ counters.h3 += 1;
89
+ text = `${counters.h2}.${counters.h3}. ${plainText}`;
90
+ }
91
+ lines[index] = `${"#".repeat(level)} ${text}`;
92
+ headings.push({ level, text });
93
+ }
94
+ return headings;
95
+ }
96
+ function buildHeadingToc(headings) {
97
+ return headings.map((heading) => {
98
+ const indent = " ".repeat(Math.max(0, heading.level - 2) * 2);
99
+ return `${indent}- [${heading.text}](#${_chunkHXED7KVTcjs.generateAnchor.call(void 0, heading.text)})`;
100
+ });
101
+ }
102
+ function stringArray(value) {
103
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
104
+ }
105
+ function buildResourceToc(input) {
106
+ const bilibili = stringArray(input.noteConfig.bilibili);
107
+ const relatedTNotes = stringArray(input.noteConfig.tnotes);
108
+ const yuque = stringArray(input.noteConfig.yuque);
109
+ if (bilibili.length + relatedTNotes.length + yuque.length === 0) return [];
110
+ const lines = ["::: details \u{1F4DA} \u76F8\u5173\u8D44\u6E90", ""];
111
+ if (bilibili.length > 0) {
112
+ lines.push(
113
+ "- [\u{1F4FA} bilibili\uFF08\u7B14\u8BB0\u89C6\u9891\u8D44\u6E90\uFF09](https://space.bilibili.com/407241004)",
114
+ ...bilibili.map(
115
+ (bvid, index) => ` - [bilibili.${input.repoName}.${input.noteIndex}.${index + 1}](https://www.bilibili.com/video/${bvid})`
116
+ )
117
+ );
118
+ }
119
+ if (relatedTNotes.length > 0) {
120
+ lines.push(
121
+ "- [\u{1F4D2} TNotes\uFF08\u76F8\u5173\u77E5\u8BC6\u5E93\uFF09](https://tnotesjs.github.io/TNotes/)",
122
+ ...relatedTNotes.map(
123
+ (repoName) => ` - [TNotes.${repoName}](https://tnotesjs.github.io/TNotes.${repoName}/)`
124
+ )
125
+ );
126
+ }
127
+ if (yuque.length > 0) {
128
+ const base = "https://www.yuque.com/tdahuyou/tnotes.yuque/";
129
+ lines.push(
130
+ `- [\u{1F4C2} TNotes.yuque\uFF08\u7B14\u8BB0\u9644\u4EF6\u8D44\u6E90\uFF09](${base})`,
131
+ ...yuque.map(
132
+ (slug) => ` - [TNotes.yuque.${input.repoName.replace("TNotes.", "")}.${input.noteIndex}](${base}${slug})`
133
+ )
134
+ );
135
+ }
136
+ lines.push("", ":::", "");
137
+ return lines;
138
+ }
139
+ async function formatTNotesNote(input) {
140
+ let content = input.content.replace(/\r\n?/g, "\n");
141
+ if (input.prettier !== false) {
142
+ content = await _prettier.format.call(void 0, content, {
143
+ parser: "markdown",
144
+ proseWrap: "never",
145
+ endOfLine: "lf"
146
+ });
147
+ }
148
+ const lines = content.replace(/\n$/, "").split("\n");
149
+ const title = generatedNoteTitle(input);
150
+ ensureGeneratedTitle(lines, title);
151
+ let region = ensureTocRegion(lines);
152
+ const headings = normalizeHeadings(lines);
153
+ region = ensureTocRegion(lines);
154
+ const toc = buildHeadingToc(headings);
155
+ const resources = buildResourceToc(input);
156
+ lines.splice(
157
+ region.start + 1,
158
+ region.end - region.start - 1,
159
+ "",
160
+ ...resources,
161
+ ...toc,
162
+ ""
163
+ );
164
+ return {
165
+ content: `${lines.join("\n").replace(/\n{3,}$/g, "\n\n")}
166
+ `,
167
+ generatedTitle: title,
168
+ generatedToc: toc
169
+ };
170
+ }
171
+
172
+
173
+
174
+
175
+
176
+ exports.NOTE_TOC_START_TAG = NOTE_TOC_START_TAG; exports.NOTE_TOC_END_TAG = NOTE_TOC_END_TAG; exports.formatTNotesNote = formatTNotesNote;
@@ -0,0 +1,11 @@
1
+ // utils/generateAnchor.ts
2
+ import GithubSlugger from "github-slugger";
3
+ var slugger = new GithubSlugger();
4
+ var generateAnchor = (label) => {
5
+ slugger.reset();
6
+ return slugger.slug(label);
7
+ };
8
+
9
+ export {
10
+ generateAnchor
11
+ };