remark-math 项目教程

remark-math 项目教程

remark-mathremark and rehype plugins to support math项目地址:https://gitcode.com/gh_mirrors/re/remark-math

1、项目的目录结构及介绍

remark-math/
├── .github/
│   └── workflows/
├── examples/
│   ├── example.md
│   └── example.js
├── lib/
│   ├── index.js
│   └── ...
├── test/
│   ├── fixtures/
│   └── index.js
├── .gitignore
├── .npmrc
├── .prettierrc
├── LICENSE
├── README.md
├── package.json
└── yarn.lock
  • .github/workflows: 包含 GitHub Actions 的工作流配置文件。
  • examples: 包含示例 Markdown 文件和对应的 JavaScript 文件。
  • lib: 包含项目的主要代码文件。
  • test: 包含项目的测试文件和测试用例。
  • .gitignore: 指定 Git 忽略的文件和目录。
  • .npmrc: npm 配置文件。
  • .prettierrc: Prettier 代码格式化配置文件。
  • LICENSE: 项目许可证。
  • README.md: 项目说明文档。
  • package.json: 项目依赖和脚本配置文件。
  • yarn.lock: Yarn 锁定文件,确保依赖版本一致。

2、项目的启动文件介绍

项目的启动文件位于 examples/example.js,该文件展示了如何使用 remark-math 插件来处理 Markdown 文件中的数学公式。

import rehypeKatex from 'rehype-katex';
import rehypeStringify from 'rehype-stringify';
import remarkMath from 'remark-math';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import { read } from 'to-vfile';
import { unified } from 'unified';

const file = await unified()
  .use(remarkParse)
  .use(remarkMath)
  .use(remarkRehype)
  .use(rehypeKatex)
  .use(rehypeStringify)
  .process(await read('example.md'));

console.log(String(file));
  • remarkParse: 将 Markdown 解析为抽象语法树(AST)。
  • remarkMath: 支持 Markdown 中的数学公式语法。
  • remarkRehype: 将 remark 的 AST 转换为 rehype 的 AST。
  • rehypeKatex: 使用 KaTeX 渲染数学公式。
  • rehypeStringify: 将 rehype 的 AST 转换为 HTML 字符串。

3、项目的配置文件介绍

  • .prettierrc: 代码格式化配置文件,用于统一代码风格。
  • package.json: 项目依赖和脚本配置文件,包含项目的名称、版本、依赖等信息。
{
  "name": "remark-math",
  "version": "4.0.0",
  "description": "remark plugin to support math",
  "license": "MIT",
  "keywords": [
    "unified",
    "remark",
    "remark-plugin",
    "plugin",
    "mdast",
    "markdown",
    "math",
    "latex",
    "tex"
  ],
  "repository": "remarkjs/remark-math",
  "bugs": "https://github.com/remarkjs/remark-math/issues",
  "funding": {
    "type": "opencollective",
    "url": "https://opencollective.com/unified"
  },
  "author": "Junyoung Choi <fluke8259@gmail.com> (https://rokt33r.github.io)",
  "contributors": [
    "Junyoung Choi <fluke8259@gmail.com> (https://rokt33r.github.io)",
    "TANIGUCHI Masaya <taniguchi@tsuyabu.in>"
  ],
  "files": [
    "index.js",
    "block.js",
    "inline.js"
  ],
  "main": "index.js",
  "types": "index.d.ts",
  "dependencies": {
    "mdast-util-math": "^0

remark-mathremark and rehype plugins to support math项目地址:https://gitcode.com/gh_mirrors/re/remark-math

  • 12
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郑眉允Well-Born

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值