优化Presentation组件,支持添加背景

This commit is contained in:
jingrow 2025-09-03 02:39:15 +08:00
parent a86ddfcbe3
commit 06e9867d61
2 changed files with 33 additions and 4 deletions

View File

@ -28,6 +28,25 @@
color: white !important; color: white !important;
} }
/* 带背景的幻灯片文字颜色 */
.reveal-container .reveal .slides section[data-background] {
color: white !important;
}
.reveal-container .reveal .slides section[data-background] h1,
.reveal-container .reveal .slides section[data-background] h2,
.reveal-container .reveal .slides section[data-background] h3,
.reveal-container .reveal .slides section[data-background] h4,
.reveal-container .reveal .slides section[data-background] h5,
.reveal-container .reveal .slides section[data-background] h6 {
color: white !important;
}
.reveal-container .reveal .slides section[data-background] p,
.reveal-container .reveal .slides section[data-background] li {
color: rgba(255, 255, 255, 0.9) !important;
}
.reveal-container .reveal .slides section h1, .reveal-container .reveal .slides section h1,
.reveal-container .reveal .slides section h2, .reveal-container .reveal .slides section h2,
.reveal-container .reveal .slides section h3, .reveal-container .reveal .slides section h3,

View File

@ -25,7 +25,7 @@ const REVEAL_CONFIG = {
fragmentInURL: false, fragmentInURL: false,
embedded: false, embedded: false,
help: true, help: true,
showNotes: false, showNotes: true,
autoPlayMedia: null, autoPlayMedia: null,
preloadIframes: null, preloadIframes: null,
autoSlide: 0, autoSlide: 0,
@ -99,14 +99,24 @@ export default function Presentation({ data }) {
const trimmedSection = section.trim(); const trimmedSection = section.trim();
if (!trimmedSection) return ''; if (!trimmedSection) return '';
const htmlContent = marked(trimmedSection); //
const backgroundMatch = trimmedSection.match(/<!-- \.slide: data-background="([^"]+)"[^>]* -->/);
let backgroundAttr = '';
let contentWithoutBackground = trimmedSection;
if (backgroundMatch) {
backgroundAttr = ` data-background="${backgroundMatch[1]}"`;
contentWithoutBackground = trimmedSection.replace(/<!-- \.slide: data-background="[^"]+"[^>]* -->/g, '');
}
const htmlContent = marked(contentWithoutBackground);
// //
if (index === 0 && !htmlContent.includes('<h1>') && data.title) { if (index === 0 && !htmlContent.includes('<h1>') && data.title) {
return `<section><h1>${data.title}</h1>${htmlContent}</section>`; return `<section${backgroundAttr}><h1>${data.title}</h1>${htmlContent}</section>`;
} }
return `<section>${htmlContent}</section>`; return `<section${backgroundAttr}>${htmlContent}</section>`;
}).join(''); }).join('');
}; };