#include "support/lstrings.h"
#include "support/textutils.h"
+#include "support/regex.h"
+
#include <stack>
#include <iostream>
#include <algorithm>
return p;
}
+ParagraphList::const_iterator findLastBibliographyParagraph(
+ ParagraphList::const_iterator p,
+ ParagraphList::const_iterator const & pend) {
+ for (++p; p != pend && p->layout().latextype == LATEX_BIB_ENVIRONMENT; ++p);
+
+ return p;
+}
+
ParagraphList::const_iterator findEndOfEnvironment(
ParagraphList::const_iterator const & pstart,
xs << xml::CR();
}
- // Generate the required paragraphs.
+ // Generate the required paragraphs, but only if they are .
for (; par != pend; ++par) {
// Start the precooked bibliography entry. This is very much like opening a paragraph tag.
// Don't forget the citation ID!
Inset const *ip = par->getInset(0);
if (ip != nullptr && ip->lyxCode() == BIBITEM_CODE) {
const auto * bibitem = dynamic_cast<const InsetBibitem*>(par->getInset(i));
- attr = from_utf8("xml:id='") + bibitem->bibLabel() + from_utf8("'");
+ attr = from_utf8("xml:id='") + bibitem->getParam("key") + from_utf8("'");
break;
}
}
((open_par && (!runparams.docbook_in_par || nextpar != pend))
|| (!open_par && runparams.docbook_in_par && par == pbegin && nextpar != pend));
- if (open_par) {
- openParTag(xs, lay);
- }
+ // Determine if this paragraph has some real content. Things like new pages are not caught
+ // by Paragraph::empty(), even though they do not generate anything useful in DocBook.
+ odocstringstream os2;
+ XMLStream xs2(os2);
+ par->simpleDocBookOnePar(buf, xs2, runparams, text.outerFont(distance(begin, par)), open_par, close_par, 0);
- par->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)), open_par, close_par, 0);
+ docstring cleaned = os2.str();
+ static const lyx::regex reg("[ \\r\\n]*");
+ cleaned = from_utf8(lyx::regex_replace(to_utf8(cleaned), reg, string("")));
- if (close_par) {
- closeTag(xs, lay);
- xs << xml::CR();
+ if (!cleaned.empty()) {
+ if (open_par)
+ openParTag(xs, lay);
+
+ xs << XMLStream::ESCAPE_NONE << os2.str();
+
+ if (close_par) {
+ closeTag(xs, lay);
+ xs << xml::CR();
+ }
}
}
return pend;
par = makeParagraphs(buf, xs, runparams, text, par, send);
break;
case LATEX_BIB_ENVIRONMENT:
- send = findLastParagraph(par, pend);
+ send = findLastBibliographyParagraph(par, pend);
par = makeParagraphBibliography(buf, xs, runparams, text, par, send);
break;
case LATEX_COMMAND:
break;
}
case LATEX_BIB_ENVIRONMENT: {
- send = findLastParagraph(par, pend);
+ send = findLastBibliographyParagraph(par, pend);
par = makeParagraphBibliography(buf, xs, ourparams, text, par, send);
break;
}
pit_type epitInfo;
tie(shouldBeInInfo, mustBeInInfo, bpitInfo, epitInfo) = info;
- // The abstract must go in <info>.
+ // Perform an additional check on the abstract. Sometimes, there are many paragraphs that should go
+ // into the abstract, but none generates actual content. Thus, first generate to a temporary stream,
+ // then only create the <abstract> tag if these paragraphs generate some content.
+ // This check must be performed *before* a decision on whether or not to output <info> is made.
bool hasAbstract = hasAbstractBetween(paragraphs, bpitAbstract, epitAbstract);
+ docstring abstract;
+ if (hasAbstract) {
+ odocstringstream os2;
+ XMLStream xs2(os2);
+ generateDocBookParagraphWithoutSectioning(text, buf, xs2, runparams, paragraphs, bpitAbstract, epitAbstract);
+
+ // Actually output the abstract if there is something to do. Don't count line feeds or spaces in this,
+ // even though they must be properly output if there is some abstract.
+ docstring abstractContent = os2.str();
+ static const lyx::regex reg("[ \\r\\n]*");
+ abstractContent = from_utf8(lyx::regex_replace(to_utf8(abstractContent), reg, string("")));
+
+ // Nothing? Then there is no abstract!
+ if (abstractContent.empty())
+ hasAbstract = false;
+ }
+
+ // The abstract must go in <info>.
bool needInfo = !mustBeInInfo.empty() || hasAbstract;
// Start the <info> tag if required.
// Output the elements that should go in <info>.
generateDocBookParagraphWithoutSectioning(text, buf, xs, runparams, paragraphs, bpitInfo, epitInfo);
- if (hasAbstract) {
- // Sometimes, there are many paragraphs that should go into the abstract, but none generates actual content.
- // Thus, first generate to a temporary stream, then only create the <abstract> tag if these paragraphs
- // generate some content.
- odocstringstream os2;
- XMLStream xs2(os2);
- generateDocBookParagraphWithoutSectioning(text, buf, xs2, runparams, paragraphs, bpitAbstract, epitAbstract);
-
- // Actually output the abstract if there is something to do.
- if (!os2.str().empty()) {
- string tag = paragraphs[bpitAbstract].layout().docbookforceabstracttag();
- if (tag == "NONE")
- tag = "abstract";
+ if (hasAbstract && !abstract.empty()) { // The second test is probably superfluous.
+ string tag = paragraphs[bpitAbstract].layout().docbookforceabstracttag();
+ if (tag == "NONE")
+ tag = "abstract";
- xs << xml::StartTag(tag);
- xs << xml::CR();
- xs << XMLStream::ESCAPE_NONE << os2.str();
- xs << xml::EndTag(tag);
- xs << xml::CR();
- }
+ xs << xml::StartTag(tag);
+ xs << xml::CR();
+ xs << XMLStream::ESCAPE_NONE << abstract;
+ xs << xml::EndTag(tag);
+ xs << xml::CR();
}
// End the <info> tag if it was started.