2
0

GrowiSlides.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 { PresentationRichSlideSection, RichSlideSection } from './RichSlideSection';
  7. type Props = {
  8. options: PresentationOptions,
  9. children?: string,
  10. presentation?: boolean,
  11. }
  12. export const GrowiSlides = (props: Props): JSX.Element => {
  13. const {
  14. options, children, presentation,
  15. } = props;
  16. const {
  17. rendererOptions, isDarkMode, disableSeparationByHeader,
  18. } = options;
  19. if (rendererOptions == null || rendererOptions.remarkPlugins == null || rendererOptions.components == null) {
  20. return <></>;
  21. }
  22. rendererOptions.remarkPlugins.push([
  23. extractSections.remarkPlugin,
  24. {
  25. isDarkMode,
  26. disableSeparationByHeader,
  27. },
  28. ]);
  29. rendererOptions.components.section = presentation ? PresentationRichSlideSection : RichSlideSection;
  30. const marpit = presentation ? presentationMarpit : slideMarpit;
  31. const { css } = marpit.render('');
  32. return (
  33. <>
  34. <Head>
  35. <style>{css}</style>
  36. </Head>
  37. <div className={`slides ${MARP_CONTAINER_CLASS_NAME}`}>
  38. <ReactMarkdown {...rendererOptions}>
  39. { children ?? '## No Contents' }
  40. </ReactMarkdown>
  41. </div>
  42. </>
  43. );
  44. };