Skip to content

Commit 8d89242

Browse files
committed
Fix documentation having too many #
rustdoc used to remove `#` from the the liens starting with `##`, but it no longer does that for non-rust languages. As a result, we shoudln't add the `#` otherwise it will appear with too many `#`, but we still need to re-add it in the test because it was stripped by the test. Fixes #22
1 parent 0ed8e43 commit 8d89242

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

lib.rs

+26-22
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,38 @@ in where they occur. Use them to group features, for example.
4141
## Examples:
4242
4343
*/
44-
// Note: because rustdoc escapes the first `#` of a line starting with `#`,
45-
// these docs comments have one more `#` ,
4644
#![doc = self_test!(/**
4745
[package]
4846
name = "..."
49-
## ...
47+
# ...
5048
5149
[features]
5250
default = ["foo"]
53-
##! This comments goes on top
51+
#! This comments goes on top
5452
55-
### The foo feature enables the `foo` functions
53+
## The foo feature enables the `foo` functions
5654
foo = []
5755
58-
### The bar feature enables the bar module
56+
## The bar feature enables the bar module
5957
bar = []
6058
61-
##! ### Experimental features
62-
##! The following features are experimental
59+
#! ### Experimental features
60+
#! The following features are experimental
6361
64-
### Enable the fusion reactor
65-
###
66-
### ⚠️ Can lead to explosions
62+
## Enable the fusion reactor
63+
##
64+
## ⚠️ Can lead to explosions
6765
fusion = []
6866
6967
[dependencies]
7068
document-features = "0.2"
7169
72-
##! ### Optional dependencies
70+
#! ### Optional dependencies
7371
74-
### Enable this feature to implement the trait for the types from the genial crate
72+
## Enable this feature to implement the trait for the types from the genial crate
7573
genial = { version = "0.2", optional = true }
7674
77-
### This awesome dependency is specified in its own table
75+
## This awesome dependency is specified in its own table
7876
[dependencies.awesome]
7977
version = "1.3.5"
8078
optional = true
@@ -465,14 +463,20 @@ fn test_get_balanced() {
465463
#[doc(hidden)]
466464
/// Helper macro for the tests. Do not use
467465
pub fn self_test_helper(input: TokenStream) -> TokenStream {
468-
process_toml((&input).to_string().trim_matches(|c| c == '"' || c == '#'), &Args::default())
469-
.map_or_else(
470-
|e| error(&e),
471-
|r| {
472-
std::iter::once(proc_macro::TokenTree::from(proc_macro::Literal::string(&r)))
473-
.collect()
474-
},
475-
)
466+
let mut code = String::new();
467+
for line in (&input).to_string().trim_matches(|c| c == '"' || c == '#').lines() {
468+
// Rustdoc removes the lines that starts with `# ` and removes one `#` from lines that starts with # followed by space.
469+
// We need to re-add the `#` that was removed by rustdoc to get the original.
470+
if line.strip_prefix('#').map_or(false, |x| x.is_empty() || x.starts_with(' ')) {
471+
code += "#";
472+
}
473+
code += line;
474+
code += "\n";
475+
}
476+
process_toml(&code, &Args::default()).map_or_else(
477+
|e| error(&e),
478+
|r| std::iter::once(proc_macro::TokenTree::from(proc_macro::Literal::string(&r))).collect(),
479+
)
476480
}
477481

478482
#[cfg(feature = "self-test")]

0 commit comments

Comments
 (0)