-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from johnnyhuy/feature/add-spoilers
feat: Added remark spoilers plugin
- Loading branch information
Showing
12 changed files
with
440 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Johnny Huynh <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# remark-spoilers | ||
|
||
remark spoiler plugin that uses native [details and summary](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary) HTML elements. | ||
|
||
```html | ||
<details> | ||
<summary>I have keys but no doors. I have space but no room. You can enter but can’t leave. What am I?</summary> | ||
A keyboard. | ||
</details> | ||
``` | ||
|
||
## Installation | ||
|
||
```bash | ||
npm i remark-spoilers | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import remark from 'remark' | ||
import html from 'remark-html' | ||
import spoilers from 'remark-spoilers' | ||
|
||
remark() | ||
.use(html) | ||
.use(spoilers) | ||
|
||
... | ||
``` | ||
|
||
## Options | ||
|
||
### `.use(spoilers [, options])` | ||
|
||
Add the spoilers plugin to remark. | ||
|
||
### `options` | ||
|
||
#### `options.defaultSummary` | ||
|
||
The default summary text in the spoiler. | ||
|
||
**Default** `Open spoiler` | ||
|
||
#### `options.token` | ||
|
||
Token used to open and close spoilers text. | ||
|
||
**Default** `!spoiler` | ||
|
||
#### `options.detailsClassName` | ||
|
||
Class name for the `<details />` HTML element. No class name set by default. | ||
|
||
**Default** `''` | ||
|
||
#### `options.summaryClassName` | ||
|
||
Class name for the `<summary />` HTML element. No class name set by default. | ||
|
||
**Default** `''` | ||
|
||
## Examples | ||
|
||
```markdown | ||
# Basic spoiler | ||
!spoiler | ||
Hello world, I'm in a spoiler | ||
!spoiler | ||
|
||
# Basic spoiler with custom summary | ||
!spoiler Hello summary, click me to open the spoiler! | ||
Hello world, I'm in a spoiler | ||
!spoiler | ||
``` |
49 changes: 49 additions & 0 deletions
49
packages/remark-spoilers/__tests__/__snapshots__/index.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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> | ||
<p>why isn't this working!?</p> | ||
<p>there's no end!!!</p> | ||
" | ||
`; | ||
|
||
exports[`spoilers should not show spoiler if duped start token with summary 1`] = ` | ||
"<details><summary>testestestsetset</summary></details> | ||
<details><summary>testipsum</summary></details> | ||
<p>!spoiler yeet</p> | ||
<p>why isn't this working!?</p> | ||
<p>there's no end!!!</p> | ||
" | ||
`; | ||
|
||
exports[`spoilers should not show spoiler if not closed 1`] = ` | ||
"<p>!spoiler</p> | ||
<p>why isn't this working!?</p> | ||
<p>there's no end!!!</p> | ||
" | ||
`; | ||
|
||
exports[`spoilers should show multiple spoilers 1`] = ` | ||
"<h1>Hello world</h1> | ||
<p>This is some text.</p> | ||
<details><summary>Click me to see a surprise</summary><p>peek-a-boo!</p></details> | ||
<p>between the spoilers</p> | ||
<details><summary>Another click me to see a surprise</summary><p>peek-a-boo!</p></details> | ||
<p>the end</p> | ||
" | ||
`; | ||
|
||
exports[`spoilers should show spoiler with custom summary 1`] = ` | ||
"<details><summary>Click me to see a surprise</summary><p>peek-a-boo!</p></details> | ||
" | ||
`; | ||
|
||
exports[`spoilers should show spoiler without custom summary 1`] = ` | ||
"<details><p>peek-a-boo!</p></details> | ||
" | ||
`; |
Oops, something went wrong.