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

Can I set the default "center" alignment for image captions? #1098

Open
lamtuanamc opened this issue Sep 24, 2024 · 1 comment
Open

Can I set the default "center" alignment for image captions? #1098

lamtuanamc opened this issue Sep 24, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@lamtuanamc
Copy link

When inserting an image block, I want to set the caption text alignment to "center" by default.

In the previous version of BlockNote (0.14.x), I was able to do this with the following code:

defaultBlockSpecs.image.config.propSchema.textAlignment = {
  default: 'center',
  values: ['left', 'center', 'right', 'justify'],
};

However, in newest version, I can't seem to set it this way anymore, as the default value is now 'left', and it's no longer a string type.

@lamtuanamc lamtuanamc added the enhancement New feature or request label Sep 24, 2024
@matthewlipski
Copy link
Collaborator

This should work:

editor.schema.blockSchema.image.propSchema.textAlignment.default =
    "center" as any;
  editor.schema.blockSpecs.image.config.propSchema.textAlignment.default =
    "center" as any;

Also make sure to add this CSS:

.bn-block-content[data-content-type="image"]:not([data-text-alignment]) {
  justify-content: center;
  text-align: center;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants