From dcf90fe57501717fd3e77e2e4c9b594bbc1b8cbf Mon Sep 17 00:00:00 2001 From: JackLee <809262979@qq.com> Date: Mon, 3 Mar 2025 21:26:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=B1=BB=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 6 ------ src/ctai_history_textedit.cpp | 6 +++--- src/ctai_history_textedit.h | 2 +- src/{ctai_parsestring.cpp => ctai_markdown.cpp} | 10 +++++----- src/{ctai_parsestring.h => ctai_markdown.h} | 11 +++++++---- 5 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 .gitmodules rename src/{ctai_parsestring.cpp => ctai_markdown.cpp} (85%) rename src/{ctai_parsestring.h => ctai_markdown.h} (51%) diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 1e3f127..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "3rdparty/cmark-gfm"] - path = 3rdparty/cmark-gfm - url = https://github.com/github/cmark-gfm.git -[submodule "3rdparty/md4qt"] - path = 3rdparty/md4qt - url = https://github.com/igormironchik/md4qt.git diff --git a/src/ctai_history_textedit.cpp b/src/ctai_history_textedit.cpp index 0e991af..e438e5e 100644 --- a/src/ctai_history_textedit.cpp +++ b/src/ctai_history_textedit.cpp @@ -281,16 +281,16 @@ void ctai_history_textedit::add_message(const model_data &message) m_tokens_data.total_tokens = "总消耗tokens:" + QSN(message.postback_total_tokens); m_tokens_data.cache_hit_tokens = "提示词缓存命中消耗tokens:" + QSN(message.postback_prompt_cache_hit_tokens); m_tokens_data.cache_miss_tokens = "提示词缓存未命中消耗tokens:" + QSN(message.postback_prompt_cache_miss_tokens); - disp_data = ctai_parse::markdown_to_html(QSL(message.postback_model_data)); + disp_data =ctai_markdown::md_to_html(QSL(message.postback_model_data)); m_msg_sned_id = QSL(message.postback_send_id); } else { disp_header = "ID:" + QSL(message.send_user_id) + " | Time:" + QSL(message.send_user_time); - disp_data = ctai_parse::markdown_to_html(QSL(message.send_user_data)); + disp_data = ctai_markdown::md_to_html(QSL(message.send_user_data)); m_msg_sned_id = QSL(message.send_user_id); } - m_msg_header->setText(disp_header); + m_msg_header->setText(disp_header); m_msg_history->setHtml(disp_data); } void ctai_history_textedit::on_delete_clicked() diff --git a/src/ctai_history_textedit.h b/src/ctai_history_textedit.h index 5b7241e..bbfa8b4 100644 --- a/src/ctai_history_textedit.h +++ b/src/ctai_history_textedit.h @@ -21,7 +21,7 @@ #include #include #include "ctai_base.h" -#include "ctai_parsestring.h" +#include "ctai_markdown.h" typedef struct tokens_args{ QString prompt_tokens={}; diff --git a/src/ctai_parsestring.cpp b/src/ctai_markdown.cpp similarity index 85% rename from src/ctai_parsestring.cpp rename to src/ctai_markdown.cpp index f9fb489..338b0b7 100644 --- a/src/ctai_parsestring.cpp +++ b/src/ctai_markdown.cpp @@ -1,11 +1,10 @@ -#include "ctai_parsestring.h" +#include "ctai_markdown.h" -namespace ctai_parse { +namespace ctai_markdown { -QString markdown_to_html(const QString& text) { +QString md_to_html(const QString& text) { // 转换为UTF-8编码的字符串 - QByteArray markdown = text.toUtf8(); - + QByteArray markdown = text.toUtf8(); // 使用cmark解析Markdown char *html = cmark_markdown_to_html( markdown.constData(), @@ -16,6 +15,7 @@ QString markdown_to_html(const QString& text) { // 转换回QString并处理代码块 QString result = QString::fromUtf8(html); free(html); + qDebug()<<"处理的块:"< #include +#include -namespace ctai_parse { +namespace ctai_markdown { // Markdown 转 HTML - QString markdown_to_html(const QString& text); + QString md_to_html(const QString& text); // 纯文本转义 QString escape_html(const QString& text); // 处理代码块样式 QString process_code_blocks(QString html); + + void savePDF(QString fileName); } #endif // CTAI_PARSESTRING_H \ No newline at end of file