]> git.lyx.org Git - features.git/commitdiff
Handle other text ranges in XHTML output.
authorRichard Heck <rgheck@lyx.org>
Wed, 27 Mar 2013 16:49:03 +0000 (12:49 -0400)
committerRichard Heck <rgheck@lyx.org>
Wed, 27 Mar 2013 17:51:26 +0000 (13:51 -0400)
src/LaTeXFeatures.cpp
src/Paragraph.cpp
src/output_xhtml.cpp

index 10adb14c3bf67ffc740cad5dd13296baa24e29db..1d0f8b0f893c7e9992ec446ee0b295ce21b0492c 100644 (file)
@@ -314,6 +314,25 @@ static docstring const rtloutputdblcol_def = from_ascii(
        "\\@mparswitchtrue\n");
 
 
+/////////////////////////////////////////////////////////////////////
+//
+// LyXHTML strings
+//
+/////////////////////////////////////////////////////////////////////
+
+static docstring const lyxnoun_style = from_ascii(
+       "dfn.lyxnoun {\n"
+  "  font-variant: small-caps;\n"
+  "}\n");
+
+
+// this is how it normally renders, but it might not always do so.
+static docstring const lyxstrikeout_style = from_ascii(
+       "del.strikeout {\n"
+  "  text-decoration: line-through;\n"
+  "}\n");
+
+
 /////////////////////////////////////////////////////////////////////
 //
 // LaTeXFeatures
@@ -1300,6 +1319,13 @@ docstring const LaTeXFeatures::getTClassHTMLStyles() const
        DocumentClass const & tclass = params_.documentClass();
        odocstringstream tcpreamble;
 
+       if (mustProvide("noun"))
+               tcpreamble << lyxnoun_style;
+       // this isn't exact, but it won't hurt that much if it
+       // wasn't for this.
+       if (mustProvide("ulem"))
+               tcpreamble << lyxstrikeout_style;
+
        tcpreamble << tclass.htmlstyles();
 
        list<docstring>::const_iterator cit = usedLayouts_.begin();
index 75dbff36f4f004af0dd705baf3d9cfd4f6c533b4..fffcfa54bbba61efb780e4bc69b01b448c2f4bd2 100644 (file)
@@ -2831,6 +2831,19 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 }
 
 
+void doFontSwitch(XHTMLStream & xs, bool startrange,
+       bool & flag, FontState curstate, std::string tag, std::string attr = "")
+{
+       if (curstate == FONT_ON) {
+               xs << html::StartTag(tag, attr);
+               flag = true;
+       } else if (flag && !startrange) {
+               xs << html::EndTag(tag);
+               flag = false;
+       }
+}
+
+
 docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
                                    XHTMLStream & xs,
                                    OutputParams const & runparams,
@@ -2841,6 +2854,11 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
 
        bool emph_flag = false;
        bool bold_flag = false;
+       bool noun_flag = false;
+       bool ubar_flag = false;
+       bool dbar_flag = false;
+       bool sout_flag = false;
+       bool wave_flag = false;
 
        Layout const & style = *d->layout_;
 
@@ -2862,24 +2880,49 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
                        continue;
 
                Font font = getFont(buf.masterBuffer()->params(), i, outerfont);
+               bool const at_start = (i == initial);
 
                // emphasis
-               if (font_old.emph() != font.fontInfo().emph()) {
-                       if (font.fontInfo().emph() == FONT_ON) {
-                               xs << html::StartTag("em");
-                               emph_flag = true;
-                       } else if (emph_flag && i != initial) {
-                               xs << html::EndTag("em");
-                               emph_flag = false;
-                       }
-               }
+               FontState curstate = font.fontInfo().emph();
+               if (font_old.emph() != curstate)
+                       doFontSwitch(xs, at_start, emph_flag, curstate, "em");
+
+               // noun
+               curstate = font.fontInfo().noun();
+               if (font_old.noun() != curstate)
+                       doFontSwitch(xs, at_start, noun_flag, curstate, "dfn", "class='lyxnoun'");
+
+               // underbar
+               curstate = font.fontInfo().underbar();
+               if (font_old.underbar() != curstate)
+                       doFontSwitch(xs, at_start, ubar_flag, curstate, "u");
+       
+               // strikeout
+               curstate = font.fontInfo().strikeout();
+               if (font_old.strikeout() != curstate)
+                       doFontSwitch(xs, at_start, sout_flag, curstate, "del", "class='strikeout'");
+
+               // HTML does not really have an equivalent of the next two, so we will just
+               // output a single underscore with a class, and people can style it if they
+               // wish to do so
+
+               // double underbar
+               curstate = font.fontInfo().uuline();
+               if (font_old.uuline() != curstate)
+                       doFontSwitch(xs, at_start, dbar_flag, curstate, "u", "class='dline'");
+
+               // wavy line
+               curstate = font.fontInfo().uwave();
+               if (font_old.uwave() != curstate)
+                       doFontSwitch(xs, at_start, wave_flag, curstate, "u", "class='wavyline'");
+
                // bold
                if (font_old.series() != font.fontInfo().series()) {
                        if (font.fontInfo().series() == BOLD_SERIES) {
-                               xs << html::StartTag("strong");
+                               xs << html::StartTag("b");
                                bold_flag = true;
                        } else if (bold_flag && i != initial) {
-                               xs << html::EndTag("strong");
+                               xs << html::EndTag("b");
                                bold_flag = false;
                        }
                }
index 84fc0cd2c8e21eba33a1225b798770d7c7949e3d..30eda975b4425825fd7fec2dbb0bc325aee19be7 100644 (file)
@@ -147,8 +147,9 @@ docstring cleanAttr(docstring const & str)
 
 bool isFontTag(string const & s)
 {
-       // others?
-       return s == "em" || s == "strong" || s == "i" || s == "b";
+       return s == "em" || s == "strong" || s == "i" || s == "b"
+           || s == "dfn" || s == "kbd" || s == "var" || s == "samp"
+           || s == "del";
 }