Skip to content

Commit

Permalink
fix: pass output format to render context
Browse files Browse the repository at this point in the history
  • Loading branch information
mhatzl committed Dec 13, 2023
1 parent 6350716 commit 7119efa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
12 changes: 8 additions & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ impl Unimarkup {
self.doc.output_formats()
}

pub fn render<T: OutputFormat>(&self, renderer: impl Renderer<T>) -> Result<T, RenderError> {
unimarkup_render::render::render(&self.doc, renderer)
pub fn render<T: OutputFormat>(
&self,
format: OutputFormatKind,
renderer: impl Renderer<T>,
) -> Result<T, RenderError> {
unimarkup_render::render::render(&self.doc, format, renderer)
}

pub fn render_html(&self) -> Result<Html, RenderError> {
self.render(HtmlRenderer::default())
self.render(OutputFormatKind::Html, HtmlRenderer::default())
}

pub fn render_umi(&self) -> Result<Umi, RenderError> {
self.render(UmiRenderer::default())
self.render(OutputFormatKind::Umi, UmiRenderer::default())
}
}
9 changes: 9 additions & 0 deletions core/tests/spec/markup/blocks/heading.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ tests:
html: |
<h2 id='heading-**with**-inlines.'>Heading <strong>with</strong> inlines.</h2>
- name: heading-lvl3-with-inlines

input: |
### Heading **with** inlines.
html: |
<h3 id='heading-**with**-inlines.'>Heading <strong>with</strong> inlines.</h3>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: core/tests/runner/mod.rs
info: "Test 'heading-lvl3-with-inlines' from: markup\\blocks\\heading.yml"
---
Heading-level-3(Heading **with** inlines.)
---
With input:

### Heading **with** inlines.


8 changes: 5 additions & 3 deletions render/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::html::citeproc::CiteprocWrapper;
use logid::log;
use serde_json::Value;
use std::path::PathBuf;
use unimarkup_commons::config::output::OutputFormatKind;
use unimarkup_commons::config::Config;
use unimarkup_commons::{
config::icu_locid::{locale, Locale},
Expand Down Expand Up @@ -53,14 +54,14 @@ impl<'a> Context<'a> {
self.rendered_citations.get(index)
}

fn new(doc: &'a Document) -> Self {
fn new(doc: &'a Document, format: OutputFormatKind) -> Self {
let rendered_citations: Vec<String>;
let footnotes: String;
let bibliography: String;

match CiteprocWrapper::new() {
Ok(mut citeproc) => {
let for_pagedjs = false;
let for_pagedjs = matches!(format, OutputFormatKind::Html);
let style = doc
.config
.preamble
Expand Down Expand Up @@ -147,9 +148,10 @@ impl<'a> Context<'a> {

pub fn render<T: OutputFormat>(
doc: &Document,
format: OutputFormatKind,
mut renderer: impl Renderer<T>,
) -> Result<T, RenderError> {
let context = Context::new(doc);
let context = Context::new(doc, format);
let mut t = T::new(&context);

t.append(renderer.render_blocks(&doc.blocks, &context)?)?;
Expand Down

0 comments on commit 7119efa

Please sign in to comment.