commit 82bca97379d8fbfa18b5e889ea3394e2d7ceb336
Author: Thibaut Cuvelier <tcuvel...@lyx.org>
Date:   Thu Oct 7 02:27:54 2021 +0200

    DocBook: overall structure for rendered insets.
---
 src/insets/InsetText.cpp |   53 +++++++++++++++++++++++++++++++++++++++++----
 src/insets/InsetText.h   |    8 +++++-
 2 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 635a83f..5dad3ab 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -606,7 +606,6 @@ int InsetText::plaintext(odocstringstream & os,
 }
 
 
-
 void InsetText::docbook(XMLStream & xs, OutputParams const & rp) const
 {
        docbook(xs, rp, WriteEverything);
@@ -615,8 +614,7 @@ void InsetText::docbook(XMLStream & xs, OutputParams const 
& rp) const
 
 void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions 
opts) const
 {
-       // we will always want to output all our paragraphs when we are
-       // called this way.
+       // Always output all the paragraphs.
        OutputParams runparams = rp;
        runparams.par_begin = 0;
        runparams.par_end = text().paragraphs().size();
@@ -628,13 +626,58 @@ void InsetText::docbook(XMLStream & xs, OutputParams 
const & rp, XHTMLOptions op
                return;
        }
 
-       InsetLayout const & il = getLayout();
+       InsetLayout const &il = getLayout();
 
        // Maybe this is an <info> paragraph that should not be generated at 
all (i.e. right now, its place is somewhere
        // else, typically outside the current paragraph).
        if (!rp.docbook_generate_info && il.docbookininfo() != "never")
                return;
 
+       // Maybe this inset must be rendered before being output.
+       if (il.docbookrenderasimage()) {
+               docbookRenderAsImage(xs, runparams, opts);
+               return;
+       }
+
+       // If none of the special cases before apply, output the inset.
+       docbookText(xs, runparams, opts);
+}
+
+
+void InsetText::docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, 
XHTMLOptions opts) const
+{
+       LASSERT(getLayout().docbookrenderasimage(), return);
+
+       // TODO: deal with opts. What exactly is the WriterOuterTag here, for 
instance?
+       xs << xml::StartTag("mediaobject")
+          << xml::CR();
+
+       // Output the rendered inset.
+       xs << xml::StartTag("imageobject")
+          << xml::CR();
+       xs << xml::EndTag("imageobject")
+          << xml::CR();
+
+       // Output the raw content.
+       xs << xml::StartTag("textobject")
+          << xml::CR()
+          << xml::StartTag("programlisting", "language='latex' role='" + 
getLayout().latexname() + "'");
+       docbookText(xs, rp, opts);
+       xs << xml::EndTag("programlisting")
+          << xml::CR()
+          << xml::EndTag("textobject")
+          << xml::CR();
+
+       xs << xml::EndTag("mediaobject")
+          << xml::CR();
+}
+
+
+void InsetText::docbookText(XMLStream & xs, OutputParams const & rp, 
XHTMLOptions opts) const
+{
+       InsetLayout const &il = getLayout();
+       OutputParams runparams = rp;
+
        // In some cases, the input parameters must be overridden for outer 
tags.
        bool writeOuterTag = opts & WriteOuterTag;
        if (writeOuterTag) {
@@ -667,7 +710,7 @@ void InsetText::docbook(XMLStream & xs, OutputParams const 
& rp, XHTMLOptions op
                        if (par.getInset(i) && par.getInset(i)->lyxCode() == 
ARG_CODE) {
                                InsetArgument const *arg = 
par.getInset(i)->asInsetArgument();
                                if (arg->docbookargumentaftermaintag())
-                    
appendedArguments.insert(par.getInset(i)->asInsetArgument());
+                                       
appendedArguments.insert(par.getInset(i)->asInsetArgument());
                        }
                }
        }
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index 29457aa..564702c 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -93,9 +93,9 @@ public:
        ///
        docstring insetAsXHTML(XMLStream &, OutputParams const &,
                               XHTMLOptions) const;
-       ///
+       /// Outputs the inset as DocBook, with the given options regarding 
outer tags.
        void docbook(XMLStream &, OutputParams const &, XHTMLOptions opts) 
const;
-       ///
+       /// Outputs the whole inset as DocBook.
        void docbook(XMLStream &, OutputParams const &) const override;
        ///
        void validate(LaTeXFeatures & features) const override;
@@ -238,6 +238,10 @@ protected:
        ///
        void iterateForToc(DocIterator const & cdit, bool output_active,
                                           UpdateType utype, TocBackend & 
backend) const;
+       /// Outputs an inset that must be first rendered (with the given 
options regarding outer tags).
+       void docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, 
XHTMLOptions opts) const;
+       /// Outputs the text of the inset with the correct DocBook tags (with 
the given options regarding outer tags).
+       void docbookText(XMLStream & xs, OutputParams const & rp, XHTMLOptions 
opts) const;
 private:
        /// Open the toc item for paragraph pit. Returns the paragraph index 
where
        /// it should end.
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to