11/* eslint-disable react/display-name */
2- import Slide from '../slide/slide' ;
32import { DeckContext } from '../deck/deck' ;
43import presenterNotesPlugin from '../../utils/remark-rehype-presenter-notes' ;
54import CodePane , { CodePaneProps } from '../code-pane' ;
@@ -12,9 +11,7 @@ import remarkRaw from 'rehype-raw';
1211import rehype2react from 'rehype-react' ;
1312import { isValidElementType } from 'react-is' ;
1413import { root as mdRoot } from 'mdast-builder' ;
15- import mdxComponentMap , {
16- MarkdownComponentMap
17- } from '../../utils/mdx-component-mapper' ;
14+ import mdxComponentMap from '../../utils/mdx-component-mapper' ;
1815import indentNormalizer from '../../utils/indent-normalizer' ;
1916import Notes from '../notes' ;
2017import { ListItem } from '../../index' ;
@@ -29,27 +26,25 @@ import React, {
2926 createElement ,
3027 Children
3128} from 'react' ;
32-
33- type MdComponentProps = { [ key : string ] : any } ;
34-
35- type CommonMarkdownProps = {
36- animateListItems ?: boolean ;
37- componentProps ?: MdComponentProps ;
38- children : string ;
39- } ;
40-
41- type MapAndTemplate = {
42- componentMap ?: MarkdownComponentMap ;
43- template ?: {
44- default : ElementType ;
45- getPropsForAST ?: Function ;
46- } ;
47- } ;
29+ import { separateSectionsFromJson } from '../../utils/separate-sections-from-json' ;
30+ import {
31+ CommonMarkdownProps ,
32+ MapAndTemplate ,
33+ MarkdownSlideSetProps
34+ } from './markdown-types' ;
35+ import { MarkdownSlide } from './markdown-slide-renderer' ;
36+ import {
37+ directiveParserPlugin ,
38+ directivesHandlerPlugin
39+ } from '../../utils/remark-rehype-directive' ;
4840
4941type MarkdownProps = CommonMarkdownProps & MapAndTemplate ;
50- const Container = styled ( 'div' ) ( compose ( position , layout ) ) ;
42+ const Container = styled ( 'div' ) ( compose ( position , layout ) , { height : '100%' } ) ;
5143
52- export const Markdown = forwardRef < HTMLDivElement , MarkdownProps > (
44+ export const Markdown = forwardRef <
45+ HTMLDivElement ,
46+ MarkdownProps & { slideConfig ?: Record < string , string > }
47+ > (
5348 (
5449 {
5550 componentMap : userProvidedComponentMap = mdxComponentMap ,
@@ -59,6 +54,7 @@ export const Markdown = forwardRef<HTMLDivElement, MarkdownProps>(
5954 children : rawMarkdownText ,
6055 animateListItems = false ,
6156 componentProps,
57+ slideConfig,
6258 ...props
6359 } ,
6460 ref
@@ -78,6 +74,8 @@ export const Markdown = forwardRef<HTMLDivElement, MarkdownProps>(
7874 . use ( presenterNotesPlugin , ( ...notes ) => {
7975 extractedNotes . children . push ( ...notes ) ;
8076 } )
77+ . use ( directiveParserPlugin )
78+ . use ( directivesHandlerPlugin )
8179 . runSync ( ast ) ;
8280
8381 // Pass the AST into the provided template function, which returns an object
@@ -136,6 +134,7 @@ export const Markdown = forwardRef<HTMLDivElement, MarkdownProps>(
136134 return child ;
137135 } )
138136 : props . children ;
137+
139138 return (
140139 < Component { ...props } { ...( componentProps || { } ) } >
141140 { children }
@@ -197,11 +196,12 @@ export const Markdown = forwardRef<HTMLDivElement, MarkdownProps>(
197196 ] ) ;
198197
199198 const { children, ...restProps } = templateProps ;
200-
201199 return (
202200 < Container ref = { ref } { ...props } >
203201 < TemplateComponent { ...restProps } >
204- { children }
202+ { slideConfig ?. layout === 'columns'
203+ ? children . props . children
204+ : children }
205205 { noteElements }
206206 </ TemplateComponent >
207207 </ Container >
@@ -217,42 +217,13 @@ const AppearingListItem = (
217217 </ Appear >
218218) ;
219219
220- type MarkdownSlideProps = CommonMarkdownProps & MapAndTemplate ;
221-
222- export const MarkdownSlide = ( {
223- children,
224- componentMap,
225- template,
226- animateListItems = false ,
227- componentProps = { } ,
228- ...rest
229- } : MarkdownSlideProps ) => {
230- return (
231- < Slide { ...rest } >
232- < Markdown
233- { ...{
234- componentMap,
235- template,
236- animateListItems,
237- componentProps,
238- children
239- } }
240- />
241- </ Slide >
242- ) ;
243- } ;
244-
245- type MarkdownSlideSetProps = CommonMarkdownProps & {
246- slideProps ?: Partial < MarkdownSlideProps > [ ] ;
247- } ;
248-
249220export const MarkdownSlideSet = ( {
250221 children : rawMarkdownText ,
251222 slideProps = [ ] ,
252223 ...allSlideProps
253224} : MarkdownSlideSetProps ) => {
254225 const dedentedMarkdownText = indentNormalizer ( rawMarkdownText ) ;
255- const mdSlides = dedentedMarkdownText . split ( / \n \s * - - - \n / ) ;
226+ const mdSlides = separateSectionsFromJson ( dedentedMarkdownText ) ;
256227 return (
257228 < >
258229 { mdSlides . map ( ( md , ix ) => {
@@ -261,9 +232,10 @@ export const MarkdownSlideSet = ({
261232 if ( slideProps [ ix ] ) {
262233 Object . assign ( props , slideProps [ ix ] ) ;
263234 }
235+ const { jsonObject = { } , content } = md ;
264236 return (
265- < MarkdownSlide key = { ix } { ...props } >
266- { md }
237+ < MarkdownSlide key = { ix } slideConfig = { jsonObject } { ...props } >
238+ { content }
267239 </ MarkdownSlide >
268240 ) ;
269241 } ) }
0 commit comments