-
-
Notifications
You must be signed in to change notification settings - Fork 742
feat(core): support "plain" block content #2868
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
Open
YousefED
wants to merge
2
commits into
main
Choose a base branch
from
feat/plain-block-content
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |
| Extension, | ||
| ExtensionFactoryInstance, | ||
| } from "../../editor/BlockNoteExtension.js"; | ||
| import { NON_FORMATTING_MARK_GROUP } from "../markGroups.js"; | ||
| import { PropSchema } from "../propTypes.js"; | ||
| import { | ||
| getBlockFromPos, | ||
|
|
@@ -44,7 +45,7 @@ export function applyNonSelectableBlockFix(nodeView: NodeView, editor: Editor) { | |
| export function getParseRules< | ||
| TName extends string, | ||
| TProps extends PropSchema, | ||
| TContent extends "inline" | "none" | "table", | ||
| TContent extends "inline" | "none" | "table" | "plain", | ||
| >( | ||
| config: BlockConfig<TName, TProps, TContent>, | ||
| implementation: BlockImplementation<TName, TProps, TContent>, | ||
|
|
@@ -75,7 +76,9 @@ export function getParseRules< | |
| // Because we do the parsing ourselves, we want to preserve whitespace for content we've parsed | ||
| preserveWhitespace: true, | ||
| getContent: | ||
| config.content === "inline" || config.content === "none" | ||
| config.content === "inline" || | ||
| config.content === "none" || | ||
| config.content === "plain" | ||
| ? (node, schema) => { | ||
| if (implementation.parseContent) { | ||
| const result = implementation.parseContent({ | ||
|
|
@@ -89,6 +92,13 @@ export function getParseRules< | |
| } | ||
| } | ||
|
|
||
| if (config.content === "plain") { | ||
| // Plain blocks hold unstyled text only, so we parse the | ||
| // element's text content directly into a single text node. | ||
| const text = (node as HTMLElement).textContent ?? ""; | ||
| return text ? Fragment.from(schema.text(text)) : Fragment.empty; | ||
| } | ||
|
|
||
| if (config.content === "inline") { | ||
| // Parse the inline content if it exists | ||
| const element = node as HTMLElement; | ||
|
|
@@ -140,7 +150,7 @@ export function getParseRules< | |
| export function addNodeAndExtensionsToSpec< | ||
| TName extends string, | ||
| TProps extends PropSchema, | ||
| TContent extends "inline" | "none" | "table", | ||
| TContent extends "inline" | "none" | "table" | "plain", | ||
| >( | ||
| blockConfig: BlockConfig<TName, TProps, TContent>, | ||
| blockImplementation: BlockImplementation<TName, TProps, TContent>, | ||
|
|
@@ -153,9 +163,22 @@ export function addNodeAndExtensionsToSpec< | |
| name: blockConfig.type, | ||
| content: (blockConfig.content === "inline" | ||
| ? "inline*" | ||
| : blockConfig.content === "none" | ||
| ? "" | ||
| : blockConfig.content) as TContent extends "inline" ? "inline*" : "", | ||
| : blockConfig.content === "plain" | ||
| ? "text*" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting down that it feels a bit weird that you can technically have multiple separate |
||
| : blockConfig.content === "none" | ||
| ? "" | ||
| : blockConfig.content) as TContent extends "inline" | ||
| ? "inline*" | ||
| : TContent extends "plain" | ||
| ? "text*" | ||
| : "", | ||
| // "plain" blocks hold unstyled text, so they disallow formatting marks. | ||
| // They still allow the non-formatting marks (comments and | ||
| // suggestions/diffs) — those annotate content without changing it and are | ||
| // ignored by the block model. The group's always-present suggestion marks | ||
| // keep this reference valid even when comments aren't configured. | ||
| marks: | ||
| blockConfig.content === "plain" ? NON_FORMATTING_MARK_GROUP : undefined, | ||
| group: "blockContent", | ||
| selectable: blockImplementation.meta?.selectable ?? true, | ||
| isolating: blockImplementation.meta?.isolating ?? true, | ||
|
|
@@ -180,7 +203,11 @@ export function addNodeAndExtensionsToSpec< | |
| return wrapInBlockStructure( | ||
| { | ||
| dom: div, | ||
| contentDOM: blockConfig.content === "inline" ? div : undefined, | ||
| contentDOM: | ||
| blockConfig.content === "inline" || | ||
| blockConfig.content === "plain" | ||
| ? div | ||
| : undefined, | ||
| }, | ||
| blockConfig.type, | ||
| {}, | ||
|
|
@@ -304,7 +331,7 @@ export function createBlockConfig< | |
| export function createBlockSpec< | ||
| const TName extends string, | ||
| const TProps extends PropSchema, | ||
| const TContent extends "inline" | "none", | ||
| const TContent extends "inline" | "none" | "plain", | ||
| const TOptions extends Partial<Record<string, any>> | undefined = undefined, | ||
| >( | ||
| blockConfigOrCreator: BlockConfig<TName, TProps, TContent>, | ||
|
|
@@ -323,7 +350,7 @@ export function createBlockSpec< | |
| export function createBlockSpec< | ||
| const TName extends string, | ||
| const TProps extends PropSchema, | ||
| const TContent extends "inline" | "none", | ||
| const TContent extends "inline" | "none" | "plain", | ||
| const BlockConf extends BlockConfig<TName, TProps, TContent>, | ||
| const TOptions extends Partial<Record<string, any>>, | ||
| >( | ||
|
|
@@ -349,7 +376,7 @@ export function createBlockSpec< | |
| export function createBlockSpec< | ||
| const TName extends string, | ||
| const TProps extends PropSchema, | ||
| const TContent extends "inline" | "none", | ||
| const TContent extends "inline" | "none" | "plain", | ||
| const TOptions extends Partial<Record<string, any>> | undefined = undefined, | ||
| >( | ||
| blockConfigOrCreator: BlockConfigOrCreator<TName, TProps, TContent, TOptions>, | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Update code-block input-rule payload to plain-string content.
After Line 65 switches code blocks to
"plain", this file’s triple-backtick input-rule path still returnscontent: []. That no longer matches the code block contract and can leak array content into paths now expecting a string.Suggested fix
return { type: "codeBlock", props: { language: attributes.language, }, - content: [], + content: "", };🤖 Prompt for AI Agents