@type32/codemirror-rich-obsidian-editor 0.0.10 → 0.0.11

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/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
  - https://github.com/ebullient/markdown-it-obsidian-callouts, for his awesome markdown-to-html callouts markdown-it plugin
9
9
  - https://github.com/mgmeyers/obsidian-indentation-guides, for indentation guides
10
10
  - Markdown-It
11
+ - https://github.com/thecodrr/alfaaz, for insanely fast word/line-counting functions
11
12
 
12
13
  ### Related References & Resources
13
14
  - https://github.com/heavycircle/remark-obsidian, for mostly wiki link alias & highlights & callouts parsing
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.10",
4
+ "version": "0.0.11",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -0,0 +1,9 @@
1
+ export declare function useDocumentUtils(): {
2
+ getWordCount: (text: string) => number;
3
+ getLineCount: (text: string) => number;
4
+ getCharacters: (text: string) => number;
5
+ getReadingTime: (text: string, wordsPerMinute?: number) => number;
6
+ getParagraphs: (text: string) => number;
7
+ getAvgWordLength: (text: string) => number;
8
+ isEmpty: (text: string) => boolean;
9
+ };
@@ -0,0 +1,37 @@
1
+ import { countWords, countLines } from "alfaaz";
2
+ export function useDocumentUtils() {
3
+ function getWordCount(text) {
4
+ return countWords(text);
5
+ }
6
+ function getLineCount(text) {
7
+ return countLines(text);
8
+ }
9
+ function getCharacters(text) {
10
+ return text.length;
11
+ }
12
+ function getReadingTime(text, wordsPerMinute = 200) {
13
+ const wordCount = countWords(text);
14
+ return Math.ceil(wordCount / wordsPerMinute);
15
+ }
16
+ function getParagraphs(text) {
17
+ return text.split(/\n\s*\n/).filter((p) => p.trim().length > 0).length;
18
+ }
19
+ function getAvgWordLength(text) {
20
+ const words = text.match(/\b\w+\b/g) || [];
21
+ if (words.length === 0) return 0;
22
+ const totalChars = words.reduce((sum, word) => sum + word.length, 0);
23
+ return totalChars / words.length;
24
+ }
25
+ function isEmpty(text) {
26
+ return text.trim().length === 0;
27
+ }
28
+ return {
29
+ getWordCount,
30
+ getLineCount,
31
+ getCharacters,
32
+ getReadingTime,
33
+ getParagraphs,
34
+ getAvgWordLength,
35
+ isEmpty
36
+ };
37
+ }
@@ -1,5 +1,7 @@
1
1
  import { computed, unref } from "vue";
2
2
  import { markdown } from "@codemirror/lang-markdown";
3
+ import { CustomOFM } from "../../runtime/editor/lezer-parsers/customOFMParsers";
4
+ import { GFM } from "@lezer/markdown";
3
5
  export function useEditorUtils(editor) {
4
6
  const view = computed(() => {
5
7
  const instance = unref(editor);
@@ -24,7 +26,13 @@ export function useEditorUtils(editor) {
24
26
  unref(view)?.dispatch(...specs);
25
27
  }
26
28
  function parseMarkdownToAST(markdownText) {
27
- return markdown().language.parser.parse(markdownText);
29
+ return markdown({
30
+ extensions: [
31
+ GFM,
32
+ CustomOFM,
33
+ { remove: ["SetextHeading"] }
34
+ ]
35
+ }).language.parser.parse(markdownText);
28
36
  }
29
37
  function getDocAst() {
30
38
  return parseMarkdownToAST(getDoc() || "");
@@ -75,6 +75,7 @@ export default function(config) {
75
75
  indentationListPlugin,
76
76
  // editorAttributesPlugin,
77
77
  syntaxHighlighting(proseStylesPlugin),
78
+ //@ts-ignore
78
79
  markdown(mergedConfig)
79
80
  ]
80
81
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@type32/codemirror-rich-obsidian-editor",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "OFM Editor Component for Nuxt.",
5
5
  "repository": "Type-32/codemirror-rich-obsidian",
6
6
  "license": "MIT",
@@ -46,6 +46,7 @@
46
46
  "@nuxt/image": "1.10.0",
47
47
  "@nuxt/kit": "^4.1.2",
48
48
  "@nuxt/ui": "^4.0.0-alpha.1",
49
+ "alfaaz": "^1.1.0",
49
50
  "codemirror": "^6.0.2",
50
51
  "js-yaml": "^4.1.0",
51
52
  "katex": "^0.16.22",