From 69a6c41b9417c0f069f4eeae2b0f2e932ee39be4 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Sun, 4 Dec 2022 13:27:19 -0500 Subject: [PATCH] Introduce HTMLClass tag, to make it easier to give these. --- lib/layouts/aastex.layout | 2 +- lib/layouts/aguplus.inc | 2 +- lib/layouts/apa.layout | 2 +- lib/layouts/apax.inc | 2 +- lib/layouts/bicaption.module | 2 +- lib/layouts/logicalmkup.module | 2 +- lib/layouts/scrclass.inc | 4 ++-- lib/layouts/stdinsets.inc | 8 ++++---- lib/layouts/stdlists.inc | 1 - lib/layouts/stdlyxlist.inc | 2 +- lib/scripts/layout2layout.py | 7 +++++-- src/Layout.cpp | 35 ++++++++++++++++++++++++++++++---- src/Layout.h | 14 +++++++++++--- src/TextClass.cpp | 2 +- src/insets/InsetIndex.cpp | 2 +- src/output_xhtml.cpp | 8 ++++---- 16 files changed, 66 insertions(+), 29 deletions(-) diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout index 52933dc19d..6551e2f1d7 100644 --- a/lib/layouts/aastex.layout +++ b/lib/layouts/aastex.layout @@ -619,7 +619,7 @@ InsetLayout Caption:FigCaption margin: 1ex; } EndHTMLStyle - HTMLAttr "class='float-caption float-caption-figcaption'" + HTMLClass "float-caption float-caption-figcaption" End diff --git a/lib/layouts/aguplus.inc b/lib/layouts/aguplus.inc index 1d7ceb5302..f21aa55baa 100644 --- a/lib/layouts/aguplus.inc +++ b/lib/layouts/aguplus.inc @@ -222,7 +222,7 @@ InsetLayout Caption:Table margin: 1ex; } EndHTMLStyle - HTMLAttr "class='float-caption float-caption-table'" + HTMLClass "float-caption float-caption-table" End diff --git a/lib/layouts/apa.layout b/lib/layouts/apa.layout index 5ddd1f85c5..bed15f6e4f 100644 --- a/lib/layouts/apa.layout +++ b/lib/layouts/apa.layout @@ -300,7 +300,7 @@ InsetLayout Caption:Centered margin: 1ex; } EndHTMLStyle - HTMLAttr "class='float-caption float-caption-centered'" + HTMLClass "float-caption float-caption-centered" End diff --git a/lib/layouts/apax.inc b/lib/layouts/apax.inc index 8981e36cc0..321dd08ff6 100644 --- a/lib/layouts/apax.inc +++ b/lib/layouts/apax.inc @@ -399,7 +399,7 @@ InsetLayout Caption:Centered margin: 1ex; } EndHTMLStyle - HTMLAttr "class='float-caption float-caption-centered'" + HTMLClass "float-caption float-caption-centered" End diff --git a/lib/layouts/bicaption.module b/lib/layouts/bicaption.module index 12c4f25915..fc2c10507a 100644 --- a/lib/layouts/bicaption.module +++ b/lib/layouts/bicaption.module @@ -62,5 +62,5 @@ InsetLayout Caption:Bicaption margin: 1ex; } EndHTMLStyle - HTMLAttr "class='float-caption float-caption-bicaption'" + HTMLClass "float-caption float-caption-bicaption" End diff --git a/lib/layouts/logicalmkup.module b/lib/layouts/logicalmkup.module index 78d1009f41..7c56aed5cb 100644 --- a/lib/layouts/logicalmkup.module +++ b/lib/layouts/logicalmkup.module @@ -19,7 +19,7 @@ InsetLayout Flex:Noun Requires noun InToc true HTMLTag span - HTMLAttr class='noun' + HTMLClass noun HTMLStyle span.noun { font-family: sans-serif; diff --git a/lib/layouts/scrclass.inc b/lib/layouts/scrclass.inc index c437c0eaaf..5127ab51d1 100644 --- a/lib/layouts/scrclass.inc +++ b/lib/layouts/scrclass.inc @@ -335,7 +335,7 @@ InsetLayout Caption:Above margin: 1ex; } EndHTMLStyle - HTMLAttr "class='float-caption float-caption-above'" + HTMLClass "float-caption float-caption-above" End @@ -360,7 +360,7 @@ InsetLayout Caption:Below margin: 1ex; } EndHTMLStyle - HTMLAttr "class='float-caption float-caption-below'" + HTMLClass "float-caption float-caption-below" End diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc index b102ceb4b9..57f05af855 100644 --- a/lib/layouts/stdinsets.inc +++ b/lib/layouts/stdinsets.inc @@ -666,7 +666,7 @@ InsetLayout Info:menu Font Family sans EndFont - HTMLAttr "class='info menu'" + HTMLClass "info menu'" HTMLStyle span.menu { font-family: sans-serif; } EndHTMLStyle @@ -685,7 +685,7 @@ InsetLayout Info:shortcut Font Family sans EndFont - HTMLAttr "class='info shortcut'" + HTMLCLass "info shortcut" HTMLStyle span.shortcut { font-family: sans-serif; } EndHTMLStyle @@ -706,7 +706,7 @@ InsetLayout Info:shortcuts Font Family sans EndFont - HTMLAttr "class='info shortcut'" + HTMLClass "info shortcut" HTMLStyle span.shortcuts { font-family: sans-serif; } EndHTMLStyle @@ -737,7 +737,7 @@ InsetLayout Caption:Standard margin: 1ex; } EndHTMLStyle - HTMLAttr "class='float-caption float-caption-standard'" + HTMLClass "float-caption float-caption-standard" End diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc index 1a50878991..d4a7d922a5 100644 --- a/lib/layouts/stdlists.inc +++ b/lib/layouts/stdlists.inc @@ -116,7 +116,6 @@ Style Description Series Bold EndFont HTMLTag dl - HTMLAttr class='description' HTMLItem dd HTMLLabel dt HTMLLabelFirst 1 diff --git a/lib/layouts/stdlyxlist.inc b/lib/layouts/stdlyxlist.inc index 064c357d6c..c3ea8edda5 100644 --- a/lib/layouts/stdlyxlist.inc +++ b/lib/layouts/stdlyxlist.inc @@ -29,7 +29,7 @@ Style Labeling EndFont EndArgument HTMLTag ol - HTMLAttr class='lyxlist' + HTMLClass lyxlist HTMLItem li HTMLLabel span HTMLLabelAttr class='lyxlist' diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 144cb350fd..4add2e5beb 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -11,7 +11,7 @@ # This script will update a .layout file to current format # The latest layout format is also defined in src/TextClass.cpp -currentFormat = 96 +currentFormat = 97 # Incremented to format 4, 6 April 2007, lasgouttes @@ -325,6 +325,9 @@ currentFormat = 96 # Incremented to format 96, 4 December 2022 by rikiheck # Add HTMLInToc +# Incremented to format 97, 4 December 2022 by rikiheck +# Add HTMLClass + # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). @@ -575,7 +578,7 @@ def convert(lines, end_format): i += 1 continue - if 87 <= format <= 96: + if 87 <= format <= 97: # nothing to do. i += 1 continue diff --git a/src/Layout.cpp b/src/Layout.cpp index f782c12d9b..7578d155af 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -94,6 +94,7 @@ enum LayoutTags { LT_ITEMTAG, LT_HTMLTAG, LT_HTMLATTR, + LT_HTMLCLASS, LT_HTMLITEM, LT_HTMLITEMATTR, LT_HTMLLABEL, @@ -271,6 +272,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass, { "forcelocal", LT_FORCELOCAL }, { "freespacing", LT_FREE_SPACING }, { "htmlattr", LT_HTMLATTR }, + { "htmlclass", LT_HTMLCLASS }, { "htmlforcecss", LT_HTMLFORCECSS }, { "htmlintoc", LT_HTMLINTOC }, { "htmlitem", LT_HTMLITEM }, @@ -718,6 +720,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass, lex >> htmlattr_; break; + case LT_HTMLCLASS: + lex >> htmlclass_; + break; + case LT_HTMLITEM: lex >> htmlitemtag_; break; @@ -1668,6 +1674,10 @@ void Layout::write(ostream & os) const os << "\tHTMLTag " << htmltag_ << '\n'; if (!htmlattr_.empty()) os << "\tHTMLAttr " << htmlattr_ << '\n'; + if (!htmlclass_.empty()) + os << "\tHTMLClass " << htmlclass_ << '\n'; + if (!htmlintoc_) + os << "\tHTMLInToc " << htmlintoc_ << '\n'; if (!htmlitemtag_.empty()) os << "\tHTMLItem " << htmlitemtag_ << '\n'; if (!htmlitemattr_.empty()) @@ -1809,14 +1819,31 @@ string const & Layout::htmltag() const string const & Layout::htmlattr() const { - // 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_; } +string const & Layout::htmlclass() const +{ + // If it's an enumeration, then we recalculate the class each time through + // unless it has been given explicitly. So we do nothing here. + if (htmlclass_.empty() && labeltype != LABEL_ENUMERATE) + htmlclass_ = defaultCSSClass(); + return htmlclass_; +} + + +string const & Layout::htmlGetAttrString() const { + if (!htmlfullattrs_.empty()) + return htmlfullattrs_; + htmlfullattrs_ = htmlclass(); + if (!htmlfullattrs_.empty()) + htmlfullattrs_ = "class='" + htmlfullattrs_ + "'"; + if (!htmlattr_.empty()) + htmlfullattrs_ += " " + htmlattr_; + return htmlfullattrs_; +} + string const & Layout::htmlitemtag() const { if (htmlitemtag_.empty()) diff --git a/src/Layout.h b/src/Layout.h index dd64bce759..98b702feee 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -185,6 +185,10 @@ public: /// std::string const & htmlattr() const; /// + std::string const & htmlclass() const; + /// Returns a complete attribute string, including class, etc. + std::string const & htmlGetAttrString() const; + /// std::string const & htmlitemtag() const; /// std::string const & htmlitemattr() const; @@ -491,9 +495,13 @@ private: /// /// Defaults to "div". mutable std::string htmltag_; - /// Additional attributes for inclusion with the start tag. Defaults - /// to: class="layoutname". - mutable std::string htmlattr_; + /// Additional attributes for inclusion with the start tag. + /// Note that the CSS class is handled separately. + std::string htmlattr_; + /// The CSS class to use. Calculated from the layout name if not given. + mutable std::string htmlclass_; + /// cached + mutable std::string htmlfullattrs_; /// Tag for individual paragraphs in an environment. In lists, this /// would be something like "li". But it also needs to be set for /// quotation, e.g., since the paragraphs in a quote need to be diff --git a/src/TextClass.cpp b/src/TextClass.cpp index b387ce1a19..d00446e922 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -59,7 +59,7 @@ namespace lyx { // You should also run the development/tools/updatelayouts.py script, // to update the format of all of our layout files. // -int const LAYOUT_FORMAT = 96; // rikiheck: HTMLInToc +int const LAYOUT_FORMAT = 97; // rikiheck: HTMLClass // Layout format for the current lyx file format. Controls which format is diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index f40ba031fc..a6fcae77be 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -1890,7 +1890,7 @@ docstring InsetPrintIndex::xhtml(XMLStream &, OutputParams const & op) const xs << xml::StartTag("div", tocattr); xs << xml::CR(); - xs << xml::StartTag(lay.htmltag(), lay.htmlattr()); + xs << xml::StartTag(lay.htmltag(), lay.htmlGetAttrString()); xs << translateIfPossible(indexName, op.local_font->language()->lang()); xs << xml::EndTag(lay.htmltag()); xs << xml::CR(); diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index 3fb292e4da..0c4bdb9717 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -159,7 +159,7 @@ namespace { inline void openParTag(XMLStream & xs, Layout const & lay, std::string const & parlabel) { - string attrs = lay.htmlattr(); + string attrs = lay.htmlGetAttrString(); if (!parlabel.empty()) attrs += " id='" + parlabel + "'"; xs << xml::ParTag(lay.htmltag(), attrs); @@ -185,7 +185,7 @@ void openParTag(XMLStream & xs, Layout const & lay, openParTag(xs, lay, parlabel); return; } - string attrs = lay.htmlattr() + " style='text-align: " + align + ";'"; + string attrs = lay.htmlGetAttrString() + " style='text-align: " + align + ";'"; if (!parlabel.empty()) attrs += " id='" + parlabel + "'"; xs << xml::ParTag(lay.htmltag(), attrs); @@ -225,7 +225,7 @@ void openItemTag(XMLStream & xs, Layout const & lay, openItemTag(xs, lay); return; } - string attrs = lay.htmlattr() + " style='text-align: " + align + ";'"; + string attrs = lay.htmlGetAttrString() + " style='text-align: " + align + ";'"; xs << xml::StartTag(lay.htmlitemtag(), attrs); } @@ -408,7 +408,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, depth_type const origdepth = pbegin->params().depth(); // open tag for this environment - if (bstyle.labeltype == LABEL_ENUMERATE && bstyle.htmlattr().empty()) { + if (bstyle.labeltype == LABEL_ENUMERATE && bstyle.htmlclass().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