feat(界面): 为 Gemini 配置片段添加语法高亮
补齐高亮渲染并保留纯文本回退 新增高亮 token 工具并做 HTML 转义
This commit is contained in:
@@ -107,7 +107,10 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<!-- Code Content -->
|
<!-- Code Content -->
|
||||||
<pre class="p-4 text-sm font-mono text-gray-100 overflow-x-auto"><code v-text="file.content"></code></pre>
|
<pre class="p-4 text-sm font-mono text-gray-100 overflow-x-auto">
|
||||||
|
<code v-if="file.highlighted" v-html="file.highlighted"></code>
|
||||||
|
<code v-else v-text="file.content"></code>
|
||||||
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -165,6 +168,7 @@ interface FileConfig {
|
|||||||
path: string
|
path: string
|
||||||
content: string
|
content: string
|
||||||
hint?: string // Optional hint message for this file
|
hint?: string // Optional hint message for this file
|
||||||
|
highlighted?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
@@ -310,6 +314,22 @@ const platformNote = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const escapeHtml = (value: string) => value
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''')
|
||||||
|
|
||||||
|
const wrapToken = (className: string, value: string) =>
|
||||||
|
`<span class="${className}">${escapeHtml(value)}</span>`
|
||||||
|
|
||||||
|
const keyword = (value: string) => wrapToken('text-emerald-300', value)
|
||||||
|
const variable = (value: string) => wrapToken('text-sky-200', value)
|
||||||
|
const operator = (value: string) => wrapToken('text-slate-400', value)
|
||||||
|
const string = (value: string) => wrapToken('text-amber-200', value)
|
||||||
|
const comment = (value: string) => wrapToken('text-slate-500', value)
|
||||||
|
|
||||||
// Syntax highlighting helpers
|
// Syntax highlighting helpers
|
||||||
// Generate file configs based on platform and active tab
|
// Generate file configs based on platform and active tab
|
||||||
const currentFiles = computed((): FileConfig[] => {
|
const currentFiles = computed((): FileConfig[] => {
|
||||||
@@ -382,9 +402,9 @@ ${keyword('export')} ${variable('GEMINI_MODEL')}${operator('=')}${string(`"${mod
|
|||||||
content = `set GOOGLE_GEMINI_BASE_URL=${baseUrl}
|
content = `set GOOGLE_GEMINI_BASE_URL=${baseUrl}
|
||||||
set GEMINI_API_KEY=${apiKey}
|
set GEMINI_API_KEY=${apiKey}
|
||||||
set GEMINI_MODEL=${model}`
|
set GEMINI_MODEL=${model}`
|
||||||
highlighted = `${keyword('set')} ${variable('GOOGLE_GEMINI_BASE_URL')}${operator('=')}${baseUrl}
|
highlighted = `${keyword('set')} ${variable('GOOGLE_GEMINI_BASE_URL')}${operator('=')}${string(baseUrl)}
|
||||||
${keyword('set')} ${variable('GEMINI_API_KEY')}${operator('=')}${apiKey}
|
${keyword('set')} ${variable('GEMINI_API_KEY')}${operator('=')}${string(apiKey)}
|
||||||
${keyword('set')} ${variable('GEMINI_MODEL')}${operator('=')}${model}
|
${keyword('set')} ${variable('GEMINI_MODEL')}${operator('=')}${string(model)}
|
||||||
${comment(`REM ${modelComment}`)}`
|
${comment(`REM ${modelComment}`)}`
|
||||||
break
|
break
|
||||||
case 'powershell':
|
case 'powershell':
|
||||||
|
|||||||
Reference in New Issue
Block a user