feat(phase2): 승인/거부 버튼 + bridge 프로토콜 + 테이블 변환 수정 + 중복 메시지 해결
This commit is contained in:
27
parser.py
27
parser.py
@@ -87,10 +87,21 @@ def md_to_discord_text(content: str, max_length: int = 1900) -> list[str]:
|
||||
output_lines = []
|
||||
in_mermaid = False
|
||||
in_code_block = False
|
||||
table_buffer = []
|
||||
|
||||
def flush_table():
|
||||
"""Convert buffered table rows to a code block."""
|
||||
if table_buffer:
|
||||
output_lines.append("```")
|
||||
for row in table_buffer:
|
||||
output_lines.append(row)
|
||||
output_lines.append("```")
|
||||
table_buffer.clear()
|
||||
|
||||
for line in lines:
|
||||
# Skip mermaid blocks
|
||||
if re.match(r'^```mermaid', line):
|
||||
flush_table()
|
||||
in_mermaid = True
|
||||
output_lines.append("*(mermaid 다이어그램 생략)*")
|
||||
continue
|
||||
@@ -101,6 +112,7 @@ def md_to_discord_text(content: str, max_length: int = 1900) -> list[str]:
|
||||
|
||||
# Track code blocks
|
||||
if re.match(r'^```', line) and not in_mermaid:
|
||||
flush_table()
|
||||
in_code_block = not in_code_block
|
||||
output_lines.append(line)
|
||||
continue
|
||||
@@ -111,8 +123,21 @@ def md_to_discord_text(content: str, max_length: int = 1900) -> list[str]:
|
||||
|
||||
# Skip HTML comments
|
||||
if re.match(r'^\s*<!--.*-->\s*$', line):
|
||||
flush_table()
|
||||
continue
|
||||
|
||||
# Detect table rows (lines with | separators)
|
||||
if re.match(r'^\s*\|', line):
|
||||
# Skip separator rows (|---|---|)
|
||||
if re.match(r'^\s*\|[\s\-:|]+\|\s*$', line):
|
||||
continue
|
||||
# Clean up table row
|
||||
cells = [c.strip() for c in line.strip().strip('|').split('|')]
|
||||
table_buffer.append(" ".join(cells))
|
||||
continue
|
||||
else:
|
||||
flush_table()
|
||||
|
||||
# Skip alert syntax but keep content
|
||||
alert_match = re.match(r'>\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]', line)
|
||||
if alert_match:
|
||||
@@ -153,6 +178,8 @@ def md_to_discord_text(content: str, max_length: int = 1900) -> list[str]:
|
||||
# Pass through everything else
|
||||
output_lines.append(line)
|
||||
|
||||
flush_table()
|
||||
|
||||
# Join and split into chunks
|
||||
full_text = "\n".join(output_lines).strip()
|
||||
return split_text(full_text, max_length)
|
||||
|
||||
Reference in New Issue
Block a user