npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rspress-plugin-code-block

v1.1.3

Published

Rspress plugin to import and display file contents as code blocks

Readme

rspress-plugin-code-block

一个Rspress插件,用于在构建时将文件内容嵌入到MDX文档中作为静态代码块。

安装

pnpm add rspress-plugin-code-block
npm install rspress-plugin-code-block

配置

rspress.config.ts 中添加插件:

import { defineConfig } from 'rspress/config';
import { codeBlockPlugin } from 'rspress-plugin-code-block';

export default defineConfig({
  plugins: [codeBlockPlugin()],
});

使用方法

使用 CodeBlock 组件

在MDX文件中导入并使用 CodeBlock 组件:

import { CodeBlock } from 'rspress-plugin-code-block';

<CodeBlock src="config.json" />

指定语言类型

import { CodeBlock } from 'rspress-plugin-code-block';

<CodeBlock src="utils.js" language="javascript" />

文件路径说明

  • 相对路径:相对于当前MDX文件的位置
  • 支持任意位置:文件可以放在docs目录的任何位置,不需要public目录
  • 自动语言识别:根据文件扩展名自动识别语言类型
  • 纯静态嵌入:在构建时读取文件内容,生成静态HTML

支持的文件格式

自动识别以下文件扩展名的语言类型:

  • JavaScript: .js, .jsx
  • TypeScript: .ts, .tsx
  • Python: .py
  • XML: .xml
  • JSON: .json
  • HTML: .html
  • CSS: .css
  • Shell: .sh
  • 以及更多...

特点

  • 编译时处理:在构建阶段读取文件内容,生成静态代码块
  • 无需运行时加载:不依赖fetch或网络请求
  • 支持相对路径:文件可以放在与MDX文件相同或子目录中
  • 自动语法高亮:根据文件类型自动选择语言高亮方案
  • 错误处理:文件不存在时显示友好的错误信息

开发

本地开发

  1. 克隆仓库
  2. 安装依赖:npm install
  3. 在测试项目中使用相对路径引入插件

构建

这是一个TypeScript项目,无需额外构建步骤。

许可证

MIT License