You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { useEffect, useRef } from "react";
import { Crepe } from '@milkdown/crepe';
import { replaceAll, getMarkdown } from '@milkdown/utils';
import "@milkdown/crepe/theme/common/style.css";
import "@milkdown/crepe/theme/frame.css";
export function Editor() {
const editorRef = useRef<Crepe | null>(null);
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!containerRef.current || editorRef.current) return;
const crepe = new Crepe({
root: containerRef.current,
});
crepe.create().then(() => {
editorRef.current = crepe;
// Set some initial content with a code block
crepe.editor.action(replaceAll(`# Test
\`\`\`
console.log('hello')
\`\`\`
`));
// Try to get markdown content - this will throw if code block has no language
try {
const content = crepe.editor.action(getMarkdown());
console.log('Content:', content);
} catch (e) {
console.error('Error getting markdown:', e);
}
});
return () => {
editorRef.current?.destroy();
};
}, []);
return (
<div className="h-full flex-1 flex flex-col">
<div ref={containerRef} className="flex-1 pl-8 p-4 editor-pane" />
</div>
);
}
Btw, if you do select a language, it works without any issues. So this is specific to having no language selected in a code block and trying to getMarkdown().
Expected behavior
getMarkdown() should return the markdown despite no language being selected in the code block.
Actual behavior
getMarkdown() throws error in console and does not return the current markdown
Seems directly related to new code for v7.6.1: 18db4dc
Potentially easy fix just to change if (language.toLowerCase() === 'latex') {
to: if (language?.toLowerCase() === 'latex') {
(but I'm not familiar enough to be certain)
Btw, thank you for this incredible project!
Runtime
Chrome
OS
Windows
Build and bundle tools
Vite
The text was updated successfully, but these errors were encountered:
Initial checklist
Affected packages and versions
v7.6.1
Link to runnable example
https://crepe-editor-bug-simulator.lovable.app/
Steps to reproduce
"@milkdown/crepe": "7.6.1"
"@milkdown/utils": "7.6.1"
See link for demo (check console log - it points to the new change intended to support latex)
https://crepe-editor-bug-simulator.lovable.app/
Code running that demo:
Btw, if you do select a language, it works without any issues. So this is specific to having no language selected in a code block and trying to getMarkdown().
Expected behavior
getMarkdown() should return the markdown despite no language being selected in the code block.
Actual behavior
getMarkdown() throws error in console and does not return the current markdown
Seems directly related to new code for v7.6.1:
18db4dc
Potentially easy fix just to change
if (language.toLowerCase() === 'latex') {
to:
if (language?.toLowerCase() === 'latex') {
(but I'm not familiar enough to be certain)
Btw, thank you for this incredible project!
Runtime
Chrome
OS
Windows
Build and bundle tools
Vite
The text was updated successfully, but these errors were encountered: