Skip to content

Commit 61fdf7c

Browse files
committed
fix: unnamed block tag now defaults to div, don't skip list issue test
1 parent a99e432 commit 61fdf7c

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

packages/nuemark/src/parse-blocks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function parseBlocks(lines, capture) {
114114
// tag
115115
if (c == '[' && trimmed.endsWith(']') && !trimmed.includes('][')) {
116116
const tag = parseTag(line.slice(1, -1))
117-
block = { is_tag: true, ...tag, body: [] }
117+
block = { is_tag: true, ...tag, name: tag.name || 'div', body: [] }
118118
return blocks.push(block)
119119
}
120120

@@ -182,7 +182,9 @@ function processNestedBlocks(block, capture) {
182182
const body = block.body.join('\n')
183183

184184
try {
185-
if (body && name && isYAML(body.trim())) {
185+
// TODO: add additional check for native html tags
186+
// maybe new syntax? e.g. `[yaml-tag]:\n\thi` (note colon)
187+
if (body && isYAML(body.trim())) {
186188
let data = parseYAML(body)
187189
if (Array.isArray(data)) data = { items: data }
188190
Object.assign(block.data, data)

packages/nuemark/src/render-tag.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ const TAGS = {
3939
const html = !divs || !divs[1] ? render(blocks) :
4040
divs.map(blocks => elem('div', render(blocks))).join('\n')
4141

42-
Object.assign(attr, data)
43-
44-
return elem(attr.popover ? 'dialog' : name || 'div', attr, html)
42+
if (this.to_block) Object.assign(attr, data)
43+
return elem(attr.popover ? 'dialog' : name, attr, html)
4544
},
4645

47-
4846
button(data) {
4947
const { href } = data
5048
const label = this.renderInline(data.label || data._) || this.innerHTML || ''
@@ -65,7 +63,6 @@ const TAGS = {
6563
return html && elem('dl', this.attr, html.join('\n'))
6664
},
6765

68-
6966
image() {
7067
const { attr, data } = this
7168
const { caption, href, loading = 'lazy' } = data
@@ -92,7 +89,7 @@ const TAGS = {
9289

9390
const content = data._
9491
delete data._
95-
Object.assign(attr, data)
92+
if (this.to_inline) Object.assign(attr, data)
9693

9794
return elem(name, attr, this.renderInline(content, opts))
9895
},
@@ -131,7 +128,6 @@ const TAGS = {
131128
return elem('video', attr, this.innerHTML)
132129
},
133130

134-
135131
// shortcut
136132
'!': function() {
137133
const tag = getMimeType(this.data._).startsWith('video') ? TAGS.video : TAGS.image
@@ -164,7 +160,7 @@ export function renderIcon(name, symbol, icon_dir) {
164160

165161
export function renderTag(tag, opts = {}) {
166162
const tags = { ...TAGS, ...opts.tags }
167-
const tag_fn = !tag.name || tag.to_block ? 'block' : tag.to_inline ? 'inline' : tag.name
163+
const tag_fn = tag.to_block ? 'block' : tag.to_inline ? 'inline' : tag.name
168164
const fn = tags[tag_fn]
169165

170166
if (!fn) {

packages/nuemark/test/block.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test('block html tag without children with content', () => {
5656
expect(html).toBe('<section>content</section>\n<p>no content</p>')
5757
})
5858

59-
test.skip('block html tag with starting ul', () => {
59+
test('block html tag with starting ul', () => {
6060
const { blocks } = parseBlocks(['[div]', ' - hi', ' - hello'])
6161
expect(blocks.length).toBe(1)
6262
expect(blocks[0].blocks.length).toBe(1)

0 commit comments

Comments
 (0)