관리자 인용 컨텍스트 파서 통합

This commit is contained in:
2026-07-24 14:58:21 +09:00
parent 7481773085
commit 578ee889ee
6 changed files with 47 additions and 53 deletions

View File

@@ -1,7 +1,8 @@
import { isImageUrl, parseImageMarkdownLine } from './markdown-image.js'
import { CALLOUT_BACKGROUND_OPTIONS, QUOTE_BACKGROUND_OPTIONS, parseCalloutOptions } from './markdown-callout.js'
import { CALLOUT_BACKGROUND_OPTIONS, parseCalloutOptions } from './markdown-callout.js'
import { parseCodeFenceLine } from './markdown-code-block.js'
import { parseToggleOpenerLine } from './markdown-toggle.js'
import { getQuoteLineBody, isQuoteMarkerLine, parseQuoteOptions } from './markdown-quote.js'
/**
* fenced 블록 시작 줄 인덱스를 찾는다.
@@ -75,53 +76,6 @@ const isStandaloneUrlLine = (line) => /^https?:\/\/\S+$/i.test(String(line || ''
*/
const isStandaloneImageUrlLine = (line) => isStandaloneUrlLine(line) && isImageUrl(line)
/**
* 인용 마커 줄인지 확인한다.
* @param {string} line - 마크다운 줄
* @returns {boolean} 인용 줄 여부
*/
const isQuoteMarkerLine = (line) => {
const trimmed = String(line ?? '').trim()
return trimmed === '>' || /^>\s/.test(trimmed)
}
/**
* 인용 마커를 제거한 본문을 반환한다.
* @param {string} line - 마크다운 줄
* @returns {string} 인용 본문
*/
const getQuoteLineBody = (line) => String(line ?? '').trim().replace(/^>\s?/, '')
/**
* 인용 옵션 줄을 파싱한다.
* @param {string} value - 인용 본문 줄
* @returns {{ quoteBackground: string }|null} 인용 옵션
*/
const parseQuoteOptionsLine = (value) => {
const raw = String(value ?? '').trim()
const bracketMatch = raw.match(/^\[!(.+)\]$/)
const braceMatch = raw.match(/^\{(.+)\}$/)
const optionSource = bracketMatch?.[1] || braceMatch?.[1] || ''
if (!optionSource) {
return null
}
const tokens = optionSource.trim().split(/\s+/)
let quoteBackground = ''
tokens.forEach((token) => {
const [key, rawOptionValue] = token.split('=')
const optionValue = String(rawOptionValue || '').trim()
if (key?.toLowerCase() === 'bg' && QUOTE_BACKGROUND_OPTIONS.includes(optionValue)) {
quoteBackground = optionValue
}
})
return quoteBackground ? { quoteBackground } : null
}
/**
* 인용 블록을 파싱한다.
* @param {string[]} lines - 본문 줄 목록
@@ -145,7 +99,7 @@ const resolveQuoteBlock = (lines, currentLine) => {
}
const firstQuoteBody = getQuoteLineBody(lines[startLine] || '')
const quoteOptions = parseQuoteOptionsLine(firstQuoteBody)
const quoteOptions = parseQuoteOptions(firstQuoteBody)
return {
kind: 'quote',