JSPM

remark-collapse

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16111
  • Score
    100M100P100Q134582F
  • License MIT

Package Exports

  • remark-collapse

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (remark-collapse) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Remark Collapse

Find range of a target heading and make it collapsible by <details> and <summary> like the below.

Open example

Tada! 🎉

<details><summary>Open example</summary>

Tada! 🎉

</details>

Installation

npm install remark-collapse

Usage

const processor = remark()
  .use(collapse, {test: 'tango'})

const inputString = [
  '# Heading1',
  '',
  '## tango',
  '',
  'target content',
  '',
  '## Another heading2',
  ''
].join('\n')

const resultString = processor.processSync(inputString).toString()

resultString

# Heading1

## tango

<details><summary>Open tango</summary>

target content

</details>

## Another heading2

API

To find heading range, Remark Collapse uses mdast-util-heading-range.

options.test (string, RegExp, function(string, Node): boolean)

Required. Test to be passed to mdast-util-heading-range#heading

test — Heading to look for. When string, wrapped in new RegExp('^(' + value + ')$', 'i'); when RegExp, wrapped in function (value) {expression.test(value)}.

options.summary (function(string): string, string)

Summarizing function. By default, it uses text of the target heading and prepends Open to it.

function defaultSummarizer (str) {
  return 'Open ' + str
}

Example

function defuseTimeBomb (str) {
  return 'Tick... Tock... Tick... Tock...⏱'
}

const processor = remark()
  .use(collapse, {
    test: 'tango',
    summary: defuseTimeBomb
    /* Also, you can provide a string
    summary: 'Tick... Tock... Tick... Tock...⏱'
    */
  })

const inputString = [
  '# tango',
  '',
  '**KABOOM!!**',
  ''
].join()

const resultString = processor.processSync(inputString).toString()

resultString

# tango

<details><summary>Tick... Tock... Tick... Tock...⏱</summary>

**KABOOM!!**

</details>

Result

Tick... Tock... Tick... Tock...⏱

KABOOM!!

License

MIT © Junyoung Choi