1 use crate::book
::BookItem
;
3 use crate::renderer
::{RenderContext, Renderer}
;
9 /// A renderer to output the Markdown after the preprocessors have run. Mostly useful
10 /// when debugging preprocessors.
11 pub struct MarkdownRenderer
;
13 impl MarkdownRenderer
{
14 /// Create a new `MarkdownRenderer` instance.
15 pub fn new() -> Self {
20 impl Renderer
for MarkdownRenderer
{
21 fn name(&self) -> &str {
25 fn render(&self, ctx
: &RenderContext
) -> Result
<()> {
26 let destination
= &ctx
.destination
;
29 if destination
.exists() {
30 utils
::fs
::remove_dir_content(destination
)
31 .with_context(|| "Unable to remove stale Markdown output")?
;
34 trace
!("markdown render");
35 for item
in book
.iter() {
36 if let BookItem
::Chapter(ref ch
) = *item
{
37 if !ch
.is_draft_chapter() {
38 utils
::fs
::write_file(
40 &ch
.path
.as_ref().expect("Checked path exists before"),
41 ch
.content
.as_bytes(),
47 fs
::create_dir_all(&destination
)
48 .with_context(|| "Unexpected error when constructing destination path")?
;