Slides.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // TODO: to change better slide style
  21. // https://redmine.weseek.co.jp/issues/125680
  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. type Props = {
  32. options: PresentationOptions,
  33. children?: string,
  34. hasMarpFlag?: boolean,
  35. }
  36. export const Slides = (props: Props): JSX.Element => {
  37. const { options, children, hasMarpFlag } = props;
  38. const {
  39. rendererOptions, isDarkMode, disableSeparationByHeader,
  40. } = options;
  41. // TODO: can Marp rendering
  42. // https://redmine.weseek.co.jp/issues/115673
  43. if (hasMarpFlag) {
  44. return (
  45. <></>
  46. );
  47. }
  48. rendererOptions.remarkPlugins?.push([
  49. extractSections.remarkPlugin,
  50. {
  51. isDarkMode,
  52. disableSeparationByHeader,
  53. },
  54. ]);
  55. const { css } = marp.render('', { htmlAsArray: true });
  56. return (
  57. <>
  58. <Head>
  59. <style>{css}</style>
  60. </Head>
  61. <ReactMarkdown {...rendererOptions}>
  62. { children ?? '## No Contents' }
  63. </ReactMarkdown>
  64. </>
  65. );
  66. };