Skip to content

Commit c5da3b4

Browse files
authored
feat: add formula editor (#1484)
- Remove katex npm dependency, use existing window.MathJax instead - Add renderWithMathJax() helper in FormulaEditorDialog for preview and snippet rendering - Add escapeHtml to packages/core/src/utils/basicHelpers.ts - Handle formula click in preview area to open formula editor (useCursorSync) - Fix mobile scroll: formula library panel now scrollable on small screens - EditorContextMenu/InsertDropdown: don't pass sourceRaw for selection-based editing, use replaceSelection() instead - formula.ts: fix isWrapped detection to only check if unwrapFormula actually stripped delimiters - editor.ts: replaceText() now replaces the occurrence nearest to the current cursor - FormulaEditorDialog: cache MathJax snippet renders to avoid redundant re-renders - katex.ts: remove unused data-math-latex attribute to reduce HTML output size close #1483
1 parent d8bae22 commit c5da3b4

11 files changed

Lines changed: 581 additions & 3 deletions

File tree

apps/web/src/components/editor/EditorContextMenu.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { useRenderStore } from '@/stores/render'
3939
import { useThemeStore } from '@/stores/theme'
4040
import { useUIStore } from '@/stores/ui'
4141
import { copyPlain } from '@/utils/clipboard'
42+
import { normalizeFormulaInput } from '@/utils/formula'
4243
4344
const confirmStore = useConfirmStore()
4445
const cssEditorStore = useCssEditorStore()
@@ -85,6 +86,14 @@ function clearContent() {
8586
editorStore.clearContent()
8687
}
8788
89+
function openFormulaEditor() {
90+
const selection = normalizeFormulaInput(editorStore.getSelection())
91+
uiStore.openFormulaEditor({
92+
value: selection.latex,
93+
displayMode: selection.displayMode,
94+
})
95+
}
96+
8897
// 复制到剪贴板
8998
async function copyToClipboard() {
9099
const selectedText = editorStore.getSelection()
@@ -154,6 +163,10 @@ function downloadAsCardImage() {
154163
<Image class="mr-2 h-4 w-4" />
155164
图片
156165
</ContextMenuItem>
166+
<ContextMenuItem @click="openFormulaEditor()">
167+
<span class="mr-2 inline-flex h-4 w-4 items-center justify-center text-xs font-semibold">ƒ</span>
168+
公式
169+
</ContextMenuItem>
157170
<ContextMenuItem @click="toggleShowInsertFormDialog()">
158171
<Table class="mr-2 h-4 w-4" />
159172
表格

0 commit comments

Comments
 (0)