[LyX features/feature/docbook] XHTML: fix generation of many useless </section>.
Thibaut Cuvelier
tcuvelier at lyx.org
Thu Sep 10 22:22:07 UTC 2020
The branch, feature/docbook, has been updated.
- Log -----------------------------------------------------------------
commit 1da73ace5072643c298c807e4c2a3f3ebb1ef41f
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Fri Sep 11 00:44:49 2020 +0200
XHTML: fix generation of many useless </section>.
diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp
index 7d9a69b..4892a35 100644
--- a/src/output_xhtml.cpp
+++ b/src/output_xhtml.cpp
@@ -611,20 +611,26 @@ void xhtmlParagraphs(Text const & text,
// Think about adding <section> and/or </section>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 <section> if opening a
- // <h2> 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: h1; back: h2; close two <section> (first the <h2>, then the <h1>, so a new <h1> 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) { // <h1> 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) { // <h1> 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) { // <h1> is the document title.
xs << xml::StartTag("section");
xs << xml::CR();
}
commit 982b435dd5f91fba142180eba7b9962bb045d7f7
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Fri Sep 11 00:39:41 2020 +0200
XML: bad fix for a crash that only happened in XHTML.
As an error is output, I suppose that this behaviour is OK.
diff --git a/src/xml.cpp b/src/xml.cpp
index 478f961..149032a 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -477,7 +477,8 @@ XMLStream &XMLStream::operator<<(xml::EndTag const &etag)
+ "' when other tags were pending. Last pending tag is `"
+ to_utf8(pending_tags_.back()->writeTag())
+ "'. Tag discarded.");
- pending_tags_.erase(dit);
+ if (!pending_tags_.empty())
+ pending_tags_.erase(dit);
return *this;
}
}
-----------------------------------------------------------------------
Summary of changes:
src/output_xhtml.cpp | 22 ++++++++++++++--------
src/xml.cpp | 3 ++-
2 files changed, 16 insertions(+), 9 deletions(-)
hooks/post-receive
--
Repository for new features
More information about the lyx-cvs
mailing list