Skip to Content
์ง๋ ฌํ™”

์ง๋ ฌํ™”

@inkio/editor๋Š” ๊ธฐ๋ณธ ์ง๋ ฌํ™” ์œ ํ‹ธ๋ฆฌํ‹ฐ๋ฅผ ์ œ๊ณตํ•˜๊ณ , ๋ฉ˜์…˜/ํ•ด์‹œํƒœ๊ทธ ์ถ”์ถœ์€ @inkio/extension์—์„œ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

import { toPlainText, toSummary, getContentStats, } from '@inkio/editor'; import { extractMentions, extractHashtags } from '@inkio/extension';

toPlainText

์—๋””ํ„ฐ JSON์„ ์ผ๋ฐ˜ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

const text = toPlainText(editorContent); // '์ œ๋ชฉ ๋ณธ๋ฌธ ๋‚ด์šฉ...'

ํ…์ŠคํŠธ ๋…ธ๋“œ์™€ ํ•˜๋“œ ๋ธŒ๋ ˆ์ดํฌ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ผ๋ฐ˜ ํ…์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

toSummary

์ฝ˜ํ…์ธ ์˜ ์š”์•ฝ ํ…์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

const summary = toSummary(editorContent); // ๊ธฐ๋ณธ 140์ž const shortSummary = toSummary(editorContent, 80); // 80์ž ์ œํ•œ // '์ œ๋ชฉ ๋ณธ๋ฌธ ๋‚ด์šฉ...'

maxLength๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ...์ด ๋ถ™์Šต๋‹ˆ๋‹ค.

getContentStats

์ฝ˜ํ…์ธ  ํ†ต๊ณ„๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

const stats = getContentStats(editorContent); // { words: 42, chars: 256, blocks: 8 }
ํ•„๋“œ์„ค๋ช…
words๊ณต๋ฐฑ ๊ธฐ์ค€ ๋‹จ์–ด ์ˆ˜
chars์ด ๋ฌธ์ž ์ˆ˜
blocks๋ธ”๋ก ๋…ธ๋“œ ์ˆ˜ (paragraph, heading, list ๋“ฑ)

extractMentions

์ฝ˜ํ…์ธ ์—์„œ ๋ฉ˜์…˜์„ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.

const mentions = extractMentions(editorContent); // [{ id: '1', label: 'Alice' }, { id: '2', label: 'Bob' }]

์ค‘๋ณต์€ ์ž๋™์œผ๋กœ ์ œ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.

extractHashtags

์ฝ˜ํ…์ธ ์—์„œ ํ•ด์‹œํƒœ๊ทธ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.

const tags = extractHashtags(editorContent); // ['react', 'typescript', 'frontend']

# ์ ‘๋‘์‚ฌ๊ฐ€ ์ œ๊ฑฐ๋œ ์ƒํƒœ๋กœ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

ํ™œ์šฉ ์˜ˆ์‹œ

๊ฒ€์ƒ‰ ์ธ๋ฑ์‹ฑ

async function indexDocument(docId: string, content: JSONContent) { const plainText = toPlainText(content); const mentions = extractMentions(content); const hashtags = extractHashtags(content); await searchIndex.upsert({ id: docId, text: plainText, mentions: mentions.map(m => m.id), tags: hashtags, }); }

๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ƒ์„ฑ

function DocumentCard({ content }: { content: JSONContent }) { const summary = toSummary(content, 120); const stats = getContentStats(content); return ( <div> <p>{summary}</p> <span>{stats.words}๋‹จ์–ด ยท {stats.blocks}๋ธ”๋ก</span> </div> ); }

์•Œ๋ฆผ ํ…์ŠคํŠธ

function buildNotification(content: JSONContent, authorName: string) { const mentions = extractMentions(content); const summary = toSummary(content, 50); return mentions.map(m => ({ userId: m.id, message: `${authorName}๋‹˜์ด ํšŒ์›๋‹˜์„ ๋ฉ˜์…˜ํ–ˆ์Šต๋‹ˆ๋‹ค: "${summary}"`, })); }
Last updated on