@karuga/remark-include_

0.3.5 • Public • Published

remark-include

@include directives for remark / mdast

features:

  • recursive includes (include a file which in turn includes another file)
  • include patterns (@include mydir/*.md will include all matching files)

downsides:

  • this operates after parsing is done
  • syntax restrictions (e.g. there must be blank lines before and after a block of imports)

alternatives (remark-based):

usage

simple imports:

@import foo.md
@import bar/baz.md

wildcard imports:

<!-- prettier-ignore-start -->

@import bar/*.md

<!-- prettier-ignore-end -->

note: code formatters (like prettier) may have to be disabled (e.g. to prevent replacing * with \*):

using the remark plugin:

const { remarkInclude } = require("@karuga/remark-include");

const processor = remark().use(remarkInclude);

const input = "@include foo.md";
const output = (await processor.process(input)).toString();
// output will be the contents of foo.md

using the mdast transformer:

const { mdastInclude } = require("@karuga/remark-include");

const input = {
  type: "root",
  children: [
    { type: "paragraph" /*...*/ }
    /*...*/
  ]
};
const output = await mdastInclude(input);

Readme

Keywords

none

Package Sidebar

Install

npm i @karuga/remark-include_

Weekly Downloads

0

Version

0.3.5

License

ISC

Unpacked Size

9.62 kB

Total Files

18

Last publish

Collaborators

  • karuga