|
1 | 1 | # Introduction to Fable.Python |
2 | 2 |
|
3 | | -*Generated on 2025-12-22 13:28 UTC using Fable v5.0.0-alpha.21* |
| 3 | +*Generated on 2025-12-22 14:44 UTC using Fable v5.0.0-alpha.21* |
4 | 4 |
|
5 | 5 | > This post is part of the [F# Advent Calendar |
6 | 6 | 2025](https://sergeytihon.com/2025/11/03/f-advent-calendar-in-english-2025/). Thank you, Sergey Tihon, for organizing |
@@ -3656,28 +3656,6 @@ def extract_symbol(symbol: str, lines: Array[str]) -> str | None: |
3656 | 3656 | Read the input file, convert it, and print the result: |
3657 | 3657 |
|
3658 | 3658 | ```fsharp |
3659 | | -/// Gets the value following a flag argument (e.g., --python-file path.py). |
3660 | | -let getFlagValue (flag: string) (args: string[]) : string option = |
3661 | | - // Find the index of the flag in args |
3662 | | - args |
3663 | | - |> Array.tryFindIndex ((=) flag) |
3664 | | - // Return the next argument if it exists |
3665 | | - |> Option.bind (fun i -> if i + 1 < args.Length then Some args.[i + 1] else None) |
3666 | | -
|
3667 | | -/// Extracts positional arguments (file paths) from command line args. |
3668 | | -/// Filters out flags (--foo) and their values (--python-file path.py). |
3669 | | -let getPositionalArgs (args: string[]) : string[] = |
3670 | | - let isFlag (arg: string) = arg.StartsWith "--" |
3671 | | - let isValueOfFlag i = i > 0 && args.[i - 1] = "--python-file" |
3672 | | -
|
3673 | | - // Pair each argument with its index |
3674 | | - args |
3675 | | - |> Array.indexed |
3676 | | - // Keep only non-flags that aren't values of flags |
3677 | | - |> Array.filter (fun (i, arg) -> not (isFlag arg) && not (isValueOfFlag i)) |
3678 | | - // Extract just the argument strings |
3679 | | - |> Array.map snd |
3680 | | -
|
3681 | 3659 | /// Main entry point. Converts a literate F# file to Markdown. |
3682 | 3660 | /// Use --increase-headers flag to bump all header levels by one. |
3683 | 3661 | /// Use --python-file <path> to enable include-python directives. |
@@ -3726,7 +3704,8 @@ python output/Fable.Literate/app.py chapters/introduction.fs > docs/introduction |
3726 | 3704 | ``` |
3727 | 3705 |
|
3728 | 3706 | That's it! A complete literate programming converter in under 200 lines of F#, |
3729 | | -compiled to Python, processing this very blog post. |
| 3707 | +compiled to Python, processing this very blog post. See |
| 3708 | +the [full source](https://github.com/cardamomcode/fable-python/tree/main/Fable.Literate) on GitHub for all the details. |
3730 | 3709 |
|
3731 | 3710 | ## Summary |
3732 | 3711 |
|
|
0 commit comments