-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug Report]setMarkdown内容不可编辑 #997
Comments
奇怪,没有重现出来,可以尝试在 |
我选择编辑区,没有光标,但是可以全选。使用 如果将鼠标光标放到文本的最后,就会出现光标闪烁,也不会报错。参照之前的issue,我已经将cherry实例换成全局单例了,但还是不行呜呜呜 <template>
<div class="article-container">
<!-- 文章标题 -->
<div class="article-header">
<h1 v-if="article">{{ article.title }}</h1>
<p v-if="loading" class="loading">加载中...</p>
<p v-if="error" class="error">加载失败,请稍后再试。</p>
</div>
<!-- 文章内容 (Markdown 渲染) -->
<div id="markdown-container"></div>
</div>
</template>
<script>
import api from "@/api/article.js"
import "@/assets/article_detail.css";
import 'cherry-markdown/src/sass/themes/diy.scss'
import 'cherry-markdown/dist/cherry-markdown.css';
import {getCherryInstance} from "@/utils/cherryMarkdown.js";
export default {
data() {
return {
article: null, // 存储文章数据
loading: true, // 加载状态
error: false, // 错误状态
cherryInstancePreviewer: null, // Cherry 实例
};
},
async created() {
},
async mounted() {
this.cherryInstancePreviewer = getCherryInstance();
const articleID = this.$route.query.articleID;
if (articleID) {
await this.fetchArticle(articleID);
console.info("created() -> fetchArticle(articleID =", articleID, ")");
} else {
this.error = true;
}
},
methods: {
async fetchArticle(articleID) {
this.loading = true;
try {
const response = await fetch(api.articleDetails + `?articleID=${articleID}`);
if (!response.ok) throw new Error('Failed to fetch article.');
const result = JSON.parse(await response.text()); // 解析 JSON
console.log("Parsed JSON:", result);
this.article = result.data
console.log(this.result);
// 解析 Markdown
if (!this.cherryInstancePreviewer) console.info("this.cherryInstancePreviewer failed.")
if (this.cherryInstancePreviewer && this.article.content) {
this.cherryInstancePreviewer.setMarkdown(this.article.content, true);
this.cherryInstancePreviewer.editor.editor.refresh();
this.cherryInstancePreviewer.editor.editor.setCursor(this.cherryInstancePreviewer.getMarkdown().length)
this.cherryInstancePreviewer.switchModel('edit&preview');
// this.cherryInstancePreviewer.switchModel('previewOnly');
// this.cherryInstancePreviewer.switchModel('editOnly');
}
} catch (error) {
console.error('Error fetching article:', error);
this.error = true;
} finally {
this.loading = false;
}
},
},
};
</script>
cherry单例
```javascript
import 'cherry-markdown/src/sass/themes/diy.scss'
import Cherry from "cherry-markdown";
import 'cherry-markdown/dist/cherry-markdown.css';
let cherryInstance = null; // 单例实例
export function getCherryInstance() {
if (!cherryInstance) {
cherryInstance = new Cherry({
id: "markdown-container",
value: `# 公式测试`,
externals: {
echarts: window.echarts,
katex: window.katex || null,
MathJax: window.MathJax,
},
nameSpace: 'cherry',
themeSettings: {
// 主题列表,用于切换主题
themeList: [
{className: 'div', label: 'div'},
{className: 'default', label: 'default'},
{className: 'dark', label: 'dark'},
],
// 目前应用的主题
mainTheme: 'div',
// 目前应用的代码块主题
codeBlockTheme: 'default',
},
engine: {
syntax: {
mathBlock: {
plugins: true, // 默认加载插件
engine: 'MathJax', // katex或MathJax
src: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js',
},
inlineMath: {
engine: 'MathJax', // katex或MathJax
src: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"
},
header: {
anchorStyle: "autonumber",
strict: false,
},
},
},
toolbars: {
toolbar: ['bold', 'italic', 'strikethrough', '|',
'color', 'ruby', '|',
'list', 'panel', 'detail', '|',
'theme', {insert: ['image', 'audio', 'video', 'link', 'code', 'formula', 'toc', 'table', 'drawIo']},
'togglePreview', 'switchModel',
],
},
});
}
return cherryInstance;
} |
哦哦,是因为Cherry对象无法被代理,可以看这个issue哈:#381 (comment) |
Prerequisites
There isn't an existing issue that reports the same bug to avoid duplicates.
The provided information offers a minimal reproducible example of the bug, (Why create a Minimal).
For Q&A, please open a GitHub Discussion instead.
Version
v0.8.52
Reproduction Link
No response
Describe the Bug
使用setMarkdown的内容不可编辑,但是其余的位置可以插入和编辑,求助!!
全局Control+X之后再粘贴,就可以输入了。。
System Information
Contributing
Yes, I would like to submit a PR for this issue.
The text was updated successfully, but these errors were encountered: