X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_xhtml.cpp;h=e960e2c5d53ea0f8ba846e612b5c6dcd60cd26b0;hb=7855c0c1fc98b154768d3014883873387bd64c95;hp=35f0ea5c6d69017531f0890ab2cdd5646df38ace;hpb=84cca2dd944cf11f8c69532dff91e9d91c8b2ab3;p=lyx.git diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index 35f0ea5c6d..e960e2c5d5 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -85,53 +85,10 @@ docstring htmlize(docstring const & str, XHTMLStream::EscapeSettings e) } -string escapeChar(char c, XHTMLStream::EscapeSettings e) +docstring escapeChar(char c, XHTMLStream::EscapeSettings e) { - string str; - switch (e) { - case XHTMLStream::ESCAPE_NONE: - str += c; - break; - case XHTMLStream::ESCAPE_ALL: - if (c == '<') { - str += "<"; - break; - } else if (c == '>') { - str += ">"; - break; - } - // fall through - case XHTMLStream::ESCAPE_AND: - if (c == '&') - str += "&"; - else - str +=c ; - break; - } - return str; -} - - -// escape what needs escaping -string htmlize(string const & str, XHTMLStream::EscapeSettings e) -{ - ostringstream d; - string::const_iterator it = str.begin(); - string::const_iterator en = str.end(); - for (; it != en; ++it) - d << escapeChar(*it, e); - return d.str(); -} - - -string cleanAttr(string const & str) -{ - string newname; - string::const_iterator it = str.begin(); - string::const_iterator en = str.end(); - for (; it != en; ++it) - newname += isAlnumASCII(*it) ? *it : '_'; - return newname; + LATTEST(static_cast(c) < 0x80); + return escapeChar(static_cast(c), e); } @@ -150,11 +107,11 @@ docstring cleanAttr(docstring const & str) docstring StartTag::writeTag() const { - string output = "<" + tag_; + docstring output = '<' + from_utf8(tag_); if (!attr_.empty()) - output += " " + html::htmlize(attr_, XHTMLStream::ESCAPE_NONE); + output += ' ' + html::htmlize(from_utf8(attr_), XHTMLStream::ESCAPE_NONE); output += ">"; - return from_utf8(output); + return output; } @@ -193,11 +150,11 @@ docstring ParTag::writeTag() const docstring CompTag::writeTag() const { - string output = "<" + tag_; + docstring output = '<' + from_utf8(tag_); if (!attr_.empty()) - output += " " + html::htmlize(attr_, XHTMLStream::ESCAPE_NONE); + output += ' ' + html::htmlize(from_utf8(attr_), XHTMLStream::ESCAPE_NONE); output += " />"; - return from_utf8(output); + return output; } @@ -205,7 +162,7 @@ docstring CompTag::writeTag() const namespace { string fontToTag(html::FontTypes type) - { +{ switch(type) { case FT_EMPH: return "em"; @@ -245,68 +202,66 @@ string fontToTag(html::FontTypes type) return ""; } -StartTag fontToStartTag(html::FontTypes type) - { - string tag = fontToTag(type); +string fontToAttribute(html::FontTypes type) +{ switch(type) { case FT_EMPH: - return html::StartTag(tag); case FT_BOLD: - return html::StartTag(tag); + return ""; case FT_NOUN: - return html::StartTag(tag, "class='lyxnoun'"); + return "class='lyxnoun'"; case FT_UBAR: - return html::StartTag(tag); + return ""; case FT_DBAR: - return html::StartTag(tag, "class='dline'"); + return "class='dline'"; case FT_SOUT: - return html::StartTag(tag, "class='strikeout'"); + return "class='strikeout'"; case FT_WAVE: - return html::StartTag(tag, "class='wline'"); + return "class='wline'"; case FT_ITALIC: - return html::StartTag(tag); + return ""; case FT_UPRIGHT: - return html::StartTag(tag, "style='font-style:normal;'"); + return "style='font-style:normal;'"; case FT_SLANTED: - return html::StartTag(tag, "style='font-style:oblique;'"); + return "style='font-style:oblique;'"; case FT_SMALLCAPS: - return html::StartTag(tag, "style='font-variant:small-caps;'"); + return "style='font-variant:small-caps;'"; case FT_ROMAN: - return html::StartTag(tag, "style='font-family:serif;'"); + return "style='font-family:serif;'"; case FT_SANS: - return html::StartTag(tag, "style='font-family:sans-serif;'"); + return "style='font-family:sans-serif;'"; case FT_TYPE: - return html::StartTag(tag, "style='font-family:monospace;'"); + return "style='font-family:monospace;'"; case FT_SIZE_TINY: case FT_SIZE_SCRIPT: case FT_SIZE_FOOTNOTE: - return html::StartTag(tag, "style='font-size:x-small;'"); + return "style='font-size:x-small;'"; case FT_SIZE_SMALL: - return html::StartTag(tag, "style='font-size:small;'"); + return "style='font-size:small;'"; case FT_SIZE_NORMAL: - return html::StartTag(tag, "style='font-size:normal;'"); + return "style='font-size:normal;'"; case FT_SIZE_LARGE: - return html::StartTag(tag, "style='font-size:large;'"); + return "style='font-size:large;'"; case FT_SIZE_LARGER: case FT_SIZE_LARGEST: - return html::StartTag(tag, "style='font-size:x-large;'"); + return "style='font-size:x-large;'"; case FT_SIZE_HUGE: case FT_SIZE_HUGER: - return html::StartTag(tag, "style='font-size:xx-large;'"); + return "style='font-size:xx-large;'"; case FT_SIZE_INCREASE: - return html::StartTag(tag, "style='font-size:larger;'"); + return "style='font-size:larger;'"; case FT_SIZE_DECREASE: - return html::StartTag(tag, "style='font-size:smaller;'"); + return "style='font-size:smaller;'"; } // kill warning - return StartTag(""); + return ""; } } // end anonymous namespace FontTag::FontTag(FontTypes type) - : StartTag(fontToStartTag(type)), font_type_(type) + : StartTag(fontToTag(type), fontToAttribute(type)), font_type_(type) {} @@ -497,7 +452,7 @@ XHTMLStream & XHTMLStream::operator<<(char_type c) XHTMLStream & XHTMLStream::operator<<(char c) { clearTagDeque(); - string const d = html::escapeChar(c, escape_); + os_ << html::escapeChar(c, escape_); escape_ = ESCAPE_ALL; return *this; } @@ -982,9 +937,6 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, ) cnts.step(cntr, OutputUpdate); ParagraphList::const_iterator send; - // this will be positive, if we want to skip the initial word - // (if it's been taken for the label). - pos_type sep = 0; switch (style.latextype) { case LATEX_ENVIRONMENT: @@ -1000,6 +952,9 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, lastlay = 0; } + // this will be positive, if we want to skip the + // initial word (if it's been taken for the label). + pos_type sep = 0; bool const labelfirst = style.htmllabelfirst(); if (!labelfirst) openItemTag(xs, style, par->params()); @@ -1020,7 +975,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, } xs << html::CR(); } - } else { // some kind of list + } else { // some kind of list if (style.labeltype == LABEL_MANUAL) { openLabelTag(xs, style); sep = par->firstWordLyXHTML(xs, runparams);