From 3502f5c999f7c91da83d247e1a460ef30a497aa0 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Wed, 13 Oct 2021 03:01:54 +0200 Subject: [PATCH] Factor out the generation of the code to create a preview. This will be soon reused in InsetText to generate images for DocBook. --- src/insets/InsetPreview.cpp | 16 +++++++++++----- src/insets/InsetPreview.h | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp index e08fdcd39b..c4f1b8d83d 100644 --- a/src/insets/InsetPreview.cpp +++ b/src/insets/InsetPreview.cpp @@ -107,19 +107,25 @@ MacroNameSet gatherMacroDefinitions(const Buffer* buffer, const Inset * inset) } -void InsetPreview::preparePreview(DocIterator const & pos) const +docstring insetToLaTeXSnippet(const Buffer* buffer, const Inset * inset) { odocstringstream str; otexstream os(str); - OutputParams runparams(&pos.buffer()->params().encoding()); - latex(os, runparams); + OutputParams runparams(&buffer->params().encoding()); + inset->latex(os, runparams); - MacroNameSet defs = gatherMacroDefinitions(pos.buffer(), this); + MacroNameSet defs = gatherMacroDefinitions(buffer, inset); docstring macro_preamble; for (const auto& def : defs) macro_preamble.append(def); - docstring const snippet = macro_preamble + str.str(); + return macro_preamble + str.str(); +} + + +void InsetPreview::preparePreview(DocIterator const & pos) const +{ + docstring const snippet = insetToLaTeXSnippet(pos.buffer(), this); preview_->addPreview(snippet, *pos.buffer()); } diff --git a/src/insets/InsetPreview.h b/src/insets/InsetPreview.h index 55353e72d7..db2a2af96b 100644 --- a/src/insets/InsetPreview.h +++ b/src/insets/InsetPreview.h @@ -90,6 +90,8 @@ protected: /// gathers the list of macro definitions used in the given inset MacroNameSet gatherMacroDefinitions(const Buffer* buffer, const Inset * inset); +/// returns the LaTeX snippet to compute the preview of the given inset +docstring insetToLaTeXSnippet(const Buffer* buffer, const Inset * inset); } // namespace lyx -- 2.39.5