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

simple latex block #818

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
change latex to inline content
  • Loading branch information
jkcs committed Jun 7, 2024
commit 1809a2167f25888498b9ffc30144cc9864533dd6
21 changes: 13 additions & 8 deletions examples/05-custom-schema/05-latex-block/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
BlockNoteSchema,
defaultBlockSpecs,
defaultInlineContentSpecs,
filterSuggestionItems,
insertOrUpdateBlock,
} from "@blocknote/core";
Expand All @@ -18,8 +18,8 @@ import { LaTex } from "./LaTex";
// Our schema with block specs, which contain the configs and implementations for blocks
// that we want our editor to use.
const schema = BlockNoteSchema.create({
blockSpecs: {
...defaultBlockSpecs,
inlineContentSpecs: {
...defaultInlineContentSpecs,
latex: LaTex,
},
});
Expand All @@ -33,11 +33,16 @@ const insertLaTex = (editor: typeof schema.BlockNoteEditor) => ({
group: "Other",
onItemClick: () => {
insertOrUpdateBlock(editor, {
type: "latex",
props: {
open: true
},
content: '\\sqrt{a^2 + b^2}'
type: "paragraph",
content: [
{
type: "latex",
props: {
open: true
},
content: '\\sqrt{a^2 + b^2}'
}
]
});
},
});
Expand Down
8 changes: 3 additions & 5 deletions examples/05-custom-schema/05-latex-block/LaTex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NodeViewWrapper,
ReactNodeViewRenderer,
} from "@tiptap/react";
import { createStronglyTypedTiptapNode, createInternalBlockSpec } from "@blocknote/core";
import { createStronglyTypedTiptapNode, createInternalInlineContentSpec } from "@blocknote/core";
import { mergeAttributes } from "@tiptap/core";
import { ChangeEvent, useEffect, useState, useRef } from "react";
import "./styles.css";
Expand Down Expand Up @@ -221,15 +221,13 @@ const node = createStronglyTypedTiptapNode({
addNodeView: LaTexView(),
});

export const LaTex = createInternalBlockSpec(
export const LaTex = createInternalInlineContentSpec(
{
content: "inline",
content: "styled",
type: "latex",
propSchema: propSchema,
},
{
node,
toExternalHTML: undefined as any,
toInternalHTML: undefined as any,
},
);
Loading