ลิงก์
เลือกข้อความแล้วเชื่อมต่อที่อยู่ หากป้อนที่อยู่โดยไม่เลือกข้อความ ที่อยู่นั้นจะถูกใส่เป็นข้อความลิงก์เอง การป้อนที่อยู่ http:// หรือ https:// แล้วกด Space หรือ Enter ก็เปลี่ยนเป็นลิงก์ได้เช่นกัน
ลิงก์เก็บได้เฉพาะ http:, https: และพาธไซต์เดียวกันที่เริ่มด้วย . หรือ / ที่อยู่ซึ่งระบุแหล่งที่มาไม่ได้ชัดเจน เช่น javascript: หรือ //example.com จะถูกปฏิเสธ ลิงก์ไฟล์แนบที่สร้างจากการอัปโหลดยังเก็บข้อมูลไฟล์ไว้ด้วย และไม่สามารถสร้างเองแบบลิงก์ทั่วไปได้
npm install nabi-noteimport {
createLocale, createNabiWith, mountSurface, mountToolbar,
mountContextToolbar, mountHints, watchSettle, subscriptWing, linkWing,
footnoteWing, mountViewTools,
} from 'nabi-note'
const selected = [
subscriptWing,
linkWing,
footnoteWing,
]
const locale = createLocale('th')
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('a').build()การวาง URL
หากเนื้อหาที่วางทั้งหมดหลังตัดอักขระช่องว่างด้านหน้าและด้านท้ายออกเป็น URL http:// หรือ https:// ที่ถูกต้อง เนื้อหานั้นจะถูกแทรกเป็นลิงก์ทันที URL ในประโยค ข้อความที่มีหลาย URL และพาธแบบสัมพัทธ์จะใช้พฤติกรรมการวางเดิม ในบล็อกโค้ดและตัวแก้ไขที่ไม่มี wing ลิงก์ เนื้อหาจะยังเป็นข้อความ ข้อมูลคลิปบอร์ดภายในที่ถูกต้องซึ่งคัดลอกจากตัวแก้ไขจะได้รับความสำคัญก่อน เพื่อรักษารูปแบบเดิม
ใช้คอลแบ็ก onPasteUrl ใน mountSurface() เพื่อกำหนดข้อความที่แสดงของลิงก์
| อาร์กิวเมนต์ | ค่า |
|---|---|
url | URL แบบเต็มหลังตัดอักขระช่องว่างด้านหน้าและด้านท้ายออก |
isSameOrigin | โปรโตคอล โฮสต์ และพอร์ตของ URL ตรงกับ origin ของเอกสารที่มีตัวแก้ไขอยู่หรือไม่ |
path | พาธที่ขึ้นต้นด้วย / รวม query และ fragment ตัวอย่าง: /posts/1?a=2#top |
const surface = mountSurface({
nabi,
registry,
root: document.querySelector<HTMLElement>('#editor')!,
onPasteUrl(url, isSameOrigin, path) {
if (isSameOrigin && path === '/guide') return 'NABI NOTE'
return url
},
})หากสตริงที่ส่งกลับมีอักขระอื่นนอกจากช่องว่าง สตริงนั้นจะกลายเป็นข้อความที่แสดง หากไม่มีคอลแบ็ก ส่งกลับค่าว่างหรือค่าที่ไม่ใช่สตริง หรือเกิดข้อผิดพลาด URL ที่วางจะยังเป็นข้อความที่แสดง สตริงที่ส่งกลับจะไม่ถูกตีความเป็น HTML และไม่เปลี่ยนที่อยู่ของลิงก์
คอลแบ็กรองรับฟังก์ชัน async และ Promise ด้วย ลิงก์ URL จะถูกแทรกทันทีระหว่างรอคำตอบ เมื่อได้รับผลลัพธ์ที่ถูกต้องในภายหลัง จะเปลี่ยนเฉพาะข้อความที่แสดงของลิงก์นั้น ผลลัพธ์ที่มาถึงช้าจะถูกละเว้นหากลิงก์ถูกแก้ไขหรือลบ มีการโหลดเอกสารใหม่ หรือ surface ถูกยกเลิกการเมานต์แล้ว
รูปแบบ CSS
จัดรูปแบบลิงก์ทั่วไปด้วย .nabi-content a และลิงก์ไฟล์แนบแยกต่างหากด้วย .nabi-content a[data-nabi-file]
.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);
}ส่วน ::before และ ::after ของลิงก์ไฟล์แนบใช้แสดงไอคอนไฟล์และนามสกุล จึงไม่ควรเปลี่ยนหรือลบ content