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 string escapeChar(char c, XHTMLStream::EscapeSettings e)
92 case XHTMLStream::ESCAPE_NONE:
95 case XHTMLStream::ESCAPE_ALL:
99 } else if (c == '>') {
104 case XHTMLStream::ESCAPE_AND:
115 // escape what needs escaping
116 string htmlize(string const & str, XHTMLStream::EscapeSettings e)
119 string::const_iterator it = str.begin();
120 string::const_iterator en = str.end();
121 for (; it != en; ++it)
122 d << escapeChar(*it, e);
127 string cleanAttr(string const & str)
130 string::const_iterator it = str.begin();
131 string::const_iterator en = str.end();
132 for (; it != en; ++it)
133 newname += isAlnumASCII(*it) ? *it : '_';
138 docstring cleanAttr(docstring const & str)
141 docstring::const_iterator it = str.begin();
142 docstring::const_iterator en = str.end();
143 for (; it != en; ++it) {
144 char_type const c = *it;
145 newname += isAlnumASCII(c) ? c : char_type('_');
151 docstring StartTag::writeTag() const
153 string output = "<" + tag_;
155 output += " " + html::htmlize(attr_, XHTMLStream::ESCAPE_NONE);
157 return from_utf8(output);
161 docstring StartTag::writeEndTag() const
163 string output = "</" + tag_ + ">";
164 return from_utf8(output);
168 bool StartTag::operator==(FontTag const & rhs) const
174 docstring EndTag::writeEndTag() const
176 string output = "</" + tag_ + ">";
177 return from_utf8(output);
181 docstring ParTag::writeTag() const
183 docstring output = StartTag::writeTag();
188 string const pattr = "id='" + parid_ + "'";
189 output += html::CompTag("a", pattr).writeTag();
194 docstring CompTag::writeTag() const
196 string output = "<" + tag_;
198 output += " " + html::htmlize(attr_, XHTMLStream::ESCAPE_NONE);
200 return from_utf8(output);
207 string fontToTag(html::FontTypes type)
232 case FT_SIZE_FOOTNOTE:
237 case FT_SIZE_LARGEST:
240 case FT_SIZE_INCREASE:
241 case FT_SIZE_DECREASE:
248 StartTag fontToStartTag(html::FontTypes type)
250 string tag = fontToTag(type);
253 return html::StartTag(tag);
255 return html::StartTag(tag);
257 return html::StartTag(tag, "class='lyxnoun'");
259 return html::StartTag(tag);
261 return html::StartTag(tag, "class='dline'");
263 return html::StartTag(tag, "class='strikeout'");
265 return html::StartTag(tag, "class='wline'");
267 return html::StartTag(tag);
269 return html::StartTag(tag, "style='font-style:normal;'");
271 return html::StartTag(tag, "style='font-style:oblique;'");
273 return html::StartTag(tag, "style='font-variant:small-caps;'");
275 return html::StartTag(tag, "style='font-family:serif;'");
277 return html::StartTag(tag, "style='font-family:sans-serif;'");
279 return html::StartTag(tag, "style='font-family:monospace;'");
282 case FT_SIZE_FOOTNOTE:
283 return html::StartTag(tag, "style='font-size:x-small;'");
285 return html::StartTag(tag, "style='font-size:small;'");
287 return html::StartTag(tag, "style='font-size:normal;'");
289 return html::StartTag(tag, "style='font-size:large;'");
291 case FT_SIZE_LARGEST:
292 return html::StartTag(tag, "style='font-size:x-large;'");
295 return html::StartTag(tag, "style='font-size:xx-large;'");
296 case FT_SIZE_INCREASE:
297 return html::StartTag(tag, "style='font-size:larger;'");
298 case FT_SIZE_DECREASE:
299 return html::StartTag(tag, "style='font-size:smaller;'");
305 } // end anonymous namespace
308 FontTag::FontTag(FontTypes type)
309 : StartTag(fontToStartTag(type)), font_type_(type)
313 bool FontTag::operator==(StartTag const & tag) const
315 FontTag const * const ftag = tag.asFontTag();
318 return (font_type_ == ftag->font_type_);
322 EndFontTag::EndFontTag(FontTypes type)
323 : EndTag(fontToTag(type)), font_type_(type)
330 ////////////////////////////////////////////////////////////////
334 ////////////////////////////////////////////////////////////////
336 XHTMLStream::XHTMLStream(odocstream & os)
337 : os_(os), escape_(ESCAPE_ALL)
342 void XHTMLStream::dumpTagStack(string const & msg) const
344 writeError(msg + ": Tag Stack");
345 TagStack::const_reverse_iterator it = tag_stack_.rbegin();
346 TagStack::const_reverse_iterator en = tag_stack_.rend();
347 for (; it != en; ++it) {
348 writeError(it->tag_);
350 writeError("Pending Tags");
351 it = pending_tags_.rbegin();
352 en = pending_tags_.rend();
353 for (; it != en; ++it) {
354 writeError(it->tag_);
356 writeError("End Tag Stack");
361 void XHTMLStream::writeError(std::string const & s) const
364 os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
369 // an illegal tag for internal use
370 static html::StartTag const parsep_tag("&LyX_parsep_tag&");
374 bool XHTMLStream::closeFontTags()
376 if (isTagPending(parsep_tag))
377 // we haven't had any content
380 // this may be a useless check, since we ought at least to have
381 // the parsep_tag. but it can't hurt too much to be careful.
382 if (tag_stack_.empty())
385 // first, we close any open font tags we can close
386 TagPtr curtag = tag_stack_.back();
387 while (curtag->asFontTag()) {
388 os_ << curtag->writeEndTag();
389 tag_stack_.pop_back();
390 // this shouldn't happen, since then the font tags
391 // weren't in any other tag.
392 LBUFERR(!tag_stack_.empty());
393 curtag = tag_stack_.back();
396 if (*curtag == parsep_tag)
399 // so we've hit a non-font tag.
400 writeError("Tags still open in closeFontTags(). Probably not a problem,\n"
401 "but you might want to check these tags:");
402 TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
403 TagDeque::const_reverse_iterator const en = tag_stack_.rend();
404 for (; it != en; ++it) {
405 if (**it == parsep_tag)
407 writeError((*it)->tag_);
413 void XHTMLStream::startParagraph(bool keep_empty)
415 pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag)));
421 void XHTMLStream::endParagraph()
423 if (isTagPending(parsep_tag)) {
424 // this case is normal. it just means we didn't have content,
425 // so the parsep_tag never got moved onto the tag stack.
426 while (!pending_tags_.empty()) {
427 // clear all pending tags up to and including the parsep tag.
428 // note that we work from the back, because we want to get rid
429 // of everything that hasn't been used.
430 TagPtr const cur_tag = pending_tags_.back();
431 pending_tags_.pop_back();
432 if (*cur_tag == parsep_tag)
438 if (!isTagOpen(parsep_tag)) {
439 writeError("No paragraph separation tag found in endParagraph().");
443 // this case is also normal, if the parsep tag is the last one
444 // on the stack. otherwise, it's an error.
445 while (!tag_stack_.empty()) {
446 TagPtr const cur_tag = tag_stack_.back();
447 tag_stack_.pop_back();
448 if (*cur_tag == parsep_tag)
450 writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing.");
451 os_ << cur_tag->writeEndTag();
456 void XHTMLStream::clearTagDeque()
458 while (!pending_tags_.empty()) {
459 TagPtr const tag = pending_tags_.front();
460 if (*tag != parsep_tag)
462 os_ << tag->writeTag();
463 tag_stack_.push_back(tag);
464 pending_tags_.pop_front();
469 XHTMLStream & XHTMLStream::operator<<(docstring const & d)
472 os_ << html::htmlize(d, escape_);
473 escape_ = ESCAPE_ALL;
478 XHTMLStream & XHTMLStream::operator<<(const char * s)
481 docstring const d = from_ascii(s);
482 os_ << html::htmlize(d, escape_);
483 escape_ = ESCAPE_ALL;
488 XHTMLStream & XHTMLStream::operator<<(char_type c)
491 os_ << html::escapeChar(c, escape_);
492 escape_ = ESCAPE_ALL;
497 XHTMLStream & XHTMLStream::operator<<(char c)
500 string const d = html::escapeChar(c, escape_);
501 escape_ = ESCAPE_ALL;
506 XHTMLStream & XHTMLStream::operator<<(int i)
510 escape_ = ESCAPE_ALL;
515 XHTMLStream & XHTMLStream::operator<<(EscapeSettings e)
522 XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag)
524 if (tag.tag_.empty())
526 pending_tags_.push_back(makeTagPtr(tag));
533 XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag)
535 if (tag.tag_.empty())
537 pending_tags_.push_back(makeTagPtr(tag));
542 XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
544 if (tag.tag_.empty())
547 os_ << tag.writeTag();
553 XHTMLStream & XHTMLStream::operator<<(html::FontTag const & tag)
555 if (tag.tag_.empty())
557 pending_tags_.push_back(makeTagPtr(tag));
562 XHTMLStream & XHTMLStream::operator<<(html::CR const &)
565 os_ << from_ascii("\n");
570 bool XHTMLStream::isTagOpen(html::StartTag const & stag) const
572 TagDeque::const_iterator sit = tag_stack_.begin();
573 TagDeque::const_iterator const sen = tag_stack_.end();
574 for (; sit != sen; ++sit)
581 bool XHTMLStream::isTagOpen(html::EndTag const & etag) const
583 TagDeque::const_iterator sit = tag_stack_.begin();
584 TagDeque::const_iterator const sen = tag_stack_.end();
585 for (; sit != sen; ++sit)
592 bool XHTMLStream::isTagPending(html::StartTag const & stag) const
594 TagDeque::const_iterator sit = pending_tags_.begin();
595 TagDeque::const_iterator const sen = pending_tags_.end();
596 for (; sit != sen; ++sit)
603 // this is complicated, because we want to make sure that
604 // everything is properly nested. the code ought to make
605 // sure of that, but we won't assert (yet) if we run into
606 // a problem. we'll just output error messages and try our
607 // best to make things work.
608 XHTMLStream & XHTMLStream::operator<<(html::EndTag const & etag)
610 if (etag.tag_.empty())
613 // if this tag is pending, we can simply discard it.
614 if (!pending_tags_.empty()) {
616 if (etag == *pending_tags_.back()) {
617 // we have <tag></tag>, so we discard it and remove it
618 // from the pending_tags_.
619 pending_tags_.pop_back();
623 // there is a pending tag that isn't the one we are trying
626 // is this tag itself pending?
627 // non-const iterators because we may call erase().
628 TagDeque::iterator dit = pending_tags_.begin();
629 TagDeque::iterator const den = pending_tags_.end();
630 for (; dit != den; ++dit) {
632 // it was pending, so we just erase it
633 writeError("Tried to close pending tag `" + etag.tag_
634 + "' when other tags were pending. Last pending tag is `"
635 + to_utf8(pending_tags_.back()->writeTag())
636 + "'. Tag discarded.");
637 pending_tags_.erase(dit);
641 // so etag isn't itself pending. is it even open?
642 if (!isTagOpen(etag)) {
643 writeError("Tried to close `" + etag.tag_
644 + "' when tag was not open. Tag discarded.");
647 // ok, so etag is open.
648 // our strategy will be as below: we will do what we need to
649 // do to close this tag.
650 string estr = "Closing tag `" + etag.tag_
651 + "' when other tags are pending. Discarded pending tags:\n";
652 for (dit = pending_tags_.begin(); dit != den; ++dit)
653 estr += to_utf8(html::htmlize((*dit)->writeTag(), XHTMLStream::ESCAPE_ALL)) + "\n";
655 // clear the pending tags...
656 pending_tags_.clear();
657 // ...and then just fall through.
660 // make sure there are tags to be closed
661 if (tag_stack_.empty()) {
662 writeError("Tried to close `" + etag.tag_
663 + "' when no tags were open!");
667 // is the tag we are closing the last one we opened?
668 if (etag == *tag_stack_.back()) {
670 os_ << etag.writeEndTag();
671 // ...and forget about it
672 tag_stack_.pop_back();
676 // we are trying to close a tag other than the one last opened.
677 // let's first see if this particular tag is still open somehow.
678 if (!isTagOpen(etag)) {
679 writeError("Tried to close `" + etag.tag_
680 + "' when tag was not open. Tag discarded.");
684 // so the tag was opened, but other tags have been opened since
685 // and not yet closed.
686 // if it's a font tag, though...
687 if (etag.asFontTag()) {
688 // it won't be a problem if the other tags open since this one
689 // are also font tags.
690 TagDeque::const_reverse_iterator rit = tag_stack_.rbegin();
691 TagDeque::const_reverse_iterator ren = tag_stack_.rend();
692 for (; rit != ren; ++rit) {
695 if (!(*rit)->asFontTag()) {
696 // we'll just leave it and, presumably, have to close it later.
697 writeError("Unable to close font tag `" + etag.tag_
698 + "' due to open non-font tag `" + (*rit)->tag_ + "'.");
704 // <em>this is <strong>bold
705 // and are being asked to closed em. we want:
706 // <em>this is <strong>bold</strong></em><strong>
707 // first, we close the intervening tags...
708 TagPtr curtag = tag_stack_.back();
709 // ...remembering them in a stack.
711 while (etag != *curtag) {
712 os_ << curtag->writeEndTag();
713 fontstack.push_back(curtag);
714 tag_stack_.pop_back();
715 curtag = tag_stack_.back();
717 os_ << etag.writeEndTag();
718 tag_stack_.pop_back();
720 // ...and restore the other tags.
721 rit = fontstack.rbegin();
722 ren = fontstack.rend();
723 for (; rit != ren; ++rit)
724 pending_tags_.push_back(*rit);
728 // it wasn't a font tag.
729 // so other tags were opened before this one and not properly closed.
730 // so we'll close them, too. that may cause other issues later, but it
731 // at least guarantees proper nesting.
732 writeError("Closing tag `" + etag.tag_
733 + "' when other tags are open, namely:");
734 TagPtr curtag = tag_stack_.back();
735 while (etag != *curtag) {
736 writeError(curtag->tag_);
737 if (*curtag != parsep_tag)
738 os_ << curtag->writeEndTag();
739 tag_stack_.pop_back();
740 curtag = tag_stack_.back();
742 // curtag is now the one we actually want.
743 os_ << curtag->writeEndTag();
744 tag_stack_.pop_back();
749 // End code for XHTMLStream
753 // convenience functions
755 inline void openTag(XHTMLStream & xs, Layout const & lay)
757 xs << html::StartTag(lay.htmltag(), lay.htmlattr());
761 void openTag(XHTMLStream & xs, Layout const & lay,
762 ParagraphParameters const & params)
764 // FIXME Are there other things we should handle here?
765 string const align = alignmentToCSS(params.align());
770 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
771 xs << html::StartTag(lay.htmltag(), attrs);
775 inline void openParTag(XHTMLStream & xs, Layout const & lay,
776 std::string parlabel)
778 xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
782 void openParTag(XHTMLStream & xs, Layout const & lay,
783 ParagraphParameters const & params,
784 std::string parlabel)
786 // FIXME Are there other things we should handle here?
787 string const align = alignmentToCSS(params.align());
789 openParTag(xs, lay, parlabel);
792 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
793 xs << html::ParTag(lay.htmltag(), attrs, parlabel);
797 inline void closeTag(XHTMLStream & xs, Layout const & lay)
799 xs << html::EndTag(lay.htmltag());
803 inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
805 xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
809 inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
811 xs << html::EndTag(lay.htmllabeltag());
815 inline void openItemTag(XHTMLStream & xs, Layout const & lay)
817 xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
821 void openItemTag(XHTMLStream & xs, Layout const & lay,
822 ParagraphParameters const & params)
824 // FIXME Are there other things we should handle here?
825 string const align = alignmentToCSS(params.align());
827 openItemTag(xs, lay);
830 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
831 xs << html::StartTag(lay.htmlitemtag(), attrs);
835 inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
837 xs << html::EndTag(lay.htmlitemtag());
840 // end of convenience functions
842 ParagraphList::const_iterator findLastParagraph(
843 ParagraphList::const_iterator p,
844 ParagraphList::const_iterator const & pend)
846 for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p)
853 ParagraphList::const_iterator findEndOfEnvironment(
854 ParagraphList::const_iterator const pstart,
855 ParagraphList::const_iterator const & pend)
857 ParagraphList::const_iterator p = pstart;
858 Layout const & bstyle = p->layout();
859 size_t const depth = p->params().depth();
860 for (++p; p != pend; ++p) {
861 Layout const & style = p->layout();
862 // It shouldn't happen that e.g. a section command occurs inside
863 // a quotation environment, at a higher depth, but as of 6/2009,
864 // it can happen. We pretend that it's just at lowest depth.
865 if (style.latextype == LATEX_COMMAND)
868 // If depth is down, we're done
869 if (p->params().depth() < depth)
872 // If depth is up, we're not done
873 if (p->params().depth() > depth)
876 // FIXME I am not sure about the first check.
877 // Surely we *could* have different layouts that count as
878 // LATEX_PARAGRAPH, right?
879 if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
886 ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
888 OutputParams const & runparams,
890 ParagraphList::const_iterator const & pbegin,
891 ParagraphList::const_iterator const & pend)
893 ParagraphList::const_iterator const begin = text.paragraphs().begin();
894 ParagraphList::const_iterator par = pbegin;
895 for (; par != pend; ++par) {
896 Layout const & lay = par->layout();
897 if (!lay.counter.empty())
898 buf.masterBuffer()->params().
899 documentClass().counters().step(lay.counter, OutputUpdate);
900 // FIXME We should see if there's a label to be output and
901 // do something with it.
905 // If we are already in a paragraph, and this is the first one, then we
906 // do not want to open the paragraph tag.
907 // we also do not want to open it if the current layout does not permit
908 // multiple paragraphs.
909 bool const opened = runparams.html_make_pars &&
910 (par != pbegin || !runparams.html_in_par);
911 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
914 openParTag(xs, lay, par->params(),
915 make_parid ? par->magicLabel() : "");
917 docstring const deferred =
918 par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)));
920 // We want to issue the closing tag if either:
921 // (i) We opened it, and either html_in_par is false,
922 // or we're not in the last paragraph, anyway.
923 // (ii) We didn't open it and html_in_par is true,
924 // but we are in the first par, and there is a next par.
925 ParagraphList::const_iterator nextpar = par;
927 bool const needclose =
928 (opened && (!runparams.html_in_par || nextpar != pend))
929 || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
934 if (!deferred.empty()) {
935 xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
942 ParagraphList::const_iterator makeBibliography(Buffer const & buf,
944 OutputParams const & runparams,
946 ParagraphList::const_iterator const & pbegin,
947 ParagraphList::const_iterator const & pend)
950 // Use TextClass::htmlTOCLayout() to figure out how we should look.
951 xs << html::StartTag("h2", "class='bibliography'")
952 << pbegin->layout().labelstring(false)
953 << html::EndTag("h2")
955 << html::StartTag("div", "class='bibliography'")
957 makeParagraphs(buf, xs, runparams, text, pbegin, pend);
958 xs << html::EndTag("div");
963 bool isNormalEnv(Layout const & lay)
965 return lay.latextype == LATEX_ENVIRONMENT
966 || lay.latextype == LATEX_BIB_ENVIRONMENT;
970 ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
972 OutputParams const & runparams,
974 ParagraphList::const_iterator const & pbegin,
975 ParagraphList::const_iterator const & pend)
977 ParagraphList::const_iterator const begin = text.paragraphs().begin();
978 ParagraphList::const_iterator par = pbegin;
979 Layout const & bstyle = par->layout();
980 depth_type const origdepth = pbegin->params().depth();
982 // open tag for this environment
983 openParTag(xs, bstyle, pbegin->magicLabel());
986 // we will on occasion need to remember a layout from before.
987 Layout const * lastlay = 0;
989 while (par != pend) {
990 Layout const & style = par->layout();
991 // the counter only gets stepped if we're in some kind of list,
992 // or if it's the first time through.
993 // note that enum, etc, are handled automatically.
994 // FIXME There may be a bug here about user defined enumeration
995 // types. If so, then we'll need to take the counter and add "i",
996 // "ii", etc, as with enum.
997 Counters & cnts = buf.masterBuffer()->params().documentClass().counters();
998 docstring const & cntr = style.counter;
999 if (!style.counter.empty()
1000 && (par == pbegin || !isNormalEnv(style))
1001 && cnts.hasCounter(cntr)
1003 cnts.step(cntr, OutputUpdate);
1004 ParagraphList::const_iterator send;
1005 // this will be positive, if we want to skip the initial word
1006 // (if it's been taken for the label).
1009 switch (style.latextype) {
1010 case LATEX_ENVIRONMENT:
1011 case LATEX_LIST_ENVIRONMENT:
1012 case LATEX_ITEM_ENVIRONMENT: {
1013 // There are two possiblities in this case.
1014 // One is that we are still in the environment in which we
1015 // started---which we will be if the depth is the same.
1016 if (par->params().depth() == origdepth) {
1017 LATTEST(bstyle == style);
1019 closeItemTag(xs, *lastlay);
1023 bool const labelfirst = style.htmllabelfirst();
1025 openItemTag(xs, style, par->params());
1028 if (style.labeltype != LABEL_NO_LABEL &&
1029 style.htmllabeltag() != "NONE") {
1030 if (isNormalEnv(style)) {
1031 // in this case, we print the label only for the first
1032 // paragraph (as in a theorem).
1033 if (par == pbegin) {
1034 docstring const lbl =
1035 pbegin->params().labelString();
1037 openLabelTag(xs, style);
1039 closeLabelTag(xs, style);
1043 } else { // some kind of list
1044 if (style.labeltype == LABEL_MANUAL) {
1045 openLabelTag(xs, style);
1046 sep = par->firstWordLyXHTML(xs, runparams);
1047 closeLabelTag(xs, style);
1051 openLabelTag(xs, style);
1052 xs << par->params().labelString();
1053 closeLabelTag(xs, style);
1057 } // end label output
1060 openItemTag(xs, style, par->params());
1062 par->simpleLyXHTMLOnePar(buf, xs, runparams,
1063 text.outerFont(distance(begin, par)), sep);
1066 // We may not want to close the tag yet, in particular:
1067 // If we're not at the end...
1069 // and are doing items...
1070 && !isNormalEnv(style)
1071 // and if the depth has changed...
1072 && par->params().depth() != origdepth) {
1073 // then we'll save this layout for later, and close it when
1074 // we get another item.
1077 closeItemTag(xs, style);
1080 // The other possibility is that the depth has increased, in which
1081 // case we need to recurse.
1083 send = findEndOfEnvironment(par, pend);
1084 par = makeEnvironment(buf, xs, runparams, text, par, send);
1088 case LATEX_PARAGRAPH:
1089 send = findLastParagraph(par, pend);
1090 par = makeParagraphs(buf, xs, runparams, text, par, send);
1093 case LATEX_BIB_ENVIRONMENT:
1096 par = makeParagraphs(buf, xs, runparams, text, par, send);
1106 closeItemTag(xs, *lastlay);
1107 closeTag(xs, bstyle);
1113 void makeCommand(Buffer const & buf,
1115 OutputParams const & runparams,
1117 ParagraphList::const_iterator const & pbegin)
1119 Layout const & style = pbegin->layout();
1120 if (!style.counter.empty())
1121 buf.masterBuffer()->params().
1122 documentClass().counters().step(style.counter, OutputUpdate);
1124 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
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 // FIXME Probably also need now to account for labels ABOVE and CENTERED.
1132 if (style.labeltype != LABEL_NO_LABEL) {
1133 openLabelTag(xs, style);
1134 xs << pbegin->params().labelString();
1135 closeLabelTag(xs, style);
1136 // Otherwise the label might run together with the text
1137 xs << from_ascii(" ");
1140 ParagraphList::const_iterator const begin = text.paragraphs().begin();
1141 pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
1142 text.outerFont(distance(begin, pbegin)));
1143 closeTag(xs, style);
1147 } // end anonymous namespace
1150 void xhtmlParagraphs(Text const & text,
1153 OutputParams const & runparams)
1155 ParagraphList const & paragraphs = text.paragraphs();
1156 if (runparams.par_begin == runparams.par_end) {
1157 runparams.par_begin = 0;
1158 runparams.par_end = paragraphs.size();
1160 pit_type bpit = runparams.par_begin;
1161 pit_type const epit = runparams.par_end;
1162 LASSERT(bpit < epit,
1163 { xs << XHTMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
1165 OutputParams ourparams = runparams;
1166 ParagraphList::const_iterator const pend =
1167 (epit == (int) paragraphs.size()) ?
1168 paragraphs.end() : paragraphs.constIterator(epit);
1169 while (bpit < epit) {
1170 ParagraphList::const_iterator par = paragraphs.constIterator(bpit);
1171 if (par->params().startOfAppendix()) {
1172 // We want to reset the counter corresponding to toplevel sectioning
1173 Layout const & lay =
1174 buf.masterBuffer()->params().documentClass().getTOCLayout();
1175 docstring const cnt = lay.counter;
1178 buf.masterBuffer()->params().documentClass().counters();
1182 Layout const & style = par->layout();
1183 ParagraphList::const_iterator const lastpar = par;
1184 ParagraphList::const_iterator send;
1186 switch (style.latextype) {
1187 case LATEX_COMMAND: {
1188 // The files with which we are working never have more than
1189 // one paragraph in a command structure.
1191 // if (ourparams.html_in_par)
1192 // fix it so we don't get sections inside standard, e.g.
1193 // note that we may then need to make runparams not const, so we
1194 // can communicate that back.
1195 // FIXME Maybe this fix should be in the routines themselves, in case
1196 // they are called from elsewhere.
1197 makeCommand(buf, xs, ourparams, text, par);
1201 case LATEX_ENVIRONMENT:
1202 case LATEX_LIST_ENVIRONMENT:
1203 case LATEX_ITEM_ENVIRONMENT: {
1204 // FIXME Same fix here.
1205 send = findEndOfEnvironment(par, pend);
1206 par = makeEnvironment(buf, xs, ourparams, text, par, send);
1209 case LATEX_BIB_ENVIRONMENT: {
1210 // FIXME Same fix here.
1211 send = findEndOfEnvironment(par, pend);
1212 par = makeBibliography(buf, xs, ourparams, text, par, send);
1215 case LATEX_PARAGRAPH:
1216 send = findLastParagraph(par, pend);
1217 par = makeParagraphs(buf, xs, ourparams, text, par, send);
1220 bpit += distance(lastpar, par);
1225 string alignmentToCSS(LyXAlignment align)
1228 case LYX_ALIGN_BLOCK:
1229 // we are NOT going to use text-align: justify!!
1230 case LYX_ALIGN_LEFT:
1232 case LYX_ALIGN_RIGHT:
1234 case LYX_ALIGN_CENTER: