From 8d15e23f3cc348b92f9d102801a4157a64fc9f83 Mon Sep 17 00:00:00 2001
From: Will Miao <13051207myq@gmail.com>
Date: Wed, 2 Apr 2025 19:36:52 +0800
Subject: [PATCH] Add markdown support for changelog in modal
- Introduced a simple markdown parser to convert markdown syntax in changelog items to HTML.
- Updated modal CSS to style markdown elements, enhancing the presentation of changelog items.
- Improved user experience by allowing formatted text in changelog, including bold, italic, code, and links.
---
static/css/components/modal.css | 40 +++++++++++++++++++++++++++++
static/js/managers/UpdateService.js | 22 +++++++++++++++-
2 files changed, 61 insertions(+), 1 deletion(-)
diff --git a/static/css/components/modal.css b/static/css/components/modal.css
index b23264b1..1153bbc4 100644
--- a/static/css/components/modal.css
+++ b/static/css/components/modal.css
@@ -514,4 +514,44 @@ input:checked + .toggle-slider:before {
font-style: italic;
margin-top: var(--space-1);
text-align: center;
+}
+
+/* Add styles for markdown elements in changelog */
+.changelog-item ul {
+ padding-left: 20px;
+ margin-top: 8px;
+}
+
+.changelog-item li {
+ margin-bottom: 6px;
+ line-height: 1.4;
+}
+
+.changelog-item strong {
+ font-weight: 600;
+}
+
+.changelog-item em {
+ font-style: italic;
+}
+
+.changelog-item code {
+ background: rgba(0, 0, 0, 0.05);
+ padding: 2px 4px;
+ border-radius: 3px;
+ font-family: monospace;
+ font-size: 0.9em;
+}
+
+[data-theme="dark"] .changelog-item code {
+ background: rgba(255, 255, 255, 0.1);
+}
+
+.changelog-item a {
+ color: var(--lora-accent);
+ text-decoration: none;
+}
+
+.changelog-item a:hover {
+ text-decoration: underline;
}
\ No newline at end of file
diff --git a/static/js/managers/UpdateService.js b/static/js/managers/UpdateService.js
index aa15fd83..1aa1074f 100644
--- a/static/js/managers/UpdateService.js
+++ b/static/js/managers/UpdateService.js
@@ -178,7 +178,8 @@ export class UpdateService {
if (this.updateInfo.changelog && this.updateInfo.changelog.length > 0) {
this.updateInfo.changelog.forEach(item => {
const listItem = document.createElement('li');
- listItem.textContent = item;
+ // Parse markdown in changelog items
+ listItem.innerHTML = this.parseMarkdown(item);
changelogList.appendChild(listItem);
});
} else {
@@ -201,6 +202,25 @@ export class UpdateService {
}
}
+ // Simple markdown parser for changelog items
+ parseMarkdown(text) {
+ if (!text) return '';
+
+ // Handle bold text (**text**)
+ text = text.replace(/\*\*(.*?)\*\*/g, '$1');
+
+ // Handle italic text (*text*)
+ text = text.replace(/\*(.*?)\*/g, '$1');
+
+ // Handle inline code (`code`)
+ text = text.replace(/`(.*?)`/g, '$1');
+
+ // Handle links [text](url)
+ text = text.replace(/\[(.*?)\]\((.*?)\)/g, '$1');
+
+ return text;
+ }
+
toggleUpdateModal() {
const updateModal = modalManager.getModal('updateModal');