|
15 | 15 |
|
16 | 16 | def main():
|
17 | 17 | args = _parse_args()
|
18 |
| - for filename in args.input: |
| 18 | + for filename in args.inputs: |
19 | 19 | _do_file(args, Path(filename))
|
20 | 20 |
|
21 | 21 |
|
@@ -43,27 +43,27 @@ def _do_file(args, input_file):
|
43 | 43 | sys.exit(1)
|
44 | 44 |
|
45 | 45 | # Parse markdown and extract code blocks
|
46 |
| - _report(args.verbose, f"Processing {input_file}...") |
| 46 | + _report(args.verbose > 0, f"Processing {input_file}...") |
47 | 47 | code_blocks = _parse_md(content)
|
48 |
| - _report(args.verbose, f"- Found {len(code_blocks)} code blocks") |
| 48 | + _report(args.verbose > 1, f"- Found {len(code_blocks)} code blocks") |
49 | 49 |
|
50 | 50 | # Execute code blocks and collect results
|
51 | 51 | execution_results = []
|
52 | 52 | figure_counter = 0
|
53 | 53 | for i, block in enumerate(code_blocks):
|
54 |
| - _report(args.verbose, f"- Executing block {i + 1}/{len(code_blocks)}") |
| 54 | + _report(args.verbose > 1, f"- Executing block {i + 1}/{len(code_blocks)}") |
55 | 55 | figure_counter, result = _run_code(block["code"], args.outdir, stem, figure_counter)
|
56 | 56 | execution_results.append(result)
|
57 |
| - _report(result["error"], f" - Warning: block {i + 1} had an error") |
58 |
| - _report(result["images"], f" - Generated {len(result['images'])} image(s)") |
| 57 | + _report(args.verbose > 0 and bool(result["error"]), f" - Warning: block {i + 1} had an error") |
| 58 | + _report(args.verbose > 1 and bool(result["images"]), f" - Generated {len(result['images'])} image(s)") |
59 | 59 |
|
60 | 60 | # Generate and save output
|
61 | 61 | content = _generate_markdown(args, content, code_blocks, execution_results, args.outdir)
|
62 | 62 | try:
|
63 | 63 | with open(output_file, "w", encoding="utf-8") as f:
|
64 | 64 | f.write(content)
|
65 |
| - _report(args.verbose, f"- Output written to {output_file}") |
66 |
| - _report(any(result["images"] for result in execution_results), f"- Images saved to {args.outdir}") |
| 65 | + _report(args.verbose > 1, f"- Output written to {output_file}") |
| 66 | + _report(args.verbose > 1 and any(result["images"] for result in execution_results), f"- Images saved to {args.outdir}") |
67 | 67 | except Exception as e:
|
68 | 68 | print(f"Error writing output file: {e}", file=sys.stderr)
|
69 | 69 | sys.exit(1)
|
@@ -149,10 +149,10 @@ def _generate_markdown(args, content, code_blocks, execution_results, output_dir
|
149 | 149 | def _parse_args():
|
150 | 150 | """Parse command-line arguments."""
|
151 | 151 | parser = argparse.ArgumentParser(description="Process Markdown files with code blocks")
|
152 |
| - parser.add_argument("input", nargs="+", help="Input .md file") |
| 152 | + parser.add_argument("inputs", nargs="+", help="Input .md files") |
153 | 153 | parser.add_argument("--inline", action="store_true", help="Inline HTML in .md")
|
154 | 154 | parser.add_argument("--outdir", type=Path, help="Output directory")
|
155 |
| - parser.add_argument("--verbose", action="store_true", help="Report progress") |
| 155 | + parser.add_argument("--verbose", type=int, default=0, help="Integer verbosity level") |
156 | 156 | return parser.parse_args()
|
157 | 157 |
|
158 | 158 |
|
|
0 commit comments