]> git.lyx.org Git - features.git/commitdiff
Try to deal with one of the big problems here, namely, that we
authorRichard Heck <rgheck@comcast.net>
Mon, 26 Oct 2009 20:53:46 +0000 (20:53 +0000)
committerRichard Heck <rgheck@comcast.net>
Mon, 26 Oct 2009 20:53:46 +0000 (20:53 +0000)
can't just output Standard as <p>, or anything else, because we
have structures like:
  this is text <branch>and more text</branch> and more
which would then come out as:
  <p>this is text <p>and more text</p> and more</p>
So we use the OutputParam html_in_par to try to signal when we
are already in a paragraph. It is expected that we will need to
do some bug fixing here.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31753 a592a061-630c-0410-9148-cb99ea01b6c8

lib/layouts/stdclass.inc
lib/layouts/stdinsets.inc
src/Paragraph.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h
src/output_xhtml.cpp

index 7debe974d5e3fba153ed03f5d7737586ec339756..6a8fccddecff8d43fcbf60e50b30e153847b1b2a 100644 (file)
@@ -35,7 +35,6 @@ Style Standard
        Align                 Block
        AlignPossible         Block, Left, Right, Center
        LabelType             No_Label
-       HTMLTag               p
 End
 
 #Input stdcharstyles.inc
index 9ccda95d50e9a2ccfc80c915e6ec9b5b075f3691..400b55efd52a7f28201f31d65a2b0fe85f3b5a31 100644 (file)
@@ -145,6 +145,7 @@ InsetLayout Note:Comment
        EndFont
        MultiPar              true
        HTMLTag               !--
+       HTMLIsBlock           false
 End
 
 
@@ -158,6 +159,7 @@ InsetLayout Note:Note
          Size                Small
        EndFont
        MultiPar              true
+       HTMLIsBlock           false
 End
 
 InsetLayout Note:Greyedout
@@ -175,6 +177,7 @@ InsetLayout Note:Greyedout
        HTMLStyle
                span.notegrey { color: gray; }
        EndHTMLStyle
+       HTMLIsBlock           false
 End
 
 InsetLayout ERT
@@ -235,6 +238,7 @@ InsetLayout Branch
        EndFont
        MultiPar              true
        InToc                 true
+       HTMLIsBlock           false
 End
 
 InsetLayout Index
index ca3b3414ec7d32442c1ac571fa3a1be35a48117d..5b72cc07e4f8ab8d42e0dc61c451c0787d5eacc6 100644 (file)
@@ -2394,9 +2394,6 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
        FontInfo font_old =
                style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
 
-       //if (style.pass_thru && !d->onlyText(buf, outerfont, initial))
-       //      os << "]]>";
-
        // parsing main loop
        for (pos_type i = initial; i < size(); ++i) {
                Font font = getFont(buf.params(), i, outerfont);
@@ -2423,8 +2420,13 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
                }
                // FIXME Other such tags? 
 
-               if (Inset const * inset = getInset(i)) {
-                       retval += inset->xhtml(os, runparams);
+               Inset const * inset = getInset(i);
+               if (inset) {
+                       InsetLayout const & il = inset->getLayout();
+                       OutputParams np = runparams;
+                       if (!il.htmlisblock())
+                               np.html_in_par = true;
+                       retval += inset->xhtml(os, np);
                } else {
                        char_type c = d->text_[i];
 
index cb245dc57318656eac7dd4974b54986d88ac9e06..9534aeb3a74bccf8ebe19a116b7165d9b2f0c0bb 100644 (file)
@@ -86,6 +86,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                IL_HTMLATTR,
                IL_HTMLINNERTAG,
                IL_HTMLINNERATTR,
+               IL_HTMLISBLOCK,
                IL_HTMLLABEL,
                IL_HTMLSTYLE,
                IL_HTMLPREAMBLE,
@@ -120,6 +121,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                { "htmlattr", IL_HTMLATTR },
                { "htmlinnerattr", IL_HTMLINNERATTR},
                { "htmlinnertag", IL_HTMLINNERTAG},
+               { "htmlisblock", IL_HTMLISBLOCK},
                { "htmllabel", IL_HTMLLABEL },
                { "htmlpreamble", IL_HTMLPREAMBLE },
                { "htmlstyle", IL_HTMLSTYLE },
@@ -292,6 +294,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                case IL_HTMLLABEL:
                        lex >> htmllabel_;
                        break;
+               case IL_HTMLISBLOCK:
+                       lex >> htmlisblock_;
+                       break;
                case IL_HTMLSTYLE:
                        htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
                        break;
index b37a0f97b9163c4c03f5e886b3b1705e437bdf5e..ccc1c46307abb0616e397fedf055fe6cd0cdbb55 100644 (file)
@@ -38,6 +38,7 @@ public:
                CONGLOMERATE,
                DEFAULT
        };
+       ///
        enum InsetLyXType {
                NOLYXTYPE,
                CHARSTYLE,
@@ -46,6 +47,7 @@ public:
                END,
                STANDARD
        };
+       ///
        enum InsetLaTeXType {
                NOLATEXTYPE,
                COMMAND,
@@ -95,6 +97,8 @@ public:
        /// 
        docstring htmlpreamble() const { return htmlpreamble_; }
        ///
+       bool htmlisblock() const { return htmlisblock_; }
+       ///
        std::set<std::string> requires() const { return requires_; };
        ///
        bool isMultiPar() const { return multipar_; };
@@ -143,20 +147,29 @@ private:
        docstring counter_;
        ///
        docstring preamble_;
-       /// 
+       /// The tag enclosing all the material in this inset.
        std::string htmltag_;
-       /// 
+       /// Additional attributes for inclusion with the start tag.
        std::string htmlattr_;
-       ///
+       /// Tag for individual paragraphs in the inset.
        std::string htmlinnertag_;
-       /// 
+       /// Attributes for that tag.
        std::string htmlinnerattr_;
-       ///
+       /// A label for this environment, possibly including a reference
+       /// to a counter. E.g., for footnote, it might be:
+       ///    <span class='notenum'>\arabic{footnote}</span>
        std::string htmllabel_;
-       /// 
+       /// CSS associated with this inset.
        docstring htmlstyle_;
-       /// 
+       /// Additional material for the header.
        docstring htmlpreamble_;
+       /// Whether this inset represents a "block" of material, i.e., a set
+       /// of paragraphs of its own (true), or should be run into the previous
+       /// paragraph (false). Examples:
+       ///   For branches, this is false.
+       ///   For footnotes, this is true.
+       /// Defaults to true.
+       bool htmlisblock_;
        ///
        std::set<std::string> requires_;
        ///
index 7b6a2dc80a960e1ceceb5443cf17ff101db8d5c6..340b363f8980ab1cfb80fab0b4784b553c016df8 100644 (file)
@@ -77,12 +77,6 @@ bool openTag(odocstream & os, string const & tag, string const & attr)
 {
        if (tag.empty())
                return false;
-       // FIXME This is completely primitive. We need something
-       // a lot better.
-       // Now do some checks on nesting of tags.
-       if (tag == "p")
-               if (find(taglist.begin(), taglist.end(), "p") != taglist.end())
-                       return false;
        os << from_ascii("<" + tag + (attr.empty() ? "" : " " + attr) + ">");
        taglist.push_back(tag);
        return true;
@@ -206,10 +200,27 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
                // do something with it.
                if (par != pbegin)
                        os << '\n';
-               bool const opened = openTag(os, lay);
+
+               // FIXME Should we really allow anything other than 'p' here?
+               
+               // If we are already in a paragraph, and this is the first one, then we
+               // do not want to open the paragraph tag.
+               bool const opened = 
+                       (par == pbegin && runparams.html_in_par) ? false : openTag(os, lay);
                docstring const deferred = par->simpleLyXHTMLOnePar(buf, os, runparams,
                                text.outerFont(distance(begin, par)));
-               if (opened) {
+
+               // We want to issue the closing tag if either:
+               //   (i)  We opened it, and either html_in_par is false,
+               //        or we're not in the last paragraph, anyway.
+               //   (ii) We didn't open it and html_in_par is true, 
+               //        but we are in the first par, and there is a next par.
+               ParagraphList::const_iterator nextpar = par;
+               nextpar++;
+               bool const needClose = 
+                       (opened && (!runparams.html_in_par || nextpar != pend))
+                       || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
+               if (needClose) {
                        closeTag(os, lay);
                        os << '\n';
                }
@@ -427,6 +438,7 @@ void xhtmlParagraphs(Text const & text,
        ParagraphList::const_iterator par = paragraphs.begin();
        ParagraphList::const_iterator pend = paragraphs.end();
 
+       OutputParams ourparams = runparams;
        while (par != pend) {
                Layout const & style = par->layout();
                ParagraphList::const_iterator lastpar = par;
@@ -436,25 +448,34 @@ void xhtmlParagraphs(Text const & text,
                case LATEX_COMMAND: {
                        // The files with which we are working never have more than
                        // one paragraph in a command structure.
-                       makeCommand(buf, os, runparams, text, par);
+                       // FIXME 
+                       // if (ourparams.html_in_par)
+                       //   fix it so we don't get sections inside standard, e.g.
+                       // note that we may then need to make runparams not const, so we
+                       // can communicate that back.
+                       // FIXME Maybe this fix should be in the routines themselves, in case
+                       // they are called from elsewhere.
+                       makeCommand(buf, os, ourparams, text, par);
                        ++par;
                        break;
                }
                case LATEX_ENVIRONMENT:
                case LATEX_LIST_ENVIRONMENT:
                case LATEX_ITEM_ENVIRONMENT: {
+                       // FIXME Same fix here.
                        send = searchEnvironmentHtml(par, pend);
-                       par = makeEnvironmentHtml(buf, os, runparams, text, par, send);
+                       par = makeEnvironmentHtml(buf, os, ourparams, text, par, send);
                        break;
                }
                case LATEX_BIB_ENVIRONMENT: {
+                       // FIXME Same fix here.
                        send = searchEnvironmentHtml(par, pend);
-                       par = makeBibliography(buf, os, runparams, text, par, send);
+                       par = makeBibliography(buf, os, ourparams, text, par, send);
                        break;
                }
                case LATEX_PARAGRAPH:
                        send = searchParagraphHtml(par, pend);
-                       par = makeParagraphs(buf, os, runparams, text, par, send);
+                       par = makeParagraphs(buf, os, ourparams, text, par, send);
                        break;
                }
                // FIXME??