vuejs / vitepress

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

bug:Can't parse go code correctly #2390

Closed jingyuexing closed 8 months ago

jingyuexing commented 12 months ago

Describe the bug

[plugin:vite:vue] Error parsing JavaScript expression: Unexpected token, expected "," (1:12)
F:/Code/vuepress-demo/src/module/i18n.md:129:14
128|        this.Ctx.SetCookie("lang", curLang.Lang, 1<<31-1, "/")
129|    }
130|    restLangs \:= make([]*langType, 0, len(langTypes)-1)
   |             ^
131|    for _, v := range langTypes {
132|        if lang != v.Lang {

Reproduction


```go
// setLangVer sets site language version.
func (this *baseRouter) setLangVer() bool {
    isNeedRedir := false
    hasCookie := false

    // 1. Check URL arguments.
    lang := this.Input().Get("lang")

    // 2. Get language information from cookies.
    if len(lang) == 0 {
        lang = this.Ctx.GetCookie("lang")
        hasCookie = true
    } else {
        isNeedRedir = true
    }

    // Check again in case someone modify by purpose.
    if !i18n.IsExist(lang) {
        lang = ""
        isNeedRedir = false
        hasCookie = false
    }

    // 3. Get language information from 'Accept-Language'.
    if len(lang) == 0 {
        al := this.Ctx.Request.Header.Get("Accept-Language")
        if len(al) > 4 {
            al = al[:5] // Only compare first 5 letters.
            if i18n.IsExist(al) {
                lang = al
            }
        }
    }

    // 4. Default language is English.
    if len(lang) == 0 {
        lang = "en-US"
        isNeedRedir = false
    }

    curLang := langType{
        Lang: lang,
    }

    // Save language information in cookies.
    if !hasCookie {
        this.Ctx.SetCookie("lang", curLang.Lang, 1<<31-1, "/")
    }
    restLangs := make([]*langType, 0, len(langTypes)-1)
    for _, v := range langTypes {
        if lang != v.Lang {
            restLangs = append(restLangs, v)
        } else {
            curLang.Name = v.Name
        }
    }

    // Set language properties.
    this.Lang = lang
    this.Data["Lang"] = curLang.Lang
    this.Data["CurLang"] = curLang.Name
    this.Data["RestLangs"] = restLangs

    return isNeedRedir
}

Expected behavior

Should be correctly parsing code blocks, not parsing templates

System Info

"vitepress": "1.0.0-alpha.76"

Additional context

No response

Validations

brc-dd commented 12 months ago

Did you miss ``` after that code block? It appears to be working fine for me: https://stackblitz.com/edit/vite-urnofi?file=docs/index.md

jingyuexing commented 12 months ago

Did you miss ``` after that code block? It appears to be working fine for me: https://stackblitz.com/edit/vite-urnofi?file=docs/index.md

nop,i'm make sure

jingyuexing commented 12 months ago

Did you miss ``` after that code block? It appears to be working fine for me: https://stackblitz.com/edit/vite-urnofi?file=docs/index.md

image

jingyuexing commented 12 months ago

Did you miss ``` after that code block? It appears to be working fine for me: https://stackblitz.com/edit/vite-urnofi?file=docs/index.md

Now wrongly changed location

jingyuexing commented 12 months ago

Did you miss ``` after that code block? It appears to be working fine for me: https://stackblitz.com/edit/vite-urnofi?file=docs/index.md

I posted the full text of the document, and it has begun to report errors

jingyuexing commented 12 months ago

fantasy!

jingyuexing commented 12 months ago

https://stackblitz.com/edit/vite-3etpsv?file=docs%2Findex.md

zonemeen commented 12 months ago
image

The error was caused by this line. What does it do?

jingyuexing commented 12 months ago
image

The error was caused by this line. What does it do?

template,is the template syntax of the backend framework

zonemeen commented 12 months ago

Does it render anything, or just display characters?

jingyuexing commented 12 months ago

Does it render anything, or just display characters?

this is beego syntax,not vue

zonemeen commented 12 months ago

Could you provide a full reproduction?

jingyuexing commented 12 months ago

Could you provide a full reproduction?

beego