From adc7820d458244a6425f269fd98737c8d42ca18a Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 14 Feb 2021 07:07:04 +0100 Subject: [PATCH] DocBook: add support for DocBookArgumentAfterMainTag. --- src/Layout.cpp | 6 ++++++ src/Layout.h | 8 +++++++- src/OutputParams.h | 3 +++ src/insets/InsetArgument.cpp | 5 ++++- src/insets/InsetArgument.h | 4 ++++ src/insets/InsetLayout.cpp | 8 ++++++++ src/insets/InsetLayout.h | 4 ++++ src/insets/InsetText.cpp | 22 +++++++++++++++++++--- 8 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Layout.cpp b/src/Layout.cpp index e037ad1c5e..e5d683ec18 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -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; diff --git a/src/Layout.h b/src/Layout.h index 4eb8412723..99cc4df547 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -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 LaTeXArgMap; diff --git a/src/OutputParams.h b/src/OutputParams.h index 05eed6b687..48ad61e7d9 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -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 docbook_prepended_arguments = {}; + /// Some parameters are output after the rest of the paragraph, they should not be generated a second time. + std::set docbook_appended_arguments = {}; + /// Are we generating this material for inclusion in a TOC-like entity? bool for_toc = false; diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index 3f26f85739..811b8845d3 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -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_. diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index 2249f2f8e6..7488e4586c 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -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 diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 391f9c932f..b6056cd098 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -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; diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 47fa633e69..b48fde7f0a 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -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; /// diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 5504a2d6c8..79425887be 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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 prependedArguments; @@ -649,6 +649,17 @@ void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions op } } + std::set 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") -- 2.39.5