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)
236 StartTag fontToStartTag(html::FontTypes type)
238 string tag = fontToTag(type);
241 return html::StartTag(tag);
243 return html::StartTag(tag);
245 return html::StartTag(tag, "class='lyxnoun'");
247 return html::StartTag(tag);
249 return html::StartTag(tag, "class='dline'");
251 return html::StartTag(tag, "class='strikeout'");
253 return html::StartTag(tag, "class='wline'");
255 return html::StartTag(tag);
257 return html::StartTag(tag, "style='font-style:normal;'");
259 return html::StartTag(tag, "style='font-style:oblique;'");
261 return html::StartTag(tag, "style='font-variant:small-caps;'");
263 return html::StartTag(tag, "style='font-family:serif;'");
265 return html::StartTag(tag, "style='font-family:sans-serif;'");
267 return html::StartTag(tag, "style='font-family:monospace;'");
273 } // end anonymous namespace
276 FontTag::FontTag(FontTypes type)
277 : StartTag(fontToStartTag(type)), font_type_(type)
281 bool FontTag::operator==(StartTag const & tag) const
283 FontTag const * const ftag = tag.asFontTag();
286 return (font_type_ == ftag->font_type_);
290 EndFontTag::EndFontTag(FontTypes type)
291 : EndTag(fontToTag(type)), font_type_(type)
298 ////////////////////////////////////////////////////////////////
302 ////////////////////////////////////////////////////////////////
304 XHTMLStream::XHTMLStream(odocstream & os)
305 : os_(os), escape_(ESCAPE_ALL)
310 void XHTMLStream::dumpTagStack(string const & msg) const
312 writeError(msg + ": Tag Stack");
313 TagStack::const_reverse_iterator it = tag_stack_.rbegin();
314 TagStack::const_reverse_iterator en = tag_stack_.rend();
315 for (; it != en; ++it) {
316 writeError(it->tag_);
318 writeError("Pending Tags");
319 it = pending_tags_.rbegin();
320 en = pending_tags_.rend();
321 for (; it != en; ++it) {
322 writeError(it->tag_);
324 writeError("End Tag Stack");
329 void XHTMLStream::writeError(std::string const & s) const
332 os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
337 // an illegal tag for internal use
338 static html::StartTag const parsep_tag("&LyX_parsep_tag&");
342 bool XHTMLStream::closeFontTags()
344 if (isTagPending(parsep_tag))
345 // we haven't had any content
348 // this may be a useless check, since we ought at least to have
349 // the parsep_tag. but it can't hurt too much to be careful.
350 if (tag_stack_.empty())
353 // first, we close any open font tags we can close
354 TagPtr curtag = tag_stack_.back();
355 while (curtag->asFontTag()) {
356 os_ << curtag->writeEndTag();
357 tag_stack_.pop_back();
358 // this shouldn't happen, since then the font tags
359 // weren't in any other tag.
360 LBUFERR(!tag_stack_.empty());
361 curtag = tag_stack_.back();
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::startParagraph(bool keep_empty)
383 pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag)));
389 void XHTMLStream::endParagraph()
391 if (isTagPending(parsep_tag)) {
392 // this case is normal. it just means we didn't have content,
393 // so the parsep_tag never got moved onto the tag stack.
394 while (!pending_tags_.empty()) {
395 // clear all pending tags up to and including the parsep tag.
396 // note that we work from the back, because we want to get rid
397 // of everything that hasn't been used.
398 TagPtr const cur_tag = pending_tags_.back();
399 pending_tags_.pop_back();
400 if (*cur_tag == parsep_tag)
406 if (!isTagOpen(parsep_tag)) {
407 writeError("No paragraph separation tag found in endParagraph().");
411 // this case is also normal, if the parsep tag is the last one
412 // on the stack. otherwise, it's an error.
413 while (!tag_stack_.empty()) {
414 TagPtr const cur_tag = tag_stack_.back();
415 tag_stack_.pop_back();
416 if (*cur_tag == parsep_tag)
418 writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing.");
419 os_ << cur_tag->writeEndTag();
424 void XHTMLStream::clearTagDeque()
426 while (!pending_tags_.empty()) {
427 TagPtr const tag = pending_tags_.front();
428 if (*tag != parsep_tag)
430 os_ << tag->writeTag();
431 tag_stack_.push_back(tag);
432 pending_tags_.pop_front();
437 XHTMLStream & XHTMLStream::operator<<(docstring const & d)
440 os_ << html::htmlize(d, escape_);
441 escape_ = ESCAPE_ALL;
446 XHTMLStream & XHTMLStream::operator<<(const char * s)
449 docstring const d = from_ascii(s);
450 os_ << html::htmlize(d, escape_);
451 escape_ = ESCAPE_ALL;
456 XHTMLStream & XHTMLStream::operator<<(char_type c)
459 os_ << html::escapeChar(c, escape_);
460 escape_ = ESCAPE_ALL;
465 XHTMLStream & XHTMLStream::operator<<(char c)
468 string const d = html::escapeChar(c, escape_);
469 escape_ = ESCAPE_ALL;
474 XHTMLStream & XHTMLStream::operator<<(int i)
478 escape_ = ESCAPE_ALL;
483 XHTMLStream & XHTMLStream::operator<<(EscapeSettings e)
490 XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag)
492 if (tag.tag_.empty())
494 pending_tags_.push_back(makeTagPtr(tag));
501 XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag)
503 if (tag.tag_.empty())
505 pending_tags_.push_back(makeTagPtr(tag));
510 XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
512 if (tag.tag_.empty())
515 os_ << tag.writeTag();
521 XHTMLStream & XHTMLStream::operator<<(html::FontTag const & tag)
523 if (tag.tag_.empty())
525 pending_tags_.push_back(makeTagPtr(tag));
530 XHTMLStream & XHTMLStream::operator<<(html::CR const &)
533 os_ << from_ascii("\n");
538 bool XHTMLStream::isTagOpen(html::StartTag const & stag) const
540 TagDeque::const_iterator sit = tag_stack_.begin();
541 TagDeque::const_iterator const sen = tag_stack_.end();
542 for (; sit != sen; ++sit)
549 bool XHTMLStream::isTagOpen(html::EndTag const & etag) const
551 TagDeque::const_iterator sit = tag_stack_.begin();
552 TagDeque::const_iterator const sen = tag_stack_.end();
553 for (; sit != sen; ++sit)
560 bool XHTMLStream::isTagPending(html::StartTag const & stag) const
562 TagDeque::const_iterator sit = pending_tags_.begin();
563 TagDeque::const_iterator const sen = pending_tags_.end();
564 for (; sit != sen; ++sit)
571 // this is complicated, because we want to make sure that
572 // everything is properly nested. the code ought to make
573 // sure of that, but we won't assert (yet) if we run into
574 // a problem. we'll just output error messages and try our
575 // best to make things work.
576 XHTMLStream & XHTMLStream::operator<<(html::EndTag const & etag)
578 if (etag.tag_.empty())
581 // if this tag is pending, we can simply discard it.
582 if (!pending_tags_.empty()) {
584 if (etag == *pending_tags_.back()) {
585 // we have <tag></tag>, so we discard it and remove it
586 // from the pending_tags_.
587 pending_tags_.pop_back();
591 // there is a pending tag that isn't the one we are trying
594 // is this tag itself pending?
595 // non-const iterators because we may call erase().
596 TagDeque::iterator dit = pending_tags_.begin();
597 TagDeque::iterator const den = pending_tags_.end();
598 for (; dit != den; ++dit) {
600 // it was pending, so we just erase it
601 writeError("Tried to close pending tag `" + etag.tag_
602 + "' when other tags were pending. Last pending tag is `"
603 + to_utf8(pending_tags_.back()->writeTag())
604 + "'. Tag discarded.");
605 pending_tags_.erase(dit);
609 // so etag isn't itself pending. is it even open?
610 if (!isTagOpen(etag)) {
611 writeError("Tried to close `" + etag.tag_
612 + "' when tag was not open. Tag discarded.");
615 // ok, so etag is open.
616 // our strategy will be as below: we will do what we need to
617 // do to close this tag.
618 string estr = "Closing tag `" + etag.tag_
619 + "' when other tags are pending. Discarded pending tags:\n";
620 for (dit = pending_tags_.begin(); dit != den; ++dit)
621 estr += to_utf8(html::htmlize((*dit)->writeTag(), XHTMLStream::ESCAPE_ALL)) + "\n";
623 // clear the pending tags...
624 pending_tags_.clear();
625 // ...and then just fall through.
628 // make sure there are tags to be closed
629 if (tag_stack_.empty()) {
630 writeError("Tried to close `" + etag.tag_
631 + "' when no tags were open!");
635 // is the tag we are closing the last one we opened?
636 if (etag == *tag_stack_.back()) {
638 os_ << etag.writeEndTag();
639 // ...and forget about it
640 tag_stack_.pop_back();
644 // we are trying to close a tag other than the one last opened.
645 // let's first see if this particular tag is still open somehow.
646 if (!isTagOpen(etag)) {
647 writeError("Tried to close `" + etag.tag_
648 + "' when tag was not open. Tag discarded.");
652 // so the tag was opened, but other tags have been opened since
653 // and not yet closed.
654 // if it's a font tag, though...
655 if (etag.asFontTag()) {
656 // it won't be a problem if the other tags open since this one
657 // are also font tags.
658 TagDeque::const_reverse_iterator rit = tag_stack_.rbegin();
659 TagDeque::const_reverse_iterator ren = tag_stack_.rend();
660 for (; rit != ren; ++rit) {
663 if (!(*rit)->asFontTag()) {
664 // we'll just leave it and, presumably, have to close it later.
665 writeError("Unable to close font tag `" + etag.tag_
666 + "' due to open non-font tag `" + (*rit)->tag_ + "'.");
672 // <em>this is <strong>bold
673 // and are being asked to closed em. we want:
674 // <em>this is <strong>bold</strong></em><strong>
675 // first, we close the intervening tags...
676 TagPtr curtag = tag_stack_.back();
677 // ...remembering them in a stack.
679 while (etag != *curtag) {
680 os_ << curtag->writeEndTag();
681 fontstack.push_back(curtag);
682 tag_stack_.pop_back();
683 curtag = tag_stack_.back();
685 os_ << etag.writeEndTag();
686 tag_stack_.pop_back();
688 // ...and restore the other tags.
689 rit = fontstack.rbegin();
690 ren = fontstack.rend();
691 for (; rit != ren; ++rit)
692 pending_tags_.push_back(*rit);
696 // it wasn't a font tag.
697 // so other tags were opened before this one and not properly closed.
698 // so we'll close them, too. that may cause other issues later, but it
699 // at least guarantees proper nesting.
700 writeError("Closing tag `" + etag.tag_
701 + "' when other tags are open, namely:");
702 TagPtr curtag = tag_stack_.back();
703 while (etag != *curtag) {
704 writeError(curtag->tag_);
705 if (*curtag != parsep_tag)
706 os_ << curtag->writeEndTag();
707 tag_stack_.pop_back();
708 curtag = tag_stack_.back();
710 // curtag is now the one we actually want.
711 os_ << curtag->writeEndTag();
712 tag_stack_.pop_back();
717 // End code for XHTMLStream
721 // convenience functions
723 inline void openTag(XHTMLStream & xs, Layout const & lay)
725 xs << html::StartTag(lay.htmltag(), lay.htmlattr());
729 void openTag(XHTMLStream & xs, Layout const & lay,
730 ParagraphParameters const & params)
732 // FIXME Are there other things we should handle here?
733 string const align = alignmentToCSS(params.align());
738 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
739 xs << html::StartTag(lay.htmltag(), attrs);
743 inline void openParTag(XHTMLStream & xs, Layout const & lay,
744 std::string parlabel)
746 xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
750 void openParTag(XHTMLStream & xs, Layout const & lay,
751 ParagraphParameters const & params,
752 std::string parlabel)
754 // FIXME Are there other things we should handle here?
755 string const align = alignmentToCSS(params.align());
757 openParTag(xs, lay, parlabel);
760 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
761 xs << html::ParTag(lay.htmltag(), attrs, parlabel);
765 inline void closeTag(XHTMLStream & xs, Layout const & lay)
767 xs << html::EndTag(lay.htmltag());
771 inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
773 xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
777 inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
779 xs << html::EndTag(lay.htmllabeltag());
783 inline void openItemTag(XHTMLStream & xs, Layout const & lay)
785 xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
789 void openItemTag(XHTMLStream & xs, Layout const & lay,
790 ParagraphParameters const & params)
792 // FIXME Are there other things we should handle here?
793 string const align = alignmentToCSS(params.align());
795 openItemTag(xs, lay);
798 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
799 xs << html::StartTag(lay.htmlitemtag(), attrs);
803 inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
805 xs << html::EndTag(lay.htmlitemtag());
808 // end of convenience functions
810 ParagraphList::const_iterator findLastParagraph(
811 ParagraphList::const_iterator p,
812 ParagraphList::const_iterator const & pend)
814 for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p)
821 ParagraphList::const_iterator findEndOfEnvironment(
822 ParagraphList::const_iterator const pstart,
823 ParagraphList::const_iterator const & pend)
825 ParagraphList::const_iterator p = pstart;
826 Layout const & bstyle = p->layout();
827 size_t const depth = p->params().depth();
828 for (++p; p != pend; ++p) {
829 Layout const & style = p->layout();
830 // It shouldn't happen that e.g. a section command occurs inside
831 // a quotation environment, at a higher depth, but as of 6/2009,
832 // it can happen. We pretend that it's just at lowest depth.
833 if (style.latextype == LATEX_COMMAND)
835 // If depth is down, we're done
836 if (p->params().depth() < depth)
838 // If depth is up, we're not done
839 if (p->params().depth() > depth)
841 // Now we know we are at the same depth
842 if (style.latextype == LATEX_PARAGRAPH
843 || style.latexname() != bstyle.latexname())
850 ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
852 OutputParams const & runparams,
854 ParagraphList::const_iterator const & pbegin,
855 ParagraphList::const_iterator const & pend)
857 ParagraphList::const_iterator const begin = text.paragraphs().begin();
858 ParagraphList::const_iterator par = pbegin;
859 for (; par != pend; ++par) {
860 Layout const & lay = par->layout();
861 if (!lay.counter.empty())
862 buf.masterBuffer()->params().
863 documentClass().counters().step(lay.counter, OutputUpdate);
864 // FIXME We should see if there's a label to be output and
865 // do something with it.
869 // If we are already in a paragraph, and this is the first one, then we
870 // do not want to open the paragraph tag.
871 // we also do not want to open it if the current layout does not permit
872 // multiple paragraphs.
873 bool const opened = runparams.html_make_pars &&
874 (par != pbegin || !runparams.html_in_par);
875 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
878 openParTag(xs, lay, par->params(),
879 make_parid ? par->magicLabel() : "");
881 docstring const deferred =
882 par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)));
884 // We want to issue the closing tag if either:
885 // (i) We opened it, and either html_in_par is false,
886 // or we're not in the last paragraph, anyway.
887 // (ii) We didn't open it and html_in_par is true,
888 // but we are in the first par, and there is a next par.
889 ParagraphList::const_iterator nextpar = par;
891 bool const needclose =
892 (opened && (!runparams.html_in_par || nextpar != pend))
893 || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
898 if (!deferred.empty()) {
899 xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
906 ParagraphList::const_iterator makeBibliography(Buffer const & buf,
908 OutputParams const & runparams,
910 ParagraphList::const_iterator const & pbegin,
911 ParagraphList::const_iterator const & pend)
914 // Use TextClass::htmlTOCLayout() to figure out how we should look.
915 xs << html::StartTag("h2", "class='bibliography'")
916 << pbegin->layout().labelstring(false)
917 << html::EndTag("h2")
919 << html::StartTag("div", "class='bibliography'")
921 makeParagraphs(buf, xs, runparams, text, pbegin, pend);
922 xs << html::EndTag("div");
927 bool isNormalEnv(Layout const & lay)
929 return lay.latextype == LATEX_ENVIRONMENT
930 || lay.latextype == LATEX_BIB_ENVIRONMENT;
934 ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
936 OutputParams const & runparams,
938 ParagraphList::const_iterator const & pbegin,
939 ParagraphList::const_iterator const & pend)
941 ParagraphList::const_iterator const begin = text.paragraphs().begin();
942 ParagraphList::const_iterator par = pbegin;
943 Layout const & bstyle = par->layout();
944 depth_type const origdepth = pbegin->params().depth();
946 // open tag for this environment
947 openParTag(xs, bstyle, pbegin->magicLabel());
950 // we will on occasion need to remember a layout from before.
951 Layout const * lastlay = 0;
953 while (par != pend) {
954 Layout const & style = par->layout();
955 // the counter only gets stepped if we're in some kind of list,
956 // or if it's the first time through.
957 // note that enum, etc, are handled automatically.
958 // FIXME There may be a bug here about user defined enumeration
959 // types. If so, then we'll need to take the counter and add "i",
960 // "ii", etc, as with enum.
961 Counters & cnts = buf.masterBuffer()->params().documentClass().counters();
962 docstring const & cntr = style.counter;
963 if (!style.counter.empty()
964 && (par == pbegin || !isNormalEnv(style))
965 && cnts.hasCounter(cntr)
967 cnts.step(cntr, OutputUpdate);
968 ParagraphList::const_iterator send;
969 // this will be positive, if we want to skip the initial word
970 // (if it's been taken for the label).
973 switch (style.latextype) {
974 case LATEX_ENVIRONMENT:
975 case LATEX_LIST_ENVIRONMENT:
976 case LATEX_ITEM_ENVIRONMENT: {
977 // There are two possiblities in this case.
978 // One is that we are still in the environment in which we
979 // started---which we will be if the depth is the same.
980 if (par->params().depth() == origdepth) {
981 LATTEST(bstyle == style);
983 closeItemTag(xs, *lastlay);
987 bool const labelfirst = style.htmllabelfirst();
989 openItemTag(xs, style, par->params());
992 if (style.labeltype != LABEL_NO_LABEL &&
993 style.htmllabeltag() != "NONE") {
994 if (isNormalEnv(style)) {
995 // in this case, we print the label only for the first
996 // paragraph (as in a theorem).
998 docstring const lbl =
999 pbegin->params().labelString();
1001 openLabelTag(xs, style);
1003 closeLabelTag(xs, style);
1007 } else { // some kind of list
1008 if (style.labeltype == LABEL_MANUAL) {
1009 openLabelTag(xs, style);
1010 sep = par->firstWordLyXHTML(xs, runparams);
1011 closeLabelTag(xs, style);
1015 openLabelTag(xs, style);
1016 xs << par->params().labelString();
1017 closeLabelTag(xs, style);
1021 } // end label output
1024 openItemTag(xs, style, par->params());
1026 par->simpleLyXHTMLOnePar(buf, xs, runparams,
1027 text.outerFont(distance(begin, par)), sep);
1030 // We may not want to close the tag yet, in particular:
1031 // If we're not at the end...
1033 // and are doing items...
1034 && !isNormalEnv(style)
1035 // and if the depth has changed...
1036 && par->params().depth() != origdepth) {
1037 // then we'll save this layout for later, and close it when
1038 // we get another item.
1041 closeItemTag(xs, style);
1044 // The other possibility is that the depth has increased, in which
1045 // case we need to recurse.
1047 send = findEndOfEnvironment(par, pend);
1048 par = makeEnvironment(buf, xs, runparams, text, par, send);
1052 case LATEX_PARAGRAPH:
1053 send = findLastParagraph(par, pend);
1054 par = makeParagraphs(buf, xs, runparams, text, par, send);
1057 case LATEX_BIB_ENVIRONMENT:
1060 par = makeParagraphs(buf, xs, runparams, text, par, send);
1070 closeItemTag(xs, *lastlay);
1071 closeTag(xs, bstyle);
1077 void makeCommand(Buffer const & buf,
1079 OutputParams const & runparams,
1081 ParagraphList::const_iterator const & pbegin)
1083 Layout const & style = pbegin->layout();
1084 if (!style.counter.empty())
1085 buf.masterBuffer()->params().
1086 documentClass().counters().step(style.counter, OutputUpdate);
1088 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
1090 openParTag(xs, style, pbegin->params(),
1091 make_parid ? pbegin->magicLabel() : "");
1093 // Label around sectioning number:
1094 // FIXME Probably need to account for LABEL_MANUAL
1095 // FIXME Probably also need now to account for labels ABOVE and CENTERED.
1096 if (style.labeltype != LABEL_NO_LABEL) {
1097 openLabelTag(xs, style);
1098 xs << pbegin->params().labelString();
1099 closeLabelTag(xs, style);
1100 // Otherwise the label might run together with the text
1101 xs << from_ascii(" ");
1104 ParagraphList::const_iterator const begin = text.paragraphs().begin();
1105 pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
1106 text.outerFont(distance(begin, pbegin)));
1107 closeTag(xs, style);
1111 } // end anonymous namespace
1114 void xhtmlParagraphs(Text const & text,
1117 OutputParams const & runparams)
1119 ParagraphList const & paragraphs = text.paragraphs();
1120 if (runparams.par_begin == runparams.par_end) {
1121 runparams.par_begin = 0;
1122 runparams.par_end = paragraphs.size();
1124 pit_type bpit = runparams.par_begin;
1125 pit_type const epit = runparams.par_end;
1126 LASSERT(bpit < epit,
1127 { xs << XHTMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
1129 OutputParams ourparams = runparams;
1130 ParagraphList::const_iterator const pend =
1131 (epit == (int) paragraphs.size()) ?
1132 paragraphs.end() : paragraphs.constIterator(epit);
1133 while (bpit < epit) {
1134 ParagraphList::const_iterator par = paragraphs.constIterator(bpit);
1135 if (par->params().startOfAppendix()) {
1136 // We want to reset the counter corresponding to toplevel sectioning
1137 Layout const & lay =
1138 buf.masterBuffer()->params().documentClass().getTOCLayout();
1139 docstring const cnt = lay.counter;
1142 buf.masterBuffer()->params().documentClass().counters();
1146 Layout const & style = par->layout();
1147 ParagraphList::const_iterator const lastpar = par;
1148 ParagraphList::const_iterator send;
1150 switch (style.latextype) {
1151 case LATEX_COMMAND: {
1152 // The files with which we are working never have more than
1153 // one paragraph in a command structure.
1155 // if (ourparams.html_in_par)
1156 // fix it so we don't get sections inside standard, e.g.
1157 // note that we may then need to make runparams not const, so we
1158 // can communicate that back.
1159 // FIXME Maybe this fix should be in the routines themselves, in case
1160 // they are called from elsewhere.
1161 makeCommand(buf, xs, ourparams, text, par);
1165 case LATEX_ENVIRONMENT:
1166 case LATEX_LIST_ENVIRONMENT:
1167 case LATEX_ITEM_ENVIRONMENT: {
1168 // FIXME Same fix here.
1169 send = findEndOfEnvironment(par, pend);
1170 par = makeEnvironment(buf, xs, ourparams, text, par, send);
1173 case LATEX_BIB_ENVIRONMENT: {
1174 // FIXME Same fix here.
1175 send = findEndOfEnvironment(par, pend);
1176 par = makeBibliography(buf, xs, ourparams, text, par, send);
1179 case LATEX_PARAGRAPH:
1180 send = findLastParagraph(par, pend);
1181 par = makeParagraphs(buf, xs, ourparams, text, par, send);
1184 bpit += distance(lastpar, par);
1189 string alignmentToCSS(LyXAlignment align)
1192 case LYX_ALIGN_BLOCK:
1193 // we are NOT going to use text-align: justify!!
1194 case LYX_ALIGN_LEFT:
1196 case LYX_ALIGN_RIGHT:
1198 case LYX_ALIGN_CENTER: