1.0.0 • Published 5 years ago

@variant/md-section v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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