Skip to content

Commit

Permalink
Merge pull request #1272 from hackmdio/bugfix/support-empty-spoiler
Browse files Browse the repository at this point in the history
Support empty spoiler container syntax
  • Loading branch information
jackycute authored Sep 7, 2019
2 parents 8452da1 + 1a85523 commit df2c0e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions public/js/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,14 +1030,19 @@ md.use(markdownitContainer, 'warning', { render: renderContainer })
md.use(markdownitContainer, 'danger', { render: renderContainer })
md.use(markdownitContainer, 'spoiler', {
validate: function (params) {
return params.trim().match(/^spoiler\s+(.*)$/)
return params.trim().match(/^spoiler(\s+.*)?$/)
},
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) {
// 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 {
// closing tag
return '</details>\n'
Expand Down
14 changes: 10 additions & 4 deletions public/js/lib/syncscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,23 @@ md.use(markdownitContainer, 'warning', { render: renderContainer })
md.use(markdownitContainer, 'danger', { render: renderContainer })
md.use(markdownitContainer, 'spoiler', {
validate: function (params) {
return params.trim().match(/^spoiler\s+(.*)$/)
return params.trim().match(/^spoiler(\s+.*)?$/)
},
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) {
// opening tag
const startline = tokens[idx].map[0] + 1
const endline = tokens[idx].map[1]

// opening tag
return `<details class="part raw" data-startline="${startline}" data-endline="${endline}"><summary>` + md.utils.escapeHtml(m[1]) + '</summary>\n'
const partClass = `class="part raw" data-startline="${startline}" data-endline="${endline}"`
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 {
// closing tag
return '</details>\n'
Expand Down

0 comments on commit df2c0e2

Please sign in to comment.