VuePress@next 使用数学公式插件

搞了一个VuePress1.0的 现在升级了一下,但是使用数学公式的插件老报错啊!经过不懈努力,终于搞定了。现在记录一下。

VuePress 介绍

VuePress 是一个以 Markdown 为中心的静态网站生成器。你可以使用 Markdown 来书写内容(如文档、博客等),然后 VuePress 会帮助你生成一个静态网站来展示它们。

遇到的问题

使用数学公式的库,根据网上找的 markdown-it-texmath,markdown-it-katex,markdown-it-mathjax3,这些都可以,然而当我使用了之后没有一个有用的,报错信息(Error: Dynamic require of "markdown-it-mathjax3" is not supported)详细的参见后面的哦!

此时我的配置:

export default defineUserConfig({
base: '',
lang: 'zh-CN',
title: '',
description: description,
head: head,
theme: defalutThemeOK,
markdown: {
code: {
lineNumbers: false,
}
},
extendsMarkdown: (md) => {
md.use(require('markdown-it-mathjax3')); // 使用这个解析 数学公式
md.linkify.set({ fuzzyEmail: false });
},
})

报错信息

⠋ Initializing and preparing dataerror error in hook extendsMarkdown from user-config
Initializing and preparing data - failed in 33ms
Error: Dynamic require of "markdown-it-mathjax3" is not supported
at file:///F:/StevenBlogs/docs/.vuepress/config.ts.166cda46.mjs:7:9
at Object.extendsMarkdown [as hook] (file:///F:/StevenBlogs/docs/.vuepress/config.ts.166cda46.mjs:161:12)
at Object.process (file:///F:/StevenBlogs/node_modules/@vuepress/core/dist/index.js:683:37)
at async resolveAppMarkdown (file:///F:/StevenBlogs/node_modules/@vuepress/core/dist/index.js:160:3)
at async appInit (file:///F:/StevenBlogs/node_modules/@vuepress/core/dist/index.js:604:18)
at async file:///F:/StevenBlogs/node_modules/@vuepress/cli/dist/index.js:489:7
at async file:///F:/StevenBlogs/node_modules/@vuepress/utils/dist/index.js:106:20
at async CAC.dev (file:///F:/StevenBlogs/node_modules/@vuepress/cli/dist/index.js:488:5)

VuePress 2 成功配置

通过各种尝试,和搜各种资料。最后算是我搞定了。

主要是参考了Maikdown It 插件的文章"@mdit/plugin-katex"[https://mdit-plugins.github.io/zh/katex.html]

  1. 卸载之前没有用的包,我用的npm;

  2. 安装新的包"@mdit/plugin-katex" npm install @mdit/plugin-katex

  3. 修改配置;

    import { katex } from '@mdit/plugin-katex'
    
    export default defineUserConfig({
    // …… 省略了没有必要的
    extendsMarkdown: (md) => {
    md.use(katex);
    md.linkify.set({ fuzzyEmail: false });
    },
    })
  4. 还需要在head加样式,要不然样式就走样子了。参考KaTeX

    export const head : HeadConfig[]=
    [
    ['meta', { name: 'theme-color', content: '#3eaf7c' }],
    ['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
    ['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
    ['link', { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css' }], // 让md支持数学公式
    ['link', { rel: "stylesheet", href: "https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js" }] // 让md支持数学公式
    ]

四步骤搞定:看看效果!

找了的一些文说明的

markdown-it-mathjax3 issues all closed

markdown-it-mathjax3 issues 57

渲染数学公式 顺便说一下这个里面有1.0的配置

1.0 VuePress 的配置

以下是我的1.0的配置,在本地运行也是正常的!

module.exports = {
head: [
['meta', { name: 'theme-color', content: '#3eaf7c' }],
['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
['link', { rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css' }], // 让md支持数学公式
['link', { rel: "stylesheet", href: "https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css" }] // 让md支持数学公式
],
themeConfig: {
plugins: [
'@vuepress/plugin-back-to-top',
'@vuepress/plugin-medium-zoom',
],
extendMarkdown(md){ // 让md支持数学公式 npm install markdown-it-katex
md.set({html:true});
md.use(require('markdown-it-katex'));
}
}
}

总结

通个这个的搞定,那么使用其他Markdown It 插件都可以去这个网站找https://mdit-plugins.github.io/zh/,然后自己改改就能轻松融入了!还是的多琢磨!

另外提一下我搞到github上的网站! haha

VuePress@next 使用数学公式插件的更多相关文章

  1. VuePress博客美化之reco主题

    vuepress博客主题-vuepress-theme-reco是一款简洁而优雅的 vuepress博客&文档主题.它既可以成为简洁而又不失美观的主题,又可以书写你的项目文档,看起来更有逼格. ...

  2. 使用github+jekyll搭建个人博客

    聊聊起初 每次看到大牛们的博客,都会激起一颗一定要搭建自己博客的心,毕竟有着一颗向大牛们看齐的心.但是一直不知道如何下手,从最初的csdn写写博客到在github上建立仓库写代码分享,虽然也能够记录一 ...

  3. VuePress教程之深入理解插件API

    VuePress教程之深入理解插件API 本文目录 1 VuePress教程之深入理解插件API 2 插件 ??? 2.1 暖暖身 2.2 插件如何运作 3 准备 3.1 Markdown 3.2 P ...

  4. 01 学习人工智能,不做笔记?做笔记不知道如何输入数学公式?“onenote+Mathematics Add-In”拯救你!onenote安装数学输入公式插件Microsoft Mathematics Add-In for Word and OneNote教程走一波

    一.Microsoft Mathematics Add-In 插件下载 Microsoft Mathematics Add-In for Word and OneNote插件下载链接: https:/ ...

  5. 为WLW开发Latex公式插件

    WLW是写博客的利器,支持离线.格式排版等,而且拥有众多的插件.博客园推荐了代码插入插件,但是没有提供WLW的公式编译插件.目前我的一般做法是:先在Word下使用MathType编辑好公式,然后将公式 ...

  6. 表单验证插件之jquery.validate.js

    提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...

  7. cnblog中添加数学公式支持

    在博客中使用数学公式,是一件相对麻烦的事儿,大量的截图和插入图片不仅耗费极大的精力,而且影响写作体验. 虽然对于公式显示已经有多种解决办法,但大多数需要安装插件.而MathML这一雄心勃勃的网页数学语 ...

  8. 第7章 jQuery插件的使用和写法

    第7章 jQuery插件的使用和写法 插件又称扩展,是一种遵循一定规范的应用程序接口写出来的程序. 插件的编写思想基于面向对象. 获取最新的插件可以查看jquery官网:http://plugins. ...

  9. 【jQuery基础学习】06 jQuery表单验证插件-Validation

    jQuery的基础部分前面都讲完了,那么就看插件了. 关于jQuery表单验证插件-Validation validation特点: 内置验证规则:拥有必填.数字.E-Mail.URL和信用卡号码等1 ...

  10. jQuery Validate 表单验证插件----自定义一个验证方法

    一.下载依赖包 网盘下载:https://yunpan.cn/cryvgGGAQ3DSW  访问密码 f224 二.引入依赖包 <script src="../../scripts/j ...

随机推荐

  1. 深度学习04-(Tensorflow简介、图与会话、张量基本操作、Tensorboard可视化、综合案例:线性回归)

    深度学习04-Tensorflow 深度学习04-(Tensorflow) Tensorflow概述 Tensorflow简介 什么是Tensorflow Tensorflow的特点 Tensorfl ...

  2. [Pytorch框架] 4.2.3 可视化理解卷积神经网络

    文章目录 4.2.3 可视化理解卷积神经网络 背景 基于Deconvolution的方法 基于Backpropagation的方法 Guided-Backpropagation CAM(Class A ...

  3. API 扫盲贴,8分钟快速搞懂 API 框架

    API(应用程序编程接口)是一种传递信息和指令的工具,它通过不同的功能和协议等手段,允许不同的软件或系统之间进行通信和交互.作为程序员或开发人员,API 是你日常工作中必不可少的组成部分.在本文中,我 ...

  4. MASA MinimalAPI源码解析:为什么我们只写了一个app.MapGet,却生成了三个接口

    源码解析:为什么我们只写了一个app.MapGet,却生成了三个接口 1.ServiceBase 1.AutoMapRoute 源码如下: AutoMapRoute自动创建map路由,MinimalA ...

  5. Layui+dtree实现左边分类列表,右边数据列表

    效果如下 代码实现 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  6. 推荐一个.Ner Core开发的配置中心开源项目

    当你把单体应用改造为微服务架构,相应的配置文件,也会被分割,被分散到各个节点.这个时候就会产生一个问题,配置信息是分散的.冗余的,变成不好维护管理.这个时候我们就需要把配置信息独立出来,成立一个配置中 ...

  7. 2021-08-08:自由之路。电子游戏“辐射4”中,任务“通向自由”要求玩家到达名为“Freedom Trail Ring”的金属表盘,并使用表盘拼写特定关键词才能开门。给定一个字符串 ring,表

    2021-08-08:自由之路.电子游戏"辐射4"中,任务"通向自由"要求玩家到达名为"Freedom Trail Ring"的金属表盘,并 ...

  8. nodejs和npm升级版本

    由于服务器环境的不同可能需要根据实际情况升降对应的nodejs 及npm 版本,最简单的例子就是 npx 只适用于 npm 5+ 看想用npx 那不升级咋办呢,还有如error eslint@7.16 ...

  9. NeoVim 学习笔记

    NeoVim 学习笔记 这篇学习笔记将用于记录本人在学习使用 NeoVim 编辑器过程中所编写的学习心得与代码.该笔记将会存放在https://github.com/owlman/study_note ...

  10. From Java To Kotlin 2:Kotlin 类型系统与泛型

    上期主要分享了 From Java To Kotlin 1 :空安全.扩展.函数.Lambda. 这是 From Java  to Kotlin   第二期. From Java  to Kotlin ...