* 设置语言
(language: string)
| 1397 | * 设置语言 |
| 1398 | */ |
| 1399 | private setLanguage(language: string): void { |
| 1400 | const pos = this.getPos(); |
| 1401 | if (pos === undefined) return; |
| 1402 | |
| 1403 | const prevLanguage = this.node.attrs.language; |
| 1404 | |
| 1405 | // 更新 ProseMirror 节点属性 |
| 1406 | this.view.dispatch( |
| 1407 | this.view.state.tr.setNodeMarkup(pos, null, { |
| 1408 | ...this.node.attrs, |
| 1409 | language, |
| 1410 | }) |
| 1411 | ); |
| 1412 | |
| 1413 | // 更新 CodeMirror 语言扩展 |
| 1414 | this.cm.dispatch({ |
| 1415 | effects: this.languageCompartment.reconfigure(getLanguageExtension(language)), |
| 1416 | }); |
| 1417 | |
| 1418 | // 更新头部(添加或移除 Mermaid 模式选择器) |
| 1419 | if ((prevLanguage === "mermaid") !== (language === "mermaid")) { |
| 1420 | this.updateHeader(language); |
| 1421 | } |
| 1422 | |
| 1423 | // 更新 Mermaid 预览 |
| 1424 | if (language === "mermaid") { |
| 1425 | this.createMermaidPreview(this.cm.state.doc.toString()); |
| 1426 | } else if (this.mermaidPreview) { |
| 1427 | this.mermaidPreview.remove(); |
| 1428 | this.mermaidPreview = null; |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | /** |
| 1433 | * 更新头部 |
no test coverage detected