GrowiSlides.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import Head from 'next/head';
  2. import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
  3. import type { PresentationOptions } from '../consts';
  4. import { MARP_CONTAINER_CLASS_NAME, presentationMarpit, slideMarpit } from '../services/growi-marpit';
  5. import * as extractSections from '../services/renderer/extract-sections';
  6. import './Slides.global.scss';
  7. import { PresentationRichSlideSection, RichSlideSection } from './RichSlideSection';
  8. type Props = {
  9. options: PresentationOptions,
  10. children?: string,
  11. presentation?: boolean,
  12. }
  13. export const GrowiSlides = (props: Props): JSX.Element => {
  14. const {
  15. options, children, presentation,
  16. } = props;
  17. const {
  18. rendererOptions, isDarkMode, disableSeparationByHeader,
  19. } = options;
  20. if (rendererOptions == null || rendererOptions.remarkPlugins == null || rendererOptions.components == null) {
  21. return <></>;
  22. }
  23. rendererOptions.remarkPlugins.push([
  24. extractSections.remarkPlugin,
  25. {
  26. isDarkMode,
  27. disableSeparationByHeader,
  28. },
  29. ]);
  30. rendererOptions.components.section = presentation ? PresentationRichSlideSection : RichSlideSection;
  31. const marpit = presentation ? presentationMarpit : slideMarpit;
  32. const { css } = marpit.render('');
  33. return (
  34. <>
  35. <Head>
  36. <style>{css}</style>
  37. </Head>
  38. <div className={`slides ${MARP_CONTAINER_CLASS_NAME}`}>
  39. <ReactMarkdown {...rendererOptions}>
  40. { children ?? '## No Contents' }
  41. </ReactMarkdown>
  42. </div>
  43. </>
  44. );
  45. };