Skip to content

Commit dfe29e2

Browse files
committed
auto merge of #9704 : alexcrichton/rust/rustdoc-comments, r=huonw
This addresses some of @huonw's in #9691 about the startling lack of documentation guiding one throughout the innards of rustdoc::html r? @huonw
2 parents e44b40c + cdb7701 commit dfe29e2

File tree

4 files changed

+187
-14
lines changed

4 files changed

+187
-14
lines changed

src/librustdoc/html/escape.rs

+7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! HTML Escaping
12+
//!
13+
//! This module contains one unit-struct which can be used to HTML-escape a
14+
//! string of text (for use in a format string).
15+
1116
use std::fmt;
1217

18+
/// Wrapper struct which will emit the HTML-escaped version of the contained
19+
/// string when passed to a format string.
1320
pub struct Escape<'self>(&'self str);
1421

1522
impl<'self> fmt::Default for Escape<'self> {

src/librustdoc/html/format.rs

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! HTML formatting module
12+
//!
13+
//! This module contains a large number of `fmt::Default` implementations for
14+
//! various types in `rustdoc::clean`. These implementations all currently
15+
//! assume that HTML output is desired, although it may be possible to redesign
16+
//! them in the future to instead emit any format desired.
17+
1118
use std::fmt;
1219
use std::local_data;
1320
use std::rt::io;
@@ -19,8 +26,13 @@ use clean;
1926
use html::render;
2027
use html::render::{cache_key, current_location_key};
2128

29+
/// Helper to render an optional visibility with a space after it (if the
30+
/// visibility is preset)
2231
pub struct VisSpace(Option<ast::visibility>);
32+
/// Similarly to VisSpace, this structure is used to render a purity with a
33+
/// space after it.
2334
pub struct PuritySpace(ast::purity);
35+
/// Wrapper struct for properly emitting a method declaration.
2436
pub struct Method<'self>(&'self clean::SelfTy, &'self clean::FnDecl);
2537

2638
impl fmt::Default for clean::Generics {
@@ -98,6 +110,8 @@ impl fmt::Default for clean::Path {
98110
}
99111
}
100112

113+
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
114+
/// rendering function with the necessary arguments for linking to a local path.
101115
fn resolved_path(w: &mut io::Writer, id: ast::NodeId, p: &clean::Path,
102116
print_all: bool) {
103117
path(w, p, print_all,
@@ -115,6 +129,8 @@ fn resolved_path(w: &mut io::Writer, id: ast::NodeId, p: &clean::Path,
115129
});
116130
}
117131

132+
/// Used when rendering an `ExternalPath` structure. Like `resolved_path` this
133+
/// will invoke `path` with proper linking-style arguments.
118134
fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool,
119135
fqn: &[~str], kind: clean::TypeKind, crate: ast::CrateNum) {
120136
path(w, p, print_all,
@@ -230,6 +246,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
230246
}
231247
}
232248

249+
/// Helper to render type parameters
233250
fn typarams(w: &mut io::Writer, typarams: &Option<~[clean::TyParamBound]>) {
234251
match *typarams {
235252
Some(ref params) => {

src/librustdoc/html/markdown.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@
1010

1111
#[allow(cstack)]; // each rendering task runs on a fixed stack segment.
1212

13+
//! Markdown formatting for rustdoc
14+
//!
15+
//! This module implements markdown formatting through the sundown C-library
16+
//! (bundled into the rust runtime). This module self-contains the C bindings
17+
//! and necessary legwork to render markdown, and exposes all of the
18+
//! functionality through a unit-struct, `Markdown`, which has an implementation
19+
//! of `fmt::Default`. Example usage:
20+
//!
21+
//! ```rust
22+
//! let s = "My *markdown* _text_";
23+
//! let html = format!("{}", Markdown(s));
24+
//! // ... something using html
25+
//! ```
26+
1327
use std::fmt;
1428
use std::libc;
1529
use std::rt::io;
1630
use std::vec;
1731

32+
/// A unit struct which has the `fmt::Default` trait implemented. When
33+
/// formatted, this struct will emit the HTML corresponding to the rendered
34+
/// version of the contained markdown string.
1835
pub struct Markdown<'self>(&'self str);
1936

2037
static OUTPUT_UNIT: libc::size_t = 64;
@@ -110,7 +127,6 @@ impl<'self> fmt::Default for Markdown<'self> {
110127
fn fmt(md: &Markdown<'self>, fmt: &mut fmt::Formatter) {
111128
// This is actually common enough to special-case
112129
if md.len() == 0 { return; }
113-
114130
render(fmt.buf, md.as_slice());
115131
}
116132
}

0 commit comments

Comments
 (0)