Remark transformer for extracting an excerpt.
This is a remark plugin for transformer for extracting an excerpt, similar to WordPress's excerpt functionality.
$ npm i remark-excerpt
$ yarn add remark-excerpt
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:
const remark = require('remark');
const excerpt = require('remark-excerpt');
const vfile = require('to-vfile');
(async () => {
const file = await vfile.read('example.md');
const result = await remark().use(excerpt).process(file);
console.log(result.toString());
})();
Now, running node example
yields:
# Title
Paragraph 1.
Paragraph 2.
You can try this yourself by downloading or cloning the project, installing dependencies, and running yarn example
.
Returns markdown content specified before the excerpt comment.
Type: String
Default: excerpt
, more
, preview
, or teaser
Specifies the excerpt comment identifier to look for.
MIT © Michael Novotny