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
338 // this may be a useless check, since we ought at least to have
339 // the parsep_tag. but it can't hurt too much to be careful.
340 if (tag_stack_.empty())
343 // first, we close any open font tags we can close
344 TagPtr curtag = tag_stack_.back();
345 while (curtag->asFontTag()) {
346 os_ << curtag->writeEndTag();
347 tag_stack_.pop_back();
348 // this shouldn't happen, since then the font tags
349 // weren't in any other tag.
350 LBUFERR(!tag_stack_.empty());
351 curtag = tag_stack_.back();
354 if (*curtag == parsep_tag)
357 // so we've hit a non-font tag.
358 writeError("Tags still open in closeFontTags(). Probably not a problem,\n"
359 "but you might want to check these tags:");
360 TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
361 TagDeque::const_reverse_iterator const en = tag_stack_.rend();
362 for (; it != en; ++it) {
363 if (**it == parsep_tag)
365 writeError((*it)->tag_);
371 void XHTMLStream::startDivision(bool keep_empty)
373 pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag)));
379 void XHTMLStream::endDivision()
381 if (isTagPending(parsep_tag)) {
382 // this case is normal. it just means we didn't have content,
383 // so the parsep_tag never got moved onto the tag stack.
384 while (!pending_tags_.empty()) {
385 // clear all pending tags up to and including the parsep tag.
386 // note that we work from the back, because we want to get rid
387 // of everything that hasn't been used.
388 TagPtr const cur_tag = pending_tags_.back();
389 pending_tags_.pop_back();
390 if (*cur_tag == parsep_tag)
396 if (!isTagOpen(parsep_tag)) {
397 writeError("No division separation tag found in endDivision().");
401 // this case is also normal, if the parsep tag is the last one
402 // on the stack. otherwise, it's an error.
403 while (!tag_stack_.empty()) {
404 TagPtr const cur_tag = tag_stack_.back();
405 tag_stack_.pop_back();
406 if (*cur_tag == parsep_tag)
408 writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing.");
409 os_ << cur_tag->writeEndTag();
414 void XHTMLStream::clearTagDeque()
416 while (!pending_tags_.empty()) {
417 TagPtr const tag = pending_tags_.front();
418 if (*tag != parsep_tag)
420 os_ << tag->writeTag();
421 tag_stack_.push_back(tag);
422 pending_tags_.pop_front();
427 XHTMLStream & XHTMLStream::operator<<(docstring const & d)
430 os_ << html::htmlize(d, escape_);
431 escape_ = ESCAPE_ALL;
436 XHTMLStream & XHTMLStream::operator<<(const char * s)
439 docstring const d = from_ascii(s);
440 os_ << html::htmlize(d, escape_);
441 escape_ = ESCAPE_ALL;
446 XHTMLStream & XHTMLStream::operator<<(char_type c)
449 os_ << html::escapeChar(c, escape_);
450 escape_ = ESCAPE_ALL;
455 XHTMLStream & XHTMLStream::operator<<(char c)
458 os_ << html::escapeChar(c, escape_);
459 escape_ = ESCAPE_ALL;
464 XHTMLStream & XHTMLStream::operator<<(int i)
468 escape_ = ESCAPE_ALL;
473 XHTMLStream & XHTMLStream::operator<<(EscapeSettings e)
480 XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag)
482 if (tag.tag_.empty())
484 pending_tags_.push_back(makeTagPtr(tag));
491 XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag)
493 if (tag.tag_.empty())
495 pending_tags_.push_back(makeTagPtr(tag));
500 XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
502 if (tag.tag_.empty())
505 os_ << tag.writeTag();
511 XHTMLStream & XHTMLStream::operator<<(html::FontTag const & tag)
513 if (tag.tag_.empty())
515 pending_tags_.push_back(makeTagPtr(tag));
520 XHTMLStream & XHTMLStream::operator<<(html::CR const &)
523 os_ << from_ascii("\n");
528 bool XHTMLStream::isTagOpen(html::StartTag const & stag) const
530 TagDeque::const_iterator sit = tag_stack_.begin();
531 TagDeque::const_iterator const sen = tag_stack_.end();
532 for (; sit != sen; ++sit)
539 bool XHTMLStream::isTagOpen(html::EndTag const & etag) const
541 TagDeque::const_iterator sit = tag_stack_.begin();
542 TagDeque::const_iterator const sen = tag_stack_.end();
543 for (; sit != sen; ++sit)
550 bool XHTMLStream::isTagPending(html::StartTag const & stag) const
552 TagDeque::const_iterator sit = pending_tags_.begin();
553 TagDeque::const_iterator const sen = pending_tags_.end();
554 for (; sit != sen; ++sit)
561 // this is complicated, because we want to make sure that
562 // everything is properly nested. the code ought to make
563 // sure of that, but we won't assert (yet) if we run into
564 // a problem. we'll just output error messages and try our
565 // best to make things work.
566 XHTMLStream & XHTMLStream::operator<<(html::EndTag const & etag)
568 if (etag.tag_.empty())
571 // if this tag is pending, we can simply discard it.
572 if (!pending_tags_.empty()) {
574 if (etag == *pending_tags_.back()) {
575 // we have <tag></tag>, so we discard it and remove it
576 // from the pending_tags_.
577 pending_tags_.pop_back();
581 // there is a pending tag that isn't the one we are trying
584 // is this tag itself pending?
585 // non-const iterators because we may call erase().
586 TagDeque::iterator dit = pending_tags_.begin();
587 TagDeque::iterator const den = pending_tags_.end();
588 for (; dit != den; ++dit) {
590 // it was pending, so we just erase it
591 writeError("Tried to close pending tag `" + etag.tag_
592 + "' when other tags were pending. Last pending tag is `"
593 + to_utf8(pending_tags_.back()->writeTag())
594 + "'. Tag discarded.");
595 pending_tags_.erase(dit);
599 // so etag isn't itself pending. is it even open?
600 if (!isTagOpen(etag)) {
601 writeError("Tried to close `" + etag.tag_
602 + "' when tag was not open. Tag discarded.");
605 // ok, so etag is open.
606 // our strategy will be as below: we will do what we need to
607 // do to close this tag.
608 string estr = "Closing tag `" + etag.tag_
609 + "' when other tags are pending. Discarded pending tags:\n";
610 for (dit = pending_tags_.begin(); dit != den; ++dit)
611 estr += to_utf8(html::htmlize((*dit)->writeTag(), XHTMLStream::ESCAPE_ALL)) + "\n";
613 // clear the pending tags...
614 pending_tags_.clear();
615 // ...and then just fall through.
618 // make sure there are tags to be closed
619 if (tag_stack_.empty()) {
620 writeError("Tried to close `" + etag.tag_
621 + "' when no tags were open!");
625 // is the tag we are closing the last one we opened?
626 if (etag == *tag_stack_.back()) {
628 os_ << etag.writeEndTag();
629 // ...and forget about it
630 tag_stack_.pop_back();
634 // we are trying to close a tag other than the one last opened.
635 // let's first see if this particular tag is still open somehow.
636 if (!isTagOpen(etag)) {
637 writeError("Tried to close `" + etag.tag_
638 + "' when tag was not open. Tag discarded.");
642 // so the tag was opened, but other tags have been opened since
643 // and not yet closed.
644 // if it's a font tag, though...
645 if (etag.asFontTag()) {
646 // it won't be a problem if the other tags open since this one
647 // are also font tags.
648 TagDeque::const_reverse_iterator rit = tag_stack_.rbegin();
649 TagDeque::const_reverse_iterator ren = tag_stack_.rend();
650 for (; rit != ren; ++rit) {
653 if (!(*rit)->asFontTag()) {
654 // we'll just leave it and, presumably, have to close it later.
655 writeError("Unable to close font tag `" + etag.tag_
656 + "' due to open non-font tag `" + (*rit)->tag_ + "'.");
662 // <em>this is <strong>bold
663 // and are being asked to closed em. we want:
664 // <em>this is <strong>bold</strong></em><strong>
665 // first, we close the intervening tags...
666 TagPtr curtag = tag_stack_.back();
667 // ...remembering them in a stack.
669 while (etag != *curtag) {
670 os_ << curtag->writeEndTag();
671 fontstack.push_back(curtag);
672 tag_stack_.pop_back();
673 curtag = tag_stack_.back();
675 os_ << etag.writeEndTag();
676 tag_stack_.pop_back();
678 // ...and restore the other tags.
679 rit = fontstack.rbegin();
680 ren = fontstack.rend();
681 for (; rit != ren; ++rit)
682 pending_tags_.push_back(*rit);
686 // it wasn't a font tag.
687 // so other tags were opened before this one and not properly closed.
688 // so we'll close them, too. that may cause other issues later, but it
689 // at least guarantees proper nesting.
690 writeError("Closing tag `" + etag.tag_
691 + "' when other tags are open, namely:");
692 TagPtr curtag = tag_stack_.back();
693 while (etag != *curtag) {
694 writeError(curtag->tag_);
695 if (*curtag != parsep_tag)
696 os_ << curtag->writeEndTag();
697 tag_stack_.pop_back();
698 curtag = tag_stack_.back();
700 // curtag is now the one we actually want.
701 os_ << curtag->writeEndTag();
702 tag_stack_.pop_back();
707 // End code for XHTMLStream
711 // convenience functions
713 inline void openParTag(XHTMLStream & xs, Layout const & lay,
714 std::string parlabel)
716 xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
720 void openParTag(XHTMLStream & xs, Layout const & lay,
721 ParagraphParameters const & params,
722 std::string parlabel)
724 // FIXME Are there other things we should handle here?
725 string const align = alignmentToCSS(params.align());
727 openParTag(xs, lay, parlabel);
730 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
731 xs << html::ParTag(lay.htmltag(), attrs, parlabel);
735 inline void closeTag(XHTMLStream & xs, Layout const & lay)
737 xs << html::EndTag(lay.htmltag());
741 inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
743 xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
747 inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
749 xs << html::EndTag(lay.htmllabeltag());
753 inline void openItemTag(XHTMLStream & xs, Layout const & lay)
755 xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
759 void openItemTag(XHTMLStream & xs, Layout const & lay,
760 ParagraphParameters const & params)
762 // FIXME Are there other things we should handle here?
763 string const align = alignmentToCSS(params.align());
765 openItemTag(xs, lay);
768 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
769 xs << html::StartTag(lay.htmlitemtag(), attrs);
773 inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
775 xs << html::EndTag(lay.htmlitemtag());
778 // end of convenience functions
780 ParagraphList::const_iterator findLastParagraph(
781 ParagraphList::const_iterator p,
782 ParagraphList::const_iterator const & pend)
784 for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p)
791 ParagraphList::const_iterator findEndOfEnvironment(
792 ParagraphList::const_iterator const & pstart,
793 ParagraphList::const_iterator const & pend)
795 ParagraphList::const_iterator p = pstart;
796 Layout const & bstyle = p->layout();
797 size_t const depth = p->params().depth();
798 for (++p; p != pend; ++p) {
799 Layout const & style = p->layout();
800 // It shouldn't happen that e.g. a section command occurs inside
801 // a quotation environment, at a higher depth, but as of 6/2009,
802 // it can happen. We pretend that it's just at lowest depth.
803 if (style.latextype == LATEX_COMMAND)
806 // If depth is down, we're done
807 if (p->params().depth() < depth)
810 // If depth is up, we're not done
811 if (p->params().depth() > depth)
814 // FIXME I am not sure about the first check.
815 // Surely we *could* have different layouts that count as
816 // LATEX_PARAGRAPH, right?
817 if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
824 ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
826 OutputParams const & runparams,
828 ParagraphList::const_iterator const & pbegin,
829 ParagraphList::const_iterator const & pend)
831 ParagraphList::const_iterator const begin = text.paragraphs().begin();
832 ParagraphList::const_iterator par = pbegin;
833 for (; par != pend; ++par) {
834 Layout const & lay = par->layout();
835 if (!lay.counter.empty())
836 buf.masterBuffer()->params().
837 documentClass().counters().step(lay.counter, OutputUpdate);
839 // FIXME We should see if there's a label to be output and
840 // do something with it.
844 // We want to open the paragraph tag if:
845 // (i) the current layout permits multiple paragraphs
846 // (ii) we are either not already inside a paragraph (HTMLIsBlock) OR
847 // we are, but this is not the first paragraph
848 // But we do not want to open the paragraph tag if this paragraph contains
849 // only one item, and that item is "inline", i.e., not HTMLIsBlock (such
850 // as a branch). That is the "special case" we handle first.
851 Inset const * specinset = par->size() == 1 ? par->getInset(0) : 0;
852 bool const special_case =
853 specinset && !specinset->getLayout().htmlisblock();
855 bool const open_par = runparams.html_make_pars
856 && (!runparams.html_in_par || par != pbegin)
859 // We want to issue the closing tag if either:
860 // (i) We opened it, and either html_in_par is false,
861 // or we're not in the last paragraph, anyway.
862 // (ii) We didn't open it and html_in_par is true,
863 // but we are in the first par, and there is a next par.
864 ParagraphList::const_iterator nextpar = par;
866 bool const close_par =
867 (open_par && (!runparams.html_in_par || nextpar != pend))
868 || (!open_par && runparams.html_in_par && par == pbegin && nextpar != pend);
871 // We do not issue the paragraph id if we are doing
872 // this for the TOC (or some similar purpose)
873 openParTag(xs, lay, par->params(),
874 runparams.for_toc ? "" : par->magicLabel());
877 docstring const deferred = par->simpleLyXHTMLOnePar(buf, xs,
878 runparams, text.outerFont(distance(begin, par)),
879 open_par, close_par);
881 if (!deferred.empty()) {
882 xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
893 ParagraphList::const_iterator makeBibliography(Buffer const & buf,
895 OutputParams const & runparams,
897 ParagraphList::const_iterator const & pbegin,
898 ParagraphList::const_iterator const & pend)
901 // Use TextClass::htmlTOCLayout() to figure out how we should look.
902 xs << html::StartTag("h2", "class='bibliography'")
903 << pbegin->layout().labelstring(false)
904 << html::EndTag("h2")
906 << html::StartTag("div", "class='bibliography'")
908 makeParagraphs(buf, xs, runparams, text, pbegin, pend);
909 xs << html::EndTag("div");
914 bool isNormalEnv(Layout const & lay)
916 return lay.latextype == LATEX_ENVIRONMENT
917 || lay.latextype == LATEX_BIB_ENVIRONMENT;
921 ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
923 OutputParams const & runparams,
925 ParagraphList::const_iterator const & pbegin,
926 ParagraphList::const_iterator const & pend)
928 ParagraphList::const_iterator const begin = text.paragraphs().begin();
929 ParagraphList::const_iterator par = pbegin;
930 Layout const & bstyle = par->layout();
931 depth_type const origdepth = pbegin->params().depth();
933 // open tag for this environment
934 openParTag(xs, bstyle, pbegin->magicLabel());
937 // we will on occasion need to remember a layout from before.
938 Layout const * lastlay = 0;
940 while (par != pend) {
941 Layout const & style = par->layout();
942 // the counter only gets stepped if we're in some kind of list,
943 // or if it's the first time through.
944 // note that enum, etc, are handled automatically.
945 // FIXME There may be a bug here about user defined enumeration
946 // types. If so, then we'll need to take the counter and add "i",
947 // "ii", etc, as with enum.
948 Counters & cnts = buf.masterBuffer()->params().documentClass().counters();
949 docstring const & cntr = style.counter;
950 if (!style.counter.empty()
951 && (par == pbegin || !isNormalEnv(style))
952 && cnts.hasCounter(cntr)
954 cnts.step(cntr, OutputUpdate);
955 ParagraphList::const_iterator send;
957 switch (style.latextype) {
958 case LATEX_ENVIRONMENT:
959 case LATEX_LIST_ENVIRONMENT:
960 case LATEX_ITEM_ENVIRONMENT: {
961 // There are two possiblities in this case.
962 // One is that we are still in the environment in which we
963 // started---which we will be if the depth is the same.
964 if (par->params().depth() == origdepth) {
965 LATTEST(bstyle == style);
967 closeItemTag(xs, *lastlay);
971 // this will be positive, if we want to skip the
972 // initial word (if it's been taken for the label).
974 bool const labelfirst = style.htmllabelfirst();
976 openItemTag(xs, style, par->params());
979 if (style.labeltype != LABEL_NO_LABEL &&
980 style.htmllabeltag() != "NONE") {
981 if (isNormalEnv(style)) {
982 // in this case, we print the label only for the first
983 // paragraph (as in a theorem).
985 docstring const lbl =
986 pbegin->params().labelString();
988 openLabelTag(xs, style);
990 closeLabelTag(xs, style);
994 } else { // some kind of list
995 if (style.labeltype == LABEL_MANUAL) {
996 openLabelTag(xs, style);
997 sep = par->firstWordLyXHTML(xs, runparams);
998 closeLabelTag(xs, style);
1002 openLabelTag(xs, style);
1003 xs << par->params().labelString();
1004 closeLabelTag(xs, style);
1008 } // end label output
1011 openItemTag(xs, style, par->params());
1013 par->simpleLyXHTMLOnePar(buf, xs, runparams,
1014 text.outerFont(distance(begin, par)), true, true, sep);
1017 // We may not want to close the tag yet, in particular:
1018 // If we're not at the end...
1020 // and are doing items...
1021 && !isNormalEnv(style)
1022 // and if the depth has changed...
1023 && par->params().depth() != origdepth) {
1024 // then we'll save this layout for later, and close it when
1025 // we get another item.
1028 closeItemTag(xs, style);
1031 // The other possibility is that the depth has increased, in which
1032 // case we need to recurse.
1034 send = findEndOfEnvironment(par, pend);
1035 par = makeEnvironment(buf, xs, runparams, text, par, send);
1039 case LATEX_PARAGRAPH:
1040 send = findLastParagraph(par, pend);
1041 par = makeParagraphs(buf, xs, runparams, text, par, send);
1044 case LATEX_BIB_ENVIRONMENT:
1047 par = makeParagraphs(buf, xs, runparams, text, par, send);
1057 closeItemTag(xs, *lastlay);
1058 closeTag(xs, bstyle);
1064 void makeCommand(Buffer const & buf,
1066 OutputParams const & runparams,
1068 ParagraphList::const_iterator const & pbegin)
1070 Layout const & style = pbegin->layout();
1071 if (!style.counter.empty())
1072 buf.masterBuffer()->params().
1073 documentClass().counters().step(style.counter, OutputUpdate);
1075 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
1077 if (style.labeltype == LABEL_ABOVE)
1078 xs << html::StartTag("div")
1079 << pbegin->params().labelString()
1080 << html::EndTag("div");
1081 else if (style.labeltype == LABEL_CENTERED)
1082 xs << html::StartTag("div", "style = \"text-align: center;\"")
1083 << pbegin->params().labelString()
1084 << html::EndTag("div");
1086 openParTag(xs, style, pbegin->params(),
1087 make_parid ? pbegin->magicLabel() : "");
1089 // Label around sectioning number:
1090 // FIXME Probably need to account for LABEL_MANUAL
1091 if (style.labeltype != LABEL_NO_LABEL &&
1092 style.labeltype != LABEL_ABOVE &&
1093 style.labeltype != LABEL_CENTERED ) {
1094 openLabelTag(xs, style);
1095 xs << pbegin->params().labelString();
1096 closeLabelTag(xs, style);
1097 // Otherwise the label might run together with the text
1098 xs << from_ascii(" ");
1101 ParagraphList::const_iterator const begin = text.paragraphs().begin();
1102 pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
1103 text.outerFont(distance(begin, pbegin)));
1104 closeTag(xs, style);
1108 } // end anonymous namespace
1111 void xhtmlParagraphs(Text const & text,
1114 OutputParams const & runparams)
1116 ParagraphList const & paragraphs = text.paragraphs();
1117 if (runparams.par_begin == runparams.par_end) {
1118 runparams.par_begin = 0;
1119 runparams.par_end = paragraphs.size();
1121 pit_type bpit = runparams.par_begin;
1122 pit_type const epit = runparams.par_end;
1123 LASSERT(bpit < epit,
1124 { xs << XHTMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
1126 OutputParams ourparams = runparams;
1127 ParagraphList::const_iterator const pend =
1128 (epit == (int) paragraphs.size()) ?
1129 paragraphs.end() : paragraphs.constIterator(epit);
1130 while (bpit < epit) {
1131 ParagraphList::const_iterator par = paragraphs.constIterator(bpit);
1132 if (par->params().startOfAppendix()) {
1133 // We want to reset the counter corresponding to toplevel sectioning
1134 Layout const & lay =
1135 buf.masterBuffer()->params().documentClass().getTOCLayout();
1136 docstring const cnt = lay.counter;
1139 buf.masterBuffer()->params().documentClass().counters();
1143 Layout const & style = par->layout();
1144 ParagraphList::const_iterator const lastpar = par;
1145 ParagraphList::const_iterator send;
1147 switch (style.latextype) {
1148 case LATEX_COMMAND: {
1149 // The files with which we are working never have more than
1150 // one paragraph in a command structure.
1152 // if (ourparams.html_in_par)
1153 // fix it so we don't get sections inside standard, e.g.
1154 // note that we may then need to make runparams not const, so we
1155 // can communicate that back.
1156 // FIXME Maybe this fix should be in the routines themselves, in case
1157 // they are called from elsewhere.
1158 makeCommand(buf, xs, ourparams, text, par);
1162 case LATEX_ENVIRONMENT:
1163 case LATEX_LIST_ENVIRONMENT:
1164 case LATEX_ITEM_ENVIRONMENT: {
1165 // FIXME Same fix here.
1166 send = findEndOfEnvironment(par, pend);
1167 par = makeEnvironment(buf, xs, ourparams, text, par, send);
1170 case LATEX_BIB_ENVIRONMENT: {
1171 // FIXME Same fix here.
1172 send = findEndOfEnvironment(par, pend);
1173 par = makeBibliography(buf, xs, ourparams, text, par, send);
1176 case LATEX_PARAGRAPH:
1177 send = findLastParagraph(par, pend);
1178 par = makeParagraphs(buf, xs, ourparams, text, par, send);
1181 bpit += distance(lastpar, par);
1186 string alignmentToCSS(LyXAlignment align)
1189 case LYX_ALIGN_BLOCK:
1190 // we are NOT going to use text-align: justify!!
1191 case LYX_ALIGN_LEFT:
1193 case LYX_ALIGN_RIGHT:
1195 case LYX_ALIGN_CENTER: