update at 2025-09-22 14:58:45

This commit is contained in:
douboer
2025-09-22 14:58:45 +08:00
parent 0090ce9b93
commit 9b8ec73c83
10 changed files with 394 additions and 377 deletions

View File

@@ -22,8 +22,6 @@
import { EventRef, ItemView, Workspace, WorkspaceLeaf, Notice, Platform, TFile, TFolder, TAbstractFile, Plugin } from 'obsidian';
import { uevent, debounce, waitForLayoutReady } from './utils';
// [note-to-mp 重构] 引入新渲染管线
import { RenderService, RenderedArticle } from './render';
import { NMPSettings } from './settings';
import AssetsManager from './assets';
import { MarkedParser } from './markdown/parser';
@@ -64,9 +62,6 @@ export class NotePreview extends ItemView {
_articleRender: ArticleRender | null = null;
isCancelUpload: boolean = false;
isBatchRuning: boolean = false;
// [note-to-mp 重构] 新渲染服务实例与最近一次渲染结果
newRenderService: RenderService | null = null;
lastArticle?: RenderedArticle;
constructor(leaf: WorkspaceLeaf, plugin: Plugin) {
@@ -118,8 +113,6 @@ export class NotePreview extends ItemView {
}
this.buildUI();
// [note-to-mp 重构] 初始化新渲染服务
this.newRenderService = new RenderService(this.app);
this.listeners = [
this.workspace.on('file-open', () => {
this.update();
@@ -447,33 +440,31 @@ export class NotePreview extends ItemView {
return;
}
this.currentFile = af;
// [note-to-mp 重构] 使用新渲染服务进行渲染
if (this.newRenderService) {
try {
const article = await this.newRenderService.renderFile(af);
this.lastArticle = article;
if (this.articleDiv) {
this.articleDiv.empty();
const wrap = this.articleDiv.createDiv();
wrap.innerHTML = article.html;
await this.render.renderMarkdown(af);
const metadata = this.render.getMetadata();
if (metadata.appid) {
this.wechatSelect.value = metadata.appid;
}
else {
this.wechatSelect.value = this.currentAppId;
}
if (metadata.theme) {
this.assetsManager.themes.forEach(theme => {
if (theme.name === metadata.theme) {
this.themeSelect.value = theme.className;
}
// 元数据适配(当前新 meta 不含 appid/theme/highlight保持现有选择状态
if (this.wechatSelect) {
this.wechatSelect.value = this.currentAppId || '';
}
if (this.themeSelect) {
this.themeSelect.value = this.currentTheme;
}
if (this.highlightSelect) {
this.highlightSelect.value = this.currentHighlight;
}
} catch (e) {
console.error('[note-to-mp 重构] 渲染失败', e);
new Notice('渲染失败: ' + e.message);
}
} else {
// 兜底:仍使用旧渲染
await this.render.renderMarkdown(af);
});
}
else {
this.themeSelect.value = this.currentTheme;
}
if (metadata.highlight) {
this.highlightSelect.value = this.render.currentHighlight;
}
else {
this.highlightSelect.value = this.currentHighlight;
}
}