Skip to content

Commit 08acc06

Browse files
Rollup merge of rust-lang#41826 - GuillaumeGomez:add-markdown-content, r=frewsxcv
Add markdown-[before|after]-content options cc @nical r? @rust-lang/docs
2 parents 77f1bec + 95a94e3 commit 08acc06

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/librustdoc/externalfiles.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::io::prelude::*;
1313
use std::io;
1414
use std::path::Path;
1515
use std::str;
16+
use html::markdown::{Markdown, RenderType};
1617

1718
#[derive(Clone)]
1819
pub struct ExternalHtml{
@@ -28,17 +29,26 @@ pub struct ExternalHtml{
2829
}
2930

3031
impl ExternalHtml {
31-
pub fn load(in_header: &[String], before_content: &[String], after_content: &[String])
32+
pub fn load(in_header: &[String], before_content: &[String], after_content: &[String],
33+
md_before_content: &[String], md_after_content: &[String], render: RenderType)
3234
-> Option<ExternalHtml> {
3335
load_external_files(in_header)
3436
.and_then(|ih|
3537
load_external_files(before_content)
3638
.map(|bc| (ih, bc))
3739
)
40+
.and_then(|(ih, bc)|
41+
load_external_files(md_before_content)
42+
.map(|m_bc| (ih, format!("{}{}", bc, Markdown(&m_bc, render))))
43+
)
3844
.and_then(|(ih, bc)|
3945
load_external_files(after_content)
4046
.map(|ac| (ih, bc, ac))
4147
)
48+
.and_then(|(ih, bc, ac)|
49+
load_external_files(md_after_content)
50+
.map(|m_ac| (ih, bc, format!("{}{}", ac, Markdown(&m_ac, render))))
51+
)
4252
.map(|(ih, bc, ac)|
4353
ExternalHtml {
4454
in_header: ih,

src/librustdoc/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ pub fn opts() -> Vec<RustcOptGroup> {
160160
"files to include inline between the content and </body> of a rendered \
161161
Markdown file or generated documentation",
162162
"FILES")),
163+
unstable(optmulti("", "markdown-before-content",
164+
"files to include inline between <body> and the content of a rendered \
165+
Markdown file or generated documentation",
166+
"FILES")),
167+
unstable(optmulti("", "markdown-after-content",
168+
"files to include inline between the content and </body> of a rendered \
169+
Markdown file or generated documentation",
170+
"FILES")),
163171
stable(optopt("", "markdown-playground-url",
164172
"URL to send code snippets to", "URL")),
165173
stable(optflag("", "markdown-no-toc", "don't include table of contents")),
@@ -275,7 +283,10 @@ pub fn main_args(args: &[String]) -> isize {
275283
let external_html = match ExternalHtml::load(
276284
&matches.opt_strs("html-in-header"),
277285
&matches.opt_strs("html-before-content"),
278-
&matches.opt_strs("html-after-content")) {
286+
&matches.opt_strs("html-after-content"),
287+
&matches.opt_strs("markdown-before-content"),
288+
&matches.opt_strs("markdown-after-content"),
289+
render_type) {
279290
Some(eh) => eh,
280291
None => return 3,
281292
};

0 commit comments

Comments
 (0)