@variant/md-section

Get specific sections of markdown files based on headings.

Usage no npm install needed!

<script type="module">
  import variantMdSection from 'https://cdn.skypack.dev/@variant/md-section';
</script>

README

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