DocBook: streamline code to handle sections.

This commit is contained in:
Thibaut Cuvelier 2020-08-30 00:58:50 +02:00
parent f219fe1cd7
commit 17b06f5336

View File

@ -1071,18 +1071,18 @@ void docbookParagraphs(Text const &text,
if (isLayoutSectioning(style)) { if (isLayoutSectioning(style)) {
int level = style.toclevel; 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> // Need to close a previous section if it has the same level or a higher one (close <section> if opening a
// after a <h2>, <h3>, <h4>, <h5> or <h6>). More examples: // <h2> after a <h2>, <h3>, <h4>, <h5> or <h6>). More examples:
// - current: h2; back: h1; do not close any <section> // - 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) // - current: h1; back: h2; close two <section> (first the <h2>, then the <h1>, so a new <h1> can come)
while (!headerLevels.empty() && level <= headerLevels.top().first) { while (!headerLevels.empty() && level <= headerLevels.top().first) {
int stackLevel = headerLevels.top().first;
docstring stackTag = 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.
if (stackLevel != Layout::NOT_IN_TOC) int stackLevel = headerLevels.top().first;
xs << XMLStream::ESCAPE_NONE << stackTag << xml::CR(); if (stackLevel != Layout::NOT_IN_TOC) {
xs << xml::EndTag(headerLevels.top().second);
xs << xml::CR();
}
headerLevels.pop();
} }
// Open the new section: first push it onto the stack, then output it in DocBook. // Open the new section: first push it onto the stack, then output it in DocBook.
@ -1111,11 +1111,10 @@ void docbookParagraphs(Text const &text,
} }
// Write the open tag for this section. // Write the open tag for this section.
docstring tag = from_utf8("<" + sectionTag); docstring attrs;
if (!id.empty()) if (!id.empty())
tag += from_utf8(" ") + id; attrs = id;
tag += from_utf8(">"); xs << xml::StartTag(sectionTag, attrs);
xs << XMLStream::ESCAPE_NONE << tag;
xs << xml::CR(); xs << xml::CR();
} }
} }