게시물 HTML 블록 분리
This commit is contained in:
@@ -2,7 +2,6 @@ import { isImageUrl, parseImageMarkdownLine } from './markdown-image.js'
|
||||
import { CALLOUT_BACKGROUND_OPTIONS, QUOTE_BACKGROUND_OPTIONS, parseCalloutOptions } from './markdown-callout.js'
|
||||
import { parseCodeFenceLine } from './markdown-code-block.js'
|
||||
import { parseToggleOpenerLine } from './markdown-toggle.js'
|
||||
import { isIframeEmbedMarkup } from './markdown-iframe-embed.js'
|
||||
|
||||
/**
|
||||
* fenced 블록 시작 줄 인덱스를 찾는다.
|
||||
@@ -191,41 +190,40 @@ const resolveGalleryBlock = (lines, currentLine) => {
|
||||
}
|
||||
|
||||
/**
|
||||
* 임베드 fenced 블록을 파싱한다.
|
||||
* 링크·iframe·HTML fenced 블록을 파싱한다.
|
||||
* @param {string[]} lines - 본문 줄 목록
|
||||
* @param {number} currentLine - 현재 줄
|
||||
* @returns {{ kind: 'embed', startLine: number, endLine: number, url: string }|null}
|
||||
* @returns {{ kind: 'link'|'iframe'|'html', startLine: number, endLine: number, url: string }|null}
|
||||
*/
|
||||
const resolveEmbedBlock = (lines, currentLine) => {
|
||||
const standaloneUrl = String(lines[currentLine] || '').trim()
|
||||
const resolveHtmlFamilyBlock = (lines, currentLine) => {
|
||||
const blockTypes = [
|
||||
{ opener: ':::link', kind: 'link' },
|
||||
{ opener: ':::iframe', kind: 'iframe' },
|
||||
{ opener: ':::html', kind: 'html' }
|
||||
]
|
||||
|
||||
for (const blockType of blockTypes) {
|
||||
const blockStart = findFencedBlockStart(lines, currentLine, blockType.opener)
|
||||
|
||||
if (blockStart === -1) {
|
||||
continue
|
||||
}
|
||||
|
||||
const blockEnd = findFencedBlockEnd(lines, blockStart)
|
||||
|
||||
if (blockEnd === -1 || currentLine > blockEnd) {
|
||||
continue
|
||||
}
|
||||
|
||||
if ((isStandaloneUrlLine(standaloneUrl) && !isStandaloneImageUrlLine(standaloneUrl)) || isIframeEmbedMarkup(standaloneUrl)) {
|
||||
return {
|
||||
kind: 'embed',
|
||||
startLine: currentLine,
|
||||
endLine: currentLine,
|
||||
url: standaloneUrl
|
||||
kind: blockType.kind,
|
||||
startLine: blockStart,
|
||||
endLine: blockEnd,
|
||||
url: lines.slice(blockStart + 1, blockEnd).join('\n').trim()
|
||||
}
|
||||
}
|
||||
|
||||
const embedStart = findFencedBlockStart(lines, currentLine, ':::embed')
|
||||
|
||||
if (embedStart === -1) {
|
||||
return null
|
||||
}
|
||||
|
||||
const embedEnd = findFencedBlockEnd(lines, embedStart)
|
||||
|
||||
if (embedEnd === -1 || currentLine > embedEnd) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
kind: 'embed',
|
||||
startLine: embedStart,
|
||||
endLine: embedEnd,
|
||||
url: lines.slice(embedStart + 1, embedEnd).join('\n').trim()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,5 +392,5 @@ export const resolveActiveBlockContext = (markdown, lineIndex) => {
|
||||
return toggle
|
||||
}
|
||||
|
||||
return resolveEmbedBlock(lines, currentLine)
|
||||
return resolveHtmlFamilyBlock(lines, currentLine)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user