#include "support/lstrings.h"
#include "support/textutils.h"
+#include "support/regex.h"
+
#include <stack>
#include <iostream>
#include <algorithm>
+#include <sstream>
using namespace std;
using namespace lyx::support;
// Don't forget the citation ID!
docstring attr;
for (auto i = 0; i < par->size(); ++i) {
- if (par->getInset(0)->lyxCode() == BIBITEM_CODE) {
+ 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;
}
}
Inset const * firstInset = par->getInset(0);
// Floats cannot be in paragraphs.
- special_case = to_ascii(firstInset->layoutName()).substr(0, 6) == "Float:";
+ special_case = to_utf8(firstInset->layoutName()).substr(0, 6) == "Float:";
// Bibliographies cannot be in paragraphs.
if (!special_case && firstInset->asInsetCommand())
((open_par && (!runparams.docbook_in_par || nextpar != pend))
|| (!open_par && runparams.docbook_in_par && par == pbegin && nextpar != pend));
- if (open_par) {
+ if (open_par)
openParTag(xs, lay);
- }
par->simpleDocBookOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)), open_par, close_par, 0);
if (par->params().depth() == origdepth) {
LATTEST(bstyle == style);
if (lastlay != nullptr) {
- xs << XMLStream::ESCAPE_NONE << ("<!-- lastlay != nullptr; item tag: " + from_utf8(lastlay->docbookitemtag()) + "; item wrapper tag: " + from_utf8(lastlay->docbookitemwrappertag()) + " -->");
closeItemTag(xs, *lastlay);
if (lastlay->docbookitemwrappertag() != "NONE") {
- xs << XMLStream::ESCAPE_NONE << "<!-- has docbookwrappertag -->";
xs << xml::EndTag(lastlay->docbookitemwrappertag());
xs << xml::CR();
}
openLabelTag(xs, style);
xs << lbl;
closeLabelTag(xs, style);
+ } else {
+ // No new line after closeLabelTag.
+ xs << xml::CR();
}
- xs << xml::CR();
}
} else { // some kind of list
if (style.labeltype == LABEL_MANUAL) {
openLabelTag(xs, style);
sep = par->firstWordDocBook(xs, runparams);
closeLabelTag(xs, style);
- xs << xml::CR();
} else {
openLabelTag(xs, style);
xs << par->params().labelString();
closeLabelTag(xs, style);
- xs << xml::CR();
}
}
} // end label output
+ // Start generating the item.
bool wasInParagraph = runparams.docbook_in_par;
openItemTag(xs, style);
bool getsIntoParagraph = openInnerItemTag(xs, style);
OutputParams rp = runparams;
rp.docbook_in_par = wasInParagraph | getsIntoParagraph;
- par->simpleDocBookOnePar(buf, xs, rp, text.outerFont(distance(begin, par)), true, true, sep);
+ // Maybe the item is completely empty, i.e. if the first word ends at the end of the current paragraph
+ // AND if the next paragraph doesn't have the same depth (if there is such a paragraph).
+ // Common case: there is only the first word on the line, but there is a nested list instead
+ // of more text.
+ bool emptyItem = false;
+ if (sep == par->size()) {
+ auto next_par = par;
+ ++next_par;
+ if (next_par == text.paragraphs().end()) // There is no next paragraph.
+ emptyItem = true;
+ else // There is a next paragraph: check depth.
+ emptyItem = par->params().depth() >= next_par->params().depth();
+ }
+
+ if (emptyItem) {
+ // Avoid having an empty item, this is not valid DocBook. A single character is enough to force
+ // generation of a full <para>.
+ xs << ' ';
+ } else {
+ // Generate the rest of the paragraph, if need be.
+ par->simpleDocBookOnePar(buf, xs, rp, text.outerFont(distance(begin, par)), true, true, sep);
+ }
+
++par;
if (getsIntoParagraph)
closeInnerItemTag(xs, style);
}
}
- if (lastlay != 0)
+ if (lastlay != nullptr) {
closeItemTag(xs, *lastlay);
+ if (lastlay->docbookitemwrappertag() != "NONE") {
+ xs << xml::EndTag(lastlay->docbookitemwrappertag());
+ xs << xml::CR();
+ }
+ }
closeTag(xs, bstyle);
xs << xml::CR();
return pend;
// Based on layout information, store this paragraph in one set: should be in <info>, must be.
Layout const &style = par.layout();
- std::cout << "Name: " << to_utf8(style.name()) << std::endl;
- std::cout << " DocBook tag: " << style.docbooktag() << std::endl;
- std::cout << " In info: " << style.docbookininfo() << std::endl;
-
if (style.docbookininfo() == "always") {
mustBeInInfo.emplace(cpit);
} else if (style.docbookininfo() == "maybe") {
(epit == (int) paragraphs.size()) ?
paragraphs.end() : paragraphs.iterator_at(epit);
- std::cout << "generateDocBookParagraphWithoutSectioning" << std::endl;
while (bpit < epit) {
- std::cout << "iteration; bpit: " << bpit << std::endl;
tie(par, send) = makeAny(text, buf, xs, runparams, par, send, pend);
bpit += distance(lastStartedPar, par);
lastStartedPar = par;
}
- std::cout << "generateDocBookParagraphWithoutSectioning has looped; bpit: " << bpit << std::endl;
return bpit;
}
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) {
+ 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.startDivision(false);
- generateDocBookParagraphWithoutSectioning(text, buf, xs, runparams, paragraphs, bpitAbstract, epitAbstract);
- xs.endDivision();
+ xs << XMLStream::ESCAPE_NONE << abstract;
xs << xml::EndTag(tag);
xs << xml::CR();
}