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)
187 case FT_SIZE_FOOTNOTE:
192 case FT_SIZE_LARGEST:
195 case FT_SIZE_INCREASE:
196 case FT_SIZE_DECREASE:
203 string fontToAttribute(html::FontTypes type)
210 return "class='lyxnoun'";
214 return "class='dline'";
217 return "class='strikeout'";
219 return "class='wline'";
223 return "style='font-style:normal;'";
225 return "style='font-style:oblique;'";
227 return "style='font-variant:small-caps;'";
229 return "style='font-family:serif;'";
231 return "style='font-family:sans-serif;'";
233 return "style='font-family:monospace;'";
236 case FT_SIZE_FOOTNOTE:
237 return "style='font-size:x-small;'";
239 return "style='font-size:small;'";
241 return "style='font-size:normal;'";
243 return "style='font-size:large;'";
245 case FT_SIZE_LARGEST:
246 return "style='font-size:x-large;'";
249 return "style='font-size:xx-large;'";
250 case FT_SIZE_INCREASE:
251 return "style='font-size:larger;'";
252 case FT_SIZE_DECREASE:
253 return "style='font-size:smaller;'";
259 } // end anonymous namespace
262 FontTag::FontTag(FontTypes type)
263 : StartTag(fontToTag(type), fontToAttribute(type)), font_type_(type)
267 bool FontTag::operator==(StartTag const & tag) const
269 FontTag const * const ftag = tag.asFontTag();
272 return (font_type_ == ftag->font_type_);
276 EndFontTag::EndFontTag(FontTypes type)
277 : EndTag(fontToTag(type)), font_type_(type)
284 ////////////////////////////////////////////////////////////////
288 ////////////////////////////////////////////////////////////////
290 XHTMLStream::XHTMLStream(odocstream & os)
291 : os_(os), escape_(ESCAPE_ALL)
296 void XHTMLStream::dumpTagStack(string const & msg)
301 writeError("Tag Stack");
302 TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
303 TagDeque::const_reverse_iterator en = tag_stack_.rend();
304 for (; it != en; ++it) {
305 writeError(it->get()->tag_);
307 writeError("End Tag Stack");
309 writeError("Pending Tags");
310 it = pending_tags_.rbegin();
311 en = pending_tags_.rend();
312 for (; it != en; ++it) {
313 writeError(it->get()->tag_);
315 writeError("End Pending Tags");
321 void XHTMLStream::writeError(std::string const & s) const
324 os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
329 // an illegal tag for internal use
330 static html::StartTag const parsep_tag("&LyX_parsep_tag&");
334 bool XHTMLStream::closeFontTags()
336 if (isTagPending(parsep_tag))
337 // we haven't had any content
341 dumpTagStack("Beging Close Font Tags");
344 // this may be a useless check, since we ought at least to have
345 // the parsep_tag. but it can't hurt too much to be careful.
346 if (tag_stack_.empty())
349 // first, we close any open font tags we can close
350 TagPtr curtag = tag_stack_.back();
351 while (curtag->asFontTag()) {
352 os_ << curtag->writeEndTag();
353 tag_stack_.pop_back();
354 // this shouldn't happen, since then the font tags
355 // weren't in any other tag.
356 LASSERT(!tag_stack_.empty(), return true);
357 curtag = tag_stack_.back();
361 dumpTagStack("End Close Font Tags");
364 if (*curtag == parsep_tag)
367 // so we've hit a non-font tag.
368 writeError("Tags still open in closeFontTags(). Probably not a problem,\n"
369 "but you might want to check these tags:");
370 TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
371 TagDeque::const_reverse_iterator const en = tag_stack_.rend();
372 for (; it != en; ++it) {
373 if (**it == parsep_tag)
375 writeError((*it)->tag_);
381 void XHTMLStream::startDivision(bool keep_empty)
383 pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag)));
387 dumpTagStack("StartDivision");
392 void XHTMLStream::endDivision()
394 if (isTagPending(parsep_tag)) {
395 // this case is normal. it just means we didn't have content,
396 // so the parsep_tag never got moved onto the tag stack.
397 while (!pending_tags_.empty()) {
398 // clear all pending tags up to and including the parsep tag.
399 // note that we work from the back, because we want to get rid
400 // of everything that hasn't been used.
401 TagPtr const cur_tag = pending_tags_.back();
402 pending_tags_.pop_back();
403 if (*cur_tag == parsep_tag)
408 dumpTagStack("EndDivision");
414 if (!isTagOpen(parsep_tag)) {
415 writeError("No division separation tag found in endDivision().");
419 // this case is also normal, if the parsep tag is the last one
420 // on the stack. otherwise, it's an error.
421 while (!tag_stack_.empty()) {
422 TagPtr const cur_tag = tag_stack_.back();
423 tag_stack_.pop_back();
424 if (*cur_tag == parsep_tag)
426 writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing.");
427 os_ << cur_tag->writeEndTag();
431 dumpTagStack("EndDivision");
436 void XHTMLStream::clearTagDeque()
438 while (!pending_tags_.empty()) {
439 TagPtr const tag = pending_tags_.front();
440 if (*tag != parsep_tag)
442 os_ << tag->writeTag();
443 tag_stack_.push_back(tag);
444 pending_tags_.pop_front();
449 XHTMLStream & XHTMLStream::operator<<(docstring const & d)
452 os_ << html::htmlize(d, escape_);
453 escape_ = ESCAPE_ALL;
458 XHTMLStream & XHTMLStream::operator<<(const char * s)
461 docstring const d = from_ascii(s);
462 os_ << html::htmlize(d, escape_);
463 escape_ = ESCAPE_ALL;
468 XHTMLStream & XHTMLStream::operator<<(char_type c)
471 os_ << html::escapeChar(c, escape_);
472 escape_ = ESCAPE_ALL;
477 XHTMLStream & XHTMLStream::operator<<(char c)
480 os_ << html::escapeChar(c, escape_);
481 escape_ = ESCAPE_ALL;
486 XHTMLStream & XHTMLStream::operator<<(int i)
490 escape_ = ESCAPE_ALL;
495 XHTMLStream & XHTMLStream::operator<<(EscapeSettings e)
502 XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag)
504 if (tag.tag_.empty())
506 pending_tags_.push_back(makeTagPtr(tag));
513 XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag)
515 if (tag.tag_.empty())
517 pending_tags_.push_back(makeTagPtr(tag));
522 XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
524 if (tag.tag_.empty())
527 os_ << tag.writeTag();
533 XHTMLStream & XHTMLStream::operator<<(html::FontTag const & tag)
535 if (tag.tag_.empty())
537 pending_tags_.push_back(makeTagPtr(tag));
542 XHTMLStream & XHTMLStream::operator<<(html::CR const &)
545 os_ << from_ascii("\n");
550 bool XHTMLStream::isTagOpen(html::StartTag const & stag) const
552 TagDeque::const_iterator sit = tag_stack_.begin();
553 TagDeque::const_iterator const sen = tag_stack_.end();
554 for (; sit != sen; ++sit)
561 bool XHTMLStream::isTagOpen(html::EndTag const & etag) const
563 TagDeque::const_iterator sit = tag_stack_.begin();
564 TagDeque::const_iterator const sen = tag_stack_.end();
565 for (; sit != sen; ++sit)
572 bool XHTMLStream::isTagPending(html::StartTag const & stag) const
574 TagDeque::const_iterator sit = pending_tags_.begin();
575 TagDeque::const_iterator const sen = pending_tags_.end();
576 for (; sit != sen; ++sit)
583 // this is complicated, because we want to make sure that
584 // everything is properly nested. the code ought to make
585 // sure of that, but we won't assert (yet) if we run into
586 // a problem. we'll just output error messages and try our
587 // best to make things work.
588 XHTMLStream & XHTMLStream::operator<<(html::EndTag const & etag)
590 if (etag.tag_.empty())
593 // if this tag is pending, we can simply discard it.
594 if (!pending_tags_.empty()) {
596 if (etag == *pending_tags_.back()) {
597 // we have <tag></tag>, so we discard it and remove it
598 // from the pending_tags_.
599 pending_tags_.pop_back();
603 // there is a pending tag that isn't the one we are trying
606 // is this tag itself pending?
607 // non-const iterators because we may call erase().
608 TagDeque::iterator dit = pending_tags_.begin();
609 TagDeque::iterator const den = pending_tags_.end();
610 for (; dit != den; ++dit) {
612 // it was pending, so we just erase it
613 writeError("Tried to close pending tag `" + etag.tag_
614 + "' when other tags were pending. Last pending tag is `"
615 + to_utf8(pending_tags_.back()->writeTag())
616 + "'. Tag discarded.");
617 pending_tags_.erase(dit);
621 // so etag isn't itself pending. is it even open?
622 if (!isTagOpen(etag)) {
623 writeError("Tried to close `" + etag.tag_
624 + "' when tag was not open. Tag discarded.");
627 // ok, so etag is open.
628 // our strategy will be as below: we will do what we need to
629 // do to close this tag.
630 string estr = "Closing tag `" + etag.tag_
631 + "' when other tags are pending. Discarded pending tags:\n";
632 for (dit = pending_tags_.begin(); dit != den; ++dit)
633 estr += to_utf8(html::htmlize((*dit)->writeTag(), XHTMLStream::ESCAPE_ALL)) + "\n";
635 // clear the pending tags...
636 pending_tags_.clear();
637 // ...and then just fall through.
640 // make sure there are tags to be closed
641 if (tag_stack_.empty()) {
642 writeError("Tried to close `" + etag.tag_
643 + "' when no tags were open!");
647 // is the tag we are closing the last one we opened?
648 if (etag == *tag_stack_.back()) {
650 os_ << etag.writeEndTag();
651 // ...and forget about it
652 tag_stack_.pop_back();
656 // we are trying to close a tag other than the one last opened.
657 // let's first see if this particular tag is still open somehow.
658 if (!isTagOpen(etag)) {
659 writeError("Tried to close `" + etag.tag_
660 + "' when tag was not open. Tag discarded.");
664 // so the tag was opened, but other tags have been opened since
665 // and not yet closed.
666 // if it's a font tag, though...
667 if (etag.asFontTag()) {
668 // it won't be a problem if the other tags open since this one
669 // are also font tags.
670 TagDeque::const_reverse_iterator rit = tag_stack_.rbegin();
671 TagDeque::const_reverse_iterator ren = tag_stack_.rend();
672 for (; rit != ren; ++rit) {
675 if (!(*rit)->asFontTag()) {
676 // we'll just leave it and, presumably, have to close it later.
677 writeError("Unable to close font tag `" + etag.tag_
678 + "' due to open non-font tag `" + (*rit)->tag_ + "'.");
684 // <em>this is <strong>bold
685 // and are being asked to closed em. we want:
686 // <em>this is <strong>bold</strong></em><strong>
687 // first, we close the intervening tags...
688 TagPtr curtag = tag_stack_.back();
689 // ...remembering them in a stack.
691 while (etag != *curtag) {
692 os_ << curtag->writeEndTag();
693 fontstack.push_back(curtag);
694 tag_stack_.pop_back();
695 curtag = tag_stack_.back();
697 os_ << etag.writeEndTag();
698 tag_stack_.pop_back();
700 // ...and restore the other tags.
701 rit = fontstack.rbegin();
702 ren = fontstack.rend();
703 for (; rit != ren; ++rit)
704 pending_tags_.push_back(*rit);
708 // it wasn't a font tag.
709 // so other tags were opened before this one and not properly closed.
710 // so we'll close them, too. that may cause other issues later, but it
711 // at least guarantees proper nesting.
712 writeError("Closing tag `" + etag.tag_
713 + "' when other tags are open, namely:");
714 TagPtr curtag = tag_stack_.back();
715 while (etag != *curtag) {
716 writeError(curtag->tag_);
717 if (*curtag != parsep_tag)
718 os_ << curtag->writeEndTag();
719 tag_stack_.pop_back();
720 curtag = tag_stack_.back();
722 // curtag is now the one we actually want.
723 os_ << curtag->writeEndTag();
724 tag_stack_.pop_back();
729 // End code for XHTMLStream
733 // convenience functions
735 inline void openParTag(XHTMLStream & xs, Layout const & lay,
736 std::string parlabel)
738 xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
742 void openParTag(XHTMLStream & xs, Layout const & lay,
743 ParagraphParameters const & params,
744 std::string parlabel)
746 // FIXME Are there other things we should handle here?
747 string const align = alignmentToCSS(params.align());
749 openParTag(xs, lay, parlabel);
752 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
753 xs << html::ParTag(lay.htmltag(), attrs, parlabel);
757 inline void closeTag(XHTMLStream & xs, Layout const & lay)
759 xs << html::EndTag(lay.htmltag());
763 inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
765 xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
769 inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
771 xs << html::EndTag(lay.htmllabeltag());
775 inline void openItemTag(XHTMLStream & xs, Layout const & lay)
777 xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
781 void openItemTag(XHTMLStream & xs, Layout const & lay,
782 ParagraphParameters const & params)
784 // FIXME Are there other things we should handle here?
785 string const align = alignmentToCSS(params.align());
787 openItemTag(xs, lay);
790 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
791 xs << html::StartTag(lay.htmlitemtag(), attrs);
795 inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
797 xs << html::EndTag(lay.htmlitemtag());
800 // end of convenience functions
802 ParagraphList::const_iterator findLastParagraph(
803 ParagraphList::const_iterator p,
804 ParagraphList::const_iterator const & pend)
806 for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p)
813 ParagraphList::const_iterator findEndOfEnvironment(
814 ParagraphList::const_iterator const & pstart,
815 ParagraphList::const_iterator const & pend)
817 ParagraphList::const_iterator p = pstart;
818 Layout const & bstyle = p->layout();
819 size_t const depth = p->params().depth();
820 for (++p; p != pend; ++p) {
821 Layout const & style = p->layout();
822 // It shouldn't happen that e.g. a section command occurs inside
823 // a quotation environment, at a higher depth, but as of 6/2009,
824 // it can happen. We pretend that it's just at lowest depth.
825 if (style.latextype == LATEX_COMMAND)
828 // If depth is down, we're done
829 if (p->params().depth() < depth)
832 // If depth is up, we're not done
833 if (p->params().depth() > depth)
836 // FIXME I am not sure about the first check.
837 // Surely we *could* have different layouts that count as
838 // LATEX_PARAGRAPH, right?
839 if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
846 ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
848 OutputParams const & runparams,
850 ParagraphList::const_iterator const & pbegin,
851 ParagraphList::const_iterator const & pend)
853 ParagraphList::const_iterator const begin = text.paragraphs().begin();
854 ParagraphList::const_iterator par = pbegin;
855 for (; par != pend; ++par) {
856 Layout const & lay = par->layout();
857 if (!lay.counter.empty())
858 buf.masterBuffer()->params().
859 documentClass().counters().step(lay.counter, OutputUpdate);
861 // FIXME We should see if there's a label to be output and
862 // do something with it.
866 // We want to open the paragraph tag if:
867 // (i) the current layout permits multiple paragraphs
868 // (ii) we are either not already inside a paragraph (HTMLIsBlock) OR
869 // we are, but this is not the first paragraph
871 // But there is also a special case, and we first see whether we are in it.
872 // We do not want to open the paragraph tag if this paragraph contains
873 // only one item, and that item is "inline", i.e., not HTMLIsBlock (such
874 // as a branch). On the other hand, if that single item has a font change
875 // applied to it, then we still do need to open the paragraph.
877 // Obviously, this is very fragile. The main reason we need to do this is
878 // because of branches, e.g., a branch that contains an entire new section.
879 // We do not really want to wrap that whole thing in a <div>...</div>.
880 bool special_case = false;
881 Inset const * specinset = par->size() == 1 ? par->getInset(0) : 0;
882 if (specinset && !specinset->getLayout().htmlisblock()) {
883 Layout const & style = par->layout();
884 FontInfo const first_font = style.labeltype == LABEL_MANUAL ?
885 style.labelfont : style.font;
886 FontInfo const our_font =
887 par->getFont(buf.masterBuffer()->params(), 0,
888 text.outerFont(distance(begin, par))).fontInfo();
889 if (first_font == our_font)
893 bool const open_par = runparams.html_make_pars
894 && (!runparams.html_in_par || par != pbegin)
897 // We want to issue the closing tag if either:
898 // (i) We opened it, and either html_in_par is false,
899 // or we're not in the last paragraph, anyway.
900 // (ii) We didn't open it and html_in_par is true,
901 // but we are in the first par, and there is a next par.
902 ParagraphList::const_iterator nextpar = par;
904 bool const close_par =
905 (open_par && (!runparams.html_in_par || nextpar != pend))
906 || (!open_par && runparams.html_in_par && par == pbegin && nextpar != pend);
909 // We do not issue the paragraph id if we are doing
910 // this for the TOC (or some similar purpose)
911 openParTag(xs, lay, par->params(),
912 runparams.for_toc ? "" : par->magicLabel());
915 docstring const deferred = par->simpleLyXHTMLOnePar(buf, xs,
916 runparams, text.outerFont(distance(begin, par)),
917 open_par, close_par);
924 if (!deferred.empty()) {
925 xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
932 ParagraphList::const_iterator makeBibliography(Buffer const & buf,
934 OutputParams const & runparams,
936 ParagraphList::const_iterator const & pbegin,
937 ParagraphList::const_iterator const & pend)
940 // Use TextClass::htmlTOCLayout() to figure out how we should look.
941 xs << html::StartTag("h2", "class='bibliography'")
942 << pbegin->layout().labelstring(false)
943 << html::EndTag("h2")
945 << html::StartTag("div", "class='bibliography'")
947 makeParagraphs(buf, xs, runparams, text, pbegin, pend);
948 xs << html::EndTag("div");
953 bool isNormalEnv(Layout const & lay)
955 return lay.latextype == LATEX_ENVIRONMENT
956 || lay.latextype == LATEX_BIB_ENVIRONMENT;
960 ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
962 OutputParams const & runparams,
964 ParagraphList::const_iterator const & pbegin,
965 ParagraphList::const_iterator const & pend)
967 ParagraphList::const_iterator const begin = text.paragraphs().begin();
968 ParagraphList::const_iterator par = pbegin;
969 Layout const & bstyle = par->layout();
970 depth_type const origdepth = pbegin->params().depth();
972 // open tag for this environment
973 openParTag(xs, bstyle, pbegin->magicLabel());
976 // we will on occasion need to remember a layout from before.
977 Layout const * lastlay = 0;
979 while (par != pend) {
980 Layout const & style = par->layout();
981 // the counter only gets stepped if we're in some kind of list,
982 // or if it's the first time through.
983 // note that enum, etc, are handled automatically.
984 // FIXME There may be a bug here about user defined enumeration
985 // types. If so, then we'll need to take the counter and add "i",
986 // "ii", etc, as with enum.
987 Counters & cnts = buf.masterBuffer()->params().documentClass().counters();
988 docstring const & cntr = style.counter;
989 if (!style.counter.empty()
990 && (par == pbegin || !isNormalEnv(style))
991 && cnts.hasCounter(cntr)
993 cnts.step(cntr, OutputUpdate);
994 ParagraphList::const_iterator send;
996 switch (style.latextype) {
997 case LATEX_ENVIRONMENT:
998 case LATEX_LIST_ENVIRONMENT:
999 case LATEX_ITEM_ENVIRONMENT: {
1000 // There are two possiblities in this case.
1001 // One is that we are still in the environment in which we
1002 // started---which we will be if the depth is the same.
1003 if (par->params().depth() == origdepth) {
1004 LATTEST(bstyle == style);
1006 closeItemTag(xs, *lastlay);
1010 // this will be positive, if we want to skip the
1011 // initial word (if it's been taken for the label).
1013 bool const labelfirst = style.htmllabelfirst();
1015 openItemTag(xs, style, par->params());
1018 if (style.labeltype != LABEL_NO_LABEL &&
1019 style.htmllabeltag() != "NONE") {
1020 if (isNormalEnv(style)) {
1021 // in this case, we print the label only for the first
1022 // paragraph (as in a theorem).
1023 if (par == pbegin) {
1024 docstring const lbl =
1025 pbegin->params().labelString();
1027 openLabelTag(xs, style);
1029 closeLabelTag(xs, style);
1033 } else { // some kind of list
1034 if (style.labeltype == LABEL_MANUAL) {
1035 openLabelTag(xs, style);
1036 sep = par->firstWordLyXHTML(xs, runparams);
1037 closeLabelTag(xs, style);
1041 openLabelTag(xs, style);
1042 xs << par->params().labelString();
1043 closeLabelTag(xs, style);
1047 } // end label output
1050 openItemTag(xs, style, par->params());
1052 docstring deferred = par->simpleLyXHTMLOnePar(buf, xs, runparams,
1053 text.outerFont(distance(begin, par)), true, true, sep);
1054 xs << XHTMLStream::ESCAPE_NONE << deferred;
1057 // We may not want to close the tag yet, in particular:
1058 // If we're not at the end...
1060 // and are doing items...
1061 && !isNormalEnv(style)
1062 // and if the depth has changed...
1063 && par->params().depth() != origdepth) {
1064 // then we'll save this layout for later, and close it when
1065 // we get another item.
1068 closeItemTag(xs, style);
1071 // The other possibility is that the depth has increased, in which
1072 // case we need to recurse.
1074 send = findEndOfEnvironment(par, pend);
1075 par = makeEnvironment(buf, xs, runparams, text, par, send);
1079 case LATEX_PARAGRAPH:
1080 send = findLastParagraph(par, pend);
1081 par = makeParagraphs(buf, xs, runparams, text, par, send);
1084 case LATEX_BIB_ENVIRONMENT:
1087 par = makeParagraphs(buf, xs, runparams, text, par, send);
1097 closeItemTag(xs, *lastlay);
1098 closeTag(xs, bstyle);
1104 void makeCommand(Buffer const & buf,
1106 OutputParams const & runparams,
1108 ParagraphList::const_iterator const & pbegin)
1110 Layout const & style = pbegin->layout();
1111 if (!style.counter.empty())
1112 buf.masterBuffer()->params().
1113 documentClass().counters().step(style.counter, OutputUpdate);
1115 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
1117 if (style.labeltype == LABEL_ABOVE)
1118 xs << html::StartTag("div")
1119 << pbegin->params().labelString()
1120 << html::EndTag("div");
1121 else if (style.labeltype == LABEL_CENTERED)
1122 xs << html::StartTag("div", "style = \"text-align: center;\"")
1123 << pbegin->params().labelString()
1124 << html::EndTag("div");
1126 openParTag(xs, style, pbegin->params(),
1127 make_parid ? pbegin->magicLabel() : "");
1129 // Label around sectioning number:
1130 // FIXME Probably need to account for LABEL_MANUAL
1131 if (style.labeltype != LABEL_NO_LABEL &&
1132 style.labeltype != LABEL_ABOVE &&
1133 style.labeltype != LABEL_CENTERED ) {
1134 openLabelTag(xs, style);
1135 xs << pbegin->params().labelString();
1136 closeLabelTag(xs, style);
1137 // Otherwise the label might run together with the text
1138 xs << from_ascii(" ");
1141 ParagraphList::const_iterator const begin = text.paragraphs().begin();
1142 pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
1143 text.outerFont(distance(begin, pbegin)));
1144 closeTag(xs, style);
1148 } // end anonymous namespace
1151 void xhtmlParagraphs(Text const & text,
1154 OutputParams const & runparams)
1156 ParagraphList const & paragraphs = text.paragraphs();
1157 if (runparams.par_begin == runparams.par_end) {
1158 runparams.par_begin = 0;
1159 runparams.par_end = paragraphs.size();
1161 pit_type bpit = runparams.par_begin;
1162 pit_type const epit = runparams.par_end;
1163 LASSERT(bpit < epit,
1164 { xs << XHTMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
1166 OutputParams ourparams = runparams;
1167 ParagraphList::const_iterator const pend =
1168 (epit == (int) paragraphs.size()) ?
1169 paragraphs.end() : paragraphs.constIterator(epit);
1170 while (bpit < epit) {
1171 ParagraphList::const_iterator par = paragraphs.constIterator(bpit);
1172 if (par->params().startOfAppendix()) {
1173 // We want to reset the counter corresponding to toplevel sectioning
1174 Layout const & lay =
1175 buf.masterBuffer()->params().documentClass().getTOCLayout();
1176 docstring const cnt = lay.counter;
1179 buf.masterBuffer()->params().documentClass().counters();
1183 Layout const & style = par->layout();
1184 ParagraphList::const_iterator const lastpar = par;
1185 ParagraphList::const_iterator send;
1187 switch (style.latextype) {
1188 case LATEX_COMMAND: {
1189 // The files with which we are working never have more than
1190 // one paragraph in a command structure.
1192 // if (ourparams.html_in_par)
1193 // fix it so we don't get sections inside standard, e.g.
1194 // note that we may then need to make runparams not const, so we
1195 // can communicate that back.
1196 // FIXME Maybe this fix should be in the routines themselves, in case
1197 // they are called from elsewhere.
1198 makeCommand(buf, xs, ourparams, text, par);
1202 case LATEX_ENVIRONMENT:
1203 case LATEX_LIST_ENVIRONMENT:
1204 case LATEX_ITEM_ENVIRONMENT: {
1205 // FIXME Same fix here.
1206 send = findEndOfEnvironment(par, pend);
1207 par = makeEnvironment(buf, xs, ourparams, text, par, send);
1210 case LATEX_BIB_ENVIRONMENT: {
1211 // FIXME Same fix here.
1212 send = findEndOfEnvironment(par, pend);
1213 par = makeBibliography(buf, xs, ourparams, text, par, send);
1216 case LATEX_PARAGRAPH:
1217 send = findLastParagraph(par, pend);
1218 par = makeParagraphs(buf, xs, ourparams, text, par, send);
1221 bpit += distance(lastpar, par);
1226 string alignmentToCSS(LyXAlignment align)
1229 case LYX_ALIGN_BLOCK:
1230 // we are NOT going to use text-align: justify!!
1231 case LYX_ALIGN_LEFT:
1233 case LYX_ALIGN_RIGHT:
1235 case LYX_ALIGN_CENTER: