Skip to content

Commit 95a94e3

Browse files
Add markdown-[before|after]-content options
1 parent 70198a0 commit 95a94e3

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
@@ -159,6 +159,14 @@ pub fn opts() -> Vec<RustcOptGroup> {
159159
"files to include inline between the content and </body> of a rendered \
160160
Markdown file or generated documentation",
161161
"FILES")),
162+
unstable(optmulti("", "markdown-before-content",
163+
"files to include inline between <body> and the content of a rendered \
164+
Markdown file or generated documentation",
165+
"FILES")),
166+
unstable(optmulti("", "markdown-after-content",
167+
"files to include inline between the content and </body> of a rendered \
168+
Markdown file or generated documentation",
169+
"FILES")),
162170
stable(optopt("", "markdown-playground-url",
163171
"URL to send code snippets to", "URL")),
164172
stable(optflag("", "markdown-no-toc", "don't include table of contents")),
@@ -274,7 +282,10 @@ pub fn main_args(args: &[String]) -> isize {
274282
let external_html = match ExternalHtml::load(
275283
&matches.opt_strs("html-in-header"),
276284
&matches.opt_strs("html-before-content"),
277-
&matches.opt_strs("html-after-content")) {
285+
&matches.opt_strs("html-after-content"),
286+
&matches.opt_strs("markdown-before-content"),
287+
&matches.opt_strs("markdown-after-content"),
288+
render_type) {
278289
Some(eh) => eh,
279290
None => return 3,
280291
};

0 commit comments

Comments
 (0)