Skip to content

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

@Ayan0420

Description

@Ayan0420

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 💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions