From 95532537a650146d74a951b97bd8a014f151092f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20Tapanyi=C4=9Fit?= Date: Fri, 27 Dec 2024 03:04:19 +0300 Subject: [PATCH 1/4] feat: add function to convert MDX callout blocks into custom HTML syntax --- website/process_notebooks.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/website/process_notebooks.py b/website/process_notebooks.py index b5ef536ff5..4bf0aeedd3 100755 --- a/website/process_notebooks.py +++ b/website/process_notebooks.py @@ -378,16 +378,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""" +
+ <{callout_types[callout_type]}> + {inner_content} + +
+ """ + + 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"""
- <{callout_types[callout_type]}> - {inner_content} - -
""" - - # 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: From 6885a2be9a0d436c16e60aa61e583804cdb33616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20Tapanyi=C4=9Fit?= <49999308+hakantapanyigit@users.noreply.github.com> Date: Fri, 27 Dec 2024 03:23:09 +0300 Subject: [PATCH 2/4] Update process_notebooks.py --- website/process_notebooks.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/website/process_notebooks.py b/website/process_notebooks.py index 4bf0aeedd3..af7618fb04 100755 --- a/website/process_notebooks.py +++ b/website/process_notebooks.py @@ -379,12 +379,12 @@ def replace_callout(match: re.Match) -> str: callout_type = match.group(1) inner_content = match.group(2).strip() return f""" -
- <{callout_types[callout_type]}> - {inner_content} - -
- """ +
+ <{callout_types[callout_type]}> + {inner_content} + +
+""" pattern = re.compile( # Matches optional opening fences: From d8c40c286c6c49c99dc4f69f5bab237c11c0cdff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20Tapanyi=C4=9Fit?= <49999308+hakantapanyigit@users.noreply.github.com> Date: Fri, 27 Dec 2024 03:35:38 +0300 Subject: [PATCH 3/4] Update process_notebooks.py --- website/process_notebooks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/process_notebooks.py b/website/process_notebooks.py index af7618fb04..1be503597f 100755 --- a/website/process_notebooks.py +++ b/website/process_notebooks.py @@ -380,9 +380,9 @@ def replace_callout(match: re.Match) -> str: inner_content = match.group(2).strip() return f"""
- <{callout_types[callout_type]}> - {inner_content} - +<{callout_types[callout_type]}> +{inner_content} +
""" From 0bb17e4ef031e94125901ed9548d42bf6f05def6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20Tapanyi=C4=9Fit?= <49999308+hakantapanyigit@users.noreply.github.com> Date: Fri, 27 Dec 2024 03:41:31 +0300 Subject: [PATCH 4/4] Update agentchat_graph_rag_neo4j.ipynb --- notebook/agentchat_graph_rag_neo4j.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/notebook/agentchat_graph_rag_neo4j.ipynb b/notebook/agentchat_graph_rag_neo4j.ipynb index b9ef0735d8..9bc7d9ff0b 100644 --- a/notebook/agentchat_graph_rag_neo4j.ipynb +++ b/notebook/agentchat_graph_rag_neo4j.ipynb @@ -15,7 +15,9 @@ "\n", "```bash\n", "pip install ag2[neo4j]\n", - "```" + "```", + ":::\n", + "````" ] }, {