43 lines
953 B
C++
43 lines
953 B
C++
#ifndef CTAI_CMARK_GFM_H
|
|
#define CTAI_CMARK_GFM_H
|
|
|
|
#include <cmark-gfm.h>
|
|
#include <QString>
|
|
#include <QTextEdit>
|
|
#include <memory>
|
|
|
|
namespace ctai_cmark_gfm {
|
|
|
|
class MarkdownStreamProcessor {
|
|
public:
|
|
explicit MarkdownStreamProcessor(QTextEdit* textEdit);
|
|
~MarkdownStreamProcessor();
|
|
|
|
// 追加内容并处理Markdown
|
|
void appendMarkdown(const QString& text);
|
|
|
|
private:
|
|
static constexpr size_t BUFFER_SIZE = 4096;
|
|
|
|
QTextEdit* m_textEdit;
|
|
QString m_buffer;
|
|
QString m_tempText;
|
|
|
|
// 检查是否包含Markdown开始标记
|
|
bool hasMarkdownStart(const QString& text);
|
|
|
|
// 检查是否包含Markdown结束标记
|
|
bool hasMarkdownEnd(const QString& text);
|
|
|
|
// 渲染Markdown内容
|
|
QString renderMarkdown(const QString& text);
|
|
|
|
// 处理缓冲区溢出
|
|
void handleBufferOverflow();
|
|
|
|
// 替换临时文本
|
|
void replaceTempText(const QString& newContent);
|
|
};
|
|
|
|
}
|
|
#endif |