Slides.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import { Marp } from '@marp-team/marp-core';
  3. import { Element } from '@marp-team/marpit';
  4. import Head from 'next/head';
  5. import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
  6. import type { PresentationOptions } from '../consts';
  7. import * as extractSections from '../services/renderer/extract-sections';
  8. import './Slides.global.scss';
  9. export const MARP_CONTAINER_CLASS_NAME = 'marpit';
  10. const marp = new Marp({
  11. container: [
  12. new Element('div', { class: MARP_CONTAINER_CLASS_NAME }),
  13. new Element('div', { class: 'slides' }),
  14. ],
  15. inlineSVG: false,
  16. emoji: undefined,
  17. html: false,
  18. math: false,
  19. });
  20. type Props = {
  21. options: PresentationOptions,
  22. children?: string,
  23. }
  24. export const Slides = (props: Props): JSX.Element => {
  25. const { options, children } = props;
  26. const { rendererOptions, isDarkMode, disableSeparationByHeader } = options;
  27. rendererOptions.remarkPlugins?.push([
  28. extractSections.remarkPlugin,
  29. {
  30. isDarkMode,
  31. disableSeparationByHeader,
  32. },
  33. ]);
  34. const { css } = marp.render('', { htmlAsArray: true });
  35. return (
  36. <>
  37. <Head>
  38. <style>{css}</style>
  39. </Head>
  40. <ReactMarkdown {...rendererOptions}>
  41. { children ?? '## No Contents' }
  42. </ReactMarkdown>
  43. </>
  44. );
  45. };