Conversation
|
|
| # Preprocessor to hide `# ` lines in Swift code blocks (like mdbook does for Rust) | ||
| # Only strips lines for HTML output; swift-test backend sees the full code | ||
| [preprocessor.swift-hidden] | ||
| command = "python3 scripts/mdbook-swift-hidden.py" |
There was a problem hiding this comment.
Can you use the built-in mdbook support?
[output.html.code.hidelines]
swift = "#"
There was a problem hiding this comment.
Swift has # directives so might need a different character
There was a problem hiding this comment.
It seems to work! Huge simplification, thanks for pointing that out.
| [output.html.print] | ||
| enable = true | ||
|
|
||
| # Swift code example testing backend |
There was a problem hiding this comment.
This line isn't adding anything
| result_lines = [] | ||
| in_swift_block = False | ||
|
|
||
| for line in content.split("\n"): |
There was a problem hiding this comment.
Raw loop should be algorithms and/or list comprehensions
| """Process all chapters in the book, stripping hidden lines.""" | ||
|
|
||
| def process_item(item: dict) -> dict: | ||
| """Recursively process book items.""" |
|
|
||
|
|
||
| def process_book(book: dict) -> dict: | ||
| """Process all chapters in the book, stripping hidden lines.""" |
| # We support all renderers, but only modify content for html | ||
| sys.exit(0) |
|
I got partway through reading the actual code which began to smell sloppy, and when I reached the point that it decided there was a case it wasn't going to support, and it would just exit with success (the output is not HTML), that was an almost certain sign that this was generated with AI and not carefully reviewed. Please forgive me if I've gotten that wrong, but Everything we check in here, even tooling should uphold the principles of better code. that includes real meaningful contract documentation for example. |
|
Thanks for that feedback @dabrahams - I'll take a closer look and address what you've mentioned. In hindsight I should have made this a draft PR; it wasn't my intention to request a review, just share progress. |
This PR adds support for checking Swift examples, copying the Rust-mdbook experience as much as possible: lines beginning with
#will be omitted from the book output, but are used to compile the examples. Additionally, as a preprocessor step, all{ ... }blocks are replaced with{ fatalError() }.A block marked with
swift,ignorewill not be built.The examples can be checked with
mdbook build. Several examples were slightly changed to pass the check. Without the two#lines above, the following error is emitted.