+ LyXLayout_ptr const & style = layout();
+
+ string::size_type char_line_count = 5; // Heuristic choice ;-)
+
+ // gets paragraph main font
+ LyXFont font_old;
+ bool desc_on;
+ if (style->labeltype == LABEL_MANUAL) {
+ font_old = style->labelfont;
+ desc_on = true;
+ } else {
+ font_old = style->font;
+ desc_on = false;
+ }
+
+ LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
+ LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
+ LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
+ bool is_em = false;
+
+ stack<PAR_TAG> tag_state;
+ // parsing main loop
+ for (pos_type i = 0; i < size(); ++i) {
+
+ PAR_TAG tag_close = PAR_NONE;
+ list < PAR_TAG > tag_open;
+
+ LyXFont const font = getFont(buf.params(), i, outerfont);
+
+ if (font_old.family() != font.family()) {
+ switch (family_type) {
+ case LyXFont::SANS_FAMILY:
+ tag_close |= SF;
+ break;
+ case LyXFont::TYPEWRITER_FAMILY:
+ tag_close |= TT;
+ break;
+ default:
+ break;
+ }
+
+ family_type = font.family();
+
+ switch (family_type) {
+ case LyXFont::SANS_FAMILY:
+ tag_open.push_back(SF);
+ break;
+ case LyXFont::TYPEWRITER_FAMILY:
+ tag_open.push_back(TT);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (font_old.series() != font.series()) {
+ switch (series_type) {
+ case LyXFont::BOLD_SERIES:
+ tag_close |= BF;
+ break;
+ default:
+ break;
+ }
+
+ series_type = font.series();
+
+ switch (series_type) {
+ case LyXFont::BOLD_SERIES:
+ tag_open.push_back(BF);
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ if (font_old.shape() != font.shape()) {
+ switch (shape_type) {
+ case LyXFont::ITALIC_SHAPE:
+ tag_close |= IT;
+ break;
+ case LyXFont::SLANTED_SHAPE:
+ tag_close |= SL;
+ break;
+ default:
+ break;
+ }
+
+ shape_type = font.shape();
+
+ switch (shape_type) {
+ case LyXFont::ITALIC_SHAPE:
+ tag_open.push_back(IT);
+ break;
+ case LyXFont::SLANTED_SHAPE:
+ tag_open.push_back(SL);
+ break;
+ default:
+ break;
+ }
+ }
+ // handle <em> tag
+ if (font_old.emph() != font.emph()) {
+ if (font.emph() == LyXFont::ON) {
+ tag_open.push_back(EM);
+ is_em = true;
+ }
+ else if (is_em) {
+ tag_close |= EM;
+ is_em = false;
+ }
+ }
+
+ list < PAR_TAG > temp;
+ while (!tag_state.empty() && tag_close) {
+ PAR_TAG k = tag_state.top();
+ tag_state.pop();
+ os << "</" << tag_name(k) << '>';
+ if (tag_close & k)
+ reset(tag_close,k);
+ else
+ temp.push_back(k);
+ }
+
+ for(list< PAR_TAG >::const_iterator j = temp.begin();
+ j != temp.end(); ++j) {
+ tag_state.push(*j);
+ os << '<' << tag_name(*j) << '>';
+ }
+
+ for(list< PAR_TAG >::const_iterator j = tag_open.begin();
+ j != tag_open.end(); ++j) {
+ tag_state.push(*j);
+ os << '<' << tag_name(*j) << '>';
+ }
+
+ value_type c = getChar(i);
+
+
+ if (c == Paragraph::META_INSET) {
+ getInset(i)->linuxdoc(buf, os, runparams);
+ font_old = font;
+ continue;
+ }
+
+ if (style->latexparam() == "CDATA") {
+ // "TeX"-Mode on == > SGML-Mode on.
+ if (c != '\0')
+ os << c;
+ ++char_line_count;
+ } else {
+ bool ws;
+ string str;
+ boost::tie(ws, str) = sgml::escapeChar(c);
+ if (ws && !isFreeSpacing()) {
+ // in freespacing mode, spaces are
+ // non-breaking characters
+ if (desc_on) { // if char is ' ' then...
+ ++char_line_count;
+ sgmlLineBreak(os, char_line_count, 6);
+ os << "</tag>";
+ desc_on = false;
+ } else {
+ sgmlLineBreak(os, char_line_count, 1);
+ os << c;
+ }
+ } else {
+ os << str;
+ char_line_count += str.length();
+ }
+ }
+ font_old = font;
+ }
+
+ while (!tag_state.empty()) {
+ os << "</" << tag_name(tag_state.top()) << '>';
+ tag_state.pop();
+ }
+
+ // resets description flag correctly
+ if (desc_on) {
+ // <tag> not closed...
+ sgmlLineBreak(os, char_line_count, 6);
+ os << "</tag>";
+ }