YouTube

Accetta un URL di video YouTube o l'ID del video e lo trasforma in un blocco incorporato. Il documento conserva solo l'ID di 11 caratteri e la larghezza, non l'URL completo; un nuovo video parte centrato con larghezza del 70%.

La larghezza è scelta da passaggi fissi e l'allineamento è salvato nel paragrafo che avvolge il video. Nell'editor il primo clic seleziona il video; dopo la selezione, un altro clic può avviarlo. Per cambiare indirizzo, elimina il video e inseriscine uno nuovo.

Ali
Carattere di baseAltezza
HTMLCaricamento dell’editor…
JSONnabi-treeCaricamento dell’editor…
Installazione
npm install nabi-note
Codice
import {
  createNabiWith, mountSurface, mountToolbar, mountContextToolbar,
  mountHints, watchSettle, codeWing, imageWing, youtubeWing,
  mountViewTools,
} from 'nabi-note'

const selected = [
  codeWing,
  imageWing,
  youtubeWing,
]
const { nabi, registry } = createNabiWith(selected)

// Bring your own highlighter (Prism, highlight.js, Shiki, …) — the wing stays as it is
// and only the attach is swapped (`makeCodeAttach` ships from the same door)
// { ...codeWing, attach: makeCodeAttach({ highlight: (source, lang) => [{ text: source }] }) }

const root = document.querySelector('.nabi')!
const content = document.querySelector('.nabi-content')!

// The locale also sets the direction — Arabic and Urdu run right to left
mountSurface({ nabi, registry, root: content, locale: 'it' })

const settle = watchSettle(document, { surface: content })
const shared = { nabi, registry, surface: content, settle, locale: 'it' }
const toolbar = mountToolbar({ ...shared, root: document.querySelector('#toolbar')! })
const context = mountContextToolbar({ ...shared, root: document.querySelector('#context')! })
mountHints({ toolbar, context, root, surface: content })
// The preview and fullscreen buttons — they stand their own box at the end of the row
mountViewTools({ ...shared, root, container: document.querySelector('#toolbar')! })

// on every change — hook up your own code here
// nabi.onChange(() => user_callback(nabi.getHtml()))
ts
const selected = wings().use('youtube').build()

Stili CSS

Usa .nabi-content iframe per modificare bordo o angoli del video. Non cambiare la larghezza o l'allineamento salvati.

css
.article-body iframe {
  border-radius: 14px;
  box-shadow: 0 10px 28px rgb(0 0 0 / 16%);
}

Il pacchetto usa aspect-ratio, larghezza e margini di allineamento per mantenere corretta la dimensione del video; non sovrascriverli.