if (par == prevpar)
prevpar = nullptr;
+ // If the previous paragraph is empty, don't consider it when opening wrappers.
+ if (prevpar && prevpar->empty() && !prevpar->allowEmpty())
+ prevpar = nullptr;
+
// When should the wrapper be opened here? Only if the previous paragraph has the SAME wrapper tag
// (usually, they won't have the same layout) and the CURRENT one allows merging.
// The main use case is author information in several paragraphs: if the name of the author is the
if (par == nextpar)
nextpar = nullptr;
+ // If the next paragraph is empty, don't consider it when closing wrappers.
+ if (nextpar && nextpar->empty() && !nextpar->allowEmpty())
+ nextpar = nullptr;
+
// See comment in openParTag.
Layout const & lay = par->layout();
bool closeWrapper = lay.docbookwrappertag() != "NONE" && !runparams.docbook_ignore_wrapper;
return;
});
- std::stack<std::pair<int, string>> headerLevels; // Used to determine when to open/close sections: store the depth
- // of the section and the tag that was used to open it.
-
// Detect whether the document contains sections. If there are no sections, treatment is largely simplified.
// In particular, there can't be an abstract, unless it is manually marked.
bool documentHasSections;
outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
bpit = info.epit;
- // Then, iterate through the paragraphs of this document.
- bool currentlyInAppendix = false;
+ std::stack<std::pair<int, string>> headerLevels; // Used to determine when to open/close sections: store the depth
+ // of the section and the tag that was used to open it.
+ // Then, iterate through the paragraphs of this document.
auto par = text.paragraphs().iterator_at(bpit);
auto end = text.paragraphs().iterator_at(epit);
while (par != end) {
- OutputParams ourparams = runparams;
-
- if (par->params().startOfAppendix())
- currentlyInAppendix = true;
+ // Skip paragraphs not producing any output.
if (hasOnlyNotes(*par)) {
++par;
continue;
}
+ OutputParams ourparams = runparams;
Layout const &style = par->layout();
// Think about adding <section> and/or </section>s.
- if (isLayoutSectioning(style)) {
+ if (isLayoutSectioning(style) || par->params().startOfAppendix()) {
int level = style.toclevel;
// Need to close a previous section if it has the same level or a higher one (close <section> if opening a
// <h2> after a <h2>, <h3>, <h4>, <h5> or <h6>). More examples:
// - current: h2; back: h1; do not close any <section>
// - current: h1; back: h2; close two <section> (first the <h2>, then the <h1>, so a new <h1> can come)
+ // Some layouts require that Layout::NOT_IN_TOC sections still cause closing of previous sections. This is
+ // mostly to ensure that the section is positioned at a DocBook-compatible level (acknowledgements: cannot
+ // be under a section!).
while (!headerLevels.empty() && level <= headerLevels.top().first) {
// Output the tag only if it corresponds to a legit section.
int stackLevel = headerLevels.top().first;
}
// Open the new section: first push it onto the stack, then output it in DocBook.
- string sectionTag = (currentlyInAppendix && style.docbooksectiontag() == "chapter") ?
- "appendix" : style.docbooksectiontag();
+ string sectionTag = (par->params().startOfAppendix()) ? "appendix" : style.docbooksectiontag();
headerLevels.push(std::make_pair(level, sectionTag));
// Some sectioning-like elements should not be output (such as FrontMatter).
Inset const *firstInset = par->getInset(0);
if (firstInset && (firstInset->lyxCode() == BIBITEM_CODE || firstInset->lyxCode() == BIBTEX_CODE)) {
while (!headerLevels.empty()) {
+ // Don't close appendices before bibliographies.
+ if (headerLevels.top().second == "appendix")
+ break;
+
+ // Pop the section from the stack.
int level = headerLevels.top().first;
docstring tag = from_utf8("</" + headerLevels.top().second + ">");
headerLevels.pop();
- // Output the tag only if it corresponds to a legit section.
+ // Output the tag only if it corresponds to a legit section, as the rest of the code.
if (level != Layout::NOT_IN_TOC) {
xs << XMLStream::ESCAPE_NONE << tag;
xs << xml::CR();