Drop Cap
Place the first letter of a paragraph at a larger size and let the following lines flow beside it. This is paragraph-level formatting, so it is not applied to only part of a selected word.
Inside a table, drop caps apply to inner paragraphs rather than the cells themselves. Selecting several cells changes all eligible paragraphs inside them, and the toolbar state reflects the same paragraph selection.
The published view and editing view keep the same shape. While editing, the first letter is wrapped in a real element so caret and delete positions do not drift; that element is not included in the saved document content.
npm install nabi-noteimport {
createLocale, createNabiWith, mountSurface, mountToolbar,
mountContextToolbar, mountHints, watchSettle, typefaceWing, alignWing,
dropCapWing, mountViewTools,
} from 'nabi-note'
const selected = [
typefaceWing,
alignWing,
dropCapWing,
]
const locale = createLocale('en')
const { nabi, registry } = createNabiWith(selected, { locale })
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 })
const settle = watchSettle(document, { surface: content })
const shared = { nabi, registry, surface: content, settle, locale }
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()))
// Call from your language selector. Content and editing history stay intact.
// locale.setLocale('ko')const selected = wings().use('dc').build()CSS Styles
The published view and editing view use different selectors for the first letter. The published view uses [data-nabi-dropcap="1"]::first-letter, while the editing view uses the real element [data-nabi-dropcap-letter]. When changing visible values such as color, font, or size, write both selectors together so editing and published output look the same.
.article-body:not(.nabi-editing) [data-nabi-dropcap="1"]::first-letter,
.nabi-content.nabi-editing [data-nabi-dropcap-letter] {
color: var(--nabi-accent);
font-family: var(--nabi-font-serif);
}If you change size and line height, apply the same values to both selectors.
.article-body:not(.nabi-editing) [data-nabi-dropcap="1"]::first-letter,
.nabi-content.nabi-editing [data-nabi-dropcap-letter] {
font-size: 5.5em;
line-height: .85;
}Drop caps calculate the line flow around the first letter, so changing only one side or making the values too large can break the WYSIWYG shape. Still avoid adding a new ::first-letter rule to the editor. In the editor, style only the existing [data-nabi-dropcap-letter].