vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
11.33k stars 1.83k forks source link

The language 'latex-expl3' is not loaded, falling back to 'txt' for syntax highlighting. #3779

Closed ljguo1020 closed 2 weeks ago

ljguo1020 commented 2 weeks ago

Describe the bug

我想自定义一种代码高亮语言, 这是我的 LaTeX-Expl3.tmLanguage.json, 在线链接 LaTeX-Expl3.tmLanguage.json

{
    "name": "LaTeX-Expl3",
    "patterns": [
      {
        "begin": "(\\$\\$|\\$)",
        "beginCaptures": {
          "1": {
            "name": "punctuation.section.group.begin.tex"
          }
        },
        "end": "(\\1)",
        "endCaptures": {
          "1": {
            "name": "punctuation.section.group.end.tex"
          }
        },
        "name": "support.class.math.tex",
        "patterns": [
          {
            "match": "\\\\\\$",
            "name": "constant.character.escape.tex"
          },
          {
            "include": "#latex3"
          },
          {
            "include": "text.tex#math"
          },
          {
            "include": "$base"
          }
        ]
      },
      {
        "begin": "\\\\\\(",
        "beginCaptures": {
          "0": {
            "name": "punctuation.section.group.begin.tex"
          }
        },
        "end": "\\\\\\)",
        "endCaptures": {
          "0": {
            "name": "punctuation.section.group.end.tex"
          }
        },
        "name": "support.class.math.tex",
        "patterns": [
          {
            "include": "#latex3"
          },
          {
            "include": "text.tex#math"
          },
          {
            "include": "$base"
          }
        ]
      },
      {
        "begin": "\\\\\\[",
        "beginCaptures": {
          "0": {
            "name": "punctuation.section.group.begin.tex"
          }
        },
        "end": "\\\\\\]",
        "endCaptures": {
          "0": {
            "name": "punctuation.section.group.end.tex"
          }
        },
        "name": "support.class.math.tex",
        "patterns": [
          {
            "include": "#latex3"
          },
          {
            "include": "text.tex#math"
          },
          {
            "include": "$base"
          }
        ]
      },
      {
        "include": "#latex3"
      },
      {
        "include": "text.tex.latex"
      }
    ],
    "repository": {
      "latex3": {
        "patterns": [
          {
            "captures": {
              "1": {
                "name": "punctuation.definition.function.expl.latex"
              }
            },
            "match": "(\\\\|\\.)[\\w@]+:\\w*",
            "name": "keyword.control.expl.latex"
          },
          {
            "captures": {
              "1": {
                "name": "punctuation.definition.variable.expl.latex"
              }
            },
            "match": "(\\\\)[\\w@]+_[\\w@]+",
            "name": "variable.expl.latex"
          }
        ]
      }
    },
    "scopeName": "text.tex.latex.expl3"
  }

我的 vitepress 配置文件如下

import { defineConfig } from 'vitepress'

import Expl3 from '../LaTeX-Expl3.tmLanguage.json';

// https://vitepress.dev/reference/site-config
export default defineConfig({
  title: "whimsy-latexx",
  description: "Learn LaTeX(3).",
  themeConfig: {
    // https://vitepress.dev/reference/default-theme-config
    nav: [
      { text: 'Home', link: '/' },
      { text: 'Examples', link: '/markdown-examples' }
    ],

    sidebar: [
      {
        text: 'Examples',
        items: [
          { text: 'Markdown Examples', link: '/markdown-examples' },
          { text: 'Runtime API Examples', link: '/api-examples' }
        ]
      }
    ],

    socialLinks: [
      { icon: 'github', link: 'https://github.com/vuejs/vitepress' }
    ]
  }
  ,
  markdown: {
    languages: [Expl3]
  }
})

它没有正常工作,控制台出现 The language 'latex-expl3' is not loaded, falling back to 'txt' for syntax highlighting.

Reproduction

如上效果

Expected behavior

正常渲染 LaTeX3 的代码

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12400
    Memory: 6.70 GB / 15.78 GB
  Binaries:
    Node: 20.9.0 - D:\software\nodejs\node.EXE
    Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.1.0 - D:\software\nodejs\npm.CMD
    pnpm: 8.15.4 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (123.0.2420.81)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    vitepress: ^1.1.0 => 1.1.0

Additional context

No response

Validations

brc-dd commented 2 weeks ago

Name is case-sensitive. Make it "name": "latex-expl3".

xkwxdyy commented 2 weeks ago
import { defineConfig } from 'vitepress'
import latex3 from '../src/LaTeX-Expl3.tmLanguage.json';

export default defineConfig({
  ...
  themeConfig: {
    ...
  },

  markdown: {
    languages: [latex3]
  }
})

I changed the file like this, and it actually worked in the html. But there is still a error hint from VScode:

不能将类型“{ name: string; patterns: ({ begin: string; beginCaptures: { "1": { name: string; }; "0"?: undefined; }; end: string; endCaptures: { "1": { name: string; }; "0"?: undefined; }; name: string; patterns: ({ match: string; name: string; include?: undefined; } | { ...; })[]; include?: undefined; } | { ...; } | { ...; })[...”分配给类型“LanguageInput”。
  不能将类型“{ name: string; patterns: ({ begin: string; beginCaptures: { "1": { name: string; }; "0"?: undefined; }; end: string; endCaptures: { "1": { name: string; }; "0"?: undefined; }; name: string; patterns: ({ match: string; name: string; include?: undefined; } | { ...; })[]; include?: undefined; } | { ...; } | { ...; })[...”分配给类型“LanguageRegistration”。
    属性“repository”的类型不兼容。
      不能将类型“{ latex3: { patterns: { captures: { "1": { name: string; }; }; match: string; name: string; }[]; }; }”分配给类型“IRawRepository”。
        类型“{ latex3: { patterns: { captures: { "1": { name: string; }; }; match: string; name: string; }[]; }; }”缺少类型“IRawRepositoryMap”中的以下属性: $self, $base
brc-dd commented 2 weeks ago

That language is not fully compatible with Shiki types. But if it works you can use // @ts-ignore or // @ts-expect-error above that line.

xkwxdyy commented 2 weeks ago

That language is not fully compatible with Shiki types. But if it works you can use // @ts-ignore or // @ts-expect-error above that line.

It works. Thanks a lot.