forked from remirror/remirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(extension-code-block): set fallback language (remirror#1055)
- Loading branch information
Showing
5 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@remirror/extension-code-block': patch | ||
--- | ||
|
||
Fix a crash when the code block node contains an invalid language name. |
69 changes: 69 additions & 0 deletions
69
packages/remirror__extension-code-block/__stories__/code-block.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import javascript from 'refractor/lang/javascript'; | ||
import typescript from 'refractor/lang/typescript'; | ||
import { CodeBlockExtension } from 'remirror/extensions'; | ||
import { ProsemirrorDevTools } from '@remirror/dev'; | ||
import { Remirror, ThemeProvider, useEditorState, useRemirror } from '@remirror/react'; | ||
|
||
export default { title: 'Code Block extension' }; | ||
|
||
const Dev = () => { | ||
const updatedState = useEditorState(); | ||
console.log(JSON.stringify(updatedState.doc.toJSON())); | ||
return null; | ||
}; | ||
export const Basic = (): JSX.Element => { | ||
const { manager, state } = useRemirror({ extensions, content, stringHandler: 'html' }); | ||
|
||
return ( | ||
<ThemeProvider> | ||
<Remirror manager={manager} initialContent={state} autoRender> | ||
<Dev /> | ||
<ProsemirrorDevTools /> | ||
</Remirror> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
Basic.args = { | ||
autoLink: true, | ||
openLinkOnClick: true, | ||
}; | ||
|
||
const extensions = () => [ | ||
new CodeBlockExtension({ | ||
supportedLanguages: [javascript, typescript], | ||
}), | ||
]; | ||
|
||
const html = String.raw; | ||
const content = html` | ||
<pre><code data-code-block-language="typescript"> | ||
function sayHello{ | ||
console.log('hello world!') | ||
} | ||
</code></pre> | ||
`; | ||
|
||
export const WithIncorrectLanguage = (): JSX.Element => { | ||
const { manager, state } = useRemirror({ | ||
extensions, | ||
content: { | ||
type: 'doc', | ||
content: [ | ||
{ | ||
type: 'codeBlock', | ||
attrs: { language: 'THIS_LANGUAGE_DOES_NOT_EXIST', wrap: false }, | ||
content: [{ type: 'text', text: 'hello world' }], | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
return ( | ||
<ThemeProvider> | ||
<Remirror manager={manager} initialContent={state} autoRender> | ||
<ProsemirrorDevTools /> | ||
</Remirror> | ||
</ThemeProvider> | ||
); | ||
}; |
56 changes: 56 additions & 0 deletions
56
packages/remirror__extension-code-block/__stories__/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"__AUTO_GENERATED__": [ | ||
"To update the configuration edit the following field.", | ||
"`package.json > @remirror > tsconfigs > '__stories__'`", | ||
"", | ||
"Then run: `pnpm -w generate:ts`" | ||
], | ||
"extends": "../../../support/tsconfig.base.json", | ||
"compilerOptions": { | ||
"types": [], | ||
"declaration": false, | ||
"noEmit": true, | ||
"skipLibCheck": true, | ||
"importsNotUsedAsValues": "remove", | ||
"paths": { | ||
"react": [ | ||
"../../../node_modules/.pnpm/@[email protected]/node_modules/@types/react/index.d.ts" | ||
], | ||
"react/jsx-dev-runtime": [ | ||
"../../../node_modules/.pnpm/@[email protected]/node_modules/@types/react/jsx-dev-runtime.d.ts" | ||
], | ||
"react/jsx-runtime": [ | ||
"../../../node_modules/.pnpm/@[email protected]/node_modules/@types/react/jsx-runtime.d.ts" | ||
], | ||
"react-dom": [ | ||
"../../../node_modules/.pnpm/@[email protected]/node_modules/@types/react-dom/index.d.ts" | ||
], | ||
"reakit": [ | ||
"../../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/reakit/ts/index.d.ts" | ||
], | ||
"@remirror/react": ["../../remirror__react/src/index.ts"], | ||
"@storybook/react": [ | ||
"../../../node_modules/.pnpm/@[email protected]_dfad392d5450b8683a621f3ec486af19/node_modules/@storybook/react/types-6-0.d.ts" | ||
], | ||
"@remirror/dev": ["../../remirror__dev/src/index.ts"] | ||
} | ||
}, | ||
"include": ["./"], | ||
"references": [ | ||
{ | ||
"path": "../../testing/src" | ||
}, | ||
{ | ||
"path": "../../remirror/src" | ||
}, | ||
{ | ||
"path": "../../remirror__core/src" | ||
}, | ||
{ | ||
"path": "../../remirror__messages/src" | ||
}, | ||
{ | ||
"path": "../../remirror__theme/src" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters