Sections.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
  7. import * as hrSplitter from '../services/renderer/hr-splitter';
  8. export const CONTAINER_CLASS_NAME = 'marpit';
  9. const marp = new Marp({
  10. container: [
  11. new Element('div', { class: CONTAINER_CLASS_NAME }),
  12. new Element('div', { class: 'slides' }),
  13. ],
  14. inlineSVG: false,
  15. emoji: undefined,
  16. html: false,
  17. math: false,
  18. });
  19. type SectionsProps = {
  20. rendererOptions: ReactMarkdownOptions,
  21. children?: string,
  22. }
  23. export const Sections = (props: SectionsProps): JSX.Element => {
  24. const { rendererOptions, children } = props;
  25. rendererOptions.remarkPlugins?.push(hrSplitter.remarkPlugin);
  26. const { css } = marp.render('', { htmlAsArray: true });
  27. return (
  28. <>
  29. <Head>
  30. <style>{css}</style>
  31. </Head>
  32. <ReactMarkdown {...rendererOptions}>
  33. { children ?? '## No Contents' }
  34. </ReactMarkdown>
  35. </>
  36. );
  37. };