Skip to content

Commit

Permalink
Nuemark: fix tests and error with unclosed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tipiirai authored and nobkd committed Nov 14, 2024
1 parent 43544c0 commit f5e8783
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/nuemark/src/parse-inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const PARSERS = [
const body = str.slice(len, i)

// no spaces before/after the body
if (i == -1 || body.length != body.trim().length) return { text: str }
if (i == -1 || body.length != body.trim().length) {
return { text: str.slice(0, len) }
}

const tag = FORMATTING[fmt]
return { is_format: true, tag, body, end: i + len }
Expand Down
5 changes: 5 additions & 0 deletions packages/nuemark/test/inline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ test('bold + em', () => {
expect(renderInline('___ hello ___')).toBe('___ hello ___')
})

test('unclosed formatting', () => {
expect(renderInline('_foo *bar*')).toBe('_foo <em>bar</em>')
expect(renderInline('yo /foo /bar _baz_')).toBe('yo /foo /bar <em>baz</em>')
})

test('inline render basics', () => {
const tests = [
{ text: 'hey', html: 'hey' },
Expand Down
8 changes: 4 additions & 4 deletions packages/nuemark/test/tag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ test('[button] inline label', () => {
})

test('[button] nested label', () => {
const html = renderLines(['[button]', ' ![](/joku.png)'])
expect(html).toStartWith('<a role="button"><img src="/joku.png"')
const html = renderLines(['[button href=/]', ' ![](/joku.png)'])
expect(html).toStartWith('<a href="/" role="button"><img src="/joku.png"')
})


Expand Down Expand Up @@ -260,8 +260,8 @@ test('[svg]', () => {
})

test('[svg] nested in [button]', () => {
const html = renderLines(['[button]', ` [svg ${svgpath}] *Yo*`])
expect(html).toBe('<a role="button"><svg/> <em>Yo</em></a>')
const html = renderLines(['[button href="/"]', ` [svg ${svgpath}] *Yo*`])
expect(html).toBe('<a href="/" role="button"><svg/> <em>Yo</em></a>')
})


Expand Down

0 comments on commit f5e8783

Please sign in to comment.