2023-11-16 12:29:00 +00:00
# Markdown import plugin
2023-11-16 14:23:12 +00:00
This is a `markdown-it` plugin to include/import any raw files from your filesystem.
2023-11-16 12:29:00 +00:00
## Features
- No dependencies
- Recursive import
- Import whatever file
- Customizable RegEx
2023-11-16 14:23:12 +00:00
- Tested
2023-11-16 12:29:00 +00:00
## Installation
```bash
npm install @nicco .io/markdown-it-import
```
2023-11-16 14:23:12 +00:00
## Usage
Include a whole file
```md
@import (somefile.md)
```
Import specific lines
```md
@import (snippet.ts)[5-10]
```
### Example
```md
<!-- main.md -->
# Title
@import (chapter.md)
<!-- This should be tripple ` -->
`ts
@import (sum.ts)
`
```
```md
## Chapter
I will be included
```
```ts
// sum.ts
export function sum(a: number, b: number): number {
return a + b
}
```
```ts
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)
```
2023-11-16 12:29:00 +00:00
## 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.
- https://github.com/camelaissani/markdown-it-include
- https://github.com/h-hg/markdown-it-import