mirror of https://github.com/requarks/wiki
parent
8a979690a7
commit
1426e6589c
@ -0,0 +1,12 @@
|
||||
const container = require('markdown-it-container')
|
||||
|
||||
module.exports = md => md.use(container, 'spoiler', {
|
||||
validate: params => /^spoiler(?:\s+.*)?$/.test(params.trim()),
|
||||
render(tokens, idx) {
|
||||
if (tokens[idx].nesting === 1) {
|
||||
const title = tokens[idx].info.trim().slice('spoiler'.length).trim() || 'Spoiler'
|
||||
return `<details class="spoiler"><summary>${md.utils.escapeHtml(title)}</summary>\n`
|
||||
}
|
||||
return '</details>\n'
|
||||
}
|
||||
})
|
||||
@ -0,0 +1,12 @@
|
||||
const container = require('markdown-it-container')
|
||||
|
||||
module.exports = md => md.use(container, 'spoiler', {
|
||||
validate: params => /^spoiler(?:\s+.*)?$/.test(params.trim()),
|
||||
render(tokens, idx) {
|
||||
if (tokens[idx].nesting === 1) {
|
||||
const title = tokens[idx].info.trim().slice('spoiler'.length).trim() || 'Spoiler'
|
||||
return `<details class="spoiler"><summary>${md.utils.escapeHtml(title)}</summary>\n`
|
||||
}
|
||||
return '</details>\n'
|
||||
}
|
||||
})
|
||||
@ -0,0 +1,38 @@
|
||||
const renderer = require('../../../modules/rendering/markdown-core/renderer')
|
||||
|
||||
const render = input => renderer.render.call({
|
||||
input,
|
||||
children: [],
|
||||
config: {
|
||||
allowHTML: true,
|
||||
linebreaks: true,
|
||||
linkify: true,
|
||||
typographer: false,
|
||||
quotes: 'English',
|
||||
underline: false
|
||||
}
|
||||
})
|
||||
|
||||
describe('markdown-core spoiler container', () => {
|
||||
it('renders a closed details element with a default title', async () => {
|
||||
const output = await render('::: spoiler\nHidden **content**.\n:::')
|
||||
|
||||
expect(output).toContain('<details class="spoiler"><summary>Spoiler</summary>')
|
||||
expect(output).toContain('<p>Hidden <strong>content</strong>.</p>')
|
||||
expect(output).toContain('</details>')
|
||||
})
|
||||
|
||||
it('supports a custom escaped title', async () => {
|
||||
const output = await render('::: spoiler Reveal <script>alert(1)</script>\nSecret\n:::')
|
||||
|
||||
expect(output).toContain('<summary>Reveal <script>alert(1)</script></summary>')
|
||||
expect(output).not.toContain('<summary>Reveal <script>')
|
||||
})
|
||||
|
||||
it('leaves other containers unchanged', async () => {
|
||||
const output = await render('::: note\nVisible\n:::')
|
||||
|
||||
expect(output).toContain('::: note')
|
||||
expect(output).not.toContain('<details')
|
||||
})
|
||||
})
|
||||
Loading…
Reference in new issue