@type32/codemirror-rich-obsidian-editor 0.0.20 → 0.0.22

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@type32/codemirror-rich-obsidian-editor",
3
3
  "configKey": "cmOfmEditor",
4
- "version": "0.0.20",
4
+ "version": "0.0.22",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,3 +1,4 @@
1
+ import { type TocEntry } from '../editor/types/editor-types.js';
1
2
  export declare function useDocumentUtils(): {
2
3
  getWordCount: (text: string) => number;
3
4
  getLineCount: (text: string) => number;
@@ -6,4 +7,5 @@ export declare function useDocumentUtils(): {
6
7
  getParagraphs: (text: string) => number;
7
8
  getAvgWordLength: (text: string) => number;
8
9
  isEmpty: (text: string) => boolean;
10
+ getTableOfContents: (text: string) => TocEntry[];
9
11
  };
@@ -1,4 +1,7 @@
1
1
  import { useAlfaaz } from "./useAlfaaz.js";
2
+ import { markdown } from "@codemirror/lang-markdown";
3
+ import { GFM } from "@lezer/markdown";
4
+ import { CustomOFM } from "../editor/lezer-parsers/customOFMParsers.js";
2
5
  export function useDocumentUtils() {
3
6
  const alfaaz = useAlfaaz();
4
7
  function getWordCount(text) {
@@ -26,6 +29,34 @@ export function useDocumentUtils() {
26
29
  function isEmpty(text) {
27
30
  return text.trim().length === 0;
28
31
  }
32
+ function getTableOfContents(text) {
33
+ const toc = [];
34
+ if (!text) return toc;
35
+ const tree = markdown({
36
+ extensions: [GFM, CustomOFM, { remove: ["SetextHeading"] }]
37
+ }).language.parser.parse(text);
38
+ tree.iterate({
39
+ enter: (node) => {
40
+ if (node.name.startsWith("ATXHeading")) {
41
+ const levelMatch = node.name.match(/ATXHeading(\d)/);
42
+ if (levelMatch && levelMatch[1]) {
43
+ const level = parseInt(levelMatch[1], 10);
44
+ const headerMark = node.node.getChild("HeaderMark");
45
+ if (headerMark) {
46
+ const from = headerMark.to + 1;
47
+ const to = node.to;
48
+ const textContent = text.slice(from, to).trim();
49
+ toc.push({
50
+ level,
51
+ text: textContent
52
+ });
53
+ }
54
+ }
55
+ }
56
+ }
57
+ });
58
+ return toc;
59
+ }
29
60
  return {
30
61
  getWordCount,
31
62
  getLineCount,
@@ -33,6 +64,7 @@ export function useDocumentUtils() {
33
64
  getReadingTime,
34
65
  getParagraphs,
35
66
  getAvgWordLength,
36
- isEmpty
67
+ isEmpty,
68
+ getTableOfContents
37
69
  };
38
70
  }
@@ -51,4 +51,9 @@ export type Frontmatter<T extends object = {}> = {
51
51
  [key: string]: any;
52
52
  } & T
53
53
 
54
- export type UnicodeRange = number[][]
54
+ export type UnicodeRange = number[][]
55
+
56
+ export interface TocEntry {
57
+ level: number
58
+ text: string
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@type32/codemirror-rich-obsidian-editor",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "OFM Editor Component for Nuxt.",
5
5
  "repository": "Type-32/codemirror-rich-obsidian",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "@lezer/markdown": "^1.4.3",
46
46
  "@nuxt/image": "1.10.0",
47
47
  "@nuxt/kit": "^4.1.2",
48
- "@nuxt/ui": "^4.0.0-alpha.2",
48
+ "@nuxt/ui": "^4.0.0",
49
49
  "alfaaz": "^1.1.0",
50
50
  "codemirror": "^6.0.2",
51
51
  "js-yaml": "^4.1.0",
@@ -57,8 +57,8 @@
57
57
  },
58
58
  "devDependencies": {
59
59
  "@iconify-json/lucide": "^1.2.68",
60
- "@iconify-json/simple-icons": "^1.2.52",
61
- "@nuxt/devtools": "^2.6.3",
60
+ "@iconify-json/simple-icons": "^1.2.53",
61
+ "@nuxt/devtools": "^2.6.5",
62
62
  "@nuxt/eslint-config": "^1.9.0",
63
63
  "@nuxt/fonts": "0.11.4",
64
64
  "@nuxt/icon": "1.15.0",
@@ -68,11 +68,11 @@
68
68
  "@types/js-yaml": "^4.0.9",
69
69
  "@types/node": "latest",
70
70
  "changelogen": "^0.6.2",
71
- "eslint": "^9.35.0",
71
+ "eslint": "^9.36.0",
72
72
  "nuxt": "^4.1.2",
73
73
  "typescript": "~5.9.2",
74
74
  "vitest": "^3.2.4",
75
- "vue-tsc": "^3.0.7",
75
+ "vue-tsc": "^3.0.8",
76
76
  "alfaaz": "^1.1.0"
77
77
  },
78
78
  "trustedDependencies": [