feat: test containers plugin

pull/25/head
An Phan 5 years ago committed by =
parent 758e25aa5c
commit 84eb56d89b

@ -0,0 +1,29 @@
import each from 'jest-each'
import MarkdownIt from 'markdown-it'
import { containerPlugin } from '../containers'
import { getFragment } from '@/test-utils'
let md: MarkdownIt
describe('plugins/component', () => {
beforeEach(() => {
md = new MarkdownIt()
containerPlugin(md)
})
each([
['tip'],
['warning'],
['danger'],
['info'],
['custom-tip'],
['custom-warning'],
['custom-danger'],
['custom-info'],
['v-pre']
]).test('renders a "%s" block', (fileName: string) => {
expect(getFragment(__dirname, `containers/${fileName}.html`)).toEqual(
md.render(getFragment(__dirname, `containers/${fileName}.md`))
)
})
})

@ -0,0 +1,3 @@
<div class="danger custom-block"><p class="custom-block-title">Custom danger</p>
<p>This is a custom danger block.</p>
</div>

@ -0,0 +1,3 @@
::: danger Custom danger
This is a custom danger block.
:::

@ -0,0 +1,3 @@
<div class="info custom-block"><p class="custom-block-title">Custom info</p>
<p>This is a custom info block.</p>
</div>

@ -0,0 +1,3 @@
::: info Custom info
This is a custom info block.
:::

@ -0,0 +1,3 @@
<div class="tip custom-block"><p class="custom-block-title">Custom tip</p>
<p>This is a custom tip block.</p>
</div>

@ -0,0 +1,3 @@
::: tip Custom tip
This is a custom tip block.
:::

@ -0,0 +1,3 @@
<div class="warning custom-block"><p class="custom-block-title">Custom warning</p>
<p>This is a custom warning block.</p>
</div>

@ -0,0 +1,3 @@
::: warning Custom warning
This is a custom warning block.
:::

@ -0,0 +1,3 @@
<div class="danger custom-block"><p class="custom-block-title">Danger</p>
<p>This is a danger block.</p>
</div>

@ -0,0 +1,3 @@
::: danger
This is a danger block.
:::

@ -0,0 +1,3 @@
<div class="info custom-block"><p class="custom-block-title">Info</p>
<p>This is an info block.</p>
</div>

@ -0,0 +1,3 @@
::: info
This is an info block.
:::

@ -0,0 +1,3 @@
<div class="tip custom-block"><p class="custom-block-title">Tip</p>
<p>This is a tip block.</p>
</div>

@ -0,0 +1,3 @@
<div v-pre>
<p>This is a v-pre block</p>
</div>

@ -0,0 +1,3 @@
::: v-pre
This is a v-pre block
:::

@ -0,0 +1,3 @@
<div class="warning custom-block"><p class="custom-block-title">Warning</p>
<p>This is a warning block.</p>
</div>

@ -0,0 +1,3 @@
::: warning
This is a warning block.
:::

@ -4,9 +4,10 @@ import Token from 'markdown-it/lib/token'
const container = require('markdown-it-container')
export const containerPlugin = (md: MarkdownIt) => {
md.use(...createContainer('tip', 'TIP'))
.use(...createContainer('warning', 'WARNING'))
.use(...createContainer('danger', 'WARNING'))
md.use(...createContainer('tip', 'Tip'))
.use(...createContainer('warning', 'Warning'))
.use(...createContainer('danger', 'Danger'))
.use(...createContainer('info', 'Info'))
// explicitly escape Vue syntax
.use(container, 'v-pre', {
render: (tokens: Token[], idx: number) =>

Loading…
Cancel
Save