공개 마크다운 블록 파서 분리
This commit is contained in:
87
tests/markdown-block-parser.test.js
Normal file
87
tests/markdown-block-parser.test.js
Normal file
@@ -0,0 +1,87 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
BLANK_PARAGRAPH_MARKER,
|
||||
isMarkdownBlockStart,
|
||||
parseMarkdownBlocks
|
||||
} from '../lib/markdown-block-parser.js'
|
||||
|
||||
test('기본 마크다운 행을 렌더링 블록으로 변환한다', () => {
|
||||
const blocks = parseMarkdownBlocks([
|
||||
'# 제목',
|
||||
'',
|
||||
'본문 ',
|
||||
BLANK_PARAGRAPH_MARKER,
|
||||
'---'
|
||||
].join('\n'))
|
||||
|
||||
assert.deepEqual(blocks.map((block) => block.type), ['heading', 'spacer', 'paragraph', 'spacer', 'divider'])
|
||||
assert.equal(blocks[0].text, '제목')
|
||||
assert.equal(blocks[0].level, 1)
|
||||
assert.equal(blocks[2].text, '본문')
|
||||
assert.equal(blocks[3].meta.legacy, true)
|
||||
})
|
||||
|
||||
test('fenced 블록을 타입별 메타와 원본 줄 범위로 변환한다', () => {
|
||||
const blocks = parseMarkdownBlocks([
|
||||
':::gallery',
|
||||
'{size=235}',
|
||||
'',
|
||||
':::',
|
||||
':::callout bg=red emoji=none',
|
||||
'주의',
|
||||
':::',
|
||||
':::toggle open 자세히',
|
||||
'내용',
|
||||
':::'
|
||||
].join('\n'))
|
||||
|
||||
assert.deepEqual(blocks.map((block) => block.type), ['gallery', 'callout', 'toggle'])
|
||||
assert.equal(blocks[0].images.length, 2)
|
||||
assert.equal(blocks[0].images[0].pixelWidth, 235)
|
||||
assert.deepEqual(
|
||||
{
|
||||
startLine: blocks[0].meta.startLine,
|
||||
endLine: blocks[0].meta.endLine
|
||||
},
|
||||
{ startLine: 0, endLine: 3 }
|
||||
)
|
||||
assert.equal(blocks[1].calloutBackground, 'red')
|
||||
assert.equal(blocks[1].calloutEmojiEnabled, false)
|
||||
assert.equal(blocks[2].title, '자세히')
|
||||
assert.equal(blocks[2].defaultOpen, true)
|
||||
})
|
||||
|
||||
test('인용·목록·코드·표 블록을 변환한다', () => {
|
||||
const blocks = parseMarkdownBlocks([
|
||||
'> [!bg=blue]',
|
||||
'> 인용',
|
||||
'- 하나',
|
||||
'- 둘',
|
||||
'1. 첫째',
|
||||
'3. 셋째',
|
||||
'```js line-numbers',
|
||||
'const value = 1',
|
||||
'```',
|
||||
'| A | B |',
|
||||
'| --- | ---: |',
|
||||
'| a | b |'
|
||||
].join('\n'))
|
||||
|
||||
assert.deepEqual(blocks.map((block) => block.type), ['quote', 'list', 'list', 'code', 'table'])
|
||||
assert.equal(blocks[0].quoteBackground, 'blue')
|
||||
assert.equal(blocks[0].text, '인용')
|
||||
assert.deepEqual(blocks[1].text, ['하나', '둘'])
|
||||
assert.equal(blocks[2].ordered, true)
|
||||
assert.deepEqual(blocks[2].listNumbers, [1, 3])
|
||||
assert.equal(blocks[3].codeLanguage, 'js')
|
||||
assert.equal(blocks[3].codeShowLineNumbers, true)
|
||||
assert.deepEqual(blocks[4].meta.alignments, ['left', 'right'])
|
||||
})
|
||||
|
||||
test('블록 시작 줄을 판별한다', () => {
|
||||
assert.equal(isMarkdownBlockStart(':::gallery'), true)
|
||||
assert.equal(isMarkdownBlockStart('```html'), true)
|
||||
assert.equal(isMarkdownBlockStart(''), true)
|
||||
assert.equal(isMarkdownBlockStart('일반 문단'), false)
|
||||
})
|
||||
Reference in New Issue
Block a user