Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline formula will not be parsed if there are other html tags in the present line #18

Open
Areenole opened this issue Jul 1, 2024 · 1 comment
Labels
info-needed Issue requires more information from poster

Comments

@Areenole
Copy link

Areenole commented Jul 1, 2024

The modules are:

import markdownIt from "markdown-it";
import markdownItKatex from "@vscode/markdown-it-katex"
const md = markdownIt()
md.set({ html: true })
// ...

and the markdown file has lines with the forms:

- ...
- Mean <font color="#f48fb1"> $x_k = m(u_k)$ nonlinear </font>
- ...

or

Mean <font color="#f48fb1"> $x_k = m(u_k)$ nonlinear </font>

The formula here won't be parsed. However, in VSCode it is rendered correctly. This problem is temporarily solved in my project:

const regex1 = /<p>(.*?)<font color="(.*?)">(.*?)<\/p>/g;
const regex2 = /<li>(.*?)<font color="(.*?)">(.*?)<\/li>/g;
const regex_p = /<p>(.*?)<\/p>/g;

function updateMd() {
  // this is a tauri application
  invoke('read_markdown', { filename: filename }).then((value) => {
    md_context.value = md.render(value);
    md_context.value = md_context.value.replace(regex1, (match, p1, p2, p3) => {
      p3 = md.render(p3);
      p3 = p3.replace(regex_p, (match, p1) => {
        return p1;
      });
      return `<p>${p1}<font color="${p2}">${p3}</p>`;
    });

    md_context.value = md_context.value.replace(regex2, (match, p1, p2, p3) => {
      p3 = md.render(p3);
      p3 = p3.replace(regex_p, (match, p1) => {
        return p1;
      });
      return `<li>${p1}<font color="${p2}">${p3}</li>`;
    });
  })
}
@mjbvz
Copy link
Collaborator

mjbvz commented Dec 10, 2024

Can you try setting enableMathInlineInHtml:

var md = require('markdown-it')();
const mk = require('@vscode/markdown-it-katex').default;

md.use(mk, { enableMathInlineInHtml: true });

@mjbvz mjbvz added the info-needed Issue requires more information from poster label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants