Skip to content

Commit 19489ae

Browse files
authored
Rollup merge of rust-lang#79423 - camelid:smart-punct, r=jyn514
Enable smart punctuation Closes rust-lang#76690.
2 parents 11f838d + 1b29b29 commit 19489ae

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

src/doc/rustdoc/src/how-to-write-documentation.md

+21-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ what an item is, how it is used, and for what purpose it exists.
101101
Let's see an example coming from the [standard library] by taking a look at the
102102
[`std::env::args()`][env::args] function:
103103

104-
``````text
104+
``````markdown
105105
Returns the arguments which this program was started with (normally passed
106106
via the command line).
107107

@@ -135,7 +135,7 @@ for argument in env::args() {
135135

136136
Everything before the first empty line will be reused to describe the component
137137
in searches and module overviews. For example, the function `std::env::args()`
138-
above will be shown on the [`std::env`] module documentation. It is good
138+
above will be shown on the [`std::env`] module documentation. It is good
139139
practice to keep the summary to one line: concise writing is a goal of good
140140
documentation.
141141

@@ -153,9 +153,10 @@ and finally provides a code example.
153153

154154
## Markdown
155155

156-
`rustdoc` uses the [CommonMark markdown specification]. You might be
157-
interested into taking a look at their website to see what's possible to do.
158-
- [commonmark quick reference]
156+
`rustdoc` uses the [CommonMark Markdown specification]. You might be
157+
interested in taking a look at their website to see what's possible:
158+
159+
- [CommonMark quick reference]
159160
- [current spec]
160161

161162
In addition to the standard CommonMark syntax, `rustdoc` supports several
@@ -240,6 +241,21 @@ This will render as
240241

241242
See the specification for the [task list extension] for more details.
242243

244+
### Smart punctuation
245+
246+
Some ASCII punctuation sequences will be automatically turned into fancy Unicode
247+
characters:
248+
249+
| ASCII sequence | Unicode |
250+
|----------------|---------|
251+
| `--` ||
252+
| `---` ||
253+
| `...` ||
254+
| `"` | “ or ”, depending on context |
255+
| `'` | ‘ or ’, depending on context |
256+
257+
So, no need to manually enter those Unicode characters!
258+
243259
[`backtrace`]: https://docs.rs/backtrace/0.3.50/backtrace/
244260
[commonmark markdown specification]: https://commonmark.org/
245261
[commonmark quick reference]: https://commonmark.org/help/

src/librustdoc/html/markdown.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ pub(crate) fn opts() -> Options {
5252
| Options::ENABLE_FOOTNOTES
5353
| Options::ENABLE_STRIKETHROUGH
5454
| Options::ENABLE_TASKLISTS
55+
| Options::ENABLE_SMART_PUNCTUATION
5556
}
5657

5758
/// A subset of [`opts()`] used for rendering summaries.
5859
pub(crate) fn summary_opts() -> Options {
59-
Options::ENABLE_STRIKETHROUGH
60+
Options::ENABLE_STRIKETHROUGH | Options::ENABLE_SMART_PUNCTUATION
6061
}
6162

6263
/// When `to_string` is called, this struct will emit the HTML corresponding to

src/librustdoc/html/markdown/tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ fn test_short_markdown_summary() {
201201
t("Hard-break \nsummary", "Hard-break summary");
202202
t("hello [Rust] :)\n\n[Rust]: https://www.rust-lang.org", "hello Rust :)");
203203
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
204-
t("code `let x = i32;` ...", "code <code>let x = i32;</code> ...");
205-
t("type `Type<'static>` ...", "type <code>Type<'static></code> ...");
204+
t("code `let x = i32;` ...", "code <code>let x = i32;</code> ");
205+
t("type `Type<'static>` ...", "type <code>Type<'static></code> ");
206206
t("# top header", "top header");
207207
t("## header", "header");
208208
t("first paragraph\n\nsecond paragraph", "first paragraph");
@@ -227,8 +227,8 @@ fn test_plain_text_summary() {
227227
t("Hard-break \nsummary", "Hard-break summary");
228228
t("hello [Rust] :)\n\n[Rust]: https://www.rust-lang.org", "hello Rust :)");
229229
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
230-
t("code `let x = i32;` ...", "code `let x = i32;` ...");
231-
t("type `Type<'static>` ...", "type `Type<'static>` ...");
230+
t("code `let x = i32;` ...", "code `let x = i32;` ");
231+
t("type `Type<'static>` ...", "type `Type<'static>` ");
232232
t("# top header", "top header");
233233
t("# top header\n\nfollowed by some text", "top header");
234234
t("## header", "header");
@@ -251,6 +251,6 @@ fn test_markdown_html_escape() {
251251
}
252252

253253
t("`Struct<'a, T>`", "<p><code>Struct&lt;'a, T&gt;</code></p>\n");
254-
t("Struct<'a, T>", "<p>Struct&lt;'a, T&gt;</p>\n");
254+
t("Struct<'a, T>", "<p>Struct&lt;a, T&gt;</p>\n");
255255
t("Struct<br>", "<p>Struct&lt;br&gt;</p>\n");
256256
}

src/test/rustdoc/inline_cross/add-docs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ extern crate inner;
44

55

66
// @has add_docs/struct.MyStruct.html
7-
// @has add_docs/struct.MyStruct.html "Doc comment from 'pub use', Doc comment from definition"
7+
// @has add_docs/struct.MyStruct.html "Doc comment from pub use, Doc comment from definition"
88
/// Doc comment from 'pub use',
99
pub use inner::MyStruct;

src/test/rustdoc/smart-punct.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ignore-tidy-linelength
2+
3+
#![crate_name = "foo"]
4+
5+
//! This is the "start" of the 'document'! How'd you know that "it's" the start?
6+
//!
7+
//! # Header with "smart punct'"
8+
//!
9+
//! [link with "smart punct'" -- yessiree!][]
10+
//!
11+
//! [link with "smart punct'" -- yessiree!]: https://www.rust-lang.org
12+
//!
13+
//! # Code should not be smart-punct'd
14+
//!
15+
//! `this inline code -- it shouldn't have "smart punct"`
16+
//!
17+
//! ```
18+
//! let x = "don't smart-punct me -- please!";
19+
//! ```
20+
//!
21+
//! ```text
22+
//! I say "don't smart-punct me -- please!"
23+
//! ```
24+
25+
// @has "foo/index.html" "//p" "This is the “start” of the ‘document’! How’d you know that “it’s” the start?"
26+
// @has "foo/index.html" "//h1" "Header with “smart punct’”"
27+
// @has "foo/index.html" '//a[@href="https://www.rust-lang.org"]' "link with “smart punct’” – yessiree!"
28+
// @has "foo/index.html" '//code' "this inline code -- it shouldn't have \"smart punct\""
29+
// @has "foo/index.html" '//pre' "let x = \"don't smart-punct me -- please!\";"
30+
// @has "foo/index.html" '//pre' "I say \"don't smart-punct me -- please!\""

0 commit comments

Comments
 (0)