You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importosimportre# DirectoriesSNIPPETS_DIR='brute_force'# Adjust this if you have a different root directory for snippetsDOCS_DIR=os.path.join('website', 'docs') # Directory where the Markdown files are located# Regular expression pattern to find ${{path_to_file}}SNIPPET_PATTERN=r'\$\{\{(.*?)\}\}'defreplace_snippets_in_file(file_path):
"""Replaces snippet references in a Markdown file with the actual code content."""withopen(file_path, 'r', encoding='utf-8') asfile:
content=file.read()
# Find all snippet references in the filesnippets=re.findall(SNIPPET_PATTERN, content)
forsnippet_pathinsnippets:
snippet_full_path=os.path.join(SNIPPETS_DIR, snippet_path)
ifos.path.exists(snippet_full_path):
withopen(snippet_full_path, 'r', encoding='utf-8') assnippet_file:
snippet_code=snippet_file.read()
# Replace the reference with the actual code contentcontent=content.replace(f'${{{{{snippet_path}}}}}', f'```cpp\n{snippet_code}\n```')
else:
print(f"Warning: The file {snippet_full_path} does not exist.")
# Save the modified content back to the same filewithopen(file_path, 'w', encoding='utf-8') asfile:
file.write(content)
defreplace_snippets_in_docs():
"""Processes all Markdown files within DOCS_DIR and replaces snippet references."""forroot, dirs, filesinos.walk(DOCS_DIR):
forfile_nameinfiles:
iffile_name.endswith('.md'):
file_path=os.path.join(root, file_name)
replace_snippets_in_file(file_path)
print(f"Processed: {file_path}")
if__name__=='__main__':
replace_snippets_in_docs()
"scripts": {
"prebuild": "python replace_snippets.py", // This runs before the build process"build": "docusaurus build", // This is the main build command"postbuild": "python replace_snippets.py'"// This runs after the build process
}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: