GrowiSlides.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Marp } from '@marp-team/marp-core';
  2. import { Element } from '@marp-team/marpit';
  3. import Head from 'next/head';
  4. import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
  5. import type { PresentationOptions } from '../consts';
  6. import * as extractSections from '../services/renderer/extract-sections';
  7. import './Slides.global.scss';
  8. const MARP_CONTAINER_CLASS_NAME = 'marpit';
  9. // ----------------------------------------------------
  10. // TODO: to change better slide style
  11. // https://redmine.weseek.co.jp/issues/125680
  12. const marp = new Marp({
  13. container: [
  14. new Element('div', { class: MARP_CONTAINER_CLASS_NAME }),
  15. new Element('div', { class: 'slides' }),
  16. ],
  17. inlineSVG: false,
  18. emoji: undefined,
  19. html: false,
  20. math: false,
  21. });
  22. const marpSlideTheme = marp.themeSet.add(`
  23. /*!
  24. * @theme slide_preview
  25. */
  26. section {
  27. max-width: 90%;
  28. }
  29. `);
  30. marp.themeSet.default = marpSlideTheme;
  31. // ----------------------------------------------------
  32. type Props = {
  33. options: PresentationOptions,
  34. children?: string,
  35. }
  36. export const GrowiSlides = (props: Props): JSX.Element => {
  37. const { options, children } = props;
  38. const {
  39. rendererOptions, isDarkMode, disableSeparationByHeader,
  40. } = options;
  41. rendererOptions.remarkPlugins?.push([
  42. extractSections.remarkPlugin,
  43. {
  44. isDarkMode,
  45. disableSeparationByHeader,
  46. },
  47. ]);
  48. const { css } = marp.render('', { htmlAsArray: true });
  49. return (
  50. <>
  51. <Head>
  52. <style>{css}</style>
  53. </Head>
  54. <ReactMarkdown {...rendererOptions}>
  55. { children ?? '## No Contents' }
  56. </ReactMarkdown>
  57. </>
  58. );
  59. };