From f0b1e19f9ac243af972ba52c2e0da5e2bb9bf34b Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Mon, 6 Jan 2020 21:31:18 +0100 Subject: [PATCH] Fix template generated output During some rework this did no longer have a context with an output stream available. This fixes it by writing directly to the underlying output stream. --- src/generator/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/generator/mod.rs b/src/generator/mod.rs index cdce08c..66b4dfb 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -90,11 +90,15 @@ impl<'a, B: Backend<'a>, W: Write> Generator<'a, B, W> { }; let events = self.get_events(markdown, context, input); if let Some(template) = self.template.take() { - let body_index = - template.find("\nHERADOCBODY\n").expect("HERADOCBODY not found in template"); - self.default_out.write_all(&template.as_bytes()[..body_index])?; + let body_index = template + .find("\nHERADOCBODY\n") + .expect("HERADOCBODY not found in template on"); + + let head = &template.as_bytes()[..body_index]; + let tail = &template.as_bytes()[body_index + "\nHERADOCBODY\n".len()..]; + self.default_out.write_all(head)?; self.generate_body(events)?; - self.default_out.write_all(&template.as_bytes()[body_index + "\nHERADOCBODY\n".len()..])?; + self.default_out.write_all(tail)?; } else { let diagnostics = Arc::clone(&events.diagnostics); self.backend.gen_preamble(self.cfg, &mut self.default_out, &diagnostics)?;