Skip to content

Commit 864da57

Browse files
authored
Add a --html-in-md option to the markdown command. (#493)
Add a flag that tells the `markdown` command to write its HTML output into a `.md` file. This will allow it to be displayed on Github, which doesn't render HTML files but does render Markdown files which can contain HTML.
1 parent 964dff2 commit 864da57

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

crates/gen-markdown/src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ struct Markdown {
1818
#[derive(Default, Debug, Clone)]
1919
#[cfg_attr(feature = "clap", derive(clap::Args))]
2020
pub struct Opts {
21-
// ...
21+
/// Output a `.md` file containing HTML.
22+
///
23+
/// This can be useful when producing files to be displayed on Github,
24+
/// as it doesn't render HTML files, but it does render Markdown files,
25+
/// which can contain HTML.
26+
#[cfg_attr(feature = "clap", arg(long))]
27+
html_in_md: bool,
2228
}
2329

2430
impl Opts {
@@ -124,8 +130,14 @@ impl WorldGenerator for Markdown {
124130
let mut html_output = String::new();
125131
html::push_html(&mut html_output, events.into_iter());
126132

127-
files.push(&format!("{}.md", world.name), self.src.as_bytes());
128-
files.push(&format!("{}.html", world.name), html_output.as_bytes());
133+
if self.opts.html_in_md {
134+
// Write the html output into a .md file.
135+
files.push(&format!("{}.md", world.name), html_output.as_bytes());
136+
} else {
137+
// Write the html output to an html file, and md output to a md file.
138+
files.push(&format!("{}.md", world.name), self.src.as_bytes());
139+
files.push(&format!("{}.html", world.name), html_output.as_bytes());
140+
}
129141
}
130142
}
131143

0 commit comments

Comments
 (0)