rustdoc to accept #
at the start of a markdown file #40560
This commit is contained in:
parent
49c67bd632
commit
2e14bfe0d7
1 changed files with 7 additions and 5 deletions
|
@ -28,20 +28,22 @@ use html::markdown;
|
||||||
use html::markdown::{Markdown, MarkdownWithToc, find_testable_code};
|
use html::markdown::{Markdown, MarkdownWithToc, find_testable_code};
|
||||||
use test::{TestOptions, Collector};
|
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) {
|
fn extract_leading_metadata<'a>(s: &'a str) -> (Vec<&'a str>, &'a str) {
|
||||||
let mut metadata = Vec::new();
|
let mut metadata = Vec::new();
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
for line in s.lines() {
|
for line in s.lines() {
|
||||||
if line.starts_with("%") {
|
if line.starts_with("# ") || line.starts_with("%") {
|
||||||
// remove %<whitespace>
|
// trim the whitespace after the symbol
|
||||||
metadata.push(line[1..].trim_left());
|
metadata.push(line[1..].trim_left());
|
||||||
count += line.len() + 1;
|
count += line.len() + 1;
|
||||||
} else {
|
} else {
|
||||||
return (metadata, &s[count..]);
|
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, "")
|
(metadata, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +85,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
||||||
if metadata.is_empty() {
|
if metadata.is_empty() {
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
&mut io::stderr(),
|
&mut io::stderr(),
|
||||||
"rustdoc: invalid markdown file: expecting initial line with `% ...TITLE...`"
|
"rustdoc: invalid markdown file: no initial lines starting with `# ` or `%`"
|
||||||
);
|
);
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue