From: Thibaut Cuvelier Date: Thu, 10 Sep 2020 22:44:49 +0000 (+0200) Subject: XHTML: fix generation of many useless . X-Git-Tag: lyx-2.4.0dev-acb2ca7b~181^2~20 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5f0720e9475daa2ce865fc641a4e97d94b4b36a1;p=features.git XHTML: fix generation of many useless . --- diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index 7d9a69bd6a..f8cd53e478 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -611,20 +611,26 @@ void xhtmlParagraphs(Text const & text, // Think about adding
and/or
s. if (style.category() == from_utf8("Sectioning")) { + int level = style.toclevel; + // Need to close a previous section if it has the same level or a higher one (close
if opening a - //

after a

,

,

,

, or
). More examples: + //

after a

,

,

,

or
). More examples: // - current: h2; back: h1; do not close any
// - current: h1; back: h2; close two
(first the

, then the

, so a new

can come) - // The level (h1, h2, etc.) corresponds to style.toclevel. - while (! headerLevels.empty() && style.toclevel <= headerLevels.top()) { + while (!headerLevels.empty() && level <= headerLevels.top()) { + // Output the tag only if it corresponds to a legit section. + int stackLevel = headerLevels.top(); + if (stackLevel != Layout::NOT_IN_TOC && level > 1) { //

is the document title. + xs << xml::EndTag("section"); + xs << xml::CR(); + } headerLevels.pop(); - xs << xml::EndTag("section"); - xs << xml::CR(); } - // Open the new one. - headerLevels.push(style.toclevel); - if (style.toclevel > 1) { //

is the document title. + // Open the new section: first push it onto the stack, then output it in XHTML. + headerLevels.push(level); + // Some sectioning-like elements should not be output (such as FrontMatter). + if (level != Layout::NOT_IN_TOC && level > 1) { //

is the document title. xs << xml::StartTag("section"); xs << xml::CR(); } @@ -669,9 +675,11 @@ void xhtmlParagraphs(Text const & text, // If need be, close
s, but only at the end of the document (otherwise, dealt with at the beginning // of the loop). - while (! headerLevels.empty() && headerLevels.top() > 1) { + while (!headerLevels.empty() && headerLevels.top() > Layout::NOT_IN_TOC) { + docstring tag = from_utf8("
"); headerLevels.pop(); - xs << xml::EndTag("section") << xml::CR(); + xs << XMLStream::ESCAPE_NONE << tag; + xs << xml::CR(); } }