From 6bc04367cf68accc02096e1ebadfd59325229a73 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sat, 14 Nov 2020 22:05:59 +0100 Subject: [PATCH] DocBook: add support for IGNORE tags. These paragraphs will simply have no output (no enclosing DocBook tag, no content). This change is as backward-compatible as possible: without this commit, the paragraphs will be output, but in an tag (not much more can be achieved without this). It is mostly made for metadata and formatting instructions. (As opposed to NONE, which corresponds to outputting the paragraph without enclosing DocBook tag.) --- src/insets/InsetArgument.cpp | 2 +- src/insets/InsetText.cpp | 4 ++-- src/output_docbook.cpp | 38 +++++++++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index f29ca995a5..8f1d762fa3 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -312,7 +312,7 @@ InsetLayout::InsetDecoration InsetArgument::decoration() const void InsetArgument::docbook(XMLStream & xs, OutputParams const & rp) const { - if (docbooktag_ != from_ascii("NONE")) { + if (docbooktag_ != from_ascii("NONE") && docbooktag_ != from_ascii("IGNORE")) { // TODO: implement docbooktagtype_. xs << xml::StartTag(docbooktag_, docbookattr_); InsetText::docbook(xs, rp); diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 3305eddf96..9e5f4ac02e 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -616,7 +616,7 @@ void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions op } InsetLayout const & il = getLayout(); - if (opts & WriteOuterTag && !il.docbooktag().empty() && il.docbooktag() != "NONE") { + if (opts & WriteOuterTag && !il.docbooktag().empty() && il.docbooktag() != "NONE" && il.docbooktag() != "IGNORE") { docstring attrs = docstring(); if (!il.docbookattr().empty()) attrs += from_ascii(il.docbookattr()); @@ -637,7 +637,7 @@ void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions op docbookParagraphs(text_, buffer(), xs, runparams); xs.endDivision(); - if (opts & WriteOuterTag) + if (opts & WriteOuterTag && !il.docbooktag().empty() && il.docbooktag() != "NONE" && il.docbooktag() != "IGNORE") xs << xml::EndTag(il.docbooktag()); } diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index 58e1b810f1..d25d85f573 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -412,6 +412,11 @@ void makeParagraph( OutputParams const & runparams, ParagraphList::const_iterator const & par) { + // If this kind of layout should be ignored, already leave. + if (par->layout().docbooktag() == "IGNORE") + return; + + // Useful variables. auto const begin = text.paragraphs().begin(); auto const end = text.paragraphs().end(); auto prevpar = text.paragraphs().getParagraphBefore(par); @@ -503,15 +508,16 @@ void makeParagraph( ++nextpar; auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end, special_case); for (docstring const & parXML : pars) { - if (xml::isNotOnlySpace(parXML)) { - if (open_par) - openParTag(xs, &*par, prevpar); + if (!xml::isNotOnlySpace(parXML)) + continue; - xs << XMLStream::ESCAPE_NONE << parXML; + if (open_par) + openParTag(xs, &*par, prevpar); - if (close_par) - closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); - } + xs << XMLStream::ESCAPE_NONE << parXML; + + if (close_par) + closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); } } @@ -522,6 +528,11 @@ void makeEnvironment(Text const &text, OutputParams const &runparams, ParagraphList::const_iterator const & par) { + // If this kind of layout should be ignored, already leave. + if (par->layout().docbooktag() == "IGNORE") + return; + + // Useful variables. auto const end = text.paragraphs().end(); auto nextpar = par; ++nextpar; @@ -618,10 +629,18 @@ ParagraphList::const_iterator makeListEnvironment(Text const &text, OutputParams const &runparams, ParagraphList::const_iterator const & begin) { + // Useful variables. auto par = begin; auto const end = text.paragraphs().end(); auto const envend = findEndOfEnvironment(par, end); + // If this kind of layout should be ignored, already leave. + if (begin->layout().docbooktag() == "IGNORE") { + auto nextpar = par; + ++nextpar; + return nextpar; + } + // Output the opening tag for this environment. Layout const & envstyle = par->layout(); openTag(xs, envstyle.docbookwrappertag(), envstyle.docbookwrapperattr(), envstyle.docbookwrappertagtype()); @@ -708,6 +727,11 @@ void makeCommand( OutputParams const & runparams, ParagraphList::const_iterator const & par) { + // If this kind of layout should be ignored, already leave. + if (par->layout().docbooktag() == "IGNORE") + return; + + // Useful variables. // Unlike XHTML, no need for labels, as they are handled by DocBook tags. auto const begin = text.paragraphs().begin(); auto const end = text.paragraphs().end();