Skip to content

Commit b2d1719

Browse files
committed
fix: Reduce the literate code
1 parent 72ea7a7 commit b2d1719

2 files changed

Lines changed: 10 additions & 30 deletions

File tree

‎Fable.Literate/App.fs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,7 @@ For example, the extractSymbol function in F# generates this Python:
395395

396396
(*** include-python: extractSymbol ***)
397397

398-
(**
399-
## Main Entry Point
400-
401-
Read the input file, convert it, and print the result:
402-
*)
403-
398+
(*** hide ***)
404399
/// Gets the value following a flag argument (e.g., --python-file path.py).
405400
let getFlagValue (flag: string) (args: string[]) : string option =
406401
// Find the index of the flag in args
@@ -423,6 +418,12 @@ let getPositionalArgs (args: string[]) : string[] =
423418
// Extract just the argument strings
424419
|> Array.map snd
425420

421+
(**
422+
## Main Entry Point
423+
424+
Read the input file, convert it, and print the result:
425+
*)
426+
426427
/// Main entry point. Converts a literate F# file to Markdown.
427428
/// Use --increase-headers flag to bump all header levels by one.
428429
/// Use --python-file <path> to enable include-python directives.

‎docs/blogpost.md‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Introduction to Fable.Python
22

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*
44

55
> This post is part of the [F# Advent Calendar
66
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:
36563656
Read the input file, convert it, and print the result:
36573657

36583658
```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-
36813659
/// Main entry point. Converts a literate F# file to Markdown.
36823660
/// Use --increase-headers flag to bump all header levels by one.
36833661
/// Use --python-file <path> to enable include-python directives.
@@ -3726,7 +3704,8 @@ python output/Fable.Literate/app.py chapters/introduction.fs > docs/introduction
37263704
```
37273705

37283706
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.
37303709

37313710
## Summary
37323711

0 commit comments

Comments
 (0)