refactor: Update wiki link syntax and rendering in WikiBrowser component

- Enhanced the `renderMarkdown` function to support the new `[[slug|display name]]` format for wiki links, improving link clarity and usability.
- Adjusted CSS styles for wiki links to provide a more intuitive hover effect and visual distinction.
- Updated prompts in the `prompts_wiki.go` file to reflect the new wiki link syntax, ensuring consistency across the application.

These changes improve the overall user experience by making wiki links more informative and visually appealing.
This commit is contained in:
wizardchen
2026-04-08 17:21:44 +08:00
parent 7eea22d655
commit 5d5073c96b
5 changed files with 24 additions and 23 deletions
+3 -7
View File
@@ -746,19 +746,15 @@ func (s *wikiIngestService) injectCrossLinks(ctx context.Context, kbID string, a
changed := false
for _, ref := range allRefs {
// Don't self-link
if ref.slug == p.Slug {
continue
}
// Skip if already linked with this slug
if strings.Contains(content, "[["+ref.slug+"]]") {
// Skip if already linked with this slug (either [[slug]] or [[slug|...]])
if strings.Contains(content, "[["+ref.slug+"|") || strings.Contains(content, "[["+ref.slug+"]]") {
continue
}
// Replace title mentions with [[slug]] link
// Only replace if the title appears as a standalone term (not inside an existing link)
if strings.Contains(content, ref.title) {
// Replace first occurrence only (avoid over-linking)
content = replaceFirstOutsideLinks(content, ref.title, ref.title+" [["+ref.slug+"]]")
content = replaceFirstOutsideLinks(content, ref.title, "[["+ref.slug+"|"+ref.title+"]]")
changed = true
}
}
+2 -2
View File
@@ -352,9 +352,9 @@ func (s *wikiPageService) parseOutLinks(content string) types.StringArray {
for _, match := range matches {
if len(match) > 1 {
slug := strings.TrimSpace(match[1])
// Handle [[Title|slug]] format
// Handle [[slug|display name]] format — slug is the first part
if parts := strings.SplitN(slug, "|", 2); len(parts) == 2 {
slug = strings.TrimSpace(parts[1])
slug = strings.TrimSpace(parts[0])
}
slug = normalizeSlug(slug)
if slug != "" && !seen[slug] {
@@ -30,10 +30,15 @@ func TestParseOutLinks(t *testing.T) {
want: []string{"entity/acme-corp"},
},
{
name: "pipe syntax: title|slug",
content: "See [[Acme Corp|entity/acme-corp]] for details.",
name: "pipe syntax: slug|display name",
content: "See [[entity/acme-corp|Acme Corp]] for details.",
want: []string{"entity/acme-corp"},
},
{
name: "mixed: pipe and bare links",
content: "See [[entity/acme-corp|Acme Corp]] and [[concept/rag]] here.",
want: []string{"entity/acme-corp", "concept/rag"},
},
{
name: "no links",
content: "Just plain text without any links.",