Skip to content
Merged
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ jobs:
- name: Install mdBook and plugins (Windows)
if: runner.os == 'Windows'
run: .\scripts\install-tools.ps1


# Install Swift for testing Swift code examples in the book
- name: Setup Swift
uses: swift-actions/setup-swift@v2

- name: Build with mdBook
run: mdbook build ./better-code

Expand Down
11 changes: 11 additions & 0 deletions better-code/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ description = "A principled and rigorous approach to software development"
[build]
build-dir = "book"

# 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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the built-in mdbook support?

[output.html.code.hidelines]
swift = "#"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swift has # directives so might need a different character

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to work! Huge simplification, thanks for pointing that out.


[output.html]
git-repository-url = "https://github.com/stlab/better-code"
edit-url-template = "https://github.com/stlab/better-code/edit/main/better-code/src/{path}"
Expand All @@ -19,3 +24,9 @@ enable = true

[output.html.print]
enable = true

# Swift code example testing backend
Comment thread
nickpdemarco marked this conversation as resolved.
Outdated
# Tests all Swift code blocks during `mdbook build`
# See scripts/mdbook-swift-test.py for implementation
[output.swift-test]
command = "python3 ../../../scripts/mdbook-swift-test.py"
Loading
Loading