Skip to content

Commit

Permalink
feat: add highlight syntax for code (issue octokatherine#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
DomeT99 committed Aug 30, 2024
1 parent 2018bb2 commit 15f3e63
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/EditPreviewContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const EditPreviewContainer = ({
selectedSectionSlugs={selectedSectionSlugs}
getTemplate={getTemplate}
selectedTab={selectedTab}
darkMode={darkMode}
/>
</div>
) : null}
Expand Down
11 changes: 10 additions & 1 deletion components/PreviewColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import ReactMarkdown from 'react-markdown'

import { TAB } from '../utils/constants'
import RawPreview from './RawPreview'
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
import { oneDark, oneLight } from 'react-syntax-highlighter/dist/cjs/styles/prism'

const gfm = require('remark-gfm')
export const PreviewColumn = ({ selectedSectionSlugs, getTemplate, selectedTab }) => {
export const PreviewColumn = ({ selectedSectionSlugs, getTemplate, selectedTab, darkMode }) => {
selectedSectionSlugs = [...new Set(selectedSectionSlugs)]
const markdown = selectedSectionSlugs.reduce((acc, section) => {
const template = getTemplate(section)
Expand Down Expand Up @@ -33,6 +35,13 @@ export const PreviewColumn = ({ selectedSectionSlugs, getTemplate, selectedTab }
{props.children}
</a>
),
code: ({ language, value, darkMode }) => (
<SyntaxHighlighter
style={darkMode ? oneDark : oneLight}
language={language}
children={value}
/>
),
}}
/>
) : (
Expand Down
Loading

0 comments on commit 15f3e63

Please sign in to comment.