Skip to content

Commit 5b7deb0

Browse files
committed
fixed the escaping
1 parent 2583bc1 commit 5b7deb0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

dev/generate_cli_docs.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ def clean_usage_line(usage: str) -> str:
3232
return usage.replace("Usage: cli ", "Usage: cocoindex ")
3333

3434

35+
def escape_html_tags(text: str) -> str:
36+
"""Escape HTML-like tags in text to prevent MDX parsing issues, but preserve them in code blocks."""
37+
import re
38+
39+
# Split text into code blocks and regular text
40+
# Pattern matches: `code content` (inline code blocks)
41+
parts = re.split(r"(`[^`]*`)", text)
42+
43+
result = []
44+
for i, part in enumerate(parts):
45+
if i % 2 == 0:
46+
# Even indices are regular text, escape HTML tags
47+
result.append(part.replace("<", "&lt;").replace(">", "&gt;"))
48+
else:
49+
# Odd indices are code blocks, preserve as-is
50+
result.append(part)
51+
52+
return "".join(result)
53+
54+
3555
def format_options_section(help_text: str) -> str:
3656
"""Extract and format the options section."""
3757
lines = help_text.split("\n")
@@ -66,6 +86,7 @@ def format_options_section(help_text: str) -> str:
6686
# Save previous option if exists
6787
if current_option is not None:
6888
desc = " ".join(current_description).strip()
89+
desc = escape_html_tags(desc) # Escape HTML tags for MDX compatibility
6990
formatted_options.append(f"| `{current_option}` | {desc} |")
7091

7192
# Remove the leading 2 spaces
@@ -91,6 +112,7 @@ def format_options_section(help_text: str) -> str:
91112
# Add last option
92113
if current_option is not None:
93114
desc = " ".join(current_description).strip()
115+
desc = escape_html_tags(desc) # Escape HTML tags for MDX compatibility
94116
formatted_options.append(f"| `{current_option}` | {desc} |")
95117

96118
if formatted_options:
@@ -157,7 +179,8 @@ def extract_description(help_text: str) -> str:
157179
elif in_description and line.strip():
158180
description_lines.append(line.strip())
159181

160-
return "\n\n".join(description_lines) if description_lines else ""
182+
description = "\n\n".join(description_lines) if description_lines else ""
183+
return escape_html_tags(description) # Escape HTML tags for MDX compatibility
161184

162185

163186
def generate_command_docs(docs: List[Dict[str, Any]]) -> str:

docs/docs/core/cli-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Usage: cocoindex server [OPTIONS] APP_TARGET
152152
| `-a, --address TEXT` | The address to bind the server to, in the format of IP:PORT. If unspecified, the address specified in COCOINDEX_SERVER_ADDRESS will be used. |
153153
| `-c, --cors-origin TEXT` | The origins of the clients (e.g. CocoInsight UI) to allow CORS from. Multiple origins can be specified as a comma-separated list. e.g. `https://cocoindex.io,http://localhost:3000`. Origins specified in COCOINDEX_SERVER_CORS_ORIGINS will also be included. |
154154
| `-ci, --cors-cocoindex` | Allow https://cocoindex.io to access the server. |
155-
| `-cl, --cors-local INTEGER` | Allow http://localhost:<port> to access the server. |
155+
| `-cl, --cors-local INTEGER` | Allow http://localhost:&lt;port&gt; to access the server. |
156156
| `-L, --live-update` | Continuously watch changes from data sources and apply to the target index. |
157157
| `--setup` | Automatically setup backends for the flow if it's not setup yet. |
158158
| `--reexport` | Reexport to targets even if there's no change. |

0 commit comments

Comments
 (0)