Skip to content

Commit 4b5bbb3

Browse files
Laurie BarthLaurie Barth
authored andcommitted
Add a prism preset options field
1 parent ff9037d commit 4b5bbb3

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

packages/gatsby-plugin-theme-ui/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ prevent a flash of unstyled colors when using color modes.
2323
| `themeModule` | `null` | JSON theme object, use the `require` syntax to include it in options. Make sure the package you're requiring is installed in your dependencies. |
2424
| `themeModulePath` | `null` | A string package name that the plugin will require for you. Make sure the package you're requiring is installed in your dependencies. |
2525
| `moduleExportName` | `default` | The name of the export from the theme module, applies to `themeModule` or `themeModulePath` resolution depending which one you're using |
26+
| `prismPreset` | `null` | The name of the preset you'd like to use to style code blocks inside your markdown files. The available presets can be found in the [theme-ui docs](https://theme-ui.com/packages/prism/). |
2627

2728
> Note that if your theme is exported at the top level, the `moduleExportName` of `default` is bypassed. See [theme-ui/preset-deep](https://github.com/system-ui/theme-ui/blob/master/packages/preset-deep/src/index.ts).
2829
@@ -36,8 +37,9 @@ module.exports = {
3637
plugins: [
3738
{ resolve: 'gatsby-plugin-theme-ui',
3839
options: {
39-
themeModulePath: '@theme-ui/preset-funk'
40+
themeModulePath: '@theme-ui/preset-funk',
4041
// or themeModule: require('@theme-ui/preset-funk')
42+
prismPreset: 'night-owl'
4143
}
4244
}],
4345
}

packages/gatsby-plugin-theme-ui/gatsby-node.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ exports.onPreInit = (__, options) => {
33
if(themeModulePath) {
44
options.themeModulePath = require(themeModulePath)
55
}
6+
if(prismPreset) {
7+
options.prismPreset = require(`@theme-ui/prism/presets/${prismPreset}.json`)
8+
}
69
}
710

811
exports.createSchemaCustomization = ({ actions }) => {
@@ -13,20 +16,22 @@ exports.createSchemaCustomization = ({ actions }) => {
1316
themeModule: JSON,
1417
themeModulePath: JSON,
1518
moduleExportName: String,
19+
prismPreset: JSON,
1620
}
1721
`)
1822
}
1923

2024
exports.sourceNodes = (
2125
{ actions, createContentDigest },
22-
{ moduleExportName = 'default', themeModule, themeModulePath}
26+
{ prismPreset, moduleExportName = 'default', themeModule, themeModulePath}
2327
) => {
2428
const { createNode } = actions
2529

2630
const themeUiConfig = {
2731
themeModule,
2832
themeModulePath,
2933
moduleExportName,
34+
prismPreset
3035
}
3136

3237
createNode({

packages/gatsby-plugin-theme-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"license": "MIT",
77
"peerDependencies": {
88
"gatsby": "^2.13.1",
9-
"theme-ui": "^0.3.0"
9+
"theme-ui": "^0.3.0",
10+
"@theme-ui/prism": "0.3.0"
1011
},
1112
"keywords": [
1213
"gatsby",

packages/gatsby-plugin-theme-ui/src/hooks/configOptions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const useThemeUiConfig = () => {
77
themeModule
88
themeModulePath
99
moduleExportName
10+
prismPreset
1011
}
1112
}
1213
`)

packages/gatsby-plugin-theme-ui/src/provider.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const Root = ({children}) => {
2727
}
2828

2929
themeWrapper = merge(themeWrapper, {
30+
prism: prismPreset,
3031
...theme
3132
})
3233
return (

0 commit comments

Comments
 (0)