Skip to content

Commit 62fdbff

Browse files
Support Notes for MD parsing (#762)
* Support Notes for MD parsing * Add notes helper exports
1 parent 428f31c commit 62fdbff

File tree

6 files changed

+60
-9
lines changed

6 files changed

+60
-9
lines changed

examples/js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ const TestJs = () => (
209209
<Markdown containsSlides>
210210
{`
211211
### First MD generated Slide
212+
Notes: These are notes
212213
---
213214
### Second MD Generated Slide
215+
Notes: These are more notes
214216
`}
215217
</Markdown>
216218
</Deck>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spectacle",
3-
"version": "5.5.0",
3+
"version": "6.0.0-alpha.0",
44
"description": "ReactJS Powered Presentation Framework",
55
"main": "lib/index.js",
66
"module": "es/index.js",
@@ -68,6 +68,7 @@
6868
"dependencies": {
6969
"history": "^4.9.0",
7070
"marksy": "^8.0.0",
71+
"normalize-newline": "^3.0.0",
7172
"prism-react-renderer": "^0.1.7",
7273
"query-string": "^6.8.2",
7374
"react-spring": "^8.0.25",

src/components/deck/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import styled, { ThemeContext, ThemeProvider } from 'styled-components';
4-
4+
import normalize from 'normalize-newline';
5+
import indentNormalizer from '../../utils/indent-normalizer';
56
import useDeck, { DeckContext } from '../../hooks/use-deck';
67
import isComponentType from '../../utils/is-component-type';
78
import useUrlRouting from '../../hooks/use-url-routing';
@@ -24,7 +25,8 @@ import {
2425
} from '../../utils/constants';
2526
import searchChildrenForAppear from '../../utils/search-children-appear';
2627
import OverviewDeck from './overview-deck';
27-
import { Markdown, Slide } from '../../index';
28+
import { Markdown, Slide, Notes } from '../../index';
29+
import { isolateNotes, removeNotes } from '../../utils/notes';
2830

2931
const AnimatedDeckDiv = styled(animated.div)`
3032
height: 100vh;
@@ -78,11 +80,17 @@ const mapMarkdownIntoSlides = (child, index) => {
7880
isComponentType(child, 'Markdown') &&
7981
Boolean(child.props.containsSlides)
8082
) {
81-
return child.props.children.split(/\n\s*---\n/).map((markdown, mdIndex) => (
82-
<Slide key={`md-slide-${index}-${mdIndex}`}>
83-
<Markdown>{markdown}</Markdown>
84-
</Slide>
85-
));
83+
return child.props.children.split(/\n\s*---\n/).map((markdown, mdIndex) => {
84+
const content = normalize(indentNormalizer(markdown));
85+
const contentWithoutNotes = removeNotes(content);
86+
const notes = isolateNotes(content);
87+
return (
88+
<Slide key={`md-slide-${index}-${mdIndex}`}>
89+
<Markdown>{contentWithoutNotes}</Markdown>
90+
<Notes>{notes}</Notes>
91+
</Slide>
92+
);
93+
});
8694
}
8795
return child;
8896
};

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Progress from './components/progress';
2020
import FullScreen from './components/fullscreen';
2121
import Markdown from './components/markdown';
2222
import mdxComponentMap from './utils/mdx-component-mapper';
23+
import { removeNotes, isolateNotes } from './utils/notes';
2324

2425
export {
2526
Deck,
@@ -46,5 +47,7 @@ export {
4647
Table,
4748
TableCell,
4849
TableRow,
49-
mdxComponentMap
50+
mdxComponentMap,
51+
removeNotes,
52+
isolateNotes
5053
};

src/utils/notes.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const NOTES_MARKER = 'Notes: ';
2+
const NOTES_REG = new RegExp(`^${NOTES_MARKER}`, 'm');
3+
/*
4+
* We want to pull the notes out of each slide. This RegEx looks for "Notes: "
5+
* that starts on a new line. Anything after the notes marker will be considered notes.
6+
*/
7+
export const isolateNotes = content => {
8+
const indexOfNotes = content.search(NOTES_REG);
9+
if (indexOfNotes >= 0) {
10+
// found the notes marker!
11+
return content.substring(indexOfNotes + NOTES_MARKER.length);
12+
}
13+
return '';
14+
};
15+
16+
/*
17+
* When generating the slide components, we only want the slide content to be
18+
* compiled by mdx.sync. Remove all the notes content.
19+
*/
20+
export const removeNotes = content => {
21+
const indexOfNotes = content.search(NOTES_REG);
22+
if (indexOfNotes >= 0) {
23+
// found the notes marker!
24+
return content.substring(0, indexOfNotes);
25+
}
26+
return content;
27+
};

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,11 @@ locate-path@^3.0.0:
37073707
p-locate "^3.0.0"
37083708
path-exists "^3.0.0"
37093709

3710+
lodash.flowright@^3.5.0:
3711+
version "3.5.0"
3712+
resolved "https://registry.yarnpkg.com/lodash.flowright/-/lodash.flowright-3.5.0.tgz#2b5fff399716d7e7dc5724fe9349f67065184d67"
3713+
integrity sha1-K1//OZcW1+fcVyT+k0n2cGUYTWc=
3714+
37103715
lodash@^3.10.1:
37113716
version "3.10.1"
37123717
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
@@ -4153,6 +4158,11 @@ nopt@^4.0.1:
41534158
abbrev "1"
41544159
osenv "^0.1.4"
41554160

4161+
normalize-newline@^3.0.0:
4162+
version "3.0.0"
4163+
resolved "https://registry.yarnpkg.com/normalize-newline/-/normalize-newline-3.0.0.tgz#1cbea804aba436001f83938ab21ec039d69ae9d3"
4164+
integrity sha1-HL6oBKukNgAfg5OKsh7AOdaa6dM=
4165+
41564166
normalize-path@^2.1.1:
41574167
version "2.1.1"
41584168
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9"

0 commit comments

Comments
 (0)