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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gby/markdown-it-import

v1.0.0

Published

markdown-it-import 是一个可让 markdown-it 支持导入 import 功能的插件,兼容 VitePress、VuePress,可扩展、可自定导入语法,超级可配置,默认使用 Markdown Preview Enhanced 的导入语法

Downloads

7

Readme

目录


1. 背景

假如你想在自己的所有文章下面都加上一段个人简介,而个人简介的内容都是相同的,一种方案是复制粘贴!但如果后来你更新的个人简介,你就需要在去更新每个文档!

更好的方案是:个人简介单独写在一个文档中,假设文档的路径是 片段/个人简介.md,每篇文章只需要导入该文档,如: @import "片段/个人简介.md" Markdown 渲染引擎就会自动内联该文档的内容;当我们需要更新 个人简介 时,只需在 片段/个人简介.md 这个文档中更新一次即可,其它导入该文档的文档都会自动更新!

若要实现这个方案,就需要对 Markdown 的语法进行扩展!所以,本插件诞生了!

2. 简介

本库是 markdown-it 的一个插件,专门用于扩展 markdown-it 导入语法,它有以下特性:

具有以下特性:

  • 导入文件时支持定义选项
  • 可以完全自定义导入语法,实现自己的导入规则
  • 对于 .md 格式的文件可以选择是导入为代码块,还是内联
  • 默认实现了 [Markdown Preview Enhanced 的导入语法][]
  • 兼容 VitePressVuePress
  • TypeScript 编写

详情请看:

如果您在使用的过程中遇到了问题,或者有好的建议和想法,您都可以通过以下方式联系我,期待与您的交流:

3. 安装方式

::: code-group

npm install --save-dev @gby/markdown-it-import
pnpm add -D @gby/markdown-it-import

:::

4. 教程

详情跳转至教程

markdown-it

import MarkdownIt from "markdown-it"
import importPlugin from "../dist/markdown-it-import.mjs";

const md = new MarkdownIt();

md.use(importPlugin);

也可以传递一个选项

// 也可以给插件传递一些选项
md.use(importPlugin,{
    /**
     * 导入信息的获取函数
     * @defaultValue 支持vitePress 路径的 getInfo_MPE ,Markdown Preview Enhanced 导入信息获取函数选项的函数
     */
    getInfo?:function(lineText:string,state:State, startLine: number, endLine: number, silent: boolean){
      // 自定义导入语法的解析
      return {
         // 配置相应的参数
      }
    };
    /**
     * 当导入的文件是 md 文件时,是否总是包含 md 文件,而不是渲染为代码块
     * 
     * @defaultValue true
     */
    includeMD:true;
});

VitePress

在VitePress的配置中添加以下配置

import {importPlugin} from "@gby/markdown-it-import"

export default {
  markdown:{
    config:(md)=>{
      md.use(importPlugin)
    }
  }
}

5. API接口文档

详情跳转至API接口文档


有您的支持,我会在开源的道路上,越走越远

赞赏码