]> git.lyx.org Git - lyx.git/commitdiff
DocBook: add support for DocBookArgumentAfterMainTag.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Sun, 14 Feb 2021 06:07:04 +0000 (07:07 +0100)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Wed, 17 Feb 2021 20:09:21 +0000 (21:09 +0100)
src/Layout.cpp
src/Layout.h
src/OutputParams.h
src/insets/InsetArgument.cpp
src/insets/InsetArgument.h
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h
src/insets/InsetText.cpp

index e037ad1c5e69d6840a0e4e9679d477aa46a77c86..e5d683ec1855d3f089eaa19828926c7eff5a1017 100644 (file)
@@ -1284,6 +1284,12 @@ void Layout::readArgument(Lexer & lex, bool validating)
                } else if (tok == "docbooktagtype") {
                        lex.next();
                        arg.docbooktagtype = lex.getDocString();
+               } else if (tok == "docbookargumentaftermaintag") {
+                       lex.next();
+                       arg.docbookargumentaftermaintag = lex.getBool();
+               } else if (tok == "docbookargumentbeforemaintag") {
+                       lex.next();
+                       arg.docbookargumentbeforemaintag = lex.getBool();
                } else {
                        lex.printError("Unknown tag");
                        error = true;
index 4eb8412723b9263d75427e4b71afcef11b4801d0..99cc4df5475e2dd7bdab1f04a721370cbd09d02d 100644 (file)
@@ -89,7 +89,7 @@ public:
        std::string const & latexname() const { return latexname_; }
        ///
        std::string const & itemcommand() const { return itemcommand_; }
-       /// The arguments of this layout
+       /// One argument of this layout
        struct latexarg {
                docstring labelstring;
                docstring menustring;
@@ -112,10 +112,16 @@ public:
                bool is_toc_caption = false;
                bool free_spacing = false;
                std::string newlinecmd;
+               /// The DocBook tag corresponding to this argument.
                docstring docbooktag;
                docstring docbooktagtype;
                docstring docbookattr;
+        /// Whether this argument should be output after the main tag (default: inside). The result if the argument
+        /// should be output both before and after the main tag is undefined.
                bool docbookargumentbeforemaintag = false;
+        /// Whether this argument should be output before the main tag (default: inside). The result if the argument
+        /// should be output both before and after the main tag is undefined.
+               bool docbookargumentaftermaintag = false;
        };
        ///
        typedef std::map<std::string, latexarg> LaTeXArgMap;
index 05eed6b687eb8b159bd3954bf8d0795479282193..48ad61e7d9e7f0efb72c09f12d207dfb96a13ae1 100644 (file)
@@ -393,6 +393,9 @@ public:
        /// Some parameters are output before the rest of the paragraph, they should not be generated a second time.
        std::set<InsetArgument const *> docbook_prepended_arguments = {};
 
+       /// Some parameters are output after the rest of the paragraph, they should not be generated a second time.
+       std::set<InsetArgument const *> docbook_appended_arguments = {};
+
        /// Are we generating this material for inclusion in a TOC-like entity?
        bool for_toc = false;
 
index 3f26f85739f52fdc41aa5f494ba1493c1203cd9d..811b8845d34ae73a519229099a6538572d2e3a5f 100644 (file)
@@ -127,6 +127,7 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype, bool
                docbooktagtype_ = (*lait).second.docbooktagtype;
                docbookattr_ = (*lait).second.docbookattr;
                docbookargumentbeforemaintag_ = (*lait).second.docbookargumentbeforemaintag;
+               docbookargumentaftermaintag_ = (*lait).second.docbookargumentaftermaintag;
                pass_thru_local_ = false;
                if (lait->second.is_toc_caption) {
                        is_toc_caption_ = true;
@@ -313,9 +314,11 @@ InsetDecoration InsetArgument::decoration() const
 
 
 void InsetArgument::docbook(XMLStream & xs, OutputParams const & rp) const {
-       // Ignore arguments that have already been output.
+       // Ignore arguments that have already been output or are planned to be output elsewhere.
        if (rp.docbook_prepended_arguments.find(this) != rp.docbook_prepended_arguments.end())
                return;
+       if (rp.docbook_appended_arguments.find(this) != rp.docbook_appended_arguments.end())
+               return;
 
        if (docbooktag_ != from_ascii("NONE") && docbooktag_ != from_ascii("IGNORE")) {
                // TODO: implement docbooktagtype_.
index 2249f2f8e6436647094de31fd484d138af2677e2..7488e4586c473a1d4437b819fcf2d15bd2af63b3 100644 (file)
@@ -41,6 +41,8 @@ public:
 
        bool docbookargumentbeforemaintag() const { return docbookargumentbeforemaintag_; }
 
+       bool docbookargumentaftermaintag() const { return docbookargumentaftermaintag_; }
+
        /// \name Public functions inherited from Inset class
        //@{
        ///
@@ -135,6 +137,8 @@ private:
        docstring docbookattr_;
        ///
        bool docbookargumentbeforemaintag_ = false;
+       ///
+       bool docbookargumentaftermaintag_ = false;
 
 protected:
        /// \name Protected functions inherited from Inset class
index 391f9c932f9c172e6843b4736c895e05b185c039..b6056cd09837c7223aecf3a782785e02fcbc068d 100644 (file)
@@ -96,6 +96,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
                IL_DOCBOOKSECTION,
                IL_DOCBOOKININFO,
                IL_DOCBOOKARGUMENTBEFOREMAINTAG,
+               IL_DOCBOOKARGUMENTAFTERMAINTAG,
                IL_DOCBOOKNOTINPARA,
                IL_DOCBOOKWRAPPERTAG,
                IL_DOCBOOKWRAPPERTAGTYPE,
@@ -151,6 +152,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
                { "custompars", IL_CUSTOMPARS },
                { "decoration", IL_DECORATION },
                { "display", IL_DISPLAY },
+               { "docbookargumentaftermaintag", IL_DOCBOOKARGUMENTAFTERMAINTAG },
                { "docbookargumentbeforemaintag", IL_DOCBOOKARGUMENTBEFOREMAINTAG },
                { "docbookattr", IL_DOCBOOKATTR },
                { "docbookininfo", IL_DOCBOOKININFO },
@@ -525,6 +527,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
                case IL_DOCBOOKARGUMENTBEFOREMAINTAG:
                        lex >> docbookargumentbeforemaintag_;
                        break;
+               case IL_DOCBOOKARGUMENTAFTERMAINTAG:
+                       lex >> docbookargumentaftermaintag_;
+                       break;
                case IL_DOCBOOKNOTINPARA:
                        lex >> docbooknotinpara_;
                        break;
@@ -839,6 +844,9 @@ void InsetLayout::readArgument(Lexer & lex)
                } else if (tok == "docbookargumentbeforemaintag") {
                        lex.next();
                        arg.docbookargumentbeforemaintag = lex.getBool();
+               } else if (tok == "docbookargumentaftermaintag") {
+                       lex.next();
+                       arg.docbookargumentaftermaintag = lex.getBool();
                } else {
                        lex.printError("Unknown tag");
                        error = true;
index 47fa633e6930f749a9ebcd0e4ef7e80bd0400b6a..b48fde7f0ababc7ba7a52e35d94b0e3c3dd5ad7c 100644 (file)
@@ -164,6 +164,8 @@ public:
        ///
        bool docbookargumentbeforemaintag() const { return docbookargumentbeforemaintag_; }
        ///
+       bool docbookargumentaftermaintag() const { return docbookargumentaftermaintag_; }
+       ///
        std::string docbookwrappertag() const { return docbookwrappertag_; }
        ///
        std::string docbookwrappertagtype() const;
@@ -322,6 +324,8 @@ private:
        bool docbooknotinpara_ = false;
        ///
        bool docbookargumentbeforemaintag_ = false;
+    ///
+    bool docbookargumentaftermaintag_ = false;
        ///
        bool docbooksection_ = false;
        ///
index 5504a2d6c8a06cef558a238bb0dc4c24b8108c1f..79425887bea84b0fc9c50f251988eec8f37dc57e 100644 (file)
@@ -635,7 +635,7 @@ void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions op
                writeOuterTag = !allBibitems;
        }
 
-       // Detect arguments that should be output before the paragraph.
+       // Detect arguments that should be output before/after the paragraph.
        // Don't reuse runparams.docbook_prepended_arguments, as the same object is used in InsetArgument to determine
        // whether the inset should be output or not, whatever the context (i.e. position with respect to the wrapper).
        std::set<InsetArgument const *> prependedArguments;
@@ -649,6 +649,17 @@ void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions op
                }
        }
 
+       std::set<InsetArgument const *> appendedArguments;
+       for (auto const & par : paragraphs()) {
+               for (pos_type i = 0; i < par.size(); ++i) {
+                       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());
+                       }
+               }
+       }
+
        // Start outputting this inset.
        // - First, wrapper around the inset and its main tag.
        if (writeOuterTag) {
@@ -665,14 +676,15 @@ void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions op
                }
        }
 
-       // - Think about the arguments.
+       // - Think about the arguments before the paragraph.
        OutputParams np = runparams;
        np.docbook_in_par = true;
        for (auto const & arg : prependedArguments)
                arg->docbook(xs, np);
 
-       // - Mark the newly generated arguments are not-to-be-generated-again.
+       // - Mark the newly generated arguments are not-to-be-generated-again. Do the same for arguments that will follow.
        runparams.docbook_prepended_arguments = std::move(prependedArguments);
+       runparams.docbook_appended_arguments = appendedArguments;
 
        // - Deal with the first item.
        // TODO: in things like SciPoster, this should also check if the item tag is allowed. Hard to formalise for now...
@@ -697,6 +709,10 @@ void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions op
        docbookParagraphs(text_, buffer(), xs, runparams);
        xs.endDivision();
 
+    // - Think about the arguments after the paragraph.
+    for (auto const & arg : appendedArguments)
+        arg->docbook(xs, np);
+
        // - Close the required tags.
        if (writeOuterTag) {
                if (!il.docbookitemtag().empty() && il.docbookitemtag() != "NONE" && il.docbookitemtag() != "IGNORE")