your regex logic in snippet() is brittle:
Hi there your regex logic in snippet() looks like more brittle:
p= re.compile("^#+") m= p.search(section_name)
some thing like these it is used
*you're treating section_name(a string passed by the user , like "## section") as if it's markdown content. but in reality , we want to find the section header inside the file , not check the input string format , also headers and spacing , which often fails.
The change that can be done 👍
1. Accept just the plain title text(e.g " Introduction") instead of forcing "## Introduction" .
2. Build the regex dynamically to match headings in the file.
for example
@env.macro def snippet(file_path, section_name, num_sections=1): root = env.variables['config']['docs_dir'] full_path = os.path.join(root, file_path)
with open(full_path, 'r') as myfile:
content = myfile.read()
# Match a heading that contains the given text
heading_pattern = re.compile(r'^(#+)\s+' + re.escape(section_name) + r'\s*$', re.MULTILINE)
start = heading_pattern.search(content)
if not start:
return f"Section '{section_name}' not found in {file_path}"
section_level = len(start.group(1)) # number of '#' determines level
start_index = start.end()
# Find the next heading of same or higher level
next_heading_pattern = re.compile(r'^(#{1,' + str(section_level) + r'})\s+', re.MULTILINE)
following = [m for m in next_heading_pattern.finditer(content[start_index:])]
if len(following) == 0 or (num_sections - 1) >= len(following):
result = content[start.start():]
else:
end = following[num_sections - 1]
result = content[start.start(): start_index + end.start()]
return result
- These change can make the macro more robust and user-friendly.
please let me know i am right on wrong about these concept
Hey @shashanknr172-beep
Thank you for reporting this issue. Maybe I'm missing something, but I cannot completely understand context of this issue. Could you please provide more details and context?
Hi, Sure i can provide more details on it . Currently, the snippet() macro expects the section_name argument to be passed with markdown syntax (for example, "## Introduction"). This makes the regex brittle because it tightly couples the input format to the markdown heading style.
In practice, users typically want to extract a section by its logical title (e.g., "Introduction") rather than remembering or specifying the exact markdown prefix. This becomes error-prone when files have inconsistent heading levels (#, ##, etc.) or spacing differences.
improves can be made on my basis could be 1.Separating content from presentation — accepting only the plain title text instead of markdown syntax.
2.Dynamically building a regex that automatically matches headings of any level that contain the specified title, handling spacing and formatting variations gracefully.
3.Ensuring future scalability — it will continue to work even if the markdown structure changes (like promoting ## to ###).
**the goal is to make the macro more user-friendly, flexible, and less error-prone, while keeping full backward compatibility.
I hope these has given the enough explanation regarding these concept and i also think my way of feedback with concept is correct , if any issue or my concept is wrong please let me know so that i can learn or gain more knowledge about the practical concepts.
Thankyou
Hey @shashanknr172-beep
Thanks for the clarification you provided. The think is that it isn't the proper repo to raise an issue in. The logic you provided is located in https://github.com/conductor-oss/conductor repository. Please raise an issue in the repo provided
Thank you!
ok