2 * \file output_xhtml.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * This code is based upon output_docbook.cpp
10 * Full author contact details are available in file CREDITS.
15 #include "output_xhtml.h"
18 #include "buffer_funcs.h"
19 #include "BufferParams.h"
23 #include "OutputParams.h"
24 #include "Paragraph.h"
25 #include "ParagraphList.h"
26 #include "ParagraphParameters.h"
29 #include "TextClass.h"
31 #include "support/convert.h"
32 #include "support/debug.h"
33 #include "support/lassert.h"
34 #include "support/lstrings.h"
35 #include "support/textutils.h"
39 // Uncomment to activate debugging code.
40 // #define XHTML_DEBUG
43 using namespace lyx::support;
49 docstring escapeChar(char_type c, XHTMLStream::EscapeSettings e)
53 case XHTMLStream::ESCAPE_NONE:
56 case XHTMLStream::ESCAPE_ALL:
60 } else if (c == '>') {
65 case XHTMLStream::ESCAPE_AND:
76 // escape what needs escaping
77 docstring htmlize(docstring const & str, XHTMLStream::EscapeSettings e)
80 docstring::const_iterator it = str.begin();
81 docstring::const_iterator en = str.end();
82 for (; it != en; ++it)
83 d << escapeChar(*it, e);
88 docstring escapeChar(char c, XHTMLStream::EscapeSettings e)
90 LATTEST(static_cast<unsigned char>(c) < 0x80);
91 return escapeChar(static_cast<char_type>(c), e);
95 docstring cleanAttr(docstring const & str)
98 docstring::const_iterator it = str.begin();
99 docstring::const_iterator en = str.end();
100 for (; it != en; ++it) {
101 char_type const c = *it;
102 newname += isAlnumASCII(c) ? c : char_type('_');
108 docstring StartTag::writeTag() const
110 docstring output = '<' + from_utf8(tag_);
112 output += ' ' + html::htmlize(from_utf8(attr_), XHTMLStream::ESCAPE_NONE);
118 docstring StartTag::writeEndTag() const
120 string output = "</" + tag_ + ">";
121 return from_utf8(output);
125 bool StartTag::operator==(FontTag const & rhs) const
131 docstring EndTag::writeEndTag() const
133 string output = "</" + tag_ + ">";
134 return from_utf8(output);
138 ParTag::ParTag(std::string const & tag, std::string attr,
139 std::string const & parid)
143 attr += " id='" + parid + "'";
148 docstring CompTag::writeTag() const
150 docstring output = '<' + from_utf8(tag_);
152 output += ' ' + html::htmlize(from_utf8(attr_), XHTMLStream::ESCAPE_NONE);
161 string fontToTag(html::FontTypes type)
186 case FT_SIZE_FOOTNOTE:
191 case FT_SIZE_LARGEST:
194 case FT_SIZE_INCREASE:
195 case FT_SIZE_DECREASE:
202 string fontToAttribute(html::FontTypes type)
209 return "class='lyxnoun'";
213 return "class='dline'";
215 return "class='strikeout'";
217 return "class='wline'";
221 return "style='font-style:normal;'";
223 return "style='font-style:oblique;'";
225 return "style='font-variant:small-caps;'";
227 return "style='font-family:serif;'";
229 return "style='font-family:sans-serif;'";
231 return "style='font-family:monospace;'";
234 case FT_SIZE_FOOTNOTE:
235 return "style='font-size:x-small;'";
237 return "style='font-size:small;'";
239 return "style='font-size:normal;'";
241 return "style='font-size:large;'";
243 case FT_SIZE_LARGEST:
244 return "style='font-size:x-large;'";
247 return "style='font-size:xx-large;'";
248 case FT_SIZE_INCREASE:
249 return "style='font-size:larger;'";
250 case FT_SIZE_DECREASE:
251 return "style='font-size:smaller;'";
257 } // end anonymous namespace
260 FontTag::FontTag(FontTypes type)
261 : StartTag(fontToTag(type), fontToAttribute(type)), font_type_(type)
265 bool FontTag::operator==(StartTag const & tag) const
267 FontTag const * const ftag = tag.asFontTag();
270 return (font_type_ == ftag->font_type_);
274 EndFontTag::EndFontTag(FontTypes type)
275 : EndTag(fontToTag(type)), font_type_(type)
282 ////////////////////////////////////////////////////////////////
286 ////////////////////////////////////////////////////////////////
288 XHTMLStream::XHTMLStream(odocstream & os)
289 : os_(os), escape_(ESCAPE_ALL)
294 void XHTMLStream::dumpTagStack(string const & msg) const
296 writeError(msg + ": Tag Stack");
297 TagStack::const_reverse_iterator it = tag_stack_.rbegin();
298 TagStack::const_reverse_iterator en = tag_stack_.rend();
299 for (; it != en; ++it) {
300 writeError(it->tag_);
302 writeError("Pending Tags");
303 it = pending_tags_.rbegin();
304 en = pending_tags_.rend();
305 for (; it != en; ++it) {
306 writeError(it->tag_);
308 writeError("End Tag Stack");
313 void XHTMLStream::writeError(std::string const & s) const
316 os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
321 // an illegal tag for internal use
322 static html::StartTag const parsep_tag("&LyX_parsep_tag&");
326 bool XHTMLStream::closeFontTags()
328 if (isTagPending(parsep_tag))
329 // we haven't had any content
332 // this may be a useless check, since we ought at least to have
333 // the parsep_tag. but it can't hurt too much to be careful.
334 if (tag_stack_.empty())
337 // first, we close any open font tags we can close
338 TagPtr curtag = tag_stack_.back();
339 while (curtag->asFontTag()) {
340 os_ << curtag->writeEndTag();
341 tag_stack_.pop_back();
342 // this shouldn't happen, since then the font tags
343 // weren't in any other tag.
344 LBUFERR(!tag_stack_.empty());
345 curtag = tag_stack_.back();
348 if (*curtag == parsep_tag)
351 // so we've hit a non-font tag.
352 writeError("Tags still open in closeFontTags(). Probably not a problem,\n"
353 "but you might want to check these tags:");
354 TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
355 TagDeque::const_reverse_iterator const en = tag_stack_.rend();
356 for (; it != en; ++it) {
357 if (**it == parsep_tag)
359 writeError((*it)->tag_);
365 void XHTMLStream::startParagraph(bool keep_empty)
367 pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag)));
373 void XHTMLStream::endParagraph()
375 if (isTagPending(parsep_tag)) {
376 // this case is normal. it just means we didn't have content,
377 // so the parsep_tag never got moved onto the tag stack.
378 while (!pending_tags_.empty()) {
379 // clear all pending tags up to and including the parsep tag.
380 // note that we work from the back, because we want to get rid
381 // of everything that hasn't been used.
382 TagPtr const cur_tag = pending_tags_.back();
383 pending_tags_.pop_back();
384 if (*cur_tag == parsep_tag)
390 if (!isTagOpen(parsep_tag)) {
391 writeError("No paragraph separation tag found in endParagraph().");
395 // this case is also normal, if the parsep tag is the last one
396 // on the stack. otherwise, it's an error.
397 while (!tag_stack_.empty()) {
398 TagPtr const cur_tag = tag_stack_.back();
399 tag_stack_.pop_back();
400 if (*cur_tag == parsep_tag)
402 writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing.");
403 os_ << cur_tag->writeEndTag();
408 void XHTMLStream::clearTagDeque()
410 while (!pending_tags_.empty()) {
411 TagPtr const tag = pending_tags_.front();
412 if (*tag != parsep_tag)
414 os_ << tag->writeTag();
415 tag_stack_.push_back(tag);
416 pending_tags_.pop_front();
421 XHTMLStream & XHTMLStream::operator<<(docstring const & d)
424 os_ << html::htmlize(d, escape_);
425 escape_ = ESCAPE_ALL;
430 XHTMLStream & XHTMLStream::operator<<(const char * s)
433 docstring const d = from_ascii(s);
434 os_ << html::htmlize(d, escape_);
435 escape_ = ESCAPE_ALL;
440 XHTMLStream & XHTMLStream::operator<<(char_type c)
443 os_ << html::escapeChar(c, escape_);
444 escape_ = ESCAPE_ALL;
449 XHTMLStream & XHTMLStream::operator<<(char c)
452 os_ << html::escapeChar(c, escape_);
453 escape_ = ESCAPE_ALL;
458 XHTMLStream & XHTMLStream::operator<<(int i)
462 escape_ = ESCAPE_ALL;
467 XHTMLStream & XHTMLStream::operator<<(EscapeSettings e)
474 XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag)
476 if (tag.tag_.empty())
478 pending_tags_.push_back(makeTagPtr(tag));
485 XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag)
487 if (tag.tag_.empty())
489 pending_tags_.push_back(makeTagPtr(tag));
494 XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
496 if (tag.tag_.empty())
499 os_ << tag.writeTag();
505 XHTMLStream & XHTMLStream::operator<<(html::FontTag const & tag)
507 if (tag.tag_.empty())
509 pending_tags_.push_back(makeTagPtr(tag));
514 XHTMLStream & XHTMLStream::operator<<(html::CR const &)
517 os_ << from_ascii("\n");
522 bool XHTMLStream::isTagOpen(html::StartTag const & stag) const
524 TagDeque::const_iterator sit = tag_stack_.begin();
525 TagDeque::const_iterator const sen = tag_stack_.end();
526 for (; sit != sen; ++sit)
533 bool XHTMLStream::isTagOpen(html::EndTag const & etag) const
535 TagDeque::const_iterator sit = tag_stack_.begin();
536 TagDeque::const_iterator const sen = tag_stack_.end();
537 for (; sit != sen; ++sit)
544 bool XHTMLStream::isTagPending(html::StartTag const & stag) const
546 TagDeque::const_iterator sit = pending_tags_.begin();
547 TagDeque::const_iterator const sen = pending_tags_.end();
548 for (; sit != sen; ++sit)
555 // this is complicated, because we want to make sure that
556 // everything is properly nested. the code ought to make
557 // sure of that, but we won't assert (yet) if we run into
558 // a problem. we'll just output error messages and try our
559 // best to make things work.
560 XHTMLStream & XHTMLStream::operator<<(html::EndTag const & etag)
562 if (etag.tag_.empty())
565 // if this tag is pending, we can simply discard it.
566 if (!pending_tags_.empty()) {
568 if (etag == *pending_tags_.back()) {
569 // we have <tag></tag>, so we discard it and remove it
570 // from the pending_tags_.
571 pending_tags_.pop_back();
575 // there is a pending tag that isn't the one we are trying
578 // is this tag itself pending?
579 // non-const iterators because we may call erase().
580 TagDeque::iterator dit = pending_tags_.begin();
581 TagDeque::iterator const den = pending_tags_.end();
582 for (; dit != den; ++dit) {
584 // it was pending, so we just erase it
585 writeError("Tried to close pending tag `" + etag.tag_
586 + "' when other tags were pending. Last pending tag is `"
587 + to_utf8(pending_tags_.back()->writeTag())
588 + "'. Tag discarded.");
589 pending_tags_.erase(dit);
593 // so etag isn't itself pending. is it even open?
594 if (!isTagOpen(etag)) {
595 writeError("Tried to close `" + etag.tag_
596 + "' when tag was not open. Tag discarded.");
599 // ok, so etag is open.
600 // our strategy will be as below: we will do what we need to
601 // do to close this tag.
602 string estr = "Closing tag `" + etag.tag_
603 + "' when other tags are pending. Discarded pending tags:\n";
604 for (dit = pending_tags_.begin(); dit != den; ++dit)
605 estr += to_utf8(html::htmlize((*dit)->writeTag(), XHTMLStream::ESCAPE_ALL)) + "\n";
607 // clear the pending tags...
608 pending_tags_.clear();
609 // ...and then just fall through.
612 // make sure there are tags to be closed
613 if (tag_stack_.empty()) {
614 writeError("Tried to close `" + etag.tag_
615 + "' when no tags were open!");
619 // is the tag we are closing the last one we opened?
620 if (etag == *tag_stack_.back()) {
622 os_ << etag.writeEndTag();
623 // ...and forget about it
624 tag_stack_.pop_back();
628 // we are trying to close a tag other than the one last opened.
629 // let's first see if this particular tag is still open somehow.
630 if (!isTagOpen(etag)) {
631 writeError("Tried to close `" + etag.tag_
632 + "' when tag was not open. Tag discarded.");
636 // so the tag was opened, but other tags have been opened since
637 // and not yet closed.
638 // if it's a font tag, though...
639 if (etag.asFontTag()) {
640 // it won't be a problem if the other tags open since this one
641 // are also font tags.
642 TagDeque::const_reverse_iterator rit = tag_stack_.rbegin();
643 TagDeque::const_reverse_iterator ren = tag_stack_.rend();
644 for (; rit != ren; ++rit) {
647 if (!(*rit)->asFontTag()) {
648 // we'll just leave it and, presumably, have to close it later.
649 writeError("Unable to close font tag `" + etag.tag_
650 + "' due to open non-font tag `" + (*rit)->tag_ + "'.");
656 // <em>this is <strong>bold
657 // and are being asked to closed em. we want:
658 // <em>this is <strong>bold</strong></em><strong>
659 // first, we close the intervening tags...
660 TagPtr curtag = tag_stack_.back();
661 // ...remembering them in a stack.
663 while (etag != *curtag) {
664 os_ << curtag->writeEndTag();
665 fontstack.push_back(curtag);
666 tag_stack_.pop_back();
667 curtag = tag_stack_.back();
669 os_ << etag.writeEndTag();
670 tag_stack_.pop_back();
672 // ...and restore the other tags.
673 rit = fontstack.rbegin();
674 ren = fontstack.rend();
675 for (; rit != ren; ++rit)
676 pending_tags_.push_back(*rit);
680 // it wasn't a font tag.
681 // so other tags were opened before this one and not properly closed.
682 // so we'll close them, too. that may cause other issues later, but it
683 // at least guarantees proper nesting.
684 writeError("Closing tag `" + etag.tag_
685 + "' when other tags are open, namely:");
686 TagPtr curtag = tag_stack_.back();
687 while (etag != *curtag) {
688 writeError(curtag->tag_);
689 if (*curtag != parsep_tag)
690 os_ << curtag->writeEndTag();
691 tag_stack_.pop_back();
692 curtag = tag_stack_.back();
694 // curtag is now the one we actually want.
695 os_ << curtag->writeEndTag();
696 tag_stack_.pop_back();
701 // End code for XHTMLStream
705 // convenience functions
707 inline void openParTag(XHTMLStream & xs, Layout const & lay,
708 std::string parlabel)
710 xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
714 void openParTag(XHTMLStream & xs, Layout const & lay,
715 ParagraphParameters const & params,
716 std::string parlabel)
718 // FIXME Are there other things we should handle here?
719 string const align = alignmentToCSS(params.align());
721 openParTag(xs, lay, parlabel);
724 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
725 xs << html::ParTag(lay.htmltag(), attrs, parlabel);
729 inline void closeTag(XHTMLStream & xs, Layout const & lay)
731 xs << html::EndTag(lay.htmltag());
735 inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
737 xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
741 inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
743 xs << html::EndTag(lay.htmllabeltag());
747 inline void openItemTag(XHTMLStream & xs, Layout const & lay)
749 xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
753 void openItemTag(XHTMLStream & xs, Layout const & lay,
754 ParagraphParameters const & params)
756 // FIXME Are there other things we should handle here?
757 string const align = alignmentToCSS(params.align());
759 openItemTag(xs, lay);
762 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
763 xs << html::StartTag(lay.htmlitemtag(), attrs);
767 inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
769 xs << html::EndTag(lay.htmlitemtag());
772 // end of convenience functions
774 ParagraphList::const_iterator findLastParagraph(
775 ParagraphList::const_iterator p,
776 ParagraphList::const_iterator const & pend)
778 for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p)
785 ParagraphList::const_iterator findEndOfEnvironment(
786 ParagraphList::const_iterator const & pstart,
787 ParagraphList::const_iterator const & pend)
789 ParagraphList::const_iterator p = pstart;
790 Layout const & bstyle = p->layout();
791 size_t const depth = p->params().depth();
792 for (++p; p != pend; ++p) {
793 Layout const & style = p->layout();
794 // It shouldn't happen that e.g. a section command occurs inside
795 // a quotation environment, at a higher depth, but as of 6/2009,
796 // it can happen. We pretend that it's just at lowest depth.
797 if (style.latextype == LATEX_COMMAND)
800 // If depth is down, we're done
801 if (p->params().depth() < depth)
804 // If depth is up, we're not done
805 if (p->params().depth() > depth)
808 // FIXME I am not sure about the first check.
809 // Surely we *could* have different layouts that count as
810 // LATEX_PARAGRAPH, right?
811 if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
818 ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
820 OutputParams const & runparams,
822 ParagraphList::const_iterator const & pbegin,
823 ParagraphList::const_iterator const & pend)
825 ParagraphList::const_iterator const begin = text.paragraphs().begin();
826 ParagraphList::const_iterator par = pbegin;
827 for (; par != pend; ++par) {
828 Layout const & lay = par->layout();
829 if (!lay.counter.empty())
830 buf.masterBuffer()->params().
831 documentClass().counters().step(lay.counter, OutputUpdate);
832 // FIXME We should see if there's a label to be output and
833 // do something with it.
837 // If we are already in a paragraph, and this is the first one, then we
838 // do not want to open the paragraph tag.
839 // we also do not want to open it if the current layout does not permit
840 // multiple paragraphs.
841 bool const opened = runparams.html_make_pars &&
842 (par != pbegin || !runparams.html_in_par);
843 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
846 openParTag(xs, lay, par->params(),
847 make_parid ? par->magicLabel() : "");
849 docstring const deferred =
850 par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)));
852 // We want to issue the closing tag if either:
853 // (i) We opened it, and either html_in_par is false,
854 // or we're not in the last paragraph, anyway.
855 // (ii) We didn't open it and html_in_par is true,
856 // but we are in the first par, and there is a next par.
857 ParagraphList::const_iterator nextpar = par;
859 bool const needclose =
860 (opened && (!runparams.html_in_par || nextpar != pend))
861 || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
866 if (!deferred.empty()) {
867 xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
874 ParagraphList::const_iterator makeBibliography(Buffer const & buf,
876 OutputParams const & runparams,
878 ParagraphList::const_iterator const & pbegin,
879 ParagraphList::const_iterator const & pend)
882 // Use TextClass::htmlTOCLayout() to figure out how we should look.
883 xs << html::StartTag("h2", "class='bibliography'")
884 << pbegin->layout().labelstring(false)
885 << html::EndTag("h2")
887 << html::StartTag("div", "class='bibliography'")
889 makeParagraphs(buf, xs, runparams, text, pbegin, pend);
890 xs << html::EndTag("div");
895 bool isNormalEnv(Layout const & lay)
897 return lay.latextype == LATEX_ENVIRONMENT
898 || lay.latextype == LATEX_BIB_ENVIRONMENT;
902 ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
904 OutputParams const & runparams,
906 ParagraphList::const_iterator const & pbegin,
907 ParagraphList::const_iterator const & pend)
909 ParagraphList::const_iterator const begin = text.paragraphs().begin();
910 ParagraphList::const_iterator par = pbegin;
911 Layout const & bstyle = par->layout();
912 depth_type const origdepth = pbegin->params().depth();
914 // open tag for this environment
915 openParTag(xs, bstyle, pbegin->magicLabel());
918 // we will on occasion need to remember a layout from before.
919 Layout const * lastlay = 0;
921 while (par != pend) {
922 Layout const & style = par->layout();
923 // the counter only gets stepped if we're in some kind of list,
924 // or if it's the first time through.
925 // note that enum, etc, are handled automatically.
926 // FIXME There may be a bug here about user defined enumeration
927 // types. If so, then we'll need to take the counter and add "i",
928 // "ii", etc, as with enum.
929 Counters & cnts = buf.masterBuffer()->params().documentClass().counters();
930 docstring const & cntr = style.counter;
931 if (!style.counter.empty()
932 && (par == pbegin || !isNormalEnv(style))
933 && cnts.hasCounter(cntr)
935 cnts.step(cntr, OutputUpdate);
936 ParagraphList::const_iterator send;
938 switch (style.latextype) {
939 case LATEX_ENVIRONMENT:
940 case LATEX_LIST_ENVIRONMENT:
941 case LATEX_ITEM_ENVIRONMENT: {
942 // There are two possiblities in this case.
943 // One is that we are still in the environment in which we
944 // started---which we will be if the depth is the same.
945 if (par->params().depth() == origdepth) {
946 LATTEST(bstyle == style);
948 closeItemTag(xs, *lastlay);
952 // this will be positive, if we want to skip the
953 // initial word (if it's been taken for the label).
955 bool const labelfirst = style.htmllabelfirst();
957 openItemTag(xs, style, par->params());
960 if (style.labeltype != LABEL_NO_LABEL &&
961 style.htmllabeltag() != "NONE") {
962 if (isNormalEnv(style)) {
963 // in this case, we print the label only for the first
964 // paragraph (as in a theorem).
966 docstring const lbl =
967 pbegin->params().labelString();
969 openLabelTag(xs, style);
971 closeLabelTag(xs, style);
975 } else { // some kind of list
976 if (style.labeltype == LABEL_MANUAL) {
977 openLabelTag(xs, style);
978 sep = par->firstWordLyXHTML(xs, runparams);
979 closeLabelTag(xs, style);
983 openLabelTag(xs, style);
984 xs << par->params().labelString();
985 closeLabelTag(xs, style);
989 } // end label output
992 openItemTag(xs, style, par->params());
994 par->simpleLyXHTMLOnePar(buf, xs, runparams,
995 text.outerFont(distance(begin, par)), sep);
998 // We may not want to close the tag yet, in particular:
999 // If we're not at the end...
1001 // and are doing items...
1002 && !isNormalEnv(style)
1003 // and if the depth has changed...
1004 && par->params().depth() != origdepth) {
1005 // then we'll save this layout for later, and close it when
1006 // we get another item.
1009 closeItemTag(xs, style);
1012 // The other possibility is that the depth has increased, in which
1013 // case we need to recurse.
1015 send = findEndOfEnvironment(par, pend);
1016 par = makeEnvironment(buf, xs, runparams, text, par, send);
1020 case LATEX_PARAGRAPH:
1021 send = findLastParagraph(par, pend);
1022 par = makeParagraphs(buf, xs, runparams, text, par, send);
1025 case LATEX_BIB_ENVIRONMENT:
1028 par = makeParagraphs(buf, xs, runparams, text, par, send);
1038 closeItemTag(xs, *lastlay);
1039 closeTag(xs, bstyle);
1045 void makeCommand(Buffer const & buf,
1047 OutputParams const & runparams,
1049 ParagraphList::const_iterator const & pbegin)
1051 Layout const & style = pbegin->layout();
1052 if (!style.counter.empty())
1053 buf.masterBuffer()->params().
1054 documentClass().counters().step(style.counter, OutputUpdate);
1056 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
1058 if (style.labeltype == LABEL_ABOVE)
1059 xs << html::StartTag("div")
1060 << pbegin->params().labelString()
1061 << html::EndTag("div");
1062 else if (style.labeltype == LABEL_CENTERED)
1063 xs << html::StartTag("div", "style = \"text-align: center;\"")
1064 << pbegin->params().labelString()
1065 << html::EndTag("div");
1067 openParTag(xs, style, pbegin->params(),
1068 make_parid ? pbegin->magicLabel() : "");
1070 // Label around sectioning number:
1071 // FIXME Probably need to account for LABEL_MANUAL
1072 if (style.labeltype != LABEL_NO_LABEL &&
1073 style.labeltype != LABEL_ABOVE &&
1074 style.labeltype != LABEL_CENTERED ) {
1075 openLabelTag(xs, style);
1076 xs << pbegin->params().labelString();
1077 closeLabelTag(xs, style);
1078 // Otherwise the label might run together with the text
1079 xs << from_ascii(" ");
1082 ParagraphList::const_iterator const begin = text.paragraphs().begin();
1083 pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
1084 text.outerFont(distance(begin, pbegin)));
1085 closeTag(xs, style);
1089 } // end anonymous namespace
1092 void xhtmlParagraphs(Text const & text,
1095 OutputParams const & runparams)
1097 ParagraphList const & paragraphs = text.paragraphs();
1098 if (runparams.par_begin == runparams.par_end) {
1099 runparams.par_begin = 0;
1100 runparams.par_end = paragraphs.size();
1102 pit_type bpit = runparams.par_begin;
1103 pit_type const epit = runparams.par_end;
1104 LASSERT(bpit < epit,
1105 { xs << XHTMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
1107 OutputParams ourparams = runparams;
1108 ParagraphList::const_iterator const pend =
1109 (epit == (int) paragraphs.size()) ?
1110 paragraphs.end() : paragraphs.constIterator(epit);
1111 while (bpit < epit) {
1112 ParagraphList::const_iterator par = paragraphs.constIterator(bpit);
1113 if (par->params().startOfAppendix()) {
1114 // We want to reset the counter corresponding to toplevel sectioning
1115 Layout const & lay =
1116 buf.masterBuffer()->params().documentClass().getTOCLayout();
1117 docstring const cnt = lay.counter;
1120 buf.masterBuffer()->params().documentClass().counters();
1124 Layout const & style = par->layout();
1125 ParagraphList::const_iterator const lastpar = par;
1126 ParagraphList::const_iterator send;
1128 switch (style.latextype) {
1129 case LATEX_COMMAND: {
1130 // The files with which we are working never have more than
1131 // one paragraph in a command structure.
1133 // if (ourparams.html_in_par)
1134 // fix it so we don't get sections inside standard, e.g.
1135 // note that we may then need to make runparams not const, so we
1136 // can communicate that back.
1137 // FIXME Maybe this fix should be in the routines themselves, in case
1138 // they are called from elsewhere.
1139 makeCommand(buf, xs, ourparams, text, par);
1143 case LATEX_ENVIRONMENT:
1144 case LATEX_LIST_ENVIRONMENT:
1145 case LATEX_ITEM_ENVIRONMENT: {
1146 // FIXME Same fix here.
1147 send = findEndOfEnvironment(par, pend);
1148 par = makeEnvironment(buf, xs, ourparams, text, par, send);
1151 case LATEX_BIB_ENVIRONMENT: {
1152 // FIXME Same fix here.
1153 send = findEndOfEnvironment(par, pend);
1154 par = makeBibliography(buf, xs, ourparams, text, par, send);
1157 case LATEX_PARAGRAPH:
1158 send = findLastParagraph(par, pend);
1159 par = makeParagraphs(buf, xs, ourparams, text, par, send);
1162 bpit += distance(lastpar, par);
1167 string alignmentToCSS(LyXAlignment align)
1170 case LYX_ALIGN_BLOCK:
1171 // we are NOT going to use text-align: justify!!
1172 case LYX_ALIGN_LEFT:
1174 case LYX_ALIGN_RIGHT:
1176 case LYX_ALIGN_CENTER: