Skip to content

Commit

Permalink
test: add markdown example syntax extraction tool
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Alpe <richard@bit42.se>
  • Loading branch information
rical committed Nov 28, 2023
1 parent e26ff79 commit e391aa1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions doc/md-to-cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3

import sys

def process_markdown(file_path, prompt):
blocks = []
block = []

with open(file_path, 'r') as file:
for line in file:
if line.lstrip().startswith(prompt):
line = line.strip()
pos = line.find('>')
if pos == -1 or pos == len(line) - 1:
continue

line = line[pos + 2:]
block.append(line)
elif block:
blocks.append(block.copy())
block = []

return blocks

def main():
if len(sys.argv) != 2:
print("Usage: md-to-cli.py MARKDOWN-FILE")
sys.exit(1)

file_path = sys.argv[1]
blocks = process_markdown(file_path, "admin@example:")

for block in blocks:
print(f"")
for line in block:
line = line.replace("eth0", "x2")
line = line.replace("eth1", "x3")
print(line)

if __name__ == "__main__":
main()

0 comments on commit e391aa1

Please sign in to comment.