Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MDX callout conversion & notebook code closure error #295

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 3 additions & 1 deletion notebook/agentchat_graph_rag_neo4j.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"\n",
"```bash\n",
"pip install ag2[neo4j]\n",
"```"
"```",
":::\n",
"````"
]
},
{
Expand Down
35 changes: 26 additions & 9 deletions website/process_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,33 @@ def replace_callout(match: re.Match) -> str:
"""Helper function to format individual callout blocks."""
callout_type = match.group(1)
inner_content = match.group(2).strip()
return f"""
<div class="{callout_type}">
<{callout_types[callout_type]}>
{inner_content}
</{callout_types[callout_type]}>
</div>
"""

pattern = re.compile(
# Matches optional opening fences:
# - 3 or 4 backticks (` ``` ` or ` ```` `),
# - optionally followed by "mdx-code-block",
# - optionally followed by "{=mdx}",
# - optional whitespace and line ending.
r"(?:`{3,4}(?:\s*mdx-code-block)?(?:\s*\{=mdx\})?" r"|mdx-code-block(?:\s*\{=mdx\})?)?\s*\r?\n?"
# Matches the opening line of the callout (e.g., ":::info").
r":::(\w+(?:\s+\w+)?)\r?\n"
# Matches the content inside the callout, capturing until the closing line.
r"(.*?)" # Uses non-greedy matching to capture content.
# Matches the closing line (e.g., ":::").
r"\r?\n:::\r?\n"
# Matches optional closing fences (same as the opening fences).
r"(?:`{3,4}(?:\s*mdx-code-block)?(?:\s*\{=mdx\})?" r"|mdx-code-block(?:\s*\{=mdx\})?)?\s*\r?\n?",
flags=re.DOTALL, # DOTALL allows `.` to match newline characters.
)

return f"""<div class="{callout_type}">
<{callout_types[callout_type]}>
{inner_content}
</{callout_types[callout_type]}>
</div>"""

# Pattern matches: ````mdx-code-block\n:::[type]\n[content]\n:::\n````
pattern = r"````mdx-code-block\n:::(\w+(?:\s+\w+)?)\n(.*?)\n:::\n````"
return re.sub(pattern, replace_callout, content, flags=re.DOTALL)
return pattern.sub(replace_callout, content)


def convert_mdx_image_blocks(content: str, rendered_mdx: Path, website_dir: Path) -> str:
Expand Down
Loading