Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion scripts/reference-generation/weave/generate_python_sdk_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ def fix_code_fence_indentation(text: str) -> str:
return "\n".join(result_lines)


def convert_source_badges_to_buttons(content: str) -> str:
"""Convert shields.io source badge images to SourceLink components.

This avoids Mintlify's image lightbox from triggering when clicking source links.

Converts:
<a href="..."><img ... src="...badge/-source..." ></a>
To:
<SourceLink url="..." />
"""
# Pattern matches both self-closing (/>) and non-self-closing (>) img tags
# lazydocs generates non-self-closing tags: <img ... >
pattern = r'<a href="(https://github\.com/wandb/weave/blob/[^"]+)">\s*<img[^>]*src="https://img\.shields\.io/badge/-source[^"]*"[^>]*/?>\s*</a>'
replacement = r'<SourceLink url="\1" />'
return re.sub(pattern, replacement, content)


def convert_docusaurus_to_mintlify(content: str, module_name: str) -> str:
"""Convert Docusaurus markdown to Mintlify MDX format."""
# Remove the sidebar_label frontmatter (Mintlify uses title)
Expand All @@ -190,6 +207,8 @@ def convert_docusaurus_to_mintlify(content: str, module_name: str) -> str:
description: "Python SDK reference for {module_name}"
---

import {{ SourceLink }} from '/snippets/en/_includes/source-link.mdx';

"""
content = frontmatter + content

Expand All @@ -199,7 +218,7 @@ def convert_docusaurus_to_mintlify(content: str, module_name: str) -> str:
def generate_module_docs(module, module_name: str, src_root_path: str, version: str = "master") -> str:
"""Generate documentation for a single module."""
# Use the specific version tag for source links
src_url = f"https://github.com/wandb/weave/blob/{version}"
src_url = f"https://github.com/wandb/weave/blob/v{version}"
if version == "latest":
src_url = "https://github.com/wandb/weave/blob/master"

Expand Down Expand Up @@ -371,6 +390,9 @@ def fix_parameter_lists(text):

content = fix_parameter_lists(content)

# Convert source badge images to text buttons (avoids Mintlify lightbox issue)
content = convert_source_badges_to_buttons(content)

# Convert to Mintlify format
content = convert_docusaurus_to_mintlify(content, module_name)

Expand Down
32 changes: 32 additions & 0 deletions snippets/button-links.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,35 @@
background-color: rgba(39, 39, 42, 0.8);
border-color: rgba(63, 63, 70, 1);
}

/* Compact source link for SDK reference docs */
.source-link {
float: right;
display: inline-block;
padding: 2px 8px;
border: 1px solid rgba(230, 228, 224, 0.7);
border-radius: 6px;
font-size: 12px;
font-weight: 500;
color: rgb(87, 85, 81);
background-color: rgba(255, 255, 255, 0.5);
text-decoration: none;
transition: all 0.15s ease;
}

.source-link:hover {
background-color: rgba(255, 255, 255, 0.8);
border-color: rgba(230, 228, 224, 1);
text-decoration: none;
}

.dark .source-link {
color: rgb(214, 211, 209);
background-color: rgba(39, 39, 42, 0.5);
border: 1px solid rgba(63, 63, 70, 0.7);
}

.dark .source-link:hover {
background-color: rgba(39, 39, 42, 0.8);
border-color: rgba(63, 63, 70, 1);
}
10 changes: 10 additions & 0 deletions snippets/en/_includes/source-link.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const SourceLink = ({ url }) => (
<a
href={url}
target="_blank"
rel="noopener noreferrer"
className="source-link"
>
Source
</a>
);