open-index/open-npm huggingface dataset:
npm package: @markdown-design/markdown-it-headers
Description: A markdown-it plugin for extracting markdown heading information.
Author: Zero
Latest version: 0.2.0

# markdown-it-headers

一个用于提取 markdown 标题信息的 markdown-it 插件，主要返回的标题信息请看 [MditHeadings](#MditHeadings)。

## 快速上手

### 安装

```sh
npm i @markdown-design/markdown-it-headers
```

### 使用

```js
// demo.js

import markdownit from 'markdown-it'
import { headers } from '@markdown-design/markdown-it-headers'

const md = markdownit()
md.use(headers)

const env = {}
md.render(`# foo\n## bar\nbaz`, env)
const { headings = [] } = env
console.log(headings)
// 输出：
// [
//     {
//         "level": 1,
//         "text": "foo"
//     },
//     {
//         "level": 2,
//         "text": "bar"
//     }
// ]
```

### TypeScript

```ts
// demo.ts
import { type MditHeadersEnv } from '@markdown-design/markdown-it-headers'

const env: MditHeadersEnv = {}
```

#### MditHeadersEnv

| 名称     | 类型                            |
| -------- | ------------------------------- |
| headings | [MditHeadings](#MditHeadings)[] |

#### MditHeadings

| 名称  | 说明           | 类型   |
| ----- | -------------- | ------ |
| level | 标题的级别     | number |
| text  | 标题包含的内容 | string |

## 开源协议

本项目基于 [MIT](./LICENSE) 协议。
npm package: @markdown-design/markdown-it-sanitize
Description: A markdown-it plugin built on DOMPurify.
Author: Zero
Latest version: 0.2.0

# markdown-it-sanitize

一个基于 [DOMPurify](https://github.com/cure53/DOMPurify) 的 markdown-it 插件。当开启 markdown-it 的 html 配置项时，会过滤输出的 HTML 标签，以预防 XSS 攻击。

## 快速上手

### 安装

```sh
npm i @markdown-design/markdown-it-sanitize
```

### 使用

```js
// demo.js

import markdownit from 'markdown-it'
import { sanitize } from '@markdown-design/markdown-it-sanitize'

const md = markdownit({ html: true })
md.use(sanitize)

const html = md.render('<span>foo<img src=x onerror=alert(1)//></span>')
console.log(html)
// 输出：<p><span>foo<img src="x"></span></p>
```

### 配置

你也可以传入 DOMPurify 的[配置项](https://github.com/cure53/DOMPurify#can-i-configure-dompurify)，如：

```js
// demo.js
import markdownit from 'markdown-it'
import { sanitize } from '@markdown-design/markdown-it-sanitize'

const md = markdownit({ html: true })
md.use(sanitize, { ALLOWED_TAGS: ['p', '#text'] })

const html = md.render(
  '<iframe//src=JavScript:alert&lpar;1)></ifrAMe><br>goodbye</p><h1>not me!</h1>'
)
console.log(html)
// 输出：<p>&lt;iframe//src=JavScript:alert(((1)&gt;goodbye<p></p>not me!</p>
```

## 开源协议

本项目基于 [MIT](./LICENSE) 协议。
npm package: @markdown-di/remark
Description: Remark adapter for markdown-di with AST-based transformations
Author: Pepijn Senders
Latest version: 0.1.1

# @markdown-di/remark

Remark adapter for markdown-di with AST-based transformations.

## Features

- ✅ Full AST-based transclusion (powered by @markdown-di/core)
- ✅ Heading level adjustments
- ✅ Link rewriting
- ✅ Frontmatter handling
- ✅ Works with unified/remark ecosystem

## Installation

```bash
bun add @markdown-di/remark remark remark-parse remark-stringify remark-frontmatter
```

## Usage

```typescript
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import remarkFrontmatter from 'remark-frontmatter';
import { remarkMarkdownDI } from '@markdown-di/remark';

const processor = unified()
  .use(remarkParse)
  .use(remarkFrontmatter, ['yaml'])
  .use(remarkMarkdownDI, {
    baseDir: './docs',
    headingShift: true,      // Adjust heading levels
    linkRewrite: true,       // Fix relative links
    removeFrontmatter: false // Keep frontmatter in output
  })
  .use(remarkStringify);

const result = await processor.process(myMarkdownString);
console.log(String(result));
```

## Options

### `baseDir` (required)

Base directory for resolving file paths.

```typescript
remarkMarkdownDI({ baseDir: './docs' })
```

### `headingShift` (default: `true`)

Automatically adjust heading levels when transcluding content.

```typescript
// When enabled:
// If you transclude under an H2, the transcluded H1 becomes H3
remarkMarkdownDI({ headingShift: true })
```

### `linkRewrite` (default: `true`)

Rewrite relative links after transclusion to maintain correctness.

```typescript
remarkMarkdownDI({ linkRewrite: true })
```

### `removeFrontmatter` (default: `false`)

Remove dependency declarations from frontmatter in output.

```typescript
// Keep only name/description, remove blueprints/references
remarkMarkdownDI({ removeFrontmatter: true })
```

## How It Works

1. **Parse** - Remark parses markdown to MDAST
2. **Validate** - @markdown-di/core validates frontmatter and references
3. **Resolve** - Core resolves dependencies to file paths
4. **Transclude** - Plugin replaces `{{refs}}` with file contents (as AST nodes)
5. **Transform** - Apply heading shifts and link rewrites
6. **Output** - Remark stringifies back to markdown

## Advanced Usage

### Custom Heading Shift Strategy

```typescript
remarkMarkdownDI({
  baseDir: './docs',
  headingShift: (currentDepth, contextDepth) => {
    // Custom logic
    return currentDepth + contextDepth;
  }
})
```

### Custom Link Rewriter

```typescript
remarkMarkdownDI({
  baseDir: './docs',
  linkRewrite: (url, sourcePath, targetPath) => {
    // Custom logic
    return rewrittenUrl;
  }
})
```

## License

MIT © Pepijn Senders