]> git.lyx.org Git - lyx.git/commitdiff
Clean up XHTML output a bit.
authorRichard Heck <rgheck@comcast.net>
Fri, 1 Apr 2011 19:18:25 +0000 (19:18 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 1 Apr 2011 19:18:25 +0000 (19:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38185 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetBibtex.cpp
src/insets/InsetIndex.cpp
src/insets/InsetLine.cpp
src/insets/InsetNewline.cpp
src/insets/InsetTOC.cpp
src/insets/InsetTabular.cpp
src/mathed/InsetMathHull.cpp
src/mathed/MathExtern.cpp
src/output_xhtml.cpp
src/output_xhtml.h

index 56476d3d1b29382c363c72a691ba61a2e50e8329..c54abb7624c240d37e294596e8866fd47c74e13a 100644 (file)
@@ -977,11 +977,11 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
                // which will give us all the cross-referenced info. But for every
                // entry, so there's a lot of repitition. This should be fixed.
                xs << html::StartTag("span", "class='bibtexinfo'") 
-                       << XHTMLStream::ESCAPE_AND
-                       << bibinfo.getInfo(entry.key(), buffer(), true)
-                       << html::EndTag("span")
-                       << html::EndTag("div");
-               xs.cr();
+                  << XHTMLStream::ESCAPE_AND
+                  << bibinfo.getInfo(entry.key(), buffer(), true)
+                  << html::EndTag("span")
+                  << html::EndTag("div")
+                  << html::CR();
        }
        xs << html::EndTag("div");
        return docstring();
index 60f039c381fee2a2e682f23619aa351eb0e2bcaa..f85ea2d044555bb15df3644f42d90f803cbe6299 100644 (file)
@@ -730,13 +730,11 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                // close last entry or entries, depending.
                                if (level == 3) {
                                        // close this sub-sub-entry
-                                       xs << html::EndTag("li");
-                                       xs.cr();
+                                       xs << html::EndTag("li") << html::CR();
                                        // is this another sub-sub-entry within the same sub-entry?
                                        if (!eit->same_sub(last)) {
                                                // close this level
-                                               xs << html::EndTag("ul");
-                                               xs.cr();
+                                               xs << html::EndTag("ul") << html::CR();
                                                level = 2;
                                        }
                                }
@@ -747,13 +745,11 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                // sub-entry. In that case, we do not want to close anything.
                                if (level == 2 && !eit->same_sub(last)) {
                                        // close sub-entry 
-                                       xs << html::EndTag("li");
-                                       xs.cr();
+                                       xs << html::EndTag("li") << html::CR();
                                        // is this another sub-entry with the same main entry?
                                        if (!eit->same_main(last)) {
                                                // close this level
-                                               xs << html::EndTag("ul");
-                                               xs.cr();
+                                               xs << html::EndTag("ul") << html::CR();
                                                level = 1;
                                        }
                                }
@@ -762,8 +758,7 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                // close the entry.
                                if (level == 1 && !eit->same_main(last)) {
                                        // close entry
-                                       xs << html::EndTag("li");
-                                       xs.cr();
+                                       xs << html::EndTag("li") << html::CR();
                                }
                        }
 
@@ -809,8 +804,8 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                           << XHTMLStream::ESCAPE_NONE << sub;
                                if (!subsub.empty()) {
                                        // it's actually a subsubentry, so we need to start that list
-                                       xs.cr();
-                                       xs << html::StartTag("ul", "class='subsubentry'") 
+                                       xs << html::CR()
+                                          << html::StartTag("ul", "class='subsubentry'") 
                                           << html::StartTag("li", "class='subsubentry'") 
                                           << XHTMLStream::ESCAPE_NONE << subsub;
                                        level = 3;
@@ -830,15 +825,15 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
                                        xs << html::StartTag("li", "class='main'") << main;
                                if (!sub.empty()) {
                                        // there's a sub-entry, too
-                                       xs.cr();
-                                       xs << html::StartTag("ul", "class='subentry'") 
+                                       xs << html::CR()
+                                          << html::StartTag("ul", "class='subentry'") 
                                           << html::StartTag("li", "class='subentry'") 
                                           << XHTMLStream::ESCAPE_NONE << sub;
                                        level = 2;
                                        if (!subsub.empty()) {
                                                // and a sub-sub-entry
-                                               xs.cr();
-                                               xs << html::StartTag("ul", "class='subsubentry'") 
+                                               xs << html::CR()
+                                                  << html::StartTag("ul", "class='subsubentry'") 
                                                   << html::StartTag("li", "class='subsubentry'") 
                                                   << XHTMLStream::ESCAPE_NONE << subsub;
                                                level = 3;
@@ -855,12 +850,10 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
        }
        // now we have to close all the open levels
        while (level > 0) {
-               xs << html::EndTag("li") << html::EndTag("ul");
-               xs.cr();
+               xs << html::EndTag("li") << html::EndTag("ul") << html::CR();
                --level;
        }
-       xs << html::EndTag("div");
-       xs.cr();
+       xs << html::EndTag("div") << html::CR();
        return ods.str();
 }
 
index 022392d46234acdee8ce9e667538f5efab4c7e9b..515efbba4f50931ec144fbeb11a7285435e811c6 100644 (file)
@@ -199,8 +199,7 @@ int InsetLine::docbook(odocstream & os, OutputParams const &) const
 
 docstring InsetLine::xhtml(XHTMLStream & xs, OutputParams const &) const
 {
-       xs << html::CompTag("hr");
-       xs.cr();
+       xs << html::CompTag("hr") << html::CR();
        return docstring();
 }
 
index 9e7bd384d1e2ea76821df73ced0ad8a16bbed42f..d22bb369ae8c45565b96e0d780e95f56948bade1 100644 (file)
@@ -177,8 +177,7 @@ int InsetNewline::docbook(odocstream & os, OutputParams const &) const
 
 docstring InsetNewline::xhtml(XHTMLStream & xs, OutputParams const &) const
 {
-       xs << html::CompTag("br");
-       xs.cr();
+       xs << html::CR() << html::CompTag("br") << html::CR();
        return docstring();
 }
 
index e297ef4be68738388f4dd5a2c291d5ae9513e215..7c7fa7c454279272d4b9b053d7de740fa6b8f8c1 100644 (file)
@@ -132,13 +132,13 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
                        continue;
                
                if (depth > lastdepth) {
-                       xs.cr();
+                       xs << html::CR();
                        // open as many tags as we need to open to get to this level
                        // this includes the tag for the current level
                        for (int i = lastdepth + 1; i <= depth; ++i) {
                                stringstream attr;
                                attr << "class='lyxtoc-" << i << "'";
-                               xs << html::StartTag("div", attr.str());
+                               xs << html::StartTag("div", attr.str()) << html::CR();
                        }
                        lastdepth = depth;
                }
@@ -146,18 +146,18 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
                        // close as many as we have to close to get back to this level
                        // this includes closing the last tag at this level
                        for (int i = lastdepth; i >= depth; --i) 
-                               xs << html::EndTag("div");
+                               xs << html::EndTag("div") << html::CR();
                        // now open our tag
                        stringstream attr;
                        attr << "class='lyxtoc-" << depth << "'";
-                       xs << html::StartTag("div", attr.str());
+                       xs << html::StartTag("div", attr.str()) << html::CR();
                        lastdepth = depth;
                } else {
                        // no change of level, so close and open
-                       xs << html::EndTag("div");
+                       xs << html::EndTag("div") << html::CR();
                        stringstream attr;
                        attr << "class='lyxtoc-" << depth << "'";
-                       xs << html::StartTag("div", attr.str());
+                       xs << html::StartTag("div", attr.str()) << html::CR();
                }
                
                // Now output TOC info for this entry
@@ -182,8 +182,8 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
                xs << html::EndTag("a");                
        }
        for (int i = lastdepth; i > 0; --i) 
-               xs << html::EndTag("div");
-       xs << html::EndTag("div");
+               xs << html::EndTag("div") << html::CR();
+       xs << html::EndTag("div") << html::CR();
        return ods.str();
 }
 
index 2fdd162bb1939a6df9e9b342ea42b903ef27660f..5eb59e54d2513c8100e86b0ba3de223c4ec22f7d 100644 (file)
@@ -2887,11 +2887,9 @@ docstring Tabular::xhtmlRow(XHTMLStream & xs, row_type row,
                if (isMultiColumn(cell))
                        attr << " colspan='" << columnSpan(cell) << "'";
 
-               xs << html::StartTag(celltag, attr.str());
-               xs.cr();
+               xs << html::StartTag(celltag, attr.str()) << html::CR();
                ret += cellInset(cell)->xhtml(xs, runparams);
-               xs << html::EndTag(celltag);
-               xs.cr();
+               xs << html::EndTag(celltag) << html::CR();
                ++cell;
        }
        xs << html::EndTag("tr");
@@ -2917,17 +2915,19 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
                        align = "right";
                        break;
                }
-               xs << html::StartTag("div", "class='longtable' style='text-align: " + align + ";'");
+               xs << html::StartTag("div", "class='longtable' style='text-align: " + align + ";'")
+                  << html::CR();
                if (haveLTCaption()) {
-                       xs << html::StartTag("div", "class='longtable-caption' style='text-align: " + align + ";'");
+                       xs << html::StartTag("div", "class='longtable-caption' style='text-align: " + align + ";'")
+                          << html::CR();
                        for (row_type r = 0; r < nrows(); ++r)
                                if (row_info[r].caption)
                                        ret += xhtmlRow(xs, r, runparams);
-                       xs << html::EndTag("div");
+                       xs << html::EndTag("div") << html::CR();
                }
        }
 
-       xs << html::StartTag("table");
+       xs << html::StartTag("table") << html::CR();
 
        // output header info
        bool const havefirsthead = haveLTFirstHead();
@@ -2936,40 +2936,42 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
        // in XHTML. this test accomplishes that.
        bool const havehead = !havefirsthead && haveLTHead();
        if (havehead || havefirsthead) {
-               xs << html::StartTag("thead");
+               xs << html::StartTag("thead") << html::CR();
                for (row_type r = 0; r < nrows(); ++r) {
                        if ((havefirsthead && row_info[r].endfirsthead)
                            || (havehead && row_info[r].endhead)) {
                                ret += xhtmlRow(xs, r, runparams, true);
                        }
                }
-               xs << html::EndTag("thead");
+               xs << html::EndTag("thead") << html::CR();
        }
        // output footer info
        bool const havelastfoot = haveLTLastFoot();
        // as before.
        bool const havefoot = !havelastfoot && haveLTFoot();
        if (havefoot || havelastfoot) {
-               xs << html::StartTag("tfoot");
+               xs << html::StartTag("tfoot") << html::CR();
                for (row_type r = 0; r < nrows(); ++r) {
                        if ((havelastfoot && row_info[r].endlastfoot)
                            || (havefoot && row_info[r].endfoot)) {
                                ret += xhtmlRow(xs, r, runparams);
                        }
                }
-               xs << html::EndTag("tfoot");
+               xs << html::EndTag("tfoot") << html::CR();
        }
 
-       xs << html::StartTag("tbody");
+       xs << html::StartTag("tbody") << html::CR();
        for (row_type r = 0; r < nrows(); ++r) {
                if (isValidRow(r)) {
                        ret += xhtmlRow(xs, r, runparams);
                }
        }
        xs << html::EndTag("tbody")
-          << html::EndTag("table");
+          << html::CR()
+          << html::EndTag("table")
+          << html::CR();
        if (is_long_tabular)
-               xs << html::EndTag("div");
+               xs << html::EndTag("div") << html::CR();
        return ret;
 }
 
index 23f66bd5e1f3173566d264f18bc67a6e4830b6bc..0b8b8a9e3b25e06d63ae169f95965fcb3ca12c1f 100644 (file)
@@ -2154,8 +2154,8 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
                        FileName const & mathimg = pimage->filename();
                        xs << html::StartTag(tag)
                           << html::CompTag("img", "src=\"" + mathimg.onlyFileName() + "\"")
-                          << html::EndTag(tag);
-                       xs.cr();
+                          << html::EndTag(tag)
+                          << html::CR();
                        // add the file to the list of files to be exported
                        op.exportdata->addExternalFile("xhtml", mathimg);
                        success = true;
@@ -2182,8 +2182,8 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
                xs << html::StartTag(tag, "class='math'")
                   << XHTMLStream::ESCAPE_AND
                   << latex 
-                  << html::EndTag(tag);
-               xs.cr();
+                  << html::EndTag(tag)
+                  << html::CR();
        }
        return docstring();
 }
index ce055ea33670a96c97c5bc9b177ff1f63ffcb1fd..896bdf625265218417ec6cc9069d1111707d6278 100644 (file)
@@ -948,7 +948,7 @@ void extractLims(MathData & ar)
 
 void extractStructure(MathData & ar, ExternalMath kind)
 {
-       //lyxerr << "\nStructure from: " << ar << endl;
+       lyxerr << "\nStructure from: " << ar << endl;
        if (kind != MATHML && kind != HTML)
                splitScripts(ar);
        extractDelims(ar);
@@ -965,7 +965,7 @@ void extractStructure(MathData & ar, ExternalMath kind)
                extractLims(ar);
                extractStrings(ar);
        }
-       //lyxerr << "\nStructure to: " << ar << endl;
+       lyxerr << "\nStructure to: " << ar << endl;
 }
 
 
index e8f77e3f99ca0fe5673808b9317143ec55c97292..4cc928b4b8618bc7d9ad83f0335567f677713b51 100644 (file)
@@ -197,13 +197,6 @@ XHTMLStream::XHTMLStream(odocstream & os)
 {}
 
 
-void XHTMLStream::cr() 
-{
-       // tabs?
-       os_ << from_ascii("\n");
-}
-
-
 void XHTMLStream::writeError(std::string const & s)
 {
        LYXERR0(s);
@@ -326,7 +319,15 @@ XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
        clearTagDeque();
        // tabs?
        os_ << tag.asTag();
-       cr();
+       *this << html::CR();
+       return *this;
+}
+
+
+XHTMLStream & XHTMLStream::operator<<(html::CR const &)
+{
+       // tabs?
+       os_ << from_ascii("\n");
        return *this;
 }
 
@@ -612,7 +613,7 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
                // FIXME We should see if there's a label to be output and
                // do something with it.
                if (par != pbegin)
-                       xs.cr();
+                       xs << html::CR();
 
                // If we are already in a paragraph, and this is the first one, then we
                // do not want to open the paragraph tag.
@@ -637,11 +638,10 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
                        || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
                if (needclose) {
                        closeTag(xs, lay);
-                       xs.cr();
+                       xs << html::CR();
                }
                if (!deferred.empty()) {
-                       xs << XHTMLStream::ESCAPE_NONE << deferred;
-                       xs.cr();
+                       xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
                }
        }
        return pend;
@@ -657,12 +657,12 @@ ParagraphList::const_iterator makeBibliography(Buffer const & buf,
 {
        // FIXME XHTML
        // Use TextClass::htmlTOCLayout() to figure out how we should look.
-       xs << html::StartTag("h2", "class='bibliography'");
-       xs << pbegin->layout().labelstring(false);
-       xs << html::EndTag("h2");
-       xs.cr();
+       xs << html::StartTag("h2", "class='bibliography'")
+          << pbegin->layout().labelstring(false);
+          << html::EndTag("h2");
+       xs << html::CR();
        xs << html::StartTag("div", "class='bibliography'");
-       xs.cr();
+       xs << html::CR();
        makeParagraphs(buf, xs, runparams, text, pbegin, pend);
        xs << html::EndTag("div");
        return pend;
@@ -690,7 +690,7 @@ ParagraphList::const_iterator makeEnvironmentHtml(Buffer const & buf,
 
        // open tag for this environment
        openTag(xs, bstyle);
-       xs.cr();
+       xs << html::CR();
 
        // we will on occasion need to remember a layout from before.
        Layout const * lastlay = 0;
@@ -747,20 +747,20 @@ ParagraphList::const_iterator makeEnvironmentHtml(Buffer const & buf,
                                                                xs << lbl;
                                                                closeLabelTag(xs, style);
                                                        }
-                                                       xs.cr();
+                                                       xs << html::CR();
                                                }
                                        }       else { // some kind of list
                                                if (style.labeltype == LABEL_MANUAL) {
                                                        openLabelTag(xs, style);
                                                        sep = par->firstWordLyXHTML(xs, runparams);
                                                        closeLabelTag(xs, style);
-                                                       xs.cr();
+                                                       xs << html::CR();
                                                }
                                                else {
                                                        openLabelTag(xs, style);
                                                        xs << par->params().labelString();
                                                        closeLabelTag(xs, style);
-                                                       xs.cr();
+                                                       xs << html::CR();
                                                }
                                        }
                                } // end label output
@@ -784,7 +784,7 @@ ParagraphList::const_iterator makeEnvironmentHtml(Buffer const & buf,
                                        lastlay = &style;
                                } else
                                        closeItemTag(xs, style);
-                               xs.cr();
+                               xs << html::CR();
                        }
                        // The other possibility is that the depth has increased, in which
                        // case we need to recurse.
@@ -814,7 +814,7 @@ ParagraphList::const_iterator makeEnvironmentHtml(Buffer const & buf,
        if (lastlay != 0)
                closeItemTag(xs, *lastlay);
        closeTag(xs, bstyle);
-       xs.cr();
+       xs << html::CR();
        return pend;
 }
 
@@ -845,7 +845,7 @@ void makeCommand(Buffer const & buf,
        pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
                        text.outerFont(distance(begin, pbegin)));
        closeTag(xs, style);
-       xs.cr();
+       xs << html::CR();
 }
 
 } // end anonymous namespace
index 94bdf0bd2b7f643fbf18802175444dfa6550323b..6e00557ea548b3b3be9ebc912f57743b7c14f7d7 100644 (file)
@@ -83,6 +83,9 @@ struct CompTag {
        std::string attr_;
 };
 
+// trivial struct for output of newlines
+struct CR{};
+
 } // namespace html
 
 class XHTMLStream {
@@ -90,8 +93,6 @@ public:
        ///
        explicit XHTMLStream(odocstream & os);
        ///
-       void cr();
-       ///
        odocstream & os() { return os_; }
        ///
        // int & tab() { return tab_; }
@@ -117,6 +118,8 @@ public:
        ///
        XHTMLStream & operator<<(html::CompTag const &);
        ///
+       XHTMLStream & operator<<(html::CR const &);
+       ///
        enum EscapeSettings {
                ESCAPE_NONE,
                ESCAPE_AND, // meaning &