Skip to content

Commit

Permalink
update original
Browse files Browse the repository at this point in the history
  • Loading branch information
funkill committed Dec 4, 2024
1 parent 77f1d6b commit 1b3bab9
Show file tree
Hide file tree
Showing 120 changed files with 1,520 additions and 1,500 deletions.
2 changes: 2 additions & 0 deletions rustbook-en/.git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ran dprint fmt on the repo
3a30e4c1
2 changes: 2 additions & 0 deletions rustbook-en/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ target
tmp

.nova
.vscode
.zed
47 changes: 23 additions & 24 deletions rustbook-en/ADMIN_TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ occasional maintenance tasks.
does)
- Inspect the changes (by looking at the files changed according to git) and
their effects (by looking at the files in `tmp/book-before` and
`tmp/book-after`) and commit them if they look good
`tmp/book-after`) and commit them if they look good
- Grep for `manual-regeneration` and follow the instructions in those places to
update output that cannot be generated by a script

Expand All @@ -36,9 +36,8 @@ create a new release artifact, for example if there have been code changes due
to edits or due to updating Rust and `rustfmt`, do the following:

- Create a git tag for the release and push it to GitHub, or create a new tag
by going to the GitHub UI, [drafting a new
release](https://github.com/rust-lang/book/releases/new), and entering a new
tag instead of selecting an existing tag
by going to the GitHub UI, [drafting a new release](https://github.com/rust-lang/book/releases/new), and entering a new
tag instead of selecting an existing tag
- Run `cargo run --bin release_listings`, which will generate
`tmp/listings.tar.gz`
- Upload `tmp/listings.tar.gz` in the GitHub UI for the draft release
Expand All @@ -54,50 +53,50 @@ extracted into a file. To do that:
- Find where the new listing should go in the `listings` directory.
- There is one subdirectory for each chapter
- Numbered listings should use `listing-[chapter num]-[listing num]` for
their directory names.
their directory names.
- Listings without a number should start with `no-listing-` followed by a
number that indicates its position in the chapter relative to the other
listings without numbers in the chapter, then a short description that
someone could read to find the code they're looking for.
number that indicates its position in the chapter relative to the other
listings without numbers in the chapter, then a short description that
someone could read to find the code they're looking for.
- Listings used only for displaying the output of the code (for example, when
we say "if we had written x instead of y, we would get this compiler
error:" but we don't actually show code x) should be named with
`output-only-` followed by a number that indicates its position in the
chapter relative to the other listings used only for output, then a short
description that authors or contributors could read to find the code
they're looking for.
we say "if we had written x instead of y, we would get this compiler
error:" but we don't actually show code x) should be named with
`output-only-` followed by a number that indicates its position in the
chapter relative to the other listings used only for output, then a short
description that authors or contributors could read to find the code
they're looking for.
- **Remember to adjust surrounding listing numbers as appropriate!**
- Create a full Cargo project in that directory, either by using `cargo new` or
copying another listing as a starting point.
- Add the code and any surrounding code needed to create a full working example.
- If you only want to show part of the code in the file, use anchor comments
(`// ANCHOR: some_tag` and `// ANCHOR_END: some_tag`) to mark the parts of
the file you want to show.
the file you want to show.
- For Rust code, use the `{{#rustdoc_include [filename:some_tag]}}` directive
within the code blocks in the text. The `rustdoc_include` directive gives the
code that doesn't get displayed to `rustdoc` for `mdbook test` purposes.
code that doesn't get displayed to `rustdoc` for `mdbook test` purposes.
- For anything else, use the `{{#include [filename:some_tag]}}` directive.
- If you want to display the output of a command in the text as well, create an
`output.txt` file in the listing's directory as follows:
- Run the command, like `cargo run` or `cargo test`, and copy all of the
output.
output.
- Create a new `output.txt` file with the first line `$ [the command you
ran]`.
- Paste the output you just copied.
- Run `./tools/update-rustc.sh`, which should perform some normalization on
the compiler output.
the compiler output.
- Include the output in the text with the `{{#include [filename]}}` directive.
- Add and commit output.txt.
- If you want to display output but for some reason it can't be generated by a
script (say, because of user input or external events like making a web
request), keep the output inline but make a comment that contains
`manual-regeneration` and instructions for manually updating the inline
output.
request), keep the output inline but make a comment that contains
`manual-regeneration` and instructions for manually updating the inline
output.
- If you don't want this example to even be attempted to be formatted by
`rustfmt` (for example because the example doesn't parse on purpose), add a
`rustfmt-ignore` file in the listing's directory and the reason it's not
being formatted as the contents of that file (in case it's a rustfmt bug that
might get fixed someday).
`rustfmt-ignore` file in the listing's directory and the reason it's not
being formatted as the contents of that file (in case it's a rustfmt bug that
might get fixed someday).

## See the effect of some change on the rendered book

Expand Down
3 changes: 1 addition & 2 deletions rustbook-en/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ or pull request.

[nostarch]: https://nostarch.com/rust-programming-language-2nd-edition

So far, we've been doing a larger revision to coincide with [Rust
Editions](https://doc.rust-lang.org/edition-guide/). Between those larger
So far, we've been doing a larger revision to coincide with [Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger
revisions, we will only be correcting errors. If your issue or pull request
isn't strictly fixing an error, it might sit until the next time that we're
working on a large revision: expect on the order of months or years. Thank you
Expand Down
7 changes: 4 additions & 3 deletions rustbook-en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $ cargo install mdbook --locked --version <version_num>

The book also uses two mdbook plugins which are part of this repository. If you
do not install them, you will see warnings when building and the output will not
look right, but you *will* still be able to build the book. To use the plugins,
look right, but you _will_ still be able to build the book. To use the plugins,
you should run:

```bash
Expand All @@ -55,6 +55,7 @@ The output will be in the `book` subdirectory. To check it out, open it in
your web browser.

_Firefox:_

```bash
$ firefox book/index.html # Linux
$ open -a "Firefox" book/index.html # OS X
Expand All @@ -63,6 +64,7 @@ $ start firefox.exe .\book\index.html # Windows (Cmd)
```

_Chrome:_

```bash
$ google-chrome book/index.html # Linux
$ open -a "Google Chrome" book/index.html # OS X
Expand All @@ -89,8 +91,7 @@ to keep the online version of the book close to the print version when
possible, it may take longer than you're used to for us to address your issue
or pull request.

So far, we've been doing a larger revision to coincide with [Rust
Editions](https://doc.rust-lang.org/edition-guide/). Between those larger
So far, we've been doing a larger revision to coincide with [Rust Editions](https://doc.rust-lang.org/edition-guide/). Between those larger
revisions, we will only be correcting errors. If your issue or pull request
isn't strictly fixing an error, it might sit until the next time that we're
working on a large revision: expect on the order of months or years. Thank you
Expand Down
33 changes: 33 additions & 0 deletions rustbook-en/dprint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"typescript": {
},
"json": {
},
"markdown": {
},
"malva": {
},
"excludes": [
"**/node_modules",
"**/*-lock.json",
"**/target",
// We don’t to apply auto-formatting to this *yet*, at a minimum. It may be
// helpful as a way of replacing some of the manual formatting we do in both
// the nostarch script and the script for pulling data back over from docx,
// though, so we may *start* doing so in the future.
"nostarch",
// These should never change at this point
"2018-edition",
"first-edition",
"second-edition",
"redirects",
// has empty list items which look like headings to a formatter
".github/ISSUE_TEMPLATE/bug_report.md"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.93.3.wasm",
"https://plugins.dprint.dev/json-0.19.4.wasm",
"https://plugins.dprint.dev/markdown-0.17.8.wasm",
"https://plugins.dprint.dev/g-plane/malva-v0.11.0.wasm"
]
}
68 changes: 34 additions & 34 deletions rustbook-en/ferris.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@
/** @type {Array<FerrisType>} */
const FERRIS_TYPES = [
{
attr: 'does_not_compile',
title: 'This code does not compile!'
attr: "does_not_compile",
title: "This code does not compile!",
},
{
attr: 'panics',
title: 'This code panics!'
attr: "panics",
title: "This code panics!",
},
{
attr: 'not_desired_behavior',
title: 'This code does not produce the desired behavior.'
}
]
attr: "not_desired_behavior",
title: "This code does not produce the desired behavior.",
},
];

document.addEventListener('DOMContentLoaded', () => {
document.addEventListener("DOMContentLoaded", () => {
for (let ferrisType of FERRIS_TYPES) {
attachFerrises(ferrisType)
attachFerrises(ferrisType);
}
})
});

/**
* @param {FerrisType} type
*/
function attachFerrises(type) {
let elements = document.getElementsByClassName(type.attr)
let elements = document.getElementsByClassName(type.attr);

for (let codeBlock of elements) {
// Skip SVG etc.: in principle, these should never be attached to those, but
// this means if someone happens to have a browser extension which *is*
// attaching them, it will not break the code.
if (!(codeBlock instanceof HTMLElement)) {
continue
continue;
}

let lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length
let lines = codeBlock.innerText.replace(/\n$/, "").split(/\n/).length;

/** @type {'small' | 'large'} */
let size = lines < 4 ? 'small' : 'large'
let size = lines < 4 ? "small" : "large";

let container = prepareFerrisContainer(codeBlock, size == 'small')
let container = prepareFerrisContainer(codeBlock, size == "small");
if (!container) {
continue
continue;
}

container.appendChild(createFerris(type, size))
container.appendChild(createFerris(type, size));
}
}

Expand All @@ -60,22 +60,22 @@ function attachFerrises(type) {
* @returns {Element | null} - The container element to use.
*/
function prepareFerrisContainer(element, useButtons) {
let foundButtons = element.parentElement?.querySelector('.buttons')
let foundButtons = element.parentElement?.querySelector(".buttons");
if (useButtons && foundButtons) {
return foundButtons
return foundButtons;
}

let div = document.createElement('div')
div.classList.add('ferris-container')
let div = document.createElement("div");
div.classList.add("ferris-container");

if (!element.parentElement) {
console.error(`Could not install Ferris on ${element}, which is missing a parent`);
return null;
}

element.parentElement.insertBefore(div, element)
element.parentElement.insertBefore(div, element);

return div
return div;
}

/**
Expand All @@ -84,17 +84,17 @@ function prepareFerrisContainer(element, useButtons) {
* @returns {HTMLAnchorElement} - The generated anchor element.
*/
function createFerris(type, size) {
let a = document.createElement('a')
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
a.setAttribute('target', '_blank')
let a = document.createElement("a");
a.setAttribute("href", "ch00-00-introduction.html#ferris");
a.setAttribute("target", "_blank");

let img = document.createElement('img')
img.setAttribute('src', 'img/ferris/' + type.attr + '.svg')
img.setAttribute('title', type.title)
img.classList.add('ferris')
img.classList.add('ferris-' + size)
let img = document.createElement("img");
img.setAttribute("src", "img/ferris/" + type.attr + ".svg");
img.setAttribute("title", type.title);
img.classList.add("ferris");
img.classList.add("ferris-" + size);

a.appendChild(img)
a.appendChild(img);

return a
return a;
}
4 changes: 2 additions & 2 deletions rustbook-en/packages/mdbook-trpl-note/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mdbook-trpl-note

This is a *very* simple [preprocessor][pre] for [mdBook][mdbook], focused specifically on the content of _The Rust Programming Language_ book. This preprocessor takes Markdown like this—
This is a _very_ simple [preprocessor][pre] for [mdBook][mdbook], focused specifically on the content of _The Rust Programming Language_ book. This preprocessor takes Markdown like this—

```markdown
> Note: This is some material we want to provide more emphasis for, because it
Expand Down Expand Up @@ -37,7 +37,7 @@ Here is all the important things to know about that particular subject.
This allows using the relatively standard Markdown convention of (incorrectly!) using blockquotes for “callouts” or “notes” like this, while still producing semantic HTML which conveys the actual intent.

> [!NOTE]
> This is *not* a full “admonition” preprocessor, and it is not remotely compliant with [the GitHub “alert” syntax][alerts]. It exists almost entirely for the sake of providing better semantic HTML for _The Rust Programming Language_ book with a minimum of disruption to existing workflows!
> This is _not_ a full “admonition” preprocessor, and it is not remotely compliant with [the GitHub “alert” syntax][alerts]. It exists almost entirely for the sake of providing better semantic HTML for _The Rust Programming Language_ book with a minimum of disruption to existing workflows!
>
> You are probably better off using one of the other existing alert/admonition preprocessors:
>
Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/packages/trpl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## 0.1.0

Initial release! Adds support code for the first draft of the new async chapter of the book.
Initial release! Adds support code for the first draft of the new async chapter of the book.
2 changes: 1 addition & 1 deletion rustbook-en/packages/trpl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This repository is the home of the `trpl` crate used in _The Rust Programming
Language_ book materials.

This crate mostly just re-exports items from *other* crates. It exists for two
This crate mostly just re-exports items from _other_ crates. It exists for two
main reasons:

1. So that as you read along in _The Rust Programming Language_, you can add
Expand Down
Loading

0 comments on commit 1b3bab9

Please sign in to comment.