X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_xhtml.cpp;h=7d9a69bd6ae6369627f7b734968f0f7069b4dab1;hb=7470305720d7733a27e9c6e5ef13a0774f5d0f77;hp=428e6c7f72608186c6728d84a0dc4d6aa0acc4d8;hpb=86387120bcadec444d7250fd38ba05da06f85d50;p=lyx.git diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index 428e6c7f72..7d9a69bd6a 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -34,7 +34,7 @@ #include "support/lstrings.h" #include "support/textutils.h" -#include +#include // Uncomment to activate debugging code. // #define XHTML_DEBUG @@ -161,15 +161,18 @@ namespace { // convenience functions inline void openParTag(XMLStream & xs, Layout const & lay, - std::string parlabel) + const std::string & parlabel) { - xs << xml::ParTag(lay.htmltag(), lay.htmlattr(), parlabel); + string attrs = lay.htmlattr(); + if (!parlabel.empty()) + attrs += " id='" + parlabel + "'"; + xs << xml::ParTag(lay.htmltag(), attrs); } void openParTag(XMLStream & xs, Layout const & lay, ParagraphParameters const & params, - std::string parlabel) + const std::string & parlabel) { // FIXME Are there other things we should handle here? string const align = alignmentToCSS(params.align()); @@ -178,7 +181,9 @@ void openParTag(XMLStream & xs, Layout const & lay, return; } string attrs = lay.htmlattr() + " style='text-align: " + align + ";'"; - xs << xml::ParTag(lay.htmltag(), attrs, parlabel); + if (!parlabel.empty()) + attrs += " id='" + parlabel + "'"; + xs << xml::ParTag(lay.htmltag(), attrs); } @@ -585,6 +590,8 @@ void xhtmlParagraphs(Text const & text, ParagraphList::const_iterator const pend = (epit == (int) paragraphs.size()) ? paragraphs.end() : paragraphs.iterator_at(epit); + std::stack headerLevels; + while (bpit < epit) { ParagraphList::const_iterator par = paragraphs.iterator_at(bpit); if (par->params().startOfAppendix()) { @@ -602,6 +609,27 @@ void xhtmlParagraphs(Text const & text, ParagraphList::const_iterator const lastpar = par; ParagraphList::const_iterator send; + // Think about adding
and/or
s. + if (style.category() == from_utf8("Sectioning")) { + // Need to close a previous section if it has the same level or a higher one (close
if opening a + //

after a

,

,

,

, or
). More examples: + // - current: h2; back: h1; do not close any
+ // - current: h1; back: h2; close two
(first the

, then the

, so a new

can come) + // The level (h1, h2, etc.) corresponds to style.toclevel. + while (! headerLevels.empty() && style.toclevel <= headerLevels.top()) { + headerLevels.pop(); + xs << xml::EndTag("section"); + xs << xml::CR(); + } + + // Open the new one. + headerLevels.push(style.toclevel); + if (style.toclevel > 1) { //

is the document title. + xs << xml::StartTag("section"); + xs << xml::CR(); + } + } + switch (style.latextype) { case LATEX_COMMAND: { // The files with which we are working never have more than @@ -638,6 +666,13 @@ void xhtmlParagraphs(Text const & text, } bpit += distance(lastpar, par); } + + // If need be, close
s, but only at the end of the document (otherwise, dealt with at the beginning + // of the loop). + while (! headerLevels.empty() && headerLevels.top() > 1) { + headerLevels.pop(); + xs << xml::EndTag("section") << xml::CR(); + } }