Handle other text ranges in XHTML output.

This commit is contained in:
Richard Heck 2013-03-27 12:49:03 -04:00
parent dd7d76cc6c
commit 82b8723654
3 changed files with 83 additions and 13 deletions

View 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();

View 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;
}
}

View 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";
}