Skip to content

feat/bracketed spans #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions test/bracketedSpans.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { describe, expect, test } from 'vitest'
import { starkdown } from '../src'

describe('bracketedSpans', () => {
test('html spans', () => {
expect(starkdown(`I'm <span class="c-red">red</span>`)).toEqual(
`<p>I'm <span class="c-red">red</span></p>`
)
})
test('class', () => {
expect(starkdown(`I'm [red]{.c-red}`)).toEqual(`<p>I'm <span class="c-red">red</span></p>`)
})
test('class with _', () => {
expect(starkdown(`I'm [red]{._c_red}`)).toEqual(`<p>I'm <span class="_c_red">red</span></p>`)
})
test('classes without spaces', () => {
expect(starkdown(`I'm [red]{.c-red.text-bold.t-h1}`)).toEqual(
`<p>I'm <span class="c-red text-bold t-h1">red</span></p>`
)
})
test('classes with spaces', () => {
expect(starkdown(`I'm [red]{ .c-red .text-bold .t-h1 }`)).toEqual(
`<p>I'm <span class="c-red text-bold t-h1">red</span></p>`
)
})
test('attrs without :', () => {
expect(starkdown(`I'm [red]{id="aka".c-red}`)).toEqual(
`<p>I'm <span id="aka" class="c-red">red</span></p>`
)
})
test('attrs behind class without :', () => {
expect(starkdown(`I'm [red]{.c-red id="aka"}`)).toEqual(
`<p>I'm <span class="c-red" id="aka">red</span></p>`
)
})
test('attrs with :', () => {
expect(starkdown(`I'm [red]{:id="aka".c-red}`)).toEqual(
`<p>I'm <span id="aka" class="c-red">red</span></p>`
)
})
test('attrs behind class with :', () => {
expect(starkdown(`I'm [red]{.c-red:id="aka"}`)).toEqual(
`<p>I'm <span class="c-red" id="aka">red</span></p>`
)
})
test('attrs behind class with space and :', () => {
expect(starkdown(`I'm [red]{.c-red :id="aka"}`)).toEqual(
`<p>I'm <span class="c-red" id="aka">red</span></p>`
)
})

test('parses links with attribute lists with :', () => {
expect(starkdown('[github](https://github.com){:target="_blank"}')).toEqual(
'<p><a href="https://github.com" target="_blank">github</a></p>'
)
expect(starkdown('[github](https://github.com){:.foo .bar}')).toEqual(
'<p><a href="https://github.com" class="foo bar">github</a></p>'
)
expect(starkdown('[github](https://github.com){:#foo}')).toEqual(
'<p><a href="https://github.com" id="foo">github</a></p>'
)
expect(starkdown('[github](https://github.com){:target="_blank" .foo .bar}')).toEqual(
'<p><a href="https://github.com" target="_blank" class="foo bar">github</a></p>'
)
expect(starkdown('[github](https://github.com){:target="_blank" #foo}')).toEqual(
'<p><a href="https://github.com" target="_blank" id="foo">github</a></p>'
)
expect(starkdown('[github](https://github.com){:target="_blank" .foo .bar #foo}')).toEqual(
'<p><a href="https://github.com" target="_blank" class="foo bar" id="foo">github</a></p>'
)
})

test('parses links with attribute lists without :', () => {
expect(starkdown('[github](https://github.com){target="_blank"}')).toEqual(
'<p><a href="https://github.com" target="_blank">github</a></p>'
)
expect(starkdown('[github](https://github.com){.foo .bar}')).toEqual(
'<p><a href="https://github.com" class="foo bar">github</a></p>'
)
expect(starkdown('[github](https://github.com){#foo}')).toEqual(
'<p><a href="https://github.com" id="foo">github</a></p>'
)
expect(starkdown('[github](https://github.com){target="_blank" .foo .bar}')).toEqual(
'<p><a href="https://github.com" target="_blank" class="foo bar">github</a></p>'
)
expect(starkdown('[github](https://github.com){target="_blank" #foo}')).toEqual(
'<p><a href="https://github.com" target="_blank" id="foo">github</a></p>'
)
expect(starkdown('[github](https://github.com){target="_blank" .foo .bar #foo}')).toEqual(
'<p><a href="https://github.com" target="_blank" class="foo bar" id="foo">github</a></p>'
)
})
})
21 changes: 1 addition & 20 deletions test/linksImages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,5 @@ describe('links & images', () => {
)
})

test('parses links with attribute lists', () => {
expect(starkdown('[github](https://github.com){:target="_blank"}')).toEqual(
'<p><a href="https://github.com" target="_blank">github</a></p>'
)
expect(starkdown('[github](https://github.com){:.foo .bar}')).toEqual(
'<p><a href="https://github.com" class="foo bar">github</a></p>'
)
expect(starkdown('[github](https://github.com){:#foo}')).toEqual(
'<p><a href="https://github.com" id="foo">github</a></p>'
)
expect(starkdown('[github](https://github.com){:target="_blank" .foo .bar}')).toEqual(
'<p><a href="https://github.com" target="_blank" class="foo bar">github</a></p>'
)
expect(starkdown('[github](https://github.com){:target="_blank" #foo}')).toEqual(
'<p><a href="https://github.com" target="_blank" id="foo">github</a></p>'
)
expect(starkdown('[github](https://github.com){:target="_blank" .foo .bar #foo}')).toEqual(
'<p><a href="https://github.com" target="_blank" class="foo bar" id="foo">github</a></p>'
)
})
// For links with attribute lists, see bracketedSpans
})
15 changes: 15 additions & 0 deletions test/paragraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import { starkdown } from '../src'
describe('paragraphs', () => {
test('creates single paragraphs', () => {
expect(starkdown('Here is a single Paragraph')).toEqual('<p>Here is a single Paragraph</p>')
})

test('creates single paragraphs with linebreak', () => {
expect(starkdown('Here is a\n single Paragraph')).toEqual('<p>Here is a\n single Paragraph</p>')
})

test('parses two new lines as separate paragraphs', () => {
expect(starkdown('Something with\n\na line break')).toEqual(
'<p>Something with</p><p>a line break</p>'
)
})

test('parses three new lines as separate paragraphs', () => {
expect(starkdown('Here...\n\n\n are...\n\nthree \n\nno, 4 Paragraphs!')).toEqual(
'<p>Here...</p><p>are...</p><p>three</p><p>no, 4 Paragraphs!</p>'
)
})

test('parses four new lines as separate paragraphs', () => {
expect(
starkdown(
'\nHere...\n\n\n \nare...\n\nthree\n \n\nno,\n 4 Paragraphs!\nshould not delete single linebreaks'
Expand All @@ -30,6 +36,9 @@ describe('paragraphs', () => {
expect(starkdown('Something with \na line break')).toEqual(
'<p>Something with<br />a line break</p>'
)
})

test('does not parse one space plus line break as <br />', () => {
expect(starkdown('Something with \na line break')).toEqual(
'<p>Something with \na line break</p>'
)
Expand All @@ -39,9 +48,15 @@ describe('paragraphs', () => {
expect(starkdown('Something with<br />a line break')).toEqual(
'<p>Something with<br />a line break</p>'
)
})

test('parses <br/> as <br/>', () => {
expect(starkdown('Something with<br/>a line break')).toEqual(
'<p>Something with<br/>a line break</p>'
)
})

test('parses <br> as <br>', () => {
expect(starkdown('Something with<br>a line break')).toEqual(
'<p>Something with<br>a line break</p>'
)
Expand Down