首页 > 其他分享 >VuePress@next 使用数学公式插件

VuePress@next 使用数学公式插件

时间:2023-07-28 15:44:42浏览次数:36  
标签:md 插件 markdown dist 数学公式 next VuePress katex vuepress

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/[email protected]/dist/katex.min.css' }], // 让md支持数学公式
        ['link', { rel: "stylesheet", href: "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" }]  // 让md支持数学公式
    ]
    

四步骤搞定:看看效果!

image

image

找了的一些文说明的

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

标签:md,插件,markdown,dist,数学公式,next,VuePress,katex,vuepress
From: https://www.cnblogs.com/fhlsteven/p/17587762.html

相关文章

  • 决策树插件——TreePlan Excel plugin学习指导
    决策树是一种常用的风险型决策工具,它能够帮助人们在不确定性和风险环境下做出合理的决策。决策树通过模拟决策过程,以树状结构呈现不同决策路径和结果,并通过计算风险与收益之间的权衡来选择最优的决策方案。决策树的优势在于它能够清晰地展示各种决策选项以及每个选项下可能的结果......
  • wordpress 插件 woocommerce自定义订单信息验证
    使用php钩子函数增加自定义验证add_action('woocommerce_after_checkout_validation',function($fields){if($fields['billing_phone']&&!preg_match('/^((\+1|1)?(|-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})(|-)?([2-9][0-9]{2}(|-)?[0-9......
  • 获取Jenkins默认ftp插件创建的主机密码
    场景:上任Jenkins管理员离职,它默认ftp插件创建的主机密码并没有交接到你手上。解决办法:直接使用pipeline解决。代码:pipeline{  agentany  stages{        stage('getftppassword'){      agentnone      steps{    ......
  • 定制化SOLIDWORKS插件开发服务流程解析
    SOLIDWORKS是一套三维设计软件,采用特征建模、变量化驱动可方便地实现三维建模、装配和生成工程图。SOLIDWORKS软件本身所具有的交互方式,可以使用户对已生成模型的尺寸、几何轮廓和相互约束关系随时进行修改,而不需要编程。SOLIDWORKS软件本身的方程式可以实现简单的参数逻辑变......
  • 画面速率调整——Twixtor插件的使用
    安装Twixtor最后输出选择high高画质但需要渲染,预览的用Sloppy然后通过打关键帧来做到变速的效果......
  • Next.js 开发环境设置 SSL 证书
    在Next.js中设置证书时,你可以按照以下步骤进行操作:生成自签名证书:在开发环境中,你可以使用自签名证书来启用HTTPS。可以使用工具如OpenSSL来生成自签名证书。以下是一个示例命令:opensslreq-nodes-new-x509-keyoutserver.key-outserver.crt这将生成一个名为serv......
  • k8s中如何固定一个pod的IP地址?该集群网络插件是calico
    1、首先查看calico的CIDR地址范围[root@nccztsjb-node-17~]#calicoctlgetippoolNAMECIDRSELECTORdefault-pool172.23.0.0/16all() 2、然后呢,在这个地址范围内,给pod选择一个固定的IP地址比如:172.23.45.27 通过在pod中加入annotat......
  • Jmeter45 Dubbo Sampler 插件及其教程
    转载Jmeter(五十)DubboSampler-紫陌花间客-博客园(cnblogs.com) 一、前言随着分布式普及,日常工作中多少会接触到dubbo,对于dubbo接口的调用或者压测等等。调用最简单的方式便是telnet,或者泛化调用的方式。进入telnet命令行,invoke对应方法以及传入对应的参数即可。当然......
  • 9个必备的vscode插件利器,看看哪些你在用?
    大家好,我是程序视点的小二哥正所谓:工欲善其事,必先利其器作为一名前端开发者,vscode想必大家应该都接触过,就像大多数IDE一样,VSCode也有一个扩展和主题市场,包含了数以千计质量不同的插件。作为一名熟练掌握各种前端开发工具安装和卸载的小二哥来说,为大家安利好玩有用的工具插件......
  • mybatis-plus分页插件之count优化
    分页插件配置packagecom.example.demo.conf;importcom.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;importcom.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;importorg.mybatis.spring.annotation.MapperScan;import......