解决一些小bug
This commit is contained in:
parent
8730cb19b7
commit
695f6f5a30
1
res.qrc
1
res.qrc
@ -45,6 +45,5 @@
|
|||||||
|
|
||||||
<file>res/txt/about.txt</file>
|
<file>res/txt/about.txt</file>
|
||||||
<file>res/cacert/cacert.pem</file>
|
<file>res/cacert/cacert.pem</file>
|
||||||
<file>res/qss/message_style.css</file>
|
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@ -1,145 +0,0 @@
|
|||||||
div.message {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: flex-start;
|
|
||||||
margin: 5px;
|
|
||||||
padding: 10px;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
background-color: #fff;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.header {
|
|
||||||
color: #666;
|
|
||||||
font-size: 12px;
|
|
||||||
margin-bottom: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.msg-id {
|
|
||||||
color: #0366d6;
|
|
||||||
font-weight: bold;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.content {
|
|
||||||
margin: 5px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.button-placeholder {
|
|
||||||
height: 25px;
|
|
||||||
margin-top: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
|
||||||
background-color: #f6f8fa;
|
|
||||||
padding: 2px 4px;
|
|
||||||
border-radius: 3px;
|
|
||||||
font-family: monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
|
||||||
background-color: #f6f8fa;
|
|
||||||
padding: 16px;
|
|
||||||
border-radius: 6px;
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 { font-size: 2em; margin: 0.5em 0; }
|
|
||||||
h2 { font-size: 1.5em; margin: 0.5em 0; }
|
|
||||||
h3 { font-size: 1.2em; margin: 0.5em 0; }
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: #0366d6;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
li {
|
|
||||||
margin-left: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre.python-code {
|
|
||||||
background-color: #272822;
|
|
||||||
color: #f8f8f2;
|
|
||||||
padding: 16px;
|
|
||||||
border-radius: 6px;
|
|
||||||
font-family: 'Consolas', 'Monaco', monospace;
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.5;
|
|
||||||
overflow-x: auto;
|
|
||||||
border-left: 3px solid #66d9ef;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre.code-block {
|
|
||||||
background-color: #f6f8fa;
|
|
||||||
padding: 16px;
|
|
||||||
border-radius: 6px;
|
|
||||||
font-family: 'Consolas', 'Monaco', monospace;
|
|
||||||
overflow-x: auto;
|
|
||||||
border-left: 3px solid #e1e4e8;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.math-inline {
|
|
||||||
font-family: 'Times New Roman', serif;
|
|
||||||
font-size: 16px;
|
|
||||||
padding: 0 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.math-block {
|
|
||||||
font-family: 'Times New Roman', serif;
|
|
||||||
font-size: 18px;
|
|
||||||
margin: 1em 0;
|
|
||||||
padding: 1em;
|
|
||||||
text-align: center;
|
|
||||||
background-color: #f8f9fa;
|
|
||||||
border-left: 3px solid #2196f3;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.fraction {
|
|
||||||
display: inline-block;
|
|
||||||
vertical-align: middle;
|
|
||||||
text-align: center;
|
|
||||||
padding: 0 3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.numerator {
|
|
||||||
display: block;
|
|
||||||
border-bottom: 1px solid;
|
|
||||||
padding: 0 3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.denominator {
|
|
||||||
display: block;
|
|
||||||
padding: 0 3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
sup {
|
|
||||||
font-size: 0.75em;
|
|
||||||
vertical-align: super;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub {
|
|
||||||
font-size: 0.75em;
|
|
||||||
vertical-align: sub;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-content {
|
|
||||||
flex: 1;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button-container {
|
|
||||||
flex-shrink: 0;
|
|
||||||
margin-left: 10px;
|
|
||||||
margin: 5px 0;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-divider {
|
|
||||||
border: none;
|
|
||||||
border-top: 1px solid #eee;
|
|
||||||
margin: 10px 0 5px 0;
|
|
||||||
}
|
|
||||||
@ -39,6 +39,8 @@ void ctaiHistoryTextEdit::initMsgHistoryLayout()
|
|||||||
history_layout = new QVBoxLayout();
|
history_layout = new QVBoxLayout();
|
||||||
// 历史信息QTextEdit
|
// 历史信息QTextEdit
|
||||||
m_msg_history = new QTextEdit();
|
m_msg_history = new QTextEdit();
|
||||||
|
QString style = "";
|
||||||
|
m_msg_history->document()->setDefaultStyleSheet(style);
|
||||||
m_math_convert = new ctaiMathConvert();
|
m_math_convert = new ctaiMathConvert();
|
||||||
m_msg_history->setUndoRedoEnabled(false); // 关闭撤销历史以节省内存
|
m_msg_history->setUndoRedoEnabled(false); // 关闭撤销历史以节省内存
|
||||||
m_msg_history->setAcceptRichText(true);
|
m_msg_history->setAcceptRichText(true);
|
||||||
|
|||||||
@ -83,7 +83,7 @@ void ctaiHistoryTools::slotsSaveMenu()
|
|||||||
for(int i=0;i<=ds_save_menu.count()-1;i++){
|
for(int i=0;i<=ds_save_menu.count()-1;i++){
|
||||||
QAction* action=new QAction(ds_save_menu[i]);
|
QAction* action=new QAction(ds_save_menu[i]);
|
||||||
action->setObjectName(QString::number(i));
|
action->setObjectName(QString::number(i));
|
||||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(on_save_action_slots()));
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(slotsSaveAction()));
|
||||||
save_ver.push_back(action);
|
save_ver.push_back(action);
|
||||||
m_msg_save_menu->addAction(action);
|
m_msg_save_menu->addAction(action);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -137,64 +137,17 @@ QString ctaiMathConvert::markdown_to_html(const QString &text)
|
|||||||
}
|
}
|
||||||
// 转换为HTML
|
// 转换为HTML
|
||||||
char *html = cmark_render_html(doc, options, NULL);
|
char *html = cmark_render_html(doc, options, NULL);
|
||||||
// 转换回QString并处理代码块
|
|
||||||
QString result = QString::fromUtf8(html);
|
QString result = QString::fromUtf8(html);
|
||||||
// 添加基础CSS样式
|
|
||||||
const QString css = R"(
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
|
|
||||||
line-height: 1.6;
|
|
||||||
padding: 0 1em;
|
|
||||||
}
|
|
||||||
pre {
|
|
||||||
background-color: #f6f8fa;
|
|
||||||
border-radius: 3px;
|
|
||||||
padding: 16px;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background-color: rgba(175,184,193,0.2);
|
|
||||||
border-radius: 3px;
|
|
||||||
padding: .2em .4em;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
|
|
||||||
}
|
|
||||||
pre code {
|
|
||||||
background-color: transparent;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
th, td {
|
|
||||||
border: 1px solid #d0d7de;
|
|
||||||
padding: 6px 13px;
|
|
||||||
}
|
|
||||||
th {
|
|
||||||
background-color: #f6f8fa;
|
|
||||||
}
|
|
||||||
blockquote {
|
|
||||||
color: #57606a;
|
|
||||||
border-left: 4px solid #d0d7de;
|
|
||||||
margin: 1em 0;
|
|
||||||
padding: 0 1em;
|
|
||||||
}
|
|
||||||
.custom-height {
|
|
||||||
height: 60px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
)";
|
|
||||||
// 在<head>标签后插入CSS
|
|
||||||
result.replace("<head>", "<head>" + css);
|
|
||||||
result.replace("<li", "<li class=\"custom-height\"");
|
|
||||||
replace_symbol(result);
|
replace_symbol(result);
|
||||||
// 释放内存
|
// 释放内存
|
||||||
cmark_node_free(doc);
|
cmark_node_free(doc);
|
||||||
free(html);
|
free(html);
|
||||||
|
replace_css(result);
|
||||||
return fix_img_str_line_height(result.toUtf8());
|
return fix_img_str_line_height(result.toUtf8());
|
||||||
}
|
}
|
||||||
|
void ctaiMathConvert::replace_css(QString& context){
|
||||||
|
context.replace("<li", "<li class=\"custom-height\"");
|
||||||
|
}
|
||||||
void ctaiMathConvert::replace_symbol(QString &context)
|
void ctaiMathConvert::replace_symbol(QString &context)
|
||||||
{
|
{
|
||||||
// 执行转换符号为半角
|
// 执行转换符号为半角
|
||||||
|
|||||||
@ -57,6 +57,7 @@ private:
|
|||||||
QString fix_img_str_line_height(QString html);
|
QString fix_img_str_line_height(QString html);
|
||||||
void print_ast_node(cmark_node *node, int level);
|
void print_ast_node(cmark_node *node, int level);
|
||||||
void replace_symbol(QString& context);
|
void replace_symbol(QString& context);
|
||||||
|
void replace_css(QString& context);
|
||||||
TexGuard texGuard;
|
TexGuard texGuard;
|
||||||
//宽度
|
//宽度
|
||||||
int m_render_width=600;
|
int m_render_width=600;
|
||||||
@ -72,7 +73,7 @@ private:
|
|||||||
//处理后保存模式
|
//处理后保存模式
|
||||||
bool save_mode=false;
|
bool save_mode=false;
|
||||||
//print node str debug
|
//print node str debug
|
||||||
bool debug_node_print=true;
|
bool debug_node_print=false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user