Markdown-it plugin which adds the ability to include files.
Go to file
Niccolo Borgioli a6c56e536a
trim content by default
2023-11-16 15:43:48 +01:00
src trim content by default 2023-11-16 15:43:48 +01:00
tests trim content by default 2023-11-16 15:43:48 +01:00
.gitignore initial push 2023-11-16 13:29:00 +01:00
.nvmrc initial push 2023-11-16 13:29:00 +01:00
README.md readme 2023-11-16 15:23:12 +01:00
bun.lockb add tests 2023-11-16 15:13:19 +01:00
package.json trim content by default 2023-11-16 15:43:48 +01:00
tsconfig.json initial push 2023-11-16 13:29:00 +01:00

README.md

Markdown import plugin

This is a markdown-it plugin to include/import any raw files from your filesystem.

Features

  • No dependencies
  • Recursive import
  • Import whatever file
  • Customizable RegEx
  • Tested

Installation

npm install @nicco.io/markdown-it-import

Usage

Include a whole file

@import(somefile.md)

Import specific lines

@import(snippet.ts)[5-10]

Example

<!-- main.md -->

# Title

@import(chapter.md)

<!-- This should be tripple ` -->

`ts
@import(sum.ts)
`
## Chapter

I will be included
// sum.ts
export function sum(a: number, b: number): number {
  return a + b
}
import MarkdownIt from 'markdown-it'
import fs from 'node:fs/promises'
import { Options, importPlugin } from '@nicco.io/markdown-it-import'

const input = await fs.readFile('./main.md', 'utf-8')
const html = MarkdownIt().use(importPlugin).render(input)

Similar works

There are two very similar plugins, which this one is def. inspired by, however while the one can only import .md files, the other cannot select single lines.