Skip to content

Commit

Permalink
fix: codeBlockLanguages are correctly applied
Browse files Browse the repository at this point in the history
Fixes #27
  • Loading branch information
petyosi committed Jul 23, 2023
1 parent a93d5d3 commit fa17303
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/system/Sandpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const defaultSandpackConfig: SandpackConfig = {
]
}

const defaultCodeBlockLanguages = {
export const defaultCodeBlockLanguages = {
js: 'JavaScript',
ts: 'TypeScript',
tsx: 'TypeScript (React)',
Expand All @@ -120,7 +120,7 @@ const defaultCodeBlockLanguages = {
export const [SandpackSystem] = system(
(r, [{ activeEditor, activeEditorType, createEditorSubscription }]) => {
const sandpackConfig = r.node<SandpackConfig>(defaultSandpackConfig)
const codeBlockLanguages = r.node(defaultCodeBlockLanguages)
const codeBlockLanguages = r.node<Record<string, string>>(defaultCodeBlockLanguages)
const insertSandpack = r.node<string>()
const insertCodeBlock = r.node<true>()

Expand Down
7 changes: 5 additions & 2 deletions src/ui/MDXEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
importMarkdownToLexical
} from '../import'
import { EditorSystemComponent, useEmitterValues, usePublisher } from '../system/EditorSystemComponent'
import { SandpackConfig } from '../system/Sandpack'
import { SandpackConfig, defaultCodeBlockLanguages } from '../system/Sandpack'
import { NodeDecoratorComponents } from '../types/ExtendedEditorConfig'
import { JsxComponentDescriptor } from '../types/JsxComponentDescriptors'
import { ViewMode } from '../types/ViewMode'
Expand Down Expand Up @@ -143,6 +143,7 @@ export interface MDXEditorProps {
* The supported code block languages.
*/
codeBlockLanguages?: Record<string, string>

/**
* Implement this so that users can drag and drop or paste images into the editor.
* Pass an implementation that takes a file as an argument, and returns Promise<string>, where string is the url of the image to be inserted.
Expand Down Expand Up @@ -331,7 +332,8 @@ export const MDXEditor = React.forwardRef<MDXEditorMethods, MDXEditorProps>(
visitors: exportVisitors = Object.values(defaultLexicalVisitors)
} = {},
lexicalNodes = Object.values(defaultLexicalNodes),
customLeafDirectiveEditors = []
customLeafDirectiveEditors = [],
codeBlockLanguages = defaultCodeBlockLanguages
},
ref
) => {
Expand Down Expand Up @@ -361,6 +363,7 @@ export const MDXEditor = React.forwardRef<MDXEditorMethods, MDXEditorProps>(
}}
>
<EditorSystemComponent
codeBlockLanguages={codeBlockLanguages}
markdownSource={markdown}
headMarkdown={headMarkdown || markdown}
jsxComponentDescriptors={jsxComponentDescriptors}
Expand Down

0 comments on commit fa17303

Please sign in to comment.