]> git.lyx.org Git - features.git/blobdiff - src/output_xhtml.cpp
Update XHTML debugging code a bit.
[features.git] / src / output_xhtml.cpp
index 959262d9cd469c595c08b6eb12be502902a5c66d..b50f982178a245b83a2cfc40f3d978960b123528 100644 (file)
@@ -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 += "&lt;";
-                       break;
-               } else if (c == '>') {
-                       str += "&gt;";
-                       break;
-               }
-       // fall through
-       case XHTMLStream::ESCAPE_AND:
-               if (c == '&')
-                       str += "&amp;";
-               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<unsigned char>(c) < 0x80);
+       return escapeChar(static_cast<char_type>(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;
 }
 
 
@@ -178,26 +135,23 @@ docstring EndTag::writeEndTag() const
 }
 
 
-docstring ParTag::writeTag() const
+ParTag::ParTag(std::string const & tag, std::string attr,
+       std::string const & parid)
+  : StartTag(tag)
 {
-       docstring output = StartTag::writeTag();
-
-       if (parid_.empty())
-               return output;
-
-       string const pattr = "id='" + parid_ + "'";
-       output += html::CompTag("a", pattr).writeTag();
-       return output;
+       if (!parid.empty())
+               attr += " id='" + parid + "'";
+       attr_ = attr;
 }
 
 
 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;
 }
 
 
@@ -337,21 +291,27 @@ XHTMLStream::XHTMLStream(odocstream & os)
 
 
 #ifdef XHTML_DEBUG
-void XHTMLStream::dumpTagStack(string const & msg) const
+void XHTMLStream::dumpTagStack(string const & msg)
 {
-       writeError(msg + ": Tag Stack");
-       TagStack::const_reverse_iterator it = tag_stack_.rbegin();
-       TagStack::const_reverse_iterator en = tag_stack_.rend();
+       *this << html::CR();
+       writeError(msg);
+       *this << html::CR();
+       writeError("Tag Stack");
+       TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
+       TagDeque::const_reverse_iterator en = tag_stack_.rend();
        for (; it != en; ++it) {
-               writeError(it->tag_);
+               writeError(it->get()->tag_);
        }
+       writeError("End Tag Stack");
+       *this << html::CR();
        writeError("Pending Tags");
        it = pending_tags_.rbegin();
        en = pending_tags_.rend();
        for (; it != en; ++it) {
-               writeError(it->tag_);
+               writeError(it->get()->tag_);
        }
-       writeError("End Tag Stack");
+       writeError("End Pending Tags");
+       *this << html::CR();
 }
 #endif
 
@@ -495,7 +455,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;
 }
@@ -1100,14 +1060,24 @@ void makeCommand(Buffer const & buf,
                    documentClass().counters().step(style.counter, OutputUpdate);
 
        bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
+       
+       if (style.labeltype == LABEL_ABOVE)
+               xs << html::StartTag("div")
+                  << pbegin->params().labelString()
+                  << html::EndTag("div");
+       else if (style.labeltype == LABEL_CENTERED)
+               xs << html::StartTag("div", "style = \"text-align: center;\"")
+                  << pbegin->params().labelString()
+                  << html::EndTag("div");
 
        openParTag(xs, style, pbegin->params(),
                   make_parid ? pbegin->magicLabel() : "");
 
        // Label around sectioning number:
        // FIXME Probably need to account for LABEL_MANUAL
-       // FIXME Probably also need now to account for labels ABOVE and CENTERED.
-       if (style.labeltype != LABEL_NO_LABEL) {
+       if (style.labeltype != LABEL_NO_LABEL &&
+           style.labeltype != LABEL_ABOVE &&
+           style.labeltype != LABEL_CENTERED ) {
                openLabelTag(xs, style);
                xs << pbegin->params().labelString();
                closeLabelTag(xs, style);