update code
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
togglePreview = function (mode) {
|
||||
const previewBtn = document.getElementById('preview-toggle');
|
||||
const sourceBtn = document.getElementById('source-toggle');
|
||||
const reportContent = document.getElementById('report-content');
|
||||
const markdownSource = document.getElementById('markdown-source');
|
||||
const sourceContent = document.getElementById('source-content');
|
||||
|
||||
if (mode === 'preview') {
|
||||
previewBtn.classList.add('active');
|
||||
sourceBtn.classList.remove('active');
|
||||
reportContent.style.display = 'block';
|
||||
markdownSource.style.display = 'none';
|
||||
} else {
|
||||
previewBtn.classList.remove('active');
|
||||
sourceBtn.classList.add('active');
|
||||
reportContent.style.display = 'none';
|
||||
markdownSource.style.display = 'block';
|
||||
|
||||
// 显示原始Markdown源代码
|
||||
const markdown = reportContent.getAttribute('data-markdown');
|
||||
sourceContent.textContent = markdown;
|
||||
}
|
||||
};
|
||||
// 设置默认日期为今天
|
||||
document.getElementById('date').value = new Date().toISOString().split('T')[0];
|
||||
|
||||
|
||||
function showLoading() {
|
||||
document.getElementById('loading').style.display = 'block';
|
||||
document.getElementById('report-container').style.display = 'none';
|
||||
@@ -38,14 +62,14 @@ function generateReport() {
|
||||
if (data.success) {
|
||||
// 保存原始Markdown内容到data属性
|
||||
document.getElementById('report-content').setAttribute('data-markdown', data.report);
|
||||
|
||||
// 将Markdown转换为HTML并显示
|
||||
const htmlContent = markdownToHtml(data.report);
|
||||
|
||||
// 使用专业的Markdown解析器将Markdown转换为HTML并显示
|
||||
const htmlContent = parseMarkdownWithTables(data.report);
|
||||
document.getElementById('report-content').innerHTML = htmlContent;
|
||||
|
||||
|
||||
// 重置为预览模式
|
||||
togglePreview('preview');
|
||||
|
||||
|
||||
document.getElementById('report-container').style.display = 'block';
|
||||
|
||||
// 显示统计数据
|
||||
@@ -95,8 +119,8 @@ function exportReport() {
|
||||
showError('请先生成日报');
|
||||
return;
|
||||
}
|
||||
|
||||
const blob = new Blob([reportContent], { type: 'text/markdown' });
|
||||
|
||||
const blob = new Blob([reportContent], {type: 'text/markdown'});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
@@ -110,4 +134,15 @@ function exportReport() {
|
||||
// 页面加载时自动生成今日日报
|
||||
window.addEventListener('load', function () {
|
||||
generateTodayReport();
|
||||
});
|
||||
});
|
||||
|
||||
// 使用专业的Markdown解析器解析Markdown文本,支持表格
|
||||
function parseMarkdownWithTables(markdown) {
|
||||
if (typeof MarkdownParser !== 'undefined' && typeof MergeTableParser !== 'undefined') {
|
||||
const parser = new MarkdownParser();
|
||||
return parser.parseFull(markdown);
|
||||
} else {
|
||||
// 回退到简单的markdown渲染
|
||||
return markdownToHtml(markdown);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user