@variant/md-section

1.0.0 • Public • Published

md-section

Get specific sections of markdown files based on headings.

const markdown = `
# My text

## Sub title 1

Content 1

## Sub title 2

Content 2
`;

const { getHeadlines, getSection } = require("md-sections");
const headlines = getHeadlines(markdown);

console.log(headlines);
// [
//   { level: 1, content: "My text" },
//   { level: 2, content: "Sub title 1" },
//   { level: 2, content: "Sub title 2" }
// ];

console.log(getSection(markdown, headlines[1]));
// ## Sub title 1
//
// Content 1

Or limited by max/min levels:

const markdown = `
# My text

## Sub title 1

Content 1

### Sub sub title 1

Content 1.1

## Sub title 2

Content 2
`;

const { getHeadlines, getSection } = require("md-sections");
const headlines = getHeadlines(markdown, { minLevel: 2, maxLevel: 2 });

console.log(headlines);
// [{ level: 2, content: "Sub title 1" }, { level: 2, content: "Sub title 2" }];

console.log(getSection(markdown, headlines[1]));
// ## Sub title 2
//
// Content 2

Package Sidebar

Install

npm i @variant/md-section

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

2.77 kB

Total Files

3

Last publish

Collaborators

  • toretefre
  • mikaelb
  • cbrevik
  • mathiafl