First commit
This commit is contained in:
34
utils/texttools.py
Normal file
34
utils/texttools.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# utils/texttools.py
|
||||
import re
|
||||
from typing import List
|
||||
|
||||
def split_display_sections(text: str) -> List[dict]:
|
||||
pattern = re.compile(r"^=+\s*display ([a-zA-Z0-9\-\_ ]+)\s*=+$")
|
||||
sections = []
|
||||
current_section = None
|
||||
current_content = []
|
||||
|
||||
for line in text.splitlines():
|
||||
match = pattern.match(line.strip())
|
||||
if match:
|
||||
if current_section:
|
||||
sections.append({
|
||||
"object": "raw_section",
|
||||
"section": current_section.strip(),
|
||||
"summary": f"Bloc issu de la commande display {current_section.strip()}",
|
||||
"content": "\n".join(current_content).strip()
|
||||
})
|
||||
current_section = match.group(1)
|
||||
current_content = []
|
||||
elif current_section:
|
||||
current_content.append(line)
|
||||
|
||||
if current_section:
|
||||
sections.append({
|
||||
"object": "raw_section",
|
||||
"section": current_section.strip(),
|
||||
"summary": f"Bloc issu de la commande display {current_section.strip()}",
|
||||
"content": "\n".join(current_content).strip()
|
||||
})
|
||||
|
||||
return sections
|
||||
Reference in New Issue
Block a user