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 <IGNORE> 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.)
This commit is contained in:
Thibaut Cuvelier 2020-11-14 22:05:59 +01:00
parent 222a317dd2
commit 6bc04367cf
3 changed files with 34 additions and 10 deletions

View File

@ -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);

View File

@ -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());
}

View File

@ -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();