Socket
Book a DemoInstallSign in
Socket

@eligundry/remark-excerpt

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eligundry/remark-excerpt

Remark transformer for extracting an excerpt.

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

remark-excerpt

Remark transformer for extracting an excerpt.

This is a remark plugin for transformer for extracting an excerpt, similar to WordPress's excerpt functionality.

This repo is a fork of manovotny/remark-excerpt that I extended for more related functionality and better MDX support.

This plugin is tailored for MDX support. In order to use this plugin, the following packages must be installed and included in the Remark use chain:

Installation

# npm
$ npm i @eligundry/remark-excerpt remark-parse remark-comment
# yarn
$ yarn add @eligundry/remark-excerpt remark-parse remark-comment

This package is ESM only and I sorta regret it! Life is a learning experience!

Usage

Say we have the following file, example.md:

# Title

Paragraph 1.

Paragraph 2.

<!-- excerpt -->

Paragraph 3.

Paragraph 4.

And our script, example.js, looks as follows:

import fs from 'fs'
import { remark } from 'remark'
import remarkParse from 'remark-parse'
import remarkComment from 'remark-comment'
import { excerpt } from '@eligundry/remark-excerpt'

;(async () => {
  const file = await fs.promises.read('example.md')
  const result = await remark()
    .use(remarkParse)
    .use(remarkComment, { ast: true })
    .use(excerpt)
    .process(file)

  console.log(result.toString())
})()

Now, running node example yields:

# Title

Paragraph 1.

Paragraph 2.

If you wanted to link to where the excerpt broke off, say for a read more link, you would do the following:

import fs from 'fs'
import { remark } from 'remark'
import remarkParse from 'remark-parse'
import remarkComment from 'remark-comment'
import remarkMDX from 'remark-mdx'
import { excerptBreakpoint } from '@eligundry/remark-excerpt'

;(async () => {
  const file = await fs.promises.read('example.md')
  const result = await remark()
    .use(remarkMDX)
    .use(remarkParse)
    .use(remarkComment, { ast: true })
    .use(excerptBreakpoint)
    .process(file)

  console.log(result.toString())
})()

This would yield the following:

# Title

Paragraph 1.

Paragraph 2.

<span id="read-more" />

Paragraph 3.

Paragraph 4.

API

remark().use(excerpt[, options])

Returns markdown content specified before the excerpt comment.

Options

identifier

Type: String Default: excerpt, more, preview, or teaser

Specifies the excerpt comment identifier to look for.

remark().use(excerptBreakpoint[, options])

Inserts a <span id="read-more" /> tag with MDX. This can be used for deep linking into documents from a read more link in the preview. If there are multiple <!-- excerpt --> comments, this element will be inserted at the last instance.

identifier

Type: String Default: excerpt, more, preview, or teaser

Specifies the excerpt comment identifier to look for.

breakpointID

Type: String Default: read-more

The ID to be applied to the <span /> element for the breakpoint. Can be helpful if you have multiple breakpoints that you need to scroll to from various previews.

License

MIT © Eli Gundry

Keywords

excerpt

FAQs

Package last updated on 13 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.