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)
299 writeError("Tag Stack");
300 TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
301 TagDeque::const_reverse_iterator en = tag_stack_.rend();
302 for (; it != en; ++it) {
303 writeError(it->get()->tag_);
305 writeError("End Tag Stack");
307 writeError("Pending Tags");
308 it = pending_tags_.rbegin();
309 en = pending_tags_.rend();
310 for (; it != en; ++it) {
311 writeError(it->get()->tag_);
313 writeError("End Pending Tags");
319 void XHTMLStream::writeError(std::string const & s) const
322 os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
327 // an illegal tag for internal use
328 static html::StartTag const parsep_tag("&LyX_parsep_tag&");
332 bool XHTMLStream::closeFontTags()
334 if (isTagPending(parsep_tag))
335 // we haven't had any content
339 dumpTagStack("Beging Close Font Tags");
342 // this may be a useless check, since we ought at least to have
343 // the parsep_tag. but it can't hurt too much to be careful.
344 if (tag_stack_.empty())
347 // first, we close any open font tags we can close
348 TagPtr curtag = tag_stack_.back();
349 while (curtag->asFontTag()) {
350 os_ << curtag->writeEndTag();
351 tag_stack_.pop_back();
352 // this shouldn't happen, since then the font tags
353 // weren't in any other tag.
354 LASSERT(!tag_stack_.empty(), return true);
355 curtag = tag_stack_.back();
359 dumpTagStack("End Close Font Tags");
362 if (*curtag == parsep_tag)
365 // so we've hit a non-font tag.
366 writeError("Tags still open in closeFontTags(). Probably not a problem,\n"
367 "but you might want to check these tags:");
368 TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
369 TagDeque::const_reverse_iterator const en = tag_stack_.rend();
370 for (; it != en; ++it) {
371 if (**it == parsep_tag)
373 writeError((*it)->tag_);
379 void XHTMLStream::startDivision(bool keep_empty)
381 pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag)));
385 dumpTagStack("StartDivision");
390 void XHTMLStream::endDivision()
392 if (isTagPending(parsep_tag)) {
393 // this case is normal. it just means we didn't have content,
394 // so the parsep_tag never got moved onto the tag stack.
395 while (!pending_tags_.empty()) {
396 // clear all pending tags up to and including the parsep tag.
397 // note that we work from the back, because we want to get rid
398 // of everything that hasn't been used.
399 TagPtr const cur_tag = pending_tags_.back();
400 pending_tags_.pop_back();
401 if (*cur_tag == parsep_tag)
406 dumpTagStack("EndDivision");
412 if (!isTagOpen(parsep_tag)) {
413 writeError("No division separation tag found in endDivision().");
417 // this case is also normal, if the parsep tag is the last one
418 // on the stack. otherwise, it's an error.
419 while (!tag_stack_.empty()) {
420 TagPtr const cur_tag = tag_stack_.back();
421 tag_stack_.pop_back();
422 if (*cur_tag == parsep_tag)
424 writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing.");
425 os_ << cur_tag->writeEndTag();
429 dumpTagStack("EndDivision");
434 void XHTMLStream::clearTagDeque()
436 while (!pending_tags_.empty()) {
437 TagPtr const tag = pending_tags_.front();
438 if (*tag != parsep_tag)
440 os_ << tag->writeTag();
441 tag_stack_.push_back(tag);
442 pending_tags_.pop_front();
447 XHTMLStream & XHTMLStream::operator<<(docstring const & d)
450 os_ << html::htmlize(d, escape_);
451 escape_ = ESCAPE_ALL;
456 XHTMLStream & XHTMLStream::operator<<(const char * s)
459 docstring const d = from_ascii(s);
460 os_ << html::htmlize(d, escape_);
461 escape_ = ESCAPE_ALL;
466 XHTMLStream & XHTMLStream::operator<<(char_type c)
469 os_ << html::escapeChar(c, escape_);
470 escape_ = ESCAPE_ALL;
475 XHTMLStream & XHTMLStream::operator<<(char c)
478 os_ << html::escapeChar(c, escape_);
479 escape_ = ESCAPE_ALL;
484 XHTMLStream & XHTMLStream::operator<<(int i)
488 escape_ = ESCAPE_ALL;
493 XHTMLStream & XHTMLStream::operator<<(EscapeSettings e)
500 XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag)
502 if (tag.tag_.empty())
504 pending_tags_.push_back(makeTagPtr(tag));
511 XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag)
513 if (tag.tag_.empty())
515 pending_tags_.push_back(makeTagPtr(tag));
520 XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
522 if (tag.tag_.empty())
525 os_ << tag.writeTag();
531 XHTMLStream & XHTMLStream::operator<<(html::FontTag const & tag)
533 if (tag.tag_.empty())
535 pending_tags_.push_back(makeTagPtr(tag));
540 XHTMLStream & XHTMLStream::operator<<(html::CR const &)
543 os_ << from_ascii("\n");
548 bool XHTMLStream::isTagOpen(html::StartTag const & stag) const
550 TagDeque::const_iterator sit = tag_stack_.begin();
551 TagDeque::const_iterator const sen = tag_stack_.end();
552 for (; sit != sen; ++sit)
559 bool XHTMLStream::isTagOpen(html::EndTag const & etag) const
561 TagDeque::const_iterator sit = tag_stack_.begin();
562 TagDeque::const_iterator const sen = tag_stack_.end();
563 for (; sit != sen; ++sit)
570 bool XHTMLStream::isTagPending(html::StartTag const & stag) const
572 TagDeque::const_iterator sit = pending_tags_.begin();
573 TagDeque::const_iterator const sen = pending_tags_.end();
574 for (; sit != sen; ++sit)
581 // this is complicated, because we want to make sure that
582 // everything is properly nested. the code ought to make
583 // sure of that, but we won't assert (yet) if we run into
584 // a problem. we'll just output error messages and try our
585 // best to make things work.
586 XHTMLStream & XHTMLStream::operator<<(html::EndTag const & etag)
588 if (etag.tag_.empty())
591 // if this tag is pending, we can simply discard it.
592 if (!pending_tags_.empty()) {
594 if (etag == *pending_tags_.back()) {
595 // we have <tag></tag>, so we discard it and remove it
596 // from the pending_tags_.
597 pending_tags_.pop_back();
601 // there is a pending tag that isn't the one we are trying
604 // is this tag itself pending?
605 // non-const iterators because we may call erase().
606 TagDeque::iterator dit = pending_tags_.begin();
607 TagDeque::iterator const den = pending_tags_.end();
608 for (; dit != den; ++dit) {
610 // it was pending, so we just erase it
611 writeError("Tried to close pending tag `" + etag.tag_
612 + "' when other tags were pending. Last pending tag is `"
613 + to_utf8(pending_tags_.back()->writeTag())
614 + "'. Tag discarded.");
615 pending_tags_.erase(dit);
619 // so etag isn't itself pending. is it even open?
620 if (!isTagOpen(etag)) {
621 writeError("Tried to close `" + etag.tag_
622 + "' when tag was not open. Tag discarded.");
625 // ok, so etag is open.
626 // our strategy will be as below: we will do what we need to
627 // do to close this tag.
628 string estr = "Closing tag `" + etag.tag_
629 + "' when other tags are pending. Discarded pending tags:\n";
630 for (dit = pending_tags_.begin(); dit != den; ++dit)
631 estr += to_utf8(html::htmlize((*dit)->writeTag(), XHTMLStream::ESCAPE_ALL)) + "\n";
633 // clear the pending tags...
634 pending_tags_.clear();
635 // ...and then just fall through.
638 // make sure there are tags to be closed
639 if (tag_stack_.empty()) {
640 writeError("Tried to close `" + etag.tag_
641 + "' when no tags were open!");
645 // is the tag we are closing the last one we opened?
646 if (etag == *tag_stack_.back()) {
648 os_ << etag.writeEndTag();
649 // ...and forget about it
650 tag_stack_.pop_back();
654 // we are trying to close a tag other than the one last opened.
655 // let's first see if this particular tag is still open somehow.
656 if (!isTagOpen(etag)) {
657 writeError("Tried to close `" + etag.tag_
658 + "' when tag was not open. Tag discarded.");
662 // so the tag was opened, but other tags have been opened since
663 // and not yet closed.
664 // if it's a font tag, though...
665 if (etag.asFontTag()) {
666 // it won't be a problem if the other tags open since this one
667 // are also font tags.
668 TagDeque::const_reverse_iterator rit = tag_stack_.rbegin();
669 TagDeque::const_reverse_iterator ren = tag_stack_.rend();
670 for (; rit != ren; ++rit) {
673 if (!(*rit)->asFontTag()) {
674 // we'll just leave it and, presumably, have to close it later.
675 writeError("Unable to close font tag `" + etag.tag_
676 + "' due to open non-font tag `" + (*rit)->tag_ + "'.");
682 // <em>this is <strong>bold
683 // and are being asked to closed em. we want:
684 // <em>this is <strong>bold</strong></em><strong>
685 // first, we close the intervening tags...
686 TagPtr curtag = tag_stack_.back();
687 // ...remembering them in a stack.
689 while (etag != *curtag) {
690 os_ << curtag->writeEndTag();
691 fontstack.push_back(curtag);
692 tag_stack_.pop_back();
693 curtag = tag_stack_.back();
695 os_ << etag.writeEndTag();
696 tag_stack_.pop_back();
698 // ...and restore the other tags.
699 rit = fontstack.rbegin();
700 ren = fontstack.rend();
701 for (; rit != ren; ++rit)
702 pending_tags_.push_back(*rit);
706 // it wasn't a font tag.
707 // so other tags were opened before this one and not properly closed.
708 // so we'll close them, too. that may cause other issues later, but it
709 // at least guarantees proper nesting.
710 writeError("Closing tag `" + etag.tag_
711 + "' when other tags are open, namely:");
712 TagPtr curtag = tag_stack_.back();
713 while (etag != *curtag) {
714 writeError(curtag->tag_);
715 if (*curtag != parsep_tag)
716 os_ << curtag->writeEndTag();
717 tag_stack_.pop_back();
718 curtag = tag_stack_.back();
720 // curtag is now the one we actually want.
721 os_ << curtag->writeEndTag();
722 tag_stack_.pop_back();
727 // End code for XHTMLStream
731 // convenience functions
733 inline void openParTag(XHTMLStream & xs, Layout const & lay,
734 std::string parlabel)
736 xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
740 void openParTag(XHTMLStream & xs, Layout const & lay,
741 ParagraphParameters const & params,
742 std::string parlabel)
744 // FIXME Are there other things we should handle here?
745 string const align = alignmentToCSS(params.align());
747 openParTag(xs, lay, parlabel);
750 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
751 xs << html::ParTag(lay.htmltag(), attrs, parlabel);
755 inline void closeTag(XHTMLStream & xs, Layout const & lay)
757 xs << html::EndTag(lay.htmltag());
761 inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
763 xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
767 inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
769 xs << html::EndTag(lay.htmllabeltag());
773 inline void openItemTag(XHTMLStream & xs, Layout const & lay)
775 xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
779 void openItemTag(XHTMLStream & xs, Layout const & lay,
780 ParagraphParameters const & params)
782 // FIXME Are there other things we should handle here?
783 string const align = alignmentToCSS(params.align());
785 openItemTag(xs, lay);
788 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
789 xs << html::StartTag(lay.htmlitemtag(), attrs);
793 inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
795 xs << html::EndTag(lay.htmlitemtag());
798 // end of convenience functions
800 ParagraphList::const_iterator findLastParagraph(
801 ParagraphList::const_iterator p,
802 ParagraphList::const_iterator const & pend)
804 for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p)
811 ParagraphList::const_iterator findEndOfEnvironment(
812 ParagraphList::const_iterator const & pstart,
813 ParagraphList::const_iterator const & pend)
815 ParagraphList::const_iterator p = pstart;
816 Layout const & bstyle = p->layout();
817 size_t const depth = p->params().depth();
818 for (++p; p != pend; ++p) {
819 Layout const & style = p->layout();
820 // It shouldn't happen that e.g. a section command occurs inside
821 // a quotation environment, at a higher depth, but as of 6/2009,
822 // it can happen. We pretend that it's just at lowest depth.
823 if (style.latextype == LATEX_COMMAND)
826 // If depth is down, we're done
827 if (p->params().depth() < depth)
830 // If depth is up, we're not done
831 if (p->params().depth() > depth)
834 // FIXME I am not sure about the first check.
835 // Surely we *could* have different layouts that count as
836 // LATEX_PARAGRAPH, right?
837 if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
844 ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
846 OutputParams const & runparams,
848 ParagraphList::const_iterator const & pbegin,
849 ParagraphList::const_iterator const & pend)
851 ParagraphList::const_iterator const begin = text.paragraphs().begin();
852 ParagraphList::const_iterator par = pbegin;
853 for (; par != pend; ++par) {
854 Layout const & lay = par->layout();
855 if (!lay.counter.empty())
856 buf.masterBuffer()->params().
857 documentClass().counters().step(lay.counter, OutputUpdate);
859 // FIXME We should see if there's a label to be output and
860 // do something with it.
864 // We want to open the paragraph tag if:
865 // (i) the current layout permits multiple paragraphs
866 // (ii) we are either not already inside a paragraph (HTMLIsBlock) OR
867 // we are, but this is not the first paragraph
869 // But there is also a special case, and we first see whether we are in it.
870 // We do not want to open the paragraph tag if this paragraph contains
871 // only one item, and that item is "inline", i.e., not HTMLIsBlock (such
872 // as a branch). On the other hand, if that single item has a font change
873 // applied to it, then we still do need to open the paragraph.
875 // Obviously, this is very fragile. The main reason we need to do this is
876 // because of branches, e.g., a branch that contains an entire new section.
877 // We do not really want to wrap that whole thing in a <div>...</div>.
878 bool special_case = false;
879 Inset const * specinset = par->size() == 1 ? par->getInset(0) : 0;
880 if (specinset && !specinset->getLayout().htmlisblock()) {
881 Layout const & style = par->layout();
882 FontInfo const first_font = style.labeltype == LABEL_MANUAL ?
883 style.labelfont : style.font;
884 FontInfo const our_font =
885 par->getFont(buf.masterBuffer()->params(), 0,
886 text.outerFont(distance(begin, par))).fontInfo();
887 if (first_font == our_font)
891 bool const open_par = runparams.html_make_pars
892 && (!runparams.html_in_par || par != pbegin)
895 // We want to issue the closing tag if either:
896 // (i) We opened it, and either html_in_par is false,
897 // or we're not in the last paragraph, anyway.
898 // (ii) We didn't open it and html_in_par is true,
899 // but we are in the first par, and there is a next par.
900 ParagraphList::const_iterator nextpar = par;
902 bool const close_par =
903 (open_par && (!runparams.html_in_par || nextpar != pend))
904 || (!open_par && runparams.html_in_par && par == pbegin && nextpar != pend);
907 // We do not issue the paragraph id if we are doing
908 // this for the TOC (or some similar purpose)
909 openParTag(xs, lay, par->params(),
910 runparams.for_toc ? "" : par->magicLabel());
913 docstring const deferred = par->simpleLyXHTMLOnePar(buf, xs,
914 runparams, text.outerFont(distance(begin, par)),
915 open_par, close_par);
922 if (!deferred.empty()) {
923 xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
930 ParagraphList::const_iterator makeBibliography(Buffer const & buf,
932 OutputParams const & runparams,
934 ParagraphList::const_iterator const & pbegin,
935 ParagraphList::const_iterator const & pend)
938 // Use TextClass::htmlTOCLayout() to figure out how we should look.
939 xs << html::StartTag("h2", "class='bibliography'")
940 << pbegin->layout().labelstring(false)
941 << html::EndTag("h2")
943 << html::StartTag("div", "class='bibliography'")
945 makeParagraphs(buf, xs, runparams, text, pbegin, pend);
946 xs << html::EndTag("div");
951 bool isNormalEnv(Layout const & lay)
953 return lay.latextype == LATEX_ENVIRONMENT
954 || lay.latextype == LATEX_BIB_ENVIRONMENT;
958 ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
960 OutputParams const & runparams,
962 ParagraphList::const_iterator const & pbegin,
963 ParagraphList::const_iterator const & pend)
965 ParagraphList::const_iterator const begin = text.paragraphs().begin();
966 ParagraphList::const_iterator par = pbegin;
967 Layout const & bstyle = par->layout();
968 depth_type const origdepth = pbegin->params().depth();
970 // open tag for this environment
971 openParTag(xs, bstyle, pbegin->magicLabel());
974 // we will on occasion need to remember a layout from before.
975 Layout const * lastlay = 0;
977 while (par != pend) {
978 Layout const & style = par->layout();
979 // the counter only gets stepped if we're in some kind of list,
980 // or if it's the first time through.
981 // note that enum, etc, are handled automatically.
982 // FIXME There may be a bug here about user defined enumeration
983 // types. If so, then we'll need to take the counter and add "i",
984 // "ii", etc, as with enum.
985 Counters & cnts = buf.masterBuffer()->params().documentClass().counters();
986 docstring const & cntr = style.counter;
987 if (!style.counter.empty()
988 && (par == pbegin || !isNormalEnv(style))
989 && cnts.hasCounter(cntr)
991 cnts.step(cntr, OutputUpdate);
992 ParagraphList::const_iterator send;
994 switch (style.latextype) {
995 case LATEX_ENVIRONMENT:
996 case LATEX_LIST_ENVIRONMENT:
997 case LATEX_ITEM_ENVIRONMENT: {
998 // There are two possiblities in this case.
999 // One is that we are still in the environment in which we
1000 // started---which we will be if the depth is the same.
1001 if (par->params().depth() == origdepth) {
1002 LATTEST(bstyle == style);
1004 closeItemTag(xs, *lastlay);
1008 // this will be positive, if we want to skip the
1009 // initial word (if it's been taken for the label).
1011 bool const labelfirst = style.htmllabelfirst();
1013 openItemTag(xs, style, par->params());
1016 if (style.labeltype != LABEL_NO_LABEL &&
1017 style.htmllabeltag() != "NONE") {
1018 if (isNormalEnv(style)) {
1019 // in this case, we print the label only for the first
1020 // paragraph (as in a theorem).
1021 if (par == pbegin) {
1022 docstring const lbl =
1023 pbegin->params().labelString();
1025 openLabelTag(xs, style);
1027 closeLabelTag(xs, style);
1031 } else { // some kind of list
1032 if (style.labeltype == LABEL_MANUAL) {
1033 openLabelTag(xs, style);
1034 sep = par->firstWordLyXHTML(xs, runparams);
1035 closeLabelTag(xs, style);
1039 openLabelTag(xs, style);
1040 xs << par->params().labelString();
1041 closeLabelTag(xs, style);
1045 } // end label output
1048 openItemTag(xs, style, par->params());
1050 docstring deferred = par->simpleLyXHTMLOnePar(buf, xs, runparams,
1051 text.outerFont(distance(begin, par)), true, true, sep);
1052 xs << XHTMLStream::ESCAPE_NONE << deferred;
1055 // We may not want to close the tag yet, in particular:
1056 // If we're not at the end...
1058 // and are doing items...
1059 && !isNormalEnv(style)
1060 // and if the depth has changed...
1061 && par->params().depth() != origdepth) {
1062 // then we'll save this layout for later, and close it when
1063 // we get another item.
1066 closeItemTag(xs, style);
1069 // The other possibility is that the depth has increased, in which
1070 // case we need to recurse.
1072 send = findEndOfEnvironment(par, pend);
1073 par = makeEnvironment(buf, xs, runparams, text, par, send);
1077 case LATEX_PARAGRAPH:
1078 send = findLastParagraph(par, pend);
1079 par = makeParagraphs(buf, xs, runparams, text, par, send);
1082 case LATEX_BIB_ENVIRONMENT:
1085 par = makeParagraphs(buf, xs, runparams, text, par, send);
1095 closeItemTag(xs, *lastlay);
1096 closeTag(xs, bstyle);
1102 void makeCommand(Buffer const & buf,
1104 OutputParams const & runparams,
1106 ParagraphList::const_iterator const & pbegin)
1108 Layout const & style = pbegin->layout();
1109 if (!style.counter.empty())
1110 buf.masterBuffer()->params().
1111 documentClass().counters().step(style.counter, OutputUpdate);
1113 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
1115 if (style.labeltype == LABEL_ABOVE)
1116 xs << html::StartTag("div")
1117 << pbegin->params().labelString()
1118 << html::EndTag("div");
1119 else if (style.labeltype == LABEL_CENTERED)
1120 xs << html::StartTag("div", "style = \"text-align: center;\"")
1121 << pbegin->params().labelString()
1122 << html::EndTag("div");
1124 openParTag(xs, style, pbegin->params(),
1125 make_parid ? pbegin->magicLabel() : "");
1127 // Label around sectioning number:
1128 // FIXME Probably need to account for LABEL_MANUAL
1129 if (style.labeltype != LABEL_NO_LABEL &&
1130 style.labeltype != LABEL_ABOVE &&
1131 style.labeltype != LABEL_CENTERED ) {
1132 openLabelTag(xs, style);
1133 xs << pbegin->params().labelString();
1134 closeLabelTag(xs, style);
1135 // Otherwise the label might run together with the text
1136 xs << from_ascii(" ");
1139 ParagraphList::const_iterator const begin = text.paragraphs().begin();
1140 pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
1141 text.outerFont(distance(begin, pbegin)));
1142 closeTag(xs, style);
1146 } // end anonymous namespace
1149 void xhtmlParagraphs(Text const & text,
1152 OutputParams const & runparams)
1154 ParagraphList const & paragraphs = text.paragraphs();
1155 if (runparams.par_begin == runparams.par_end) {
1156 runparams.par_begin = 0;
1157 runparams.par_end = paragraphs.size();
1159 pit_type bpit = runparams.par_begin;
1160 pit_type const epit = runparams.par_end;
1161 LASSERT(bpit < epit,
1162 { xs << XHTMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
1164 OutputParams ourparams = runparams;
1165 ParagraphList::const_iterator const pend =
1166 (epit == (int) paragraphs.size()) ?
1167 paragraphs.end() : paragraphs.constIterator(epit);
1168 while (bpit < epit) {
1169 ParagraphList::const_iterator par = paragraphs.constIterator(bpit);
1170 if (par->params().startOfAppendix()) {
1171 // We want to reset the counter corresponding to toplevel sectioning
1172 Layout const & lay =
1173 buf.masterBuffer()->params().documentClass().getTOCLayout();
1174 docstring const cnt = lay.counter;
1177 buf.masterBuffer()->params().documentClass().counters();
1181 Layout const & style = par->layout();
1182 ParagraphList::const_iterator const lastpar = par;
1183 ParagraphList::const_iterator send;
1185 switch (style.latextype) {
1186 case LATEX_COMMAND: {
1187 // The files with which we are working never have more than
1188 // one paragraph in a command structure.
1190 // if (ourparams.html_in_par)
1191 // fix it so we don't get sections inside standard, e.g.
1192 // note that we may then need to make runparams not const, so we
1193 // can communicate that back.
1194 // FIXME Maybe this fix should be in the routines themselves, in case
1195 // they are called from elsewhere.
1196 makeCommand(buf, xs, ourparams, text, par);
1200 case LATEX_ENVIRONMENT:
1201 case LATEX_LIST_ENVIRONMENT:
1202 case LATEX_ITEM_ENVIRONMENT: {
1203 // FIXME Same fix here.
1204 send = findEndOfEnvironment(par, pend);
1205 par = makeEnvironment(buf, xs, ourparams, text, par, send);
1208 case LATEX_BIB_ENVIRONMENT: {
1209 // FIXME Same fix here.
1210 send = findEndOfEnvironment(par, pend);
1211 par = makeBibliography(buf, xs, ourparams, text, par, send);
1214 case LATEX_PARAGRAPH:
1215 send = findLastParagraph(par, pend);
1216 par = makeParagraphs(buf, xs, ourparams, text, par, send);
1219 bpit += distance(lastpar, par);
1224 string alignmentToCSS(LyXAlignment align)
1227 case LYX_ALIGN_BLOCK:
1228 // we are NOT going to use text-align: justify!!
1229 case LYX_ALIGN_LEFT:
1231 case LYX_ALIGN_RIGHT:
1233 case LYX_ALIGN_CENTER: