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:
@@ -288,8 +288,12 @@ const graphDrawerContent = computed(() => {
|
||||
|
||||
function renderMarkdown(content: string): string {
|
||||
let html = content
|
||||
html = html.replace(/\[\[([^\]]+)\]\]/g, (_, slug) =>
|
||||
`<a href="#" class="wiki-content-link" data-slug="${slug}">[[${slug}]]</a>`)
|
||||
html = html.replace(/\[\[([^\]]+)\]\]/g, (_, inner: string) => {
|
||||
const pipeIdx = inner.indexOf('|')
|
||||
const slug = pipeIdx > 0 ? inner.substring(0, pipeIdx).trim() : inner.trim()
|
||||
const display = pipeIdx > 0 ? inner.substring(pipeIdx + 1).trim() : slugDisplayName(slug)
|
||||
return `<a href="#" class="wiki-content-link" data-slug="${slug}">${display}</a>`
|
||||
})
|
||||
html = html.replace(/^### (.+)$/gm, '<h3>$1</h3>')
|
||||
html = html.replace(/^## (.+)$/gm, '<h2>$1</h2>')
|
||||
html = html.replace(/^# (.+)$/gm, '<h1>$1</h1>')
|
||||
@@ -1290,13 +1294,9 @@ onMounted(() => {
|
||||
:deep(.wiki-content-link) {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
font-family: monospace;
|
||||
font-size: 13px;
|
||||
padding: 1px 4px;
|
||||
background: rgba(7, 192, 95, 0.06);
|
||||
border-radius: 3px;
|
||||
border-bottom: 1px dashed var(--td-brand-color);
|
||||
cursor: pointer;
|
||||
&:hover { background: rgba(7, 192, 95, 0.12); }
|
||||
&:hover { border-bottom-style: solid; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ const WikiSummaryPrompt = `You are a wiki editor. Given the following document c
|
||||
2. After the SUMMARY line, write a comprehensive summary of the document in Markdown format.
|
||||
3. Include the key facts, arguments, and conclusions.
|
||||
4. Use proper heading hierarchy (## for sections, ### for subsections).
|
||||
5. **Wiki-link rule**: The available_wiki_pages list above maps slugs to display names (e.g. "[[entity/zhong-guo]] = 中国"). Whenever you mention a name that matches a listed entry, you MUST write it as [[slug]] (e.g. [[entity/zhong-guo]]), NOT as bold (**name**) or plain text. Use the EXACT slugs provided — do NOT invent new slugs.
|
||||
5. **Wiki-link rule**: The available_wiki_pages list above maps slugs to display names (format: "[[slug]] = display name"). Whenever you mention a name that matches a listed entry, you MUST write it as [[slug|display name]] (e.g. [[entity/zhong-guo|中国]]), NOT as bold (**name**) or bare [[slug]]. Use the EXACT slugs provided — do NOT invent new slugs.
|
||||
6. At the end, include a "## Key Takeaways" section with bullet points.
|
||||
7. Write in {{.Language}}.
|
||||
8. Keep the summary concise but thorough (500-1500 words depending on document length).
|
||||
@@ -124,7 +124,7 @@ const WikiPageUpdatePrompt = `You are a wiki editor tasked with updating an exis
|
||||
3. Preserve all existing information that is still valid.
|
||||
4. If the new information contradicts existing content, prefer the newer information and silently replace the old claim.
|
||||
5. Add new facts, details, and context from the new document.
|
||||
6. Preserve any existing [[wiki-link]] references in the content. Do NOT invent new wiki-link slugs.
|
||||
6. Preserve any existing [[slug|name]] wiki-link references in the content. Do NOT invent new wiki-link slugs.
|
||||
7. Maintain the existing page structure and formatting style.
|
||||
8. Add a source reference to the new document at the bottom.
|
||||
9. Write in {{.Language}}.
|
||||
@@ -161,7 +161,7 @@ const WikiPageRetractPrompt = `You are a wiki editor. A source document has been
|
||||
4. If a fact is also supported by the remaining source documents, KEEP it.
|
||||
5. If you are unsure whether a fact came from the deleted document, keep it as-is — do NOT add any review notes or annotations.
|
||||
6. Update or remove the "Source: {{.DeletedDocTitle}}" reference line if present.
|
||||
7. Keep [[wiki-link]] references ONLY if the slug appears in the <valid_wiki_links> list above. Remove any [[wiki-link]] whose slug is NOT in that list.
|
||||
7. Keep [[slug|name]] wiki-link references ONLY if the slug appears in the <valid_wiki_links> list above. Remove any [[slug|name]] whose slug is NOT in that list.
|
||||
8. Maintain the existing page structure, formatting style, and language.
|
||||
9. If after removing the deleted document's contributions the page becomes nearly empty, output just: "SUMMARY: (empty page)\n# [Title]\n\n*This page's primary source document was removed.*"
|
||||
10. Write in {{.Language}}.
|
||||
@@ -247,7 +247,7 @@ Use wiki_write_page to persist valuable knowledge artifacts. Write a page when:
|
||||
|
||||
#### Page Content Guidelines
|
||||
- Write in Markdown with proper heading hierarchy
|
||||
- Use [[entity/slug]] and [[concept/slug]] syntax to link to other wiki pages
|
||||
- Use [[slug|display name]] syntax to link to other wiki pages (e.g. [[entity/acme-corp|Acme Corp]])
|
||||
- Include a one-line summary in the first paragraph (used for index listings)
|
||||
- Cite source documents when possible
|
||||
- Keep pages focused: one topic/entity/concept per page
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.",
|
||||
|
||||
Reference in New Issue
Block a user