pass css and latex svg flag back from rendering op
This could potentially help us avoid having to refetch the notetype during study in the future, though updates to Note initialization and the LaTeX handling would be required first.
This commit is contained in:
parent
02c7f7989e
commit
050ef11a96
@ -61,13 +61,15 @@ TemplateReplacementList = List[Union[str, TemplateReplacement]]
|
|||||||
class PartiallyRenderedCard:
|
class PartiallyRenderedCard:
|
||||||
qnodes: TemplateReplacementList
|
qnodes: TemplateReplacementList
|
||||||
anodes: TemplateReplacementList
|
anodes: TemplateReplacementList
|
||||||
|
css: str
|
||||||
|
latex_svg: bool
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_proto(cls, out: _pb.RenderCardOut) -> PartiallyRenderedCard:
|
def from_proto(cls, out: _pb.RenderCardOut) -> PartiallyRenderedCard:
|
||||||
qnodes = cls.nodes_from_proto(out.question_nodes)
|
qnodes = cls.nodes_from_proto(out.question_nodes)
|
||||||
anodes = cls.nodes_from_proto(out.answer_nodes)
|
anodes = cls.nodes_from_proto(out.answer_nodes)
|
||||||
|
|
||||||
return PartiallyRenderedCard(qnodes, anodes)
|
return PartiallyRenderedCard(qnodes, anodes, out.css, out.latex_svg)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def nodes_from_proto(
|
def nodes_from_proto(
|
||||||
@ -151,6 +153,7 @@ class TemplateRenderContext:
|
|||||||
self._template = template
|
self._template = template
|
||||||
self._fill_empty = fill_empty
|
self._fill_empty = fill_empty
|
||||||
self._fields: Optional[Dict] = None
|
self._fields: Optional[Dict] = None
|
||||||
|
self._latex_svg = False
|
||||||
if not notetype:
|
if not notetype:
|
||||||
self._note_type = note.model()
|
self._note_type = note.model()
|
||||||
else:
|
else:
|
||||||
@ -197,6 +200,9 @@ class TemplateRenderContext:
|
|||||||
def note_type(self) -> NotetypeDict:
|
def note_type(self) -> NotetypeDict:
|
||||||
return self._note_type
|
return self._note_type
|
||||||
|
|
||||||
|
def latex_svg(self) -> bool:
|
||||||
|
return self._latex_svg
|
||||||
|
|
||||||
# legacy
|
# legacy
|
||||||
def qfmt(self) -> str:
|
def qfmt(self) -> str:
|
||||||
return templates_for_card(self.card(), self._browser)[0]
|
return templates_for_card(self.card(), self._browser)[0]
|
||||||
@ -227,9 +233,11 @@ class TemplateRenderContext:
|
|||||||
answer_text=aout.text,
|
answer_text=aout.text,
|
||||||
question_av_tags=av_tags_to_native(qout.av_tags),
|
question_av_tags=av_tags_to_native(qout.av_tags),
|
||||||
answer_av_tags=av_tags_to_native(aout.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:
|
if not self._browser:
|
||||||
hooks.card_did_render(output, self)
|
hooks.card_did_render(output, self)
|
||||||
|
|
||||||
|
@ -704,6 +704,8 @@ message RenderUncommittedCardLegacyIn {
|
|||||||
message RenderCardOut {
|
message RenderCardOut {
|
||||||
repeated RenderedTemplateNode question_nodes = 1;
|
repeated RenderedTemplateNode question_nodes = 1;
|
||||||
repeated RenderedTemplateNode answer_nodes = 2;
|
repeated RenderedTemplateNode answer_nodes = 2;
|
||||||
|
string css = 3;
|
||||||
|
bool latex_svg = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RenderedTemplateNode {
|
message RenderedTemplateNode {
|
||||||
|
@ -175,6 +175,8 @@ impl From<RenderCardOutput> for pb::RenderCardOut {
|
|||||||
pb::RenderCardOut {
|
pb::RenderCardOut {
|
||||||
question_nodes: rendered_nodes_to_proto(o.qnodes),
|
question_nodes: rendered_nodes_to_proto(o.qnodes),
|
||||||
answer_nodes: rendered_nodes_to_proto(o.anodes),
|
answer_nodes: rendered_nodes_to_proto(o.anodes),
|
||||||
|
css: o.css,
|
||||||
|
latex_svg: o.latex_svg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ use crate::{
|
|||||||
pub struct RenderCardOutput {
|
pub struct RenderCardOutput {
|
||||||
pub qnodes: Vec<RenderedNode>,
|
pub qnodes: Vec<RenderedNode>,
|
||||||
pub anodes: Vec<RenderedNode>,
|
pub anodes: Vec<RenderedNode>,
|
||||||
|
pub css: String,
|
||||||
|
pub latex_svg: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
@ -119,7 +121,12 @@ impl Collection {
|
|||||||
nt.is_cloze(),
|
nt.is_cloze(),
|
||||||
&self.tr,
|
&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
|
// Add special fields if they don't clobber note fields
|
||||||
|
Loading…
Reference in New Issue
Block a user