SunspotsInys
V2EX  ›  Vue.js

如何在 vue3 中,使用 markdown-it-katex

  •  
  •   SunspotsInys · Feb 27, 2021 via Android · 4032 views
    This topic created in 2077 days ago, the information mentioned may be changed or developed.

    在 markdown-it-katex 给的demo 网站里面就能很好的解析 完美的解析

    而我写的

    import MakrdownIt from "markdown-it";
    import MarkdownItKatex from "markdown-it-katex";
    import "github-markdown-css";
    export function toHTML(s: string): string {
    	let mk = new MakrdownIt();
    	mk.use(MarkdownItKatex);
    	return mk.render(s);
    }
    

    解析的完全是一团糟 糟糕

    3 replies  •  2021-02-28 11:51:37 +08:00
    mmlmml1
    mmlmml1
    Feb 28, 2021❤️1
    1
    看样子像是 CSS 没加载。开发者工具看看资源是不是都加载了? HTML 模板有没有加入 CSS 相关的代码?或者手动加载 `<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css">` 看看。
    SunspotsInys
    SunspotsInys
    OP
    Feb 28, 2021
    2
    @mmlmml1 的确,css 改一下就 OK 了。但是还是有些问题,如果$后面有空格就不能解析为数学公式了,但是官方的 demo 就还可以。[691Kts.jpg]( https://imgtu.com/i/691Kts)
    mmlmml1
    mmlmml1
    Feb 28, 2021
    3
    额,这个问题在于 LaTex 里,下标前面不能加空格的,你试试看 $ 1_3 $,而不是 $ 1 _3 $.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2395 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 11:14 · PVG 19:14 · LAX 03:14 · JFK 06:14
    ♥ Do have faith in what you're doing.