Embed

Non-editable embed block (embed). Renders as <figure> around iframe/video/embed/audio (optional responsive wrapper and caption). JSON data: { type, src, caption?, width?, height?, responsive?, wrap?, ...common }.

Type: embed · Class: EmbedBlock

Access:

app.block.get()
app.blocks.findByEl(el)
app.blocks.create(type)

App code:

const block = app.block.get();

Plugin:

const block = this.app.block.get();

getContent#

Returns content.

block.getContent();

getCaption#

Returns the text content of the <figcaption> element, or an empty string when no caption exists.

Returns: string

block.getCaption();

isResponsive#

Returns whether the embed is wrapped in a responsive container (per embed.responsive option or block data).

Returns: boolean

block.isResponsive();

getData#

Returns the serializable JSON data object for this block, including type-specific fields.

Returns: object

block.getData();

update#

Applies common fields, then updates the media element, caption, responsive wrapper, and dimensions. A raw src URL may be normalized via app.embed.normalize when html is not provided.

Parameters:

  • data (object) — object with the keys below
    • src (string) — media URL (iframe/video/audio/embed src)
    • type (string) — media tag name (iframe, video, audio, embed); replaces the element when it differs
    • html (string) — iframe HTML snippet; replaces the media node from markup
    • caption (string) — figcaption text (creates the caption when missing)
    • width / height (string | number | null) — media attributes; empty/null removes them
    • responsive (boolean) — when true, ensures a responsive wrapper
    • responsiveClass (string) — CSS class for the responsive wrapper
    • wrap (boolean) — remembers whether the embed should stay wrapped in <figure> on export
    • id, classname, styles, attrs, … — common block fields (see Common update)

Returns: void

block.update({ src: 'https://www.youtube.com/embed/dQw4w9WgXcQ' });

block.update({
    type: 'iframe',
    src: 'https://player.vimeo.com/video/123',
    width: 640,
    height: 360
});

block.update({
    html: '<iframe src="https://www.youtube.com/embed/abc"></iframe>'
});

block.update({ caption: 'Product demo', responsive: true });

block.update({ width: '', height: null });