Skip to content

Commit

Permalink
fix: Actually use spoiler summary defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyhuy committed Sep 20, 2020
1 parent 18dc27c commit f1ebfba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`spoilers should not show spoiler if duped start token 1`] = `
"<details></details>
<details></details>
<details></details>
<details></details>
<details></details>
<details></details>
"<details><summary>Open spoiler</summary></details>
<details><summary>Open spoiler</summary></details>
<details><summary>Open spoiler</summary></details>
<details><summary>Open spoiler</summary></details>
<details><summary>Open spoiler</summary></details>
<details><summary>Open spoiler</summary></details>
<p>why isn't this working!?</p>
<p>there's no end!!!</p>
"
Expand Down Expand Up @@ -44,7 +44,7 @@ exports[`spoilers should show spoiler with custom summary 1`] = `
`;

exports[`spoilers should show spoiler with details class name 1`] = `
"<details class=\\"hello hello-world\\"><p>peek-a-boo!</p></details>
"<details class=\\"hello hello-world\\"><summary>Open spoiler</summary><p>peek-a-boo!</p></details>
"
`;
Expand All @@ -54,6 +54,6 @@ exports[`spoilers should show spoiler with summary class name 1`] = `
`;
exports[`spoilers should show spoiler without custom summary 1`] = `
"<details><p>peek-a-boo!</p></details>
"<details><summary>Open spoiler</summary><p>peek-a-boo!</p></details>
"
`;
40 changes: 18 additions & 22 deletions packages/remark-spoilers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,28 @@ export default function plugin(options = {}) {
const start = eat.now()
const add = eat(block)
const end = eat.now()
let children = []
let childrenBlockContent = this.tokenizeBlock(blockContent, start)

if (summary !== '') {
children.push({
type: 'summary',
data: {
hName: 'summary',
hProperties: {
class: options.summaryClassName
}
},
children: [
{
type: 'text',
value: summary
}
]
})
}

children = [...children, ...childrenBlockContent]

return add({
type: 'spoiler',
children: children,
children: [
{
type: 'summary',
data: {
hName: 'summary',
hProperties: {
class: options.summaryClassName
}
},
children: [
{
type: 'text',
value: summary !== '' ? summary : options.defaultSummary
}
]
},
...childrenBlockContent
],
data: {
hName: 'details',
hProperties: {
Expand Down

0 comments on commit f1ebfba

Please sign in to comment.