mirror of https://github.com/status-im/codimd.git
Merge pull request #1272 from hackmdio/bugfix/support-empty-spoiler
Support empty spoiler container syntax
This commit is contained in:
commit
df2c0e23b6
|
@ -1030,14 +1030,19 @@ md.use(markdownitContainer, 'warning', { render: renderContainer })
|
||||||
md.use(markdownitContainer, 'danger', { render: renderContainer })
|
md.use(markdownitContainer, 'danger', { render: renderContainer })
|
||||||
md.use(markdownitContainer, 'spoiler', {
|
md.use(markdownitContainer, 'spoiler', {
|
||||||
validate: function (params) {
|
validate: function (params) {
|
||||||
return params.trim().match(/^spoiler\s+(.*)$/)
|
return params.trim().match(/^spoiler(\s+.*)?$/)
|
||||||
},
|
},
|
||||||
render: function (tokens, idx) {
|
render: function (tokens, idx) {
|
||||||
var m = tokens[idx].info.trim().match(/^spoiler\s+(.*)$/)
|
const m = tokens[idx].info.trim().match(/^spoiler(\s+.*)?$/)
|
||||||
|
|
||||||
if (tokens[idx].nesting === 1) {
|
if (tokens[idx].nesting === 1) {
|
||||||
// opening tag
|
// opening tag
|
||||||
return '<details><summary>' + md.utils.escapeHtml(m[1]) + '</summary>\n'
|
const summary = m[1] && m[1].trim()
|
||||||
|
if (summary) {
|
||||||
|
return `<details><summary>${md.utils.escapeHtml(summary)}</summary>\n`
|
||||||
|
} else {
|
||||||
|
return `<details>\n`
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// closing tag
|
// closing tag
|
||||||
return '</details>\n'
|
return '</details>\n'
|
||||||
|
|
|
@ -112,17 +112,23 @@ md.use(markdownitContainer, 'warning', { render: renderContainer })
|
||||||
md.use(markdownitContainer, 'danger', { render: renderContainer })
|
md.use(markdownitContainer, 'danger', { render: renderContainer })
|
||||||
md.use(markdownitContainer, 'spoiler', {
|
md.use(markdownitContainer, 'spoiler', {
|
||||||
validate: function (params) {
|
validate: function (params) {
|
||||||
return params.trim().match(/^spoiler\s+(.*)$/)
|
return params.trim().match(/^spoiler(\s+.*)?$/)
|
||||||
},
|
},
|
||||||
render: function (tokens, idx) {
|
render: function (tokens, idx) {
|
||||||
var m = tokens[idx].info.trim().match(/^spoiler\s+(.*)$/)
|
const m = tokens[idx].info.trim().match(/^spoiler(\s+.*)?$/)
|
||||||
|
|
||||||
if (tokens[idx].nesting === 1) {
|
if (tokens[idx].nesting === 1) {
|
||||||
|
// opening tag
|
||||||
const startline = tokens[idx].map[0] + 1
|
const startline = tokens[idx].map[0] + 1
|
||||||
const endline = tokens[idx].map[1]
|
const endline = tokens[idx].map[1]
|
||||||
|
|
||||||
// opening tag
|
const partClass = `class="part raw" data-startline="${startline}" data-endline="${endline}"`
|
||||||
return `<details class="part raw" data-startline="${startline}" data-endline="${endline}"><summary>` + md.utils.escapeHtml(m[1]) + '</summary>\n'
|
const summary = m[1] && m[1].trim()
|
||||||
|
if (summary) {
|
||||||
|
return `<details ${partClass}><summary>${md.utils.escapeHtml(summary)}</summary>\n`
|
||||||
|
} else {
|
||||||
|
return `<details ${partClass}>\n`
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// closing tag
|
// closing tag
|
||||||
return '</details>\n'
|
return '</details>\n'
|
||||||
|
|
Loading…
Reference in New Issue