DocBook: add support for DocBookArgumentAfterMainTag.

This commit is contained in:
Thibaut Cuvelier 2021-02-14 07:07:04 +01:00
parent ba672f7f79
commit adc7820d45
8 changed files with 55 additions and 5 deletions

View 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;

View 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;

View 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;

View 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_.

View 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

View 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;

View 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;
///

View 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")