reiji-h 2 лет назад
Родитель
Сommit
8fb4720fba

+ 9 - 29
packages/presentation/src/components/GrowiSlides.tsx

@@ -1,46 +1,22 @@
 import { Marp } from '@marp-team/marp-core';
-import { Element } from '@marp-team/marpit';
 import Head from 'next/head';
 import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
 
 import type { PresentationOptions } from '../consts';
 import * as extractSections from '../services/renderer/extract-sections';
 
-import './Slides.global.scss';
-
-const MARP_CONTAINER_CLASS_NAME = 'marpit';
+import { RichSlideSection } from './RichSlideSection';
 
-// ----------------------------------------------------
-// TODO: to change better slide style
-// https://redmine.weseek.co.jp/issues/125680
-const marp = new Marp({
-  container: [
-    new Element('div', { class: MARP_CONTAINER_CLASS_NAME }),
-    new Element('div', { class: 'slides' }),
-  ],
-  inlineSVG: false,
-  emoji: undefined,
-  html: false,
-  math: false,
-});
-const marpSlideTheme = marp.themeSet.add(`
-    /*!
-     * @theme slide_preview
-     */
-    section {
-      max-width: 90%;
-    }
-`);
-marp.themeSet.default = marpSlideTheme;
-// ----------------------------------------------------
+import './Slides.global.scss';
 
 type Props = {
   options: PresentationOptions,
   children?: string,
+  marpit: Marp,
 }
 
 export const GrowiSlides = (props: Props): JSX.Element => {
-  const { options, children } = props;
+  const { options, children, marpit } = props;
   const {
     rendererOptions, isDarkMode, disableSeparationByHeader,
   } = options;
@@ -53,7 +29,11 @@ export const GrowiSlides = (props: Props): JSX.Element => {
     },
   ]);
 
-  const { css } = marp.render('', { htmlAsArray: true });
+  if (rendererOptions.components != null) {
+    rendererOptions.components.section = RichSlideSection;
+  }
+
+  const { css } = marpit.render('', { htmlAsArray: true });
   return (
     <>
       <Head>

+ 2 - 18
packages/presentation/src/components/MarpSlides.tsx

@@ -1,31 +1,15 @@
 import { Marp } from '@marp-team/marp-core';
-import { Element } from '@marp-team/marpit';
 import Head from 'next/head';
 
 import './Slides.global.scss';
 
-const MARP_CONTAINER_CLASS_NAME = 'marpit';
-
-const marpit = new Marp({
-  container: [
-    new Element('div', { class: MARP_CONTAINER_CLASS_NAME }),
-    new Element('div', { class: 'slides' }),
-  ],
-  slideContainer: [
-    new Element('div', { class: 'shadow rounded m-2' }),
-  ],
-  inlineSVG: true,
-  emoji: undefined,
-  html: false,
-  math: false,
-});
-
 type Props = {
   children?: string,
+  marpit: Marp,
 }
 
 export const MarpSlides = (props: Props): JSX.Element => {
-  const { children } = props;
+  const { children, marpit } = props;
 
   const { html, css } = marpit.render(children ?? '');
   return (

+ 19 - 3
packages/presentation/src/components/Slides.tsx

@@ -1,8 +1,10 @@
+import { Marp } from '@marp-team/marp-core';
+import { Element } from '@marp-team/marpit';
+
 import type { PresentationOptions } from '../consts';
 
 import { GrowiSlides } from './GrowiSlides';
 import { MarpSlides } from './MarpSlides';
-import { RichSlideSection } from './RichSlideSection';
 
 import './Slides.global.scss';
 
@@ -10,6 +12,20 @@ import './Slides.global.scss';
 // https://redmine.weseek.co.jp/issues/125680
 export const MARP_CONTAINER_CLASS_NAME = 'marpit';
 
+const marpit = new Marp({
+  container: [
+    new Element('div', { class: MARP_CONTAINER_CLASS_NAME }),
+    new Element('div', { class: 'slides' }),
+  ],
+  slideContainer: [
+    new Element('section', { class: 'shadow rounded m-2' }),
+  ],
+  inlineSVG: true,
+  emoji: undefined,
+  html: false,
+  math: false,
+});
+
 type Props = {
   options: PresentationOptions,
   children?: string,
@@ -20,9 +36,9 @@ export const Slides = (props: Props): JSX.Element => {
   const { options, children, hasMarpFlag } = props;
 
   if (hasMarpFlag) {
-    return <MarpSlides>{children}</MarpSlides>;
+    return <MarpSlides marpit={marpit}>{children}</MarpSlides>;
   }
 
-  return <GrowiSlides options={options}>{children}</GrowiSlides>;
+  return <GrowiSlides options={options} marpit={marpit}>{children}</GrowiSlides>;
 
 };