Skip to content

Better fix code blocks in /about #1325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/core/Cargo.toml.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{# The example Cargo.toml used in about.html #}
{~# The example Cargo.toml used in about.html #~}
[package]
name = "test"

Expand Down
14 changes: 5 additions & 9 deletions templates/core/about/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ <h4 id="setting-a-readme"> <a href="#setting-a-readme">Setting a README</a> </h4
<h4 id="detecting-docsrs"> <a href="#detecting-docsrs">Detecting Docs.rs</a> </h4>
<p>
To recognize Docs.rs from <code>build.rs</code> files, you can test for the environment variable <code>DOCS_RS</code>, e.g.:
{% filter dedent(levels=4) -%}
<pre><code class="lang-rust">
if let Ok(_) = std::env::var("DOCS_RS") {
{% filter dedent(levels=3) -%}
Copy link
Member Author

Choose a reason for hiding this comment

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

Hopefully the removal of the newline after <pre><code> will interact nicely with this dedent level...

<pre><code class="lang-rust">if let Ok(_) = std::env::var("DOCS_RS") {
// ... your code here ...
}
</code></pre>
}</code></pre>
{%- endfilter %}
This approach can be helpful if you need dependencies for building the library, but not for building the documentation.
</p>
Expand All @@ -49,10 +47,8 @@ <h4 id="cross-compiling"> <a href="#cross-compiling">Cross-compiling</a> </h4>
<p>
You can configure how your crate is built by adding <a href="metadata">package metadata</a> to your <code>Cargo.toml</code>, e.g.:
{% filter dedent -%}
<pre><code class="lang-toml">
[package.metadata.docs.rs]
rustc-args = ["--cfg", "docsrs"]
</code></pre>
<pre><code class="lang-toml">[package.metadata.docs.rs]
rustc-args = ["--cfg", "docsrs"]</code></pre>
{%- endfilter %}
Here, the compiler arguments are set so that <code>#[cfg(docsrs)]</code> (not to be confused with <code>#[cfg(doc)]</code>) can be used for conditional compilation.
This approach is also useful for setting <a href="https://doc.rust-lang.org/cargo/reference/features.html">cargo features</a>.
Expand Down