@variant/md-section
v1.0.0
Published
Get specific sections of markdown files based on headings.
Downloads
2
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