diff options
| author | projektir <oprojektir@gmail.com> | 2017-03-25 15:33:44 -0400 |
|---|---|---|
| committer | projektir <oprojektir@gmail.com> | 2017-03-25 15:42:44 -0400 |
| commit | 2e14bfe0d7ce376a42bdc4c7eb964fd91aad3c32 (patch) | |
| tree | 632a95970f6be1b69a74f5a35d776f7a67f02ce6 | |
| parent | 49c67bd632e961a57863805e5d0a400f97da9b93 (diff) | |
| download | rust-2e14bfe0d7ce376a42bdc4c7eb964fd91aad3c32.tar.gz rust-2e14bfe0d7ce376a42bdc4c7eb964fd91aad3c32.zip | |
rustdoc to accept `#` at the start of a markdown file #40560
| -rw-r--r-- | src/librustdoc/markdown.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index c67e2fdc2b0..5fadda030a4 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -28,20 +28,22 @@ use html::markdown; use html::markdown::{Markdown, MarkdownWithToc, find_testable_code}; use test::{TestOptions, Collector}; -/// Separate any lines at the start of the file that begin with `%`. +/// Separate any lines at the start of the file that begin with `# ` or `%`. fn extract_leading_metadata<'a>(s: &'a str) -> (Vec<&'a str>, &'a str) { let mut metadata = Vec::new(); let mut count = 0; + for line in s.lines() { - if line.starts_with("%") { - // remove %<whitespace> + if line.starts_with("# ") || line.starts_with("%") { + // trim the whitespace after the symbol metadata.push(line[1..].trim_left()); count += line.len() + 1; } else { return (metadata, &s[count..]); } } - // if we're here, then all lines were metadata % lines. + + // if we're here, then all lines were metadata `# ` or `%` lines. (metadata, "") } @@ -83,7 +85,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, if metadata.is_empty() { let _ = writeln!( &mut io::stderr(), - "rustdoc: invalid markdown file: expecting initial line with `% ...TITLE...`" + "rustdoc: invalid markdown file: no initial lines starting with `# ` or `%`" ); return 5; } |
