mirror of
https://github.com/EthanMarti/infio-copilot.git
synced 2026-05-10 17:18:19 +00:00
init
This commit is contained in:
44
src/core/edit/inline-edit-processor.ts
Normal file
44
src/core/edit/inline-edit-processor.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { MarkdownPostProcessorContext, Plugin } from "obsidian";
|
||||
import React from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
|
||||
import { InlineEdit as InlineEditComponent } from "../../components/inline-edit/InlineEdit";
|
||||
import { InfioSettings } from "../../types/settings";
|
||||
|
||||
export class InlineEdit {
|
||||
plugin: Plugin;
|
||||
settings: InfioSettings;
|
||||
|
||||
constructor(plugin: Plugin, settings: InfioSettings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Markdown 处理器入口函数
|
||||
*/
|
||||
Processor(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) {
|
||||
const sec = ctx.getSectionInfo(el);
|
||||
if (!sec) return;
|
||||
|
||||
const container = createDiv();
|
||||
const root = createRoot(container);
|
||||
|
||||
root.render(
|
||||
React.createElement(InlineEditComponent, {
|
||||
source: source,
|
||||
secStartLine: sec.lineStart,
|
||||
secEndLine: sec.lineEnd,
|
||||
plugin: this.plugin,
|
||||
settings: this.settings
|
||||
})
|
||||
);
|
||||
|
||||
// 移除父元素的代码块样式
|
||||
const parent = el.parentElement;
|
||||
if (parent) {
|
||||
parent.addClass("infio-ai-block");
|
||||
}
|
||||
el.replaceWith(container);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user