tiptap/docs/api/nodes/image.md
2022-02-09 12:21:26 +01:00

73 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: Add an image (but a beautiful one), when words arent enough.
icon: image-line
---
# Image
[![Version](https://img.shields.io/npm/v/@tiptap/extension-image.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-image)
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-image.svg)](https://npmcharts.com/compare/@tiptap/extension-image?minimal=true)
Use this extension to render `<img>` HTML tags. By default, those images are blocks. If you want to render images in line with text set the `inline` option to `true`.
:::warning Restrictions
This extension does only the rendering of images. It doesnt upload images to your server, thats a whole different story.
:::
## Installation
```bash
npm install @tiptap/extension-image
```
## Settings
### inline
Renders the image node inline, for example in a paragraph tag: `<p><img src="spacer.gif"></p>`. By default images are on the same level as paragraphs.
It totally depends on what kind of editing experience youd like to have, but can be useful if you (for example) migrate from Quill to Tiptap.
Default: `false`
```js
Image.configure({
inline: true,
})
```
### allowBase64
Allow images to be parsed as base64 strings `<img src="data:image/jpg;base64...">`.
Default: `false`
```js
Image.configure({
allowBase64: true,
})
```
### HTMLAttributes
Custom HTML attributes that should be added to the rendered HTML tag.
```js
Image.configure({
HTMLAttributes: {
class: 'my-custom-class',
},
})
```
## Commands
### setImage()
Makes the current node an image.
```js
editor.commands.setImage({ src: 'https://example.com/foobar.png' })
editor.commands.setImage({ src: 'https://example.com/foobar.png', alt: 'A boring example image', title: 'An example' })
```
## Source code
[packages/extension-image/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-image/)
## Usage
https://embed.tiptap.dev/preview/Nodes/Image