From c50f0b125ddc34b4547fb82e344a90899183fe55 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Mon, 5 Dec 2022 23:42:50 -0500 Subject: [PATCH] Add HTMLClass for InsetLayout as well. Layout format change. --- 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/scripts/layout2layout.py | 5 ++++- src/Layout.cpp | 7 +------ src/Layout.h | 2 +- src/TextClass.cpp | 2 +- src/insets/InsetCaption.cpp | 2 +- src/insets/InsetLayout.cpp | 25 +++++++++++++++++++++---- src/insets/InsetLayout.h | 10 +++++++++- src/insets/InsetText.cpp | 2 +- src/insets/InsetWrap.cpp | 2 +- 17 files changed, 52 insertions(+), 29 deletions(-) diff --git a/lib/layouts/aastex.layout b/lib/layouts/aastex.layout index 58b8b14ba1..2e34010bf3 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 7453b2a9af..4535d0cd70 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 57af913dce..ad4f5f84fc 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 9a51d372f2..669da4059b 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 d3b258a9e0..ad38b11cba 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 88ba523ba8..b872b5124f 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 b1c1c9f2da..fc7dea8fb0 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 cac502d6bd..33a56a4331 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/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 4add2e5beb..d923d65752 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 = 97 +currentFormat = 98 # Incremented to format 4, 6 April 2007, lasgouttes @@ -328,6 +328,9 @@ currentFormat = 97 # Incremented to format 97, 4 December 2022 by rikiheck # Add HTMLClass +# Incremented to format 98, 5 December 2022 by rikiheck +# Add HTMLClass for InsetLayout + # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). diff --git a/src/Layout.cpp b/src/Layout.cpp index 88d5539d96..515226da3e 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -1817,12 +1817,6 @@ string const & Layout::htmltag() const } -string const & Layout::htmlattr() const -{ - return htmlattr_; -} - - string const & Layout::htmlclass() const { // If it's an enumeration or itemize list, then we recalculate the class each @@ -1844,6 +1838,7 @@ string const & Layout::htmlGetAttrString() const { return htmlfullattrs_; } + string const & Layout::htmlitemtag() const { if (htmlitemtag_.empty()) diff --git a/src/Layout.h b/src/Layout.h index 98b702feee..e837339c49 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -183,7 +183,7 @@ public: /// std::string const & htmltag() const; /// - std::string const & htmlattr() const; + std::string const & htmlattr() const { return htmlattr_; } /// std::string const & htmlclass() const; /// Returns a complete attribute string, including class, etc. diff --git a/src/TextClass.cpp b/src/TextClass.cpp index d00446e922..8973eb0643 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 = 97; // rikiheck: HTMLClass +int const LAYOUT_FORMAT = 98; // rikiheck: HTMLClass for InsetLayout // Layout format for the current lyx file format. Controls which format is diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index ad25ee36e8..e1ace0dc92 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -311,7 +311,7 @@ docstring InsetCaption::xhtml(XMLStream & xs, OutputParams const & rp) const return docstring(); InsetLayout const & il = getLayout(); string const & tag = il.htmltag(); - string attr = il.htmlattr(); + string attr = il.htmlGetAttrString(); if (!type_.empty()) { string const our_class = "float-caption-" + type_; size_t const loc = attr.find("class='"); diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 64258a8483..0d1322aa7f 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -83,6 +83,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass, IL_FREESPACING, IL_HTMLTAG, IL_HTMLATTR, + IL_HTMLCLASS, IL_HTMLFORCECSS, IL_HTMLINNERTAG, IL_HTMLINNERATTR, @@ -188,6 +189,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass, { "forceplain", IL_FORCEPLAIN }, { "freespacing", IL_FREESPACING }, { "htmlattr", IL_HTMLATTR }, + { "htmlclass", IL_HTMLCLASS }, { "htmlforcecss", IL_HTMLFORCECSS }, { "htmlinnerattr", IL_HTMLINNERATTR}, { "htmlinnertag", IL_HTMLINNERTAG}, @@ -499,6 +501,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass, case IL_HTMLATTR: lex >> htmlattr_; break; + case IL_HTMLCLASS: + lex >> htmlclass_; + break; case IL_HTMLFORCECSS: lex >> htmlforcecss_; break; @@ -653,11 +658,23 @@ string const & InsetLayout::htmltag() const } -string const & InsetLayout::htmlattr() const +string const & InsetLayout::htmlclass() const { - if (htmlattr_.empty()) - htmlattr_ = "class=\"" + defaultCSSClass() + "\""; - return htmlattr_; + if (htmlclass_.empty()) + htmlclass_ = defaultCSSClass(); + return htmlclass_; +} + + +std::string const & InsetLayout::htmlGetAttrString() const { + if (!htmlfullattrs_.empty()) + return htmlfullattrs_; + htmlfullattrs_ = htmlclass(); + if (!htmlfullattrs_.empty()) + htmlfullattrs_ = "class='" + htmlfullattrs_ + "'"; + if (!htmlattr_.empty()) + htmlfullattrs_ += " " + htmlattr_; + return htmlfullattrs_; } diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index ed3c9a96ba..48d53038a8 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -121,7 +121,11 @@ public: std::string const & htmltag() const; /// Additional attributes for inclusion with the start tag. Default (if /// a tag is provided) is: class="name". - std::string const & htmlattr() const; + std::string const & htmlattr() const { return htmlattr_; } + /// + std::string const & htmlclass() const; + /// + std::string const & htmlGetAttrString() const; /// Tag for individual paragraphs in the inset. Default is none. std::string const & htmlinnertag() const { return htmlinnertag_; } /// Attributes for that tag. Default (if a tag is provided) is: @@ -302,6 +306,10 @@ private: /// mutable std::string htmlattr_; /// + mutable std::string htmlclass_; + /// cache + mutable std::string htmlfullattrs_; + /// std::string htmlinnertag_; /// mutable std::string htmlinnerattr_; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 4cecec8cd7..99324aaeaf 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -868,7 +868,7 @@ docstring InsetText::insetAsXHTML(XMLStream & xs, OutputParams const & rp, InsetLayout const & il = getLayout(); if (opts & WriteOuterTag) - xs << xml::StartTag(il.htmltag(), il.htmlattr()); + xs << xml::StartTag(il.htmltag(), il.htmlGetAttrString()); if ((opts & WriteLabel) && !il.counter().empty()) { BufferParams const & bp = buffer().masterBuffer()->params(); diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index 8987405cb8..69e5b259e5 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -219,7 +219,7 @@ docstring InsetWrap::xhtml(XMLStream & xs, OutputParams const & rp) const string const width = len.empty() ? "50%" : len; InsetLayout const & il = getLayout(); string const & tag = il.htmltag(); - string const attr = il.htmlattr() + " style='width:" + width + ";'"; + string const attr = il.htmlGetAttrString() + " style='width:" + width + ";'"; xs << xml::StartTag(tag, attr); docstring const deferred = InsetText::insetAsXHTML(xs, rp, InsetText::WriteInnerTag); -- 2.39.5