Skip to content

Commit

Permalink
Rollup merge of rust-lang#40828 - projektir:markdown_metadata, r=stev…
Browse files Browse the repository at this point in the history
…eklabnik

rustdoc to accept `#` at the start of a markdown file rust-lang#40560

This may be a bit odd if `#` and `%` lines are mixed up, but that's not something I've found while doing my search and replace.
  • Loading branch information
alexcrichton committed Mar 27, 2017
2 parents 6b2c4bf + 2e14bfe commit 4d93c12
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4d93c12

Please sign in to comment.