Code Surfer
Rad code slides >
README
Code Surfer
Help to keep this project alive with your support ❤️
- ```bash
- npm init code-surfer-deck my-deck
- cd my-deck
- npm start
- ```
Examples
How to use Code Surfer
It may help to know how MDX Deck works first
- ````md
- import { CodeSurfer } from "code-surfer"
- # Deck Title
- ---
- <CodeSurfer>
- ```js
- ```
- </CodeSurfer>
- ````
Here is a live deck using all the features (and its mdx source) just in case you prefer to read code instead of docs.
Focus
- ````md
- <CodeSurfer>
- ```js 1:2,3[8:10]
- ```
- </CodeSurfer>
- ````
Steps
- ````md
- <CodeSurfer>
- ```js
- ```
- ```js 1
- ```
- ```js
- ```
- </CodeSurfer>
- ````
Title and Subtitle
- ````md
- <CodeSurfer>
- ```js 1 title="Title" subtitle="Look at the first line"
- ```
- ```js 2 title="Title" subtitle="and now the second"
- ```
- </CodeSurfer>
- ````
Themes
- ````md
- import { CodeSurfer } from "code-surfer"
- import { nightOwl } from "@code-surfer/themes"
- <CodeSurfer theme={nightOwl}>
- ```js
- ```
- </CodeSurfer>
- ````
- ````md
- import { CodeSurfer } from "code-surfer"
- import { nightOwl } from "@code-surfer/themes"
- export const theme = nightOwl
- <CodeSurfer>
- ```js
- ```
- </CodeSurfer>
- ````
Exporting the theme like this will also change the text and background colors for slides that aren't using Code Surfer. If you want to keep the colors from a different mdx deck theme you can compose both themes together:export const themes = [codeSurferTheme, mdxDeckTheme]
Custom Styles
Themes use Theme UI internally
- ```js
- // custom-theme.js
- export default {
- colors: {
- background: "#222",
- text: "#ddd",
- primary: "#a66"
- },
- styles: {
- CodeSurfer: {
- pre: {
- color: "text",
- backgroundColor: "background"
- },
- code: {
- color: "text",
- backgroundColor: "background"
- },
- tokens: {
- "comment cdata doctype": {
- fontStyle: "italic"
- },
- "builtin changed keyword punctuation operator tag deleted string attr-value char number inserted": {
- color: "primary"
- },
- "line-number": {
- opacity: 0.8
- }
- },
- title: {
- backgroundColor: "background",
- color: "text"
- },
- subtitle: {
- color: "#d6deeb",
- backgroundColor: "rgba(10,10,10,0.9)"
- },
- unfocused: {
- // only the opacity of unfocused code can be changed
- opacity: 0.1
- }
- }
- }
- };
- ```
- ````md
- import { CodeSurfer } from "code-surfer"
- import customTheme from "./custom-theme"
- <CodeSurfer theme={customTheme}>
- ```js
- ```
- </CodeSurfer>
- ````
Languages
- ````md
- import { CodeSurfer } from "code-surfer"
- import "prismjs/components/prism-smalltalk"
- <CodeSurfer>
- ```smalltalk
- ```
- </CodeSurfer>
- ````
Columns
- ````md
- import { CodeSurferColumns, Step } from "code-surfer"
- <CodeSurferColumns>
- <Step subtitle="First Step">
- ```js
- ```
- ```js
- ```
- </Step>
- <Step subtitle="Second Step">
- ```js 2
- ```
- ```js 2
- ```
- </Step>
- </CodeSurferColumns>
- ````
- ````md
- import { CodeSurferColumns, Step } from "code-surfer"
- import MyComponent from "./my-component.jsx"
- <CodeSurferColumns>
- <Step>
- ```js
- ```
- # Some Markdown
- </Step>
- <Step>
- ```js 2
- ```
- <MyComponent/>
- </Step>
- </CodeSurferColumns>
- ````
Import Code
- ````md
- import { CodeSurfer } from "code-surfer"
- <CodeSurfer>
- ```js 5:10 file=./my-code.js
- ```
- ```js file=./my-other-code.js
- ```
- </CodeSurfer>
- ````
Line Numbers
- ````md
- import { CodeSurfer } from "code-surfer"
- <CodeSurfer>
- ```js showNumbers
- ```
- ```js
- ```
- </CodeSurfer>
- ````
Diffs
- ````md
- import { CodeSurfer } from "code-surfer"
- <CodeSurfer>
- ```js
- ```
- ```diff 1 subtitle="log 1"
- ```
- ```diff 2 subtitle="log 2"
- ```
- ```diff 3 subtitle="log 3"
- ```
- </CodeSurfer>
- ````