From 5faa75408b82b8825ff5572af2c821a7aa979b9b Mon Sep 17 00:00:00 2001
From: Richard Heck
Date: Mon, 26 Oct 2009 20:53:46 +0000
Subject: [PATCH] Try to deal with one of the big problems here, namely, that
we can't just output Standard as , or anything else, because we have
structures like: this is text and more text and more which
would then come out as:
this is text
and more text
and more
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 | 1 -
lib/layouts/stdinsets.inc | 4 ++++
src/Paragraph.cpp | 12 +++++-----
src/insets/InsetLayout.cpp | 5 +++++
src/insets/InsetLayout.h | 27 +++++++++++++++++------
src/output_xhtml.cpp | 45 ++++++++++++++++++++++++++++----------
6 files changed, 69 insertions(+), 25 deletions(-)
diff --git a/lib/layouts/stdclass.inc b/lib/layouts/stdclass.inc
index 7debe974d5..6a8fccddec 100644
--- a/lib/layouts/stdclass.inc
+++ b/lib/layouts/stdclass.inc
@@ -35,7 +35,6 @@ Style Standard
Align Block
AlignPossible Block, Left, Right, Center
LabelType No_Label
- HTMLTag p
End
#Input stdcharstyles.inc
diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc
index 9ccda95d50..400b55efd5 100644
--- a/lib/layouts/stdinsets.inc
+++ b/lib/layouts/stdinsets.inc
@@ -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
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index ca3b3414ec..5b72cc07e4 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -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];
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index cb245dc573..9534aeb3a7 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -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;
diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h
index b37a0f97b9..ccc1c46307 100644
--- a/src/insets/InsetLayout.h
+++ b/src/insets/InsetLayout.h
@@ -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 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:
+ /// \arabic{footnote}
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 requires_;
///
diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp
index 7b6a2dc80a..340b363f89 100644
--- a/src/output_xhtml.cpp
+++ b/src/output_xhtml.cpp
@@ -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??
--
2.39.2