You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-23 17:26:44 +02:00
Format files with dprint
(#711)
The dprint formatter is a flexible system which will use sandboxed WebAssembly formatters to format our code (mostly: it calls out to `rustfmt` for Rust code). A particularly interesting feature is that dprint can format Rust code blocks in the Markdown files. However, before we turn that on, we need to have a way to normalize the Markdown text as it is extracted[1]. That is so that the word put into the translations is kept after the reformatting. [1]: https://github.com/google/mdbook-i18n-helpers/issues/19
This commit is contained in:
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -21,8 +21,8 @@ jobs:
|
|||||||
rustup default nightly
|
rustup default nightly
|
||||||
rustup component add rustfmt
|
rustup component add rustfmt
|
||||||
|
|
||||||
- name: Check Rust formatting
|
- name: Check formatting
|
||||||
run: cargo fmt --all -- --check
|
uses: dprint/check@v2.2
|
||||||
|
|
||||||
cargo:
|
cargo:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -24,5 +24,5 @@ information on using pull requests.
|
|||||||
|
|
||||||
## Community Guidelines
|
## Community Guidelines
|
||||||
|
|
||||||
This project follows [Google's Open Source Community
|
This project follows
|
||||||
Guidelines](https://opensource.google/conduct/).
|
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).
|
||||||
|
10
README.md
10
README.md
@ -31,6 +31,7 @@ trigger when going through the code samples. We hope to improve on this via
|
|||||||
## Building
|
## Building
|
||||||
|
|
||||||
The course is built using a few tools:
|
The course is built using a few tools:
|
||||||
|
|
||||||
- [mdbook](https://github.com/rust-lang/mdBook)
|
- [mdbook](https://github.com/rust-lang/mdBook)
|
||||||
- [mdbook-svgbob](https://github.com/boozook/mdbook-svgbob)
|
- [mdbook-svgbob](https://github.com/boozook/mdbook-svgbob)
|
||||||
- [mdbook-i18n-helpers](https://github.com/google/mdbook-i18n-helpers)
|
- [mdbook-i18n-helpers](https://github.com/google/mdbook-i18n-helpers)
|
||||||
@ -64,9 +65,10 @@ and zip exercises and add them to `book/html`. To build any of the translated
|
|||||||
versions of the course, run `MDBOOK_BOOK__LANGUAGE=xx mdbook build -d book/xx`
|
versions of the course, run `MDBOOK_BOOK__LANGUAGE=xx mdbook build -d book/xx`
|
||||||
where `xx` is the ISO 639 language code (e.g. `da` for the Danish translation).
|
where `xx` is the ISO 639 language code (e.g. `da` for the Danish translation).
|
||||||
[TRANSLATIONS.md](TRANSLATIONS.md) contains further instructions.
|
[TRANSLATIONS.md](TRANSLATIONS.md) contains further instructions.
|
||||||
|
|
||||||
## Contact
|
## Contact
|
||||||
|
|
||||||
For questions or comments, please contact [Martin
|
For questions or comments, please contact
|
||||||
Geisler](mailto:mgeisler@google.com) or start a [discussion on
|
[Martin Geisler](mailto:mgeisler@google.com) or start a
|
||||||
GitHub](https://github.com/google/comprehensive-rust/discussions). We would love
|
[discussion on GitHub](https://github.com/google/comprehensive-rust/discussions).
|
||||||
to hear from you.
|
We would love to hear from you.
|
||||||
|
24
STYLE.md
24
STYLE.md
@ -37,11 +37,17 @@ When showing Rust code, please use the same spacing as `rustfmt`: `3 * x`
|
|||||||
instead of `3*x`. However, feel free to remove newlines when it can make the
|
instead of `3*x`. However, feel free to remove newlines when it can make the
|
||||||
code more compact and easier to understand, e.g., you can use
|
code more compact and easier to understand, e.g., you can use
|
||||||
|
|
||||||
|
<!-- dprint-ignore-start -->
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct Person { name: String }
|
struct Person { name: String }
|
||||||
```
|
```
|
||||||
|
|
||||||
if you like.
|
<!-- dprint-ignore-end -->
|
||||||
|
|
||||||
|
if the `Person` struct is not important for your example. Please use this
|
||||||
|
sparingly: enclose the code block in `<!-- dprint-ignore-start -->` and
|
||||||
|
`<!-- dprint-ignore-start -->` to suppress warnings about the formatting.
|
||||||
|
|
||||||
## Speaker Notes
|
## Speaker Notes
|
||||||
|
|
||||||
@ -61,8 +67,8 @@ collapsed or removed entirely from the slide.
|
|||||||
|
|
||||||
## Translations
|
## Translations
|
||||||
|
|
||||||
This section is about what you write in the translation. We describe [how to
|
This section is about what you write in the translation. We describe
|
||||||
create or update translations elsewhere](TRANSLATIONS.md).
|
[how to create or update translations elsewhere](TRANSLATIONS.md).
|
||||||
|
|
||||||
When translating the course, please take the following into account:
|
When translating the course, please take the following into account:
|
||||||
|
|
||||||
@ -70,18 +76,18 @@ When translating the course, please take the following into account:
|
|||||||
easily understood in your language, please add the translated version after
|
easily understood in your language, please add the translated version after
|
||||||
the original name.
|
the original name.
|
||||||
|
|
||||||
- If the Rust Book has been [translated into your
|
- If the Rust Book has been
|
||||||
language](https://doc.rust-lang.org/book/appendix-06-translation.html), please
|
[translated into your language](https://doc.rust-lang.org/book/appendix-06-translation.html),
|
||||||
use the same vocabulary.
|
please use the same vocabulary.
|
||||||
|
|
||||||
- Be careful to preserve the Markdown syntax of the original text. Pay special
|
- Be careful to preserve the Markdown syntax of the original text. Pay special
|
||||||
attention to reference links in all their variations: `[foo][bar]`, `[foo][]`
|
attention to reference links in all their variations: `[foo][bar]`, `[foo][]`
|
||||||
(which means `[foo][foo]`), and `[foo]` (which also means `[foo][foo]`).
|
(which means `[foo][foo]`), and `[foo]` (which also means `[foo][foo]`).
|
||||||
|
|
||||||
As an example, if you translate `[foo]`, to `[FOO]`, you must also update the
|
As an example, if you translate `[foo]`, to `[FOO]`, you must also update the
|
||||||
corresponding link definition from `[foo]: https://example.net` to `[FOO]:
|
corresponding link definition from `[foo]: https://example.net` to
|
||||||
https://example.net`. If you forget to do this, you end up with a broken link
|
`[FOO]: https://example.net`. If you forget to do this, you end up with a
|
||||||
in the translation.
|
broken link in the translation.
|
||||||
|
|
||||||
- If you find mistakes or things that sound awkward in the original English
|
- If you find mistakes or things that sound awkward in the original English
|
||||||
text, please submit PRs to fix them! Fixing typos in the translation is great,
|
text, please submit PRs to fix them! Fixing typos in the translation is great,
|
||||||
|
@ -5,9 +5,9 @@ languages! We use the [Gettext] system for translations. This means that you
|
|||||||
don't modify the Markdown files directly: instead you modify `.po` files in a
|
don't modify the Markdown files directly: instead you modify `.po` files in a
|
||||||
`po/` directory. The `.po` files are small text-based translation databases.
|
`po/` directory. The `.po` files are small text-based translation databases.
|
||||||
|
|
||||||
> **Tip:** You should not edit the `.po` files by hand. Instead use a PO
|
> **Tip:** You should not edit the `.po` files by hand. Instead use a PO editor,
|
||||||
> editor, such as [Poedit](https://poedit.net/). There are also several online
|
> such as [Poedit](https://poedit.net/). There are also several online editors
|
||||||
> editors available. This will ensure that the file is encoded correctly.
|
> available. This will ensure that the file is encoded correctly.
|
||||||
|
|
||||||
There is a `.po` file for each language. They are named after the [ISO 639]
|
There is a `.po` file for each language. They are named after the [ISO 639]
|
||||||
language codes: Danish would go into `po/da.po`, Korean would go into
|
language codes: Danish would go into `po/da.po`, Korean would go into
|
||||||
@ -25,9 +25,9 @@ GNU Gettext utilities below.
|
|||||||
|
|
||||||
We use two helpers for the translations:
|
We use two helpers for the translations:
|
||||||
|
|
||||||
* `mdbook-xgettext`: This program extracts the English text. It is an mdbook
|
- `mdbook-xgettext`: This program extracts the English text. It is an mdbook
|
||||||
renderer.
|
renderer.
|
||||||
* `mdbook-gettext`: This program translates the book into a target language. It
|
- `mdbook-gettext`: This program translates the book into a target language. It
|
||||||
is an mdbook preprocessor.
|
is an mdbook preprocessor.
|
||||||
|
|
||||||
Install both helpers with:
|
Install both helpers with:
|
||||||
|
30
dprint.json
Normal file
30
dprint.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"lineWidth": 80,
|
||||||
|
"json": {},
|
||||||
|
"markdown": {
|
||||||
|
"textWrap": "always"
|
||||||
|
},
|
||||||
|
"toml": {},
|
||||||
|
"exec": {
|
||||||
|
"associations": "**/*.rs",
|
||||||
|
"rustfmt": "rustfmt --edition 2021",
|
||||||
|
"rustfmt.associations": "**/*.rs"
|
||||||
|
},
|
||||||
|
"includes": [
|
||||||
|
"**/*.json",
|
||||||
|
"**/*.md",
|
||||||
|
"**/*.rs",
|
||||||
|
"**/*.toml"
|
||||||
|
],
|
||||||
|
"excludes": [
|
||||||
|
"/src/",
|
||||||
|
"/third_party/",
|
||||||
|
"target/"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"https://plugins.dprint.dev/exec-0.3.5.json@d687dda57be0fe9a0088ccdaefa5147649ff24127d8b3ea227536c68ee7abeab",
|
||||||
|
"https://plugins.dprint.dev/json-0.17.2.wasm",
|
||||||
|
"https://plugins.dprint.dev/markdown-0.15.2.wasm",
|
||||||
|
"https://plugins.dprint.dev/toml-0.5.4.wasm"
|
||||||
|
]
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mdbook-exerciser"
|
name = "mdbook-exerciser"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["Andrew Walbran <qwandor@google.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
authors = ["Andrew Walbran <qwandor@google.com>"]
|
|
||||||
description = "A tool for extracting starter code for exercises from Markdown files."
|
|
||||||
repository = "https://github.com/google/comprehensive-rust"
|
repository = "https://github.com/google/comprehensive-rust"
|
||||||
|
description = "A tool for extracting starter code for exercises from Markdown files."
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.68"
|
anyhow = "1.0.68"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# exerciser
|
# exerciser
|
||||||
|
|
||||||
This is an mdBook renderer to generate templates for exercises from the Markdown source. Given a
|
This is an mdBook renderer to generate templates for exercises from the Markdown
|
||||||
Markdown file `example.md` with one or more sections like:
|
source. Given a Markdown file `example.md` with one or more sections like:
|
||||||
|
|
||||||
````markdown
|
````markdown
|
||||||
<!-- File src/main.rs -->
|
<!-- File src/main.rs -->
|
||||||
@ -22,5 +22,6 @@ and mdbook configuration in `book.toml` like:
|
|||||||
output-directory = "comprehensive-rust-exercises"
|
output-directory = "comprehensive-rust-exercises"
|
||||||
```
|
```
|
||||||
|
|
||||||
It will create a file `book/exerciser/comprehensive-rust-exercises/example/src/main.rs` with the
|
It will create a file
|
||||||
|
`book/exerciser/comprehensive-rust-exercises/example/src/main.rs` with the
|
||||||
appropriate contents.
|
appropriate contents.
|
||||||
|
Reference in New Issue
Block a user