fenced 블록 탐색 helper 통합

This commit is contained in:
2026-07-24 15:20:47 +09:00
parent 578ee889ee
commit 5f6d950721
7 changed files with 107 additions and 63 deletions

View File

@@ -3,64 +3,7 @@ import { CALLOUT_BACKGROUND_OPTIONS, parseCalloutOptions } from './markdown-call
import { parseCodeFenceLine } from './markdown-code-block.js'
import { parseToggleOpenerLine } from './markdown-toggle.js'
import { getQuoteLineBody, isQuoteMarkerLine, parseQuoteOptions } from './markdown-quote.js'
/**
* fenced 블록 시작 줄 인덱스를 찾는다.
* @param {string[]} lines - 본문 줄 목록
* @param {number} currentLine - 현재 줄
* @param {string} opener - 시작 토큰
* @returns {number} 시작 줄 또는 -1
*/
const findFencedBlockStart = (lines, currentLine, opener) => {
for (let index = currentLine; index >= 0; index -= 1) {
if ((lines[index] || '').trim() === opener) {
return index
}
if ((lines[index] || '').trim() === ':::') {
break
}
}
return -1
}
/**
* 조건에 맞는 fenced 블록 시작 줄 인덱스를 찾는다.
* @param {string[]} lines - 본문 줄 목록
* @param {number} currentLine - 현재 줄
* @param {(line: string) => boolean} predicate - 시작 줄 판별 함수
* @returns {number} 시작 줄 또는 -1
*/
const findFencedBlockStartBy = (lines, currentLine, predicate) => {
for (let index = currentLine; index >= 0; index -= 1) {
if (predicate((lines[index] || '').trim())) {
return index
}
if ((lines[index] || '').trim() === ':::') {
break
}
}
return -1
}
/**
* fenced 블록 종료 줄 인덱스를 찾는다.
* @param {string[]} lines - 본문 줄 목록
* @param {number} startLine - 시작 줄
* @returns {number} 종료 줄 또는 -1
*/
const findFencedBlockEnd = (lines, startLine) => {
for (let index = startLine + 1; index < lines.length; index += 1) {
if ((lines[index] || '').trim() === ':::') {
return index
}
}
return -1
}
import { findFencedBlockEnd, findFencedBlockStart, findFencedBlockStartBy } from './markdown-fenced-meta.js'
/**
* 단독 URL 줄인지 확인한다.