Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlighting in code blocks not working properly when added in the initial content. #1231

Open
1 task
Ayan0420 opened this issue Nov 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Ayan0420
Copy link

Ayan0420 commented Nov 10, 2024

Describe the bug
The syntax highlighting in code blocks is not working properly when I add initial codeblock content with multiple lines.

To Reproduce
add Initial codeblock content with multiple lines to the editor

Example component where the content comes from the initialContent prop

"use client";
import React from "react";
import { BlockNoteSchema, defaultBlockSpecs, PartialBlock } from "@blocknote/core";
import { useCreateBlockNote } from "@blocknote/react";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useTheme } from "next-themes";

interface ViewerProps {
    initialContent?: string;
}

const schema = BlockNoteSchema.create({
    blockSpecs: {
      // Adds all default blocks.
      ...defaultBlockSpecs
    },
  });

const Viewer: React.FC<ViewerProps> = ({ initialContent }) => {
    const { theme } = useTheme()
    
    const editor = useCreateBlockNote({
        schema,
        initialContent: initialContent
            ? (JSON.parse(initialContent) as PartialBlock[])
            : undefined,
    });

    return (
        <div className="-mx-[54px] my-4">
            <BlockNoteView
                editor={editor}
                editable={false}
                onChange={() => {}}
                theme={theme as "light" | "dark"}
            />
        </div>
    );
};

export default Viewer;

Misc

  • Node version: 20.9.0
  • Package manager: 10.2.4
  • Browser: Chrome, Brave, Firefox
  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖
@Ayan0420 Ayan0420 added the bug Something isn't working label Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant