Link ​

Select text and attach an address to it. If you enter an address without selecting text, the address itself is inserted as the link text. Typing an http:// or https:// address and then pressing Space or Enter also turns it into a link.

Links only store http:, https:, and same-site paths that begin with . or /. Addresses whose origin cannot be clearly identified, such as javascript: or //example.com, are rejected. Attachment links created by uploads also store file information, and cannot be created manually like ordinary links.

Wings
Base typefaceOffset
HTMLLoading the editor…
JSONnabi-treeLoading the editor…
Install
npm install nabi-note
Code
import {
  createLocale, createNabiWith, mountSurface, mountToolbar,
  mountContextToolbar, mountHints, watchSettle, subscriptWing, linkWing,
  footnoteWing, mountViewTools,
} from 'nabi-note'

const selected = [
  subscriptWing,
  linkWing,
  footnoteWing,
]
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')
ts
const selected = wings().use('a').build()

Pasting URLs ​

If the entire pasted content, excluding surrounding whitespace, is a valid http:// or https:// URL, it is inserted as a link immediately. URLs within sentences, text containing multiple URLs, and relative paths follow the existing paste behavior. Code blocks and editors without the link wing keep the content as text. Valid internal clipboard data copied from the editor takes priority to preserve its original formatting.

Use the onPasteUrl callback in mountSurface() to choose the link's display text.

ArgumentValue
urlThe complete URL with surrounding whitespace removed
isSameOriginWhether the URL's protocol, host, and port match the origin of the document containing the editor
pathThe path starting with /, including the query and fragment. Example: /posts/1?a=2#top
ts
const surface = mountSurface({
  nabi,
  registry,
  root: document.querySelector<HTMLElement>('#editor')!,
  onPasteUrl(url, isSameOrigin, path) {
    if (isSameOrigin && path === '/guide') return 'NABI NOTE'
    return url
  },
})

A returned string containing non-whitespace text becomes the display text. If the callback is absent, returns an empty or non-string value, or fails, the pasted URL remains the display text. Returned strings are never interpreted as HTML and do not change the link address.

The callback also supports async functions and promises. The URL link is inserted immediately while the response is pending; a valid result later changes only that link's display text. A late result is ignored if the link has been edited or deleted, a new document has been loaded, or the surface has been unmounted.

CSS Styles ​

Style ordinary links with .nabi-content a, and attachment links separately with .nabi-content a[data-nabi-file].

css
.article-body a:not([data-nabi-file]) {
  color: var(--nabi-accent);
  text-decoration-thickness: .08em;
  text-underline-offset: .16em;
}

.article-body a[data-nabi-file] {
  display: inline-flex;
  gap: .35em;
  padding: .25em .55em;
  background: var(--nabi-soft);
}

The ::before and ::after parts of attachment links are used to show the file icon and extension, so it is usually best not to replace or remove their content.