diff --git a/pylib/anki/template.py b/pylib/anki/template.py index 1854d71e8..816ee376f 100644 --- a/pylib/anki/template.py +++ b/pylib/anki/template.py @@ -61,13 +61,15 @@ TemplateReplacementList = List[Union[str, TemplateReplacement]] class PartiallyRenderedCard: qnodes: TemplateReplacementList anodes: TemplateReplacementList + css: str + latex_svg: bool @classmethod def from_proto(cls, out: _pb.RenderCardOut) -> PartiallyRenderedCard: qnodes = cls.nodes_from_proto(out.question_nodes) anodes = cls.nodes_from_proto(out.answer_nodes) - return PartiallyRenderedCard(qnodes, anodes) + return PartiallyRenderedCard(qnodes, anodes, out.css, out.latex_svg) @staticmethod def nodes_from_proto( @@ -151,6 +153,7 @@ class TemplateRenderContext: self._template = template self._fill_empty = fill_empty self._fields: Optional[Dict] = None + self._latex_svg = False if not notetype: self._note_type = note.model() else: @@ -197,6 +200,9 @@ class TemplateRenderContext: def note_type(self) -> NotetypeDict: return self._note_type + def latex_svg(self) -> bool: + return self._latex_svg + # legacy def qfmt(self) -> str: return templates_for_card(self.card(), self._browser)[0] @@ -227,9 +233,11 @@ class TemplateRenderContext: answer_text=aout.text, question_av_tags=av_tags_to_native(qout.av_tags), answer_av_tags=av_tags_to_native(aout.av_tags), - css=self.note_type()["css"], + css=partial.css, ) + self._latex_svg = partial.latex_svg + if not self._browser: hooks.card_did_render(output, self) diff --git a/rslib/backend.proto b/rslib/backend.proto index b89f827bc..234228213 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -704,6 +704,8 @@ message RenderUncommittedCardLegacyIn { message RenderCardOut { repeated RenderedTemplateNode question_nodes = 1; repeated RenderedTemplateNode answer_nodes = 2; + string css = 3; + bool latex_svg = 4; } message RenderedTemplateNode { diff --git a/rslib/src/backend/cardrendering.rs b/rslib/src/backend/cardrendering.rs index b68c8ba9a..fdd085649 100644 --- a/rslib/src/backend/cardrendering.rs +++ b/rslib/src/backend/cardrendering.rs @@ -175,6 +175,8 @@ impl From for pb::RenderCardOut { pb::RenderCardOut { question_nodes: rendered_nodes_to_proto(o.qnodes), answer_nodes: rendered_nodes_to_proto(o.anodes), + css: o.css, + latex_svg: o.latex_svg, } } } diff --git a/rslib/src/notetype/render.rs b/rslib/src/notetype/render.rs index 330854f5b..e232fa68c 100644 --- a/rslib/src/notetype/render.rs +++ b/rslib/src/notetype/render.rs @@ -16,6 +16,8 @@ use crate::{ pub struct RenderCardOutput { pub qnodes: Vec, pub anodes: Vec, + pub css: String, + pub latex_svg: bool, } impl Collection { @@ -119,7 +121,12 @@ impl Collection { nt.is_cloze(), &self.tr, )?; - Ok(RenderCardOutput { qnodes, anodes }) + Ok(RenderCardOutput { + qnodes, + anodes, + css: nt.config.css.clone(), + latex_svg: nt.config.latex_svg, + }) } // Add special fields if they don't clobber note fields