Skip to content

Commit

Permalink
switch to prism on homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespohalloran committed Aug 3, 2023
1 parent b72d9af commit b665058
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 27 deletions.
25 changes: 12 additions & 13 deletions components/blocks/Features.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Actions } from './Actions'
import { Container } from './Container'
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter'
import { Prism } from '../styles/Prism'
import { tinaField } from 'tinacms/dist/react'

export function FeatureBlock({ data, index }) {
Expand Down Expand Up @@ -72,18 +72,17 @@ export function FeatureBlock({ data, index }) {
'em',
}}
>
<SyntaxHighlighter
language={
data.media[0].language
? data.media[0].language
: 'javascript'
}
useInlineStyles={false}
// wrapLines={true}
// wrapLongLines={true}
>
{data.media[0].code}
</SyntaxHighlighter>
<div className="p-2 [&>pre]:!bg-transparent">
<Prism
lang={
data.media[0].language
? data.media[0].language
: 'javascript'
}
theme="nightOwl"
value={data.media[0].code}
/>
</div>
</div>
</div>
)}
Expand Down
20 changes: 8 additions & 12 deletions components/blocks/Story.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react'
import { useInView } from 'react-intersection-observer'
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter'
import { Container } from './Container'
import { Actions } from './Actions'
import type { TinaTemplate } from '@tinacms/cli'
import { Prism } from '../styles/Prism'

const features = [
{
Expand Down Expand Up @@ -228,16 +227,13 @@ const Pane = ({ data, position, ...props }) => {
1.25 * (data.file.textScale ? data.file.textScale : 1) + 'em',
}}
>
<SyntaxHighlighter
language={
data.file.language ? data.file.language : 'javascript'
}
useInlineStyles={false}
// wrapLines={true}
// wrapLongLines={true}
>
{data.file.code}
</SyntaxHighlighter>
<div className="p-2 [&>pre]:!bg-transparent">
<Prism
lang={data.file.language ? data.file.language : 'javascript'}
theme="nightOwl"
value={data.file.code}
/>
</div>
</div>
</div>
)}
Expand Down
28 changes: 28 additions & 0 deletions components/styles/Prism.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import { Highlight, themes } from 'prism-react-renderer'

export const Prism = (props: {
value: string
lang?: string
theme?: keyof typeof themes
}) => {
return (
<Highlight
theme={themes[props.theme || 'github']}
code={props.value}
language={props.lang || ''}
>
{({ className, style, tokens, getLineProps, getTokenProps }) => (
<pre className={className} style={style}>
{tokens.map((line, i) => (
<div {...getLineProps({ line, key: i })}>
{line.map((token, key) => (
<span {...getTokenProps({ token, key })} />
))}
</div>
))}
</pre>
)}
</Highlight>
)
}
2 changes: 1 addition & 1 deletion content/blocksPages/home.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
{
"file": "about.mdx",
"code": "---\ntitle: Collaborate With Your Team\n---\n\nOnline tools help drive your business forward.\nReach new audiences and collaborate with your\nteam – **All in the cloud.**\n\n<Button\ntext=\"Get Started\"\nlink=\"/get-started\"\n/>",
"language": "mdx",
"language": "markdown",
"scale": 1,
"_template": "code"
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"parse-numeric-range": "^1.3.0",
"polished": "^3.4.4",
"postcss": "^8.4.18",
"prism-react-renderer": "^2.0.6",
"prop-types": "^15.7.2",
"qs": "^6.9.1",
"raw-loader": "^4.0.0",
Expand Down Expand Up @@ -133,4 +134,4 @@
"tslint-react": "^4.0.0",
"typescript": "^4.5.5"
}
}
}

0 comments on commit b665058

Please sign in to comment.