Sections.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. import './Sections.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 SectionsProps = {
  21. rendererOptions: ReactMarkdownOptions,
  22. children?: string,
  23. }
  24. export const Sections = (props: SectionsProps): JSX.Element => {
  25. const { rendererOptions, children } = props;
  26. rendererOptions.remarkPlugins?.push(hrSplitter.remarkPlugin);
  27. const { css } = marp.render('', { htmlAsArray: true });
  28. return (
  29. <>
  30. <Head>
  31. <style>{css}</style>
  32. </Head>
  33. <ReactMarkdown {...rendererOptions}>
  34. { children ?? '## No Contents' }
  35. </ReactMarkdown>
  36. </>
  37. );
  38. };