Skip to content

Commit

Permalink
Fix template generated output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HeroicKatora committed Apr 26, 2020
1 parent 5da1e73 commit f0b1e19
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit f0b1e19

Please sign in to comment.