GrowiSlides.tsx 1.5 KB

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