diff --git a/package-lock.json b/package-lock.json index ceda9eb..09cc670 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,15 @@ { "name": "obsidian-mathematics", - "version": "0.0.1", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-mathematics", - "version": "0.0.1", + "version": "0.2.0", "license": "MIT", "dependencies": { + "@codemirror/language": "^6.0.0", "@lezer/common": "^1.0.3", "yaml": "^2.3.1" }, @@ -33,19 +34,28 @@ "node": ">=0.10.0" } }, + "node_modules/@codemirror/language": { + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.8.0.tgz", + "integrity": "sha512-r1paAyWOZkfY0RaYEZj3Kul+MiQTEbDvYqf8gPGaRvNneHXCmfSaAVFjwRUPlgxS8yflMxw2CTu6uCMp8R8A2g==", + "dependencies": { + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "@lezer/common": "^1.0.0", + "@lezer/highlight": "^1.0.0", + "@lezer/lr": "^1.0.0", + "style-mod": "^4.0.0" + } + }, "node_modules/@codemirror/state": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.2.1.tgz", - "integrity": "sha512-RupHSZ8+OjNT38zU9fKH2sv+Dnlr8Eb8sl4NOnnqz95mCFTZUaiRP8Xv5MeeaG0px2b8Bnfe7YGwCV3nsBhbuw==", - "dev": true, - "peer": true + "integrity": "sha512-RupHSZ8+OjNT38zU9fKH2sv+Dnlr8Eb8sl4NOnnqz95mCFTZUaiRP8Xv5MeeaG0px2b8Bnfe7YGwCV3nsBhbuw==" }, "node_modules/@codemirror/view": { "version": "6.15.3", "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.15.3.tgz", "integrity": "sha512-chNgR8H7Ipx7AZUt0+Kknk7BCow/ron3mHd1VZdM7hQXiI79+UlWqcxpCiexTxZQ+iSkqndk3HHAclJOcjSuog==", - "dev": true, - "peer": true, "dependencies": { "@codemirror/state": "^6.1.4", "style-mod": "^4.0.0", @@ -505,6 +515,22 @@ "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.0.3.tgz", "integrity": "sha512-JH4wAXCgUOcCGNekQPLhVeUtIqjH0yPBs7vvUdSjyQama9618IOKFJwkv2kcqdhF0my8hQEgCTEJU0GIgnahvA==" }, + "node_modules/@lezer/highlight": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.1.6.tgz", + "integrity": "sha512-cmSJYa2us+r3SePpRCjN5ymCqCPv+zyXmDl0ciWtVaNiORT/MxM7ZgOMQZADD0o51qOaOg24qc/zBViOIwAjJg==", + "dependencies": { + "@lezer/common": "^1.0.0" + } + }, + "node_modules/@lezer/lr": { + "version": "1.3.9", + "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.3.9.tgz", + "integrity": "sha512-XPz6dzuTHlnsbA5M2DZgjflNQ+9Hi5Swhic0RULdp3oOs3rh6bqGZolosVqN/fQIT8uNiepzINJDnS39oweTHQ==", + "dependencies": { + "@lezer/common": "^1.0.0" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2047,9 +2073,7 @@ "node_modules/style-mod": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.0.3.tgz", - "integrity": "sha512-78Jv8kYJdjbvRwwijtCevYADfsI0lGzYJe4mMFdceO8l75DFFDoqBhR1jVDicDRRaX4//g1u9wKeo+ztc2h1Rw==", - "dev": true, - "peer": true + "integrity": "sha512-78Jv8kYJdjbvRwwijtCevYADfsI0lGzYJe4mMFdceO8l75DFFDoqBhR1jVDicDRRaX4//g1u9wKeo+ztc2h1Rw==" }, "node_modules/supports-color": { "version": "7.2.0", @@ -2162,9 +2186,7 @@ "node_modules/w3c-keyname": { "version": "2.2.8", "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", - "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==", - "dev": true, - "peer": true + "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==" }, "node_modules/which": { "version": "2.0.2", diff --git a/package.json b/package.json index 2c72785..8ff45d0 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@lezer/common": "^1.0.3", + "@codemirror/language": "^6.0.0", "yaml": "^2.3.1" } } diff --git a/src/callout_view.ts b/src/callout_view.ts index fda7f43..e48d78e 100644 --- a/src/callout_view.ts +++ b/src/callout_view.ts @@ -1,12 +1,9 @@ -import { Extension } from '@codemirror/state'; -import { Transaction } from '@codemirror/state'; -import { StateField } from '@codemirror/state'; -import { syntaxTree } from '@codemirror/language'; -import { RangeSetBuilder } from '@codemirror/state'; -import { EditorState } from '@codemirror/state'; -import { Decoration, DecorationSet, EditorView, WidgetType } from "@codemirror/view"; -import { SyntaxNodeRef } from '@lezer/common'; import { finishRenderMath, renderMath } from "obsidian"; +import { Extension, Transaction, StateField, RangeSetBuilder, EditorState } from '@codemirror/state'; +import { Decoration, DecorationSet, EditorView, WidgetType } from "@codemirror/view"; +import { syntaxTree } from '@codemirror/language'; + +import { nodeText } from 'utils'; const DISPLAY_MATH_BEGIN = "formatting_formatting-math_formatting-math-begin_keyword_math_math-block"; @@ -139,10 +136,6 @@ function getMathInfos(state: EditorState): MathInfo[] { return mathInfos; } -function nodeText(node: SyntaxNodeRef, state: EditorState): string { - return state.sliceDoc(node.from, node.to); -} - function isInBlockquoteOrCallout(state: EditorState): boolean { let cursor = state.selection.ranges[0].head; let tree = syntaxTree(state); diff --git a/src/math_callout_title_hider.ts b/src/math_callout_title_hider.ts index 6825238..e2d992e 100644 --- a/src/math_callout_title_hider.ts +++ b/src/math_callout_title_hider.ts @@ -1,14 +1,10 @@ -import { mathCalloutTitlePlulgin } from 'math_callouts_view'; import { RangeSetBuilder } from '@codemirror/state'; import { syntaxTree } from "@codemirror/language"; import { Decoration, DecorationSet, EditorView, MatchDecorator, PluginValue, ViewPlugin, ViewUpdate, WidgetType } from "@codemirror/view" import { MATH_CALLOUT_PATTERN, formatTitleWithoutSubtitle, matchMathCallout, readMathCalloutMetadata, readMathCalloutSettingsAndTitle } from "autoIndex" import MathPlugin from "main"; -import { SmartCalloutModal } from "modals"; import { App, Editor, MarkdownView, TFile } from "obsidian"; -import { MathSettings } from "settings"; -import { formatTitle, overwriteMathCalloutMetadata, resolveSettings } from "smart_callouts"; -import { nodeText, renderTextWithMath } from "utils"; +import { nodeText } from 'utils'; export const MATH_CALLOUT_PATTERN_GLOBAL = new RegExp(MATH_CALLOUT_PATTERN.source, "g"); diff --git a/src/modals.ts b/src/modals.ts index 7c9b257..443b6f5 100644 --- a/src/modals.ts +++ b/src/modals.ts @@ -69,18 +69,16 @@ abstract class MathSettingModal extends Modal { export class MathCalloutModal extends MathSettingModal { - constructor( app: App, plugin: MathPlugin, public view: MarkdownView, callback: (settings: MathSettings) => void, - public buttonText?: string, - public headerText?: string, + public buttonText: string, + public headerText: string, currentCalloutSettings?: CalloutSettings, ) { super(app, plugin, callback, currentCalloutSettings); - this.buttonText = buttonText ?? "Insert"; } diff --git a/src/utils.ts b/src/utils.ts index dde1e5c..9763b4a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,5 @@ +import { EditorState } from '@codemirror/state'; +import { SyntaxNodeRef } from '@lezer/common'; // Generic utility functions handing files. @@ -203,6 +205,10 @@ export function insertAfter(referenceNode: HTMLElement, newNode: HTMLElement) { referenceNode.parentNode?.insertBefore(newNode, referenceNode.nextSibling); } +export function nodeText(node: SyntaxNodeRef, state: EditorState): string { + return state.sliceDoc(node.from, node.to); +} + const ROMAN = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]; @@ -239,4 +245,4 @@ export const CONVERTER = { "Alph": toAlphUpper, "roman": toRomanLower, "Roman": toRomanUpper, -} \ No newline at end of file +}