[LyX/master] Fix bug #11769

Richard Kimberly Heck rikiheck at lyx.org
Sun Dec 4 16:56:23 UTC 2022


commit 6f4f7442ef3d5ec254e3af33ca6f1461a287200e
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date:   Sun Dec 4 12:51:47 2022 -0500

    Fix bug #11769
---
 lib/layouts/stdlists.inc |    6 ++++++
 src/Layout.cpp           |    4 +++-
 src/output_xhtml.cpp     |   46 +++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc
index 45ec559..1a50878 100644
--- a/lib/layouts/stdlists.inc
+++ b/lib/layouts/stdlists.inc
@@ -88,6 +88,12 @@ Style Enumerate
 	DocBookTag            orderedlist
 	DocBookItemTag        listitem
 	DocBookItemInnerTag   para
+	HTMLStyle
+		ol.enumi   { list-style-type: decimal; }
+		ol.enumii  { list-style-type: lower-latin; }
+		ol.enumiii { list-style-type: lower-roman; }
+		ol.enumiv  { list-style-type: upper-latin; }
+	EndHTMLStyle
 End
 
 Style Description
diff --git a/src/Layout.cpp b/src/Layout.cpp
index b94696f..f782c12 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -1809,7 +1809,9 @@ string const & Layout::htmltag() const
 
 string const & Layout::htmlattr() const
 {
-	if (htmlattr_.empty())
+	// If it's an enumeration, then we recalculate the class each time through
+	// unless it has been given explicitly
+	if (htmlattr_.empty() && labeltype != LABEL_ENUMERATE)
 		htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
 	return htmlattr_;
 }
diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp
index 47c4145..3fb292e 100644
--- a/src/output_xhtml.cpp
+++ b/src/output_xhtml.cpp
@@ -19,6 +19,7 @@
 #include "Counters.h"
 #include "Font.h"
 #include "Layout.h"
+#include "LayoutEnums.h"
 #include "Paragraph.h"
 #include "ParagraphList.h"
 #include "ParagraphParameters.h"
@@ -156,7 +157,7 @@ namespace {
 // convenience functions
 
 inline void openParTag(XMLStream & xs, Layout const & lay,
-                       const std::string & parlabel)
+                       std::string const & parlabel)
 {
 	string attrs = lay.htmlattr();
 	if (!parlabel.empty())
@@ -166,8 +167,17 @@ inline void openParTag(XMLStream & xs, Layout const & lay,
 
 
 void openParTag(XMLStream & xs, Layout const & lay,
+                std::string const & cssclass,
+                std::string const & parlabel) {
+    string attrs = "class='" + cssclass + "'";
+    if (!parlabel.empty())
+        attrs += " id='" + parlabel + "'";
+    xs << xml::ParTag(lay.htmltag(), attrs);
+}
+
+void openParTag(XMLStream & xs, Layout const & lay,
                 ParagraphParameters const & params,
-                const std::string & parlabel)
+                std::string const & parlabel)
 {
 	// FIXME Are there other things we should handle here?
 	string const align = alignmentToCSS(params.align());
@@ -398,7 +408,37 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
 	depth_type const origdepth = pbegin->params().depth();
 
 	// open tag for this environment
-	openParTag(xs, bstyle, pbegin->magicLabel());
+	if (bstyle.labeltype == LABEL_ENUMERATE && bstyle.htmlattr().empty()) {
+		// In this case, we have to calculate the CSS class ourselves, each time
+		// through
+		// FIXME We assume in these cases that the standard enumeration counter
+		// is being used. (We also do not deal with 'resume' counters, though I'm
+		// not sure that can be done at all.)
+
+		// Code borrowed from Buffer::Impl::setLabel
+		docstring enumcounter = bstyle.counter.empty() ?
+					from_ascii("enum") : bstyle.counter;
+		switch (par->itemdepth) {
+		case 2:
+			enumcounter += 'i';
+			// fall through
+		case 1:
+			enumcounter += 'i';
+			// fall through
+		case 0:
+			enumcounter += 'i';
+			break;
+		case 3:
+			enumcounter += "iv";
+			break;
+		default:
+			// not a valid enumdepth...
+			break;
+		}
+		openParTag(xs, bstyle, to_utf8(enumcounter), pbegin->magicLabel());
+	}
+	else
+		openParTag(xs, bstyle, pbegin->magicLabel());
 	xs << xml::CR();
 
 	// we will on occasion need to remember a layout from before.


More information about the lyx-cvs mailing list