From 8259fe2edd2a1ee7ad0113a8a9f23ecd4b92a2a0 Mon Sep 17 00:00:00 2001
From: Vivien <34387011+vivien8261@users.noreply.github.com>
Date: Thu, 25 Jul 2024 10:19:01 +0800
Subject: [PATCH] =?UTF-8?q?update:=20=E6=94=AF=E6=8C=81=20Markdown=20?=
=?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
amiyabot/_assets/markdown/template-dark.html | 72 --------------------
amiyabot/_assets/markdown/template.html | 35 ++++++++--
amiyabot/builtin/messageChain/__init__.py | 12 +++-
3 files changed, 38 insertions(+), 81 deletions(-)
delete mode 100644 amiyabot/_assets/markdown/template-dark.html
diff --git a/amiyabot/_assets/markdown/template-dark.html b/amiyabot/_assets/markdown/template-dark.html
deleted file mode 100644
index e8224e1..0000000
--- a/amiyabot/_assets/markdown/template-dark.html
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
-
-
-
-
-
-
-
- template
-
-
-
-
-
-
-
-
-
-
diff --git a/amiyabot/_assets/markdown/template.html b/amiyabot/_assets/markdown/template.html
index 44a699f..19d4f3f 100644
--- a/amiyabot/_assets/markdown/template.html
+++ b/amiyabot/_assets/markdown/template.html
@@ -6,7 +6,6 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
-
template
@@ -47,20 +45,45 @@
el: '#template',
computed: {
markdownBody() {
- return marked.parse(this.content)
+ return marked.parse(this.data.content)
}
},
methods: {
init(data) {
- this.$set(this, 'content', data['content'])
+ this.loadCSSText(data.css_style)
+ this.loadCSSFiles(data.is_dark)
+
+ this.$set(this, 'data', data)
this.$nextTick(() => {
hljs.highlightAll()
})
+ },
+ loadCSSText(css) {
+ const style = document.createElement('style');
+ style.innerHTML = css;
+ document.head.appendChild(style);
+ },
+ loadCSSFiles(isDark) {
+ const files = isDark ?
+ ['./style/highlight/vs2015.min.css', './style/github-markdown-dark.css'] :
+ ['./style/highlight/vs.min.css']
+
+ for (const file of files) {
+ const link = document.createElement('link');
+ link.rel = 'stylesheet'
+ link.href = file
+ document.head.appendChild(link);
+ }
}
},
data() {
return {
- content: ''
+ data: {
+ content: '',
+ max_width: 0,
+ css_style: '',
+ is_dark: false,
+ }
}
},
mounted() {
diff --git a/amiyabot/builtin/messageChain/__init__.py b/amiyabot/builtin/messageChain/__init__.py
index a8ae578..90a95f5 100644
--- a/amiyabot/builtin/messageChain/__init__.py
+++ b/amiyabot/builtin/messageChain/__init__.py
@@ -16,7 +16,6 @@
class ChainConfig:
max_length = argv('text-max-length', int) or 100
md_template = os.path.join(cur_file_folder, '../../_assets/markdown/template.html')
- md_template_dark = os.path.join(cur_file_folder, '../../_assets/markdown/template-dark.html')
class Chain:
@@ -182,14 +181,21 @@ def html(
def markdown(
self,
content: str,
+ max_width: int = 960,
+ css_style: str = '',
render_time: int = DEFAULT_RENDER_TIME,
is_dark: bool = False,
):
return self.html(
- ChainConfig.md_template_dark if is_dark else ChainConfig.md_template,
+ ChainConfig.md_template,
width=50,
height=50,
- data={'content': content},
+ data={
+ 'content': content,
+ 'max_width': max_width,
+ 'css_style': css_style,
+ 'is_dark': is_dark,
+ },
render_time=render_time,
)