Skip to content

Commit 1dd2adf

Browse files
authored
BUG: Fix indent in C++ example in one-page. (#847)
- Export `indentNormalizer` for manual use. - Add `indentNormalizer` unit tests. - Update examples/js and examples/one-page. Fixes #846 - Looks like `yarn build-one-page` also needed running to catch up.
1 parent 0126a64 commit 1dd2adf

File tree

4 files changed

+72
-18
lines changed

4 files changed

+72
-18
lines changed

examples/js/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
Progress,
2020
SpectacleLogo,
2121
Slide,
22-
Text
22+
Text,
23+
indentNormalizer
2324
} from 'spectacle';
2425

2526
// SPECTACLE_CLI_THEME_START
@@ -52,7 +53,8 @@ const template = () => (
5253
const formidableLogo =
5354
'https://avatars2.githubusercontent.com/u/5078602?s=280&v=4';
5455

55-
const cppCodeBlock = `#include <iostream>
56+
const cppCodeBlock = indentNormalizer(`
57+
#include <iostream>
5658
#include <cstdlib>
5759
#include <sstream>
5860
#include <pthread.h>
@@ -97,7 +99,7 @@ int main()
9799
}
98100
99101
return 0;
100-
}`;
102+
}`);
101103

102104
const Presentation = () => (
103105
<Deck theme={theme} template={template} transitionEffect="fade">

examples/one-page.html

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
Progress,
3636
SpectacleLogo,
3737
Slide,
38-
Text
38+
Text,
39+
indentNormalizer
3940
} = Spectacle;
4041

4142
import htm from 'https://unpkg.com/htm@^3?module';
@@ -46,9 +47,6 @@
4647
fonts: {
4748
header: '"Open Sans Condensed", Helvetica, Arial, sans-serif',
4849
text: '"Open Sans Condensed", Helvetica, Arial, sans-serif'
49-
},
50-
space: {
51-
headerMargin: '0'
5250
}
5351
};
5452
// SPECTACLE_CLI_THEME_END
@@ -67,7 +65,8 @@
6765
// SPECTACLE_CLI_TEMPLATE_END
6866

6967
const formidableLogo = 'https://avatars2.githubusercontent.com/u/5078602?s=280&v=4';
70-
const cppCodeBlock = `#include <iostream>
68+
const cppCodeBlock = indentNormalizer(`
69+
#include <iostream>
7170
#include <cstdlib>
7271
#include <sstream>
7372
#include <pthread.h>
@@ -112,26 +111,26 @@
112111
}
113112
114113
return 0;
115-
}`;
114+
}`);
116115

117116
const Presentation = () => html`
118-
<${Deck} theme=${theme} template=${template}>
117+
<${Deck} theme=${theme} template=${template} transitionEffect="fade">
119118
<${Slide}>
120119
<${FlexBox} height="100%">
121120
<${SpectacleLogo} size=${500} />
122121
</${FlexBox}>
123122
</${Slide}>
124123
<${Slide}>
125124
<${FlexBox} height="100%" flexDirection="column">
126-
<${Heading} fontSize="150px">SPECTACLE</${Heading}>
127-
<${Heading} fontSize="h2">A ReactJS Presentation Library</${Heading}>
128-
<${Heading} color="primary" fontSize="h3">Where you can write your decks in JSX, Markdown, or MDX!</${Heading}>
125+
<${Heading} margin="0px" fontSize="150px">SPECTACLE</${Heading}>
126+
<${Heading} margin="0px" fontSize="h2">A ReactJS Presentation Library</${Heading}>
127+
<${Heading} margin="0px 32px" color="primary" fontSize="h3">Where you can write your decks in JSX, Markdown, or MDX!</${Heading}>
129128
</${FlexBox}>
130129
<${Notes}>
131130
<p>Notes are shown in presenter mode. Open up localhost:3000/?presenterMode=true to see them.</p>
132131
</${Notes}>
133132
</${Slide}>
134-
<${Slide}>
133+
<${Slide} transitionEffect="slide">
135134
<${Heading}>Code Blocks</${Heading}>
136135
<${CodePane} fontSize=${18} language="cpp" autoFillHeight>
137136
${cppCodeBlock}
@@ -167,9 +166,8 @@
167166
<${Text}>Double-size Grid Item</${Text}>
168167
</${Box}>
169168
</${Grid}>
170-
<${Heading}>Create Grids in Spectacle</${Heading}>
171-
<${Grid} gridTemplateColumns="1fr 1fr 1fr" gridTemplateRows="1fr 1fr 1fr" alignItems="center" justifyContent="center" gridRowGap=${15}>
172-
${Array(9).fill('').map((_, index) => html`<${FlexBox} key=${`formidable-logo-${index}`} flex=${1}>
169+
<${Grid} gridTemplateColumns="1fr 1fr 1fr" gridTemplateRows="1fr 1fr 1fr" alignItems="center" justifyContent="center" gridRowGap=${1}>
170+
${Array(9).fill('').map((_, index) => html`<${FlexBox} paddingTop=${0} key=${`formidable-logo-${index}`} flex=${1}>
173171
<${Image} src=${formidableLogo} width=${100} />
174172
</${FlexBox}>`)}
175173
</${Grid}>

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Markdown from './components/markdown';
2828
import SpectacleLogo from './components/logo';
2929
import mdxComponentMap from './utils/mdx-component-mapper';
3030
import { removeNotes, isolateNotes } from './utils/notes';
31+
import indentNormalizer from './utils/indent-normalizer';
3132

3233
export {
3334
Deck,
@@ -59,5 +60,6 @@ export {
5960
TableBody,
6061
mdxComponentMap,
6162
removeNotes,
62-
isolateNotes
63+
isolateNotes,
64+
indentNormalizer
6365
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import indentNormalizer from './indent-normalizer';
2+
3+
describe('indentNormalizer', () => {
4+
it('handles empty cases', () => {
5+
expect(indentNormalizer()).toEqual('');
6+
expect(indentNormalizer(null)).toEqual('');
7+
expect(indentNormalizer('')).toEqual('');
8+
expect(indentNormalizer(' ')).toEqual('');
9+
expect(indentNormalizer(' \n ')).toEqual('');
10+
});
11+
12+
it('handles base cases', () => {
13+
expect(indentNormalizer('no indents')).toEqual('no indents');
14+
expect(indentNormalizer('no indents\nstill none')).toEqual(
15+
'no indents\nstill none'
16+
);
17+
});
18+
19+
it('indents to smallest non-whitespace line level', () => {
20+
expect(
21+
indentNormalizer(
22+
`
23+
first lowest
24+
second in
25+
third
26+
fourth way in
27+
`
28+
)
29+
).toEqual(
30+
`
31+
first lowest
32+
second in
33+
third
34+
fourth way in
35+
`.trim()
36+
);
37+
});
38+
39+
it('indents to smallest indent even in later lines', () => {
40+
expect(
41+
indentNormalizer(`
42+
first
43+
second in
44+
third lowest
45+
fourth way in
46+
`)
47+
).toEqual(` first
48+
second in
49+
third lowest
50+
fourth way in`);
51+
});
52+
});

0 commit comments

Comments
 (0)