Pre

Code block (pre). Renders from pre.template (default <pre><code>), optionally in <figure> with <figcaption>. JSON data: { content: string, caption?, ...common }.

Type: pre · Class: PreBlock

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();

getData#

Returns common fields plus content (code text) and caption when the template includes a figcaption.

Returns: object

block.getData();

update#

Applies common fields, refreshes DOM refs, then updates code text and/or caption (caption only when the template includes a figcaption).

Parameters:

  • data (object) — object with the keys below
    • content (string) — code text (textContent of the code target)
    • text (string) — alias for content when content is omitted
    • caption (string) — figcaption text when a caption element exists
    • id, classname, styles, attrs, … — common block fields (see Common update)

Returns: void

block.update({ content: 'console.log(1)' });

block.update({ text: 'const x = 1;' });

block.update({ content: 'npm install', caption: 'Install step' });