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 openParTag(XHTMLStream & xs, Layout const & lay,
756 std::string parlabel)
758 xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
762 void openParTag(XHTMLStream & xs, Layout const & lay,
763 ParagraphParameters const & params,
764 std::string parlabel)
766 // FIXME Are there other things we should handle here?
767 string const align = alignmentToCSS(params.align());
769 openParTag(xs, lay, parlabel);
772 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
773 xs << html::ParTag(lay.htmltag(), attrs, parlabel);
777 inline void closeTag(XHTMLStream & xs, Layout const & lay)
779 xs << html::EndTag(lay.htmltag());
783 inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
785 xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
789 inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
791 xs << html::EndTag(lay.htmllabeltag());
795 inline void openItemTag(XHTMLStream & xs, Layout const & lay)
797 xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
801 void openItemTag(XHTMLStream & xs, Layout const & lay,
802 ParagraphParameters const & params)
804 // FIXME Are there other things we should handle here?
805 string const align = alignmentToCSS(params.align());
807 openItemTag(xs, lay);
810 string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
811 xs << html::StartTag(lay.htmlitemtag(), attrs);
815 inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
817 xs << html::EndTag(lay.htmlitemtag());
820 // end of convenience functions
822 ParagraphList::const_iterator findLastParagraph(
823 ParagraphList::const_iterator p,
824 ParagraphList::const_iterator const & pend)
826 for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p)
833 ParagraphList::const_iterator findEndOfEnvironment(
834 ParagraphList::const_iterator const & pstart,
835 ParagraphList::const_iterator const & pend)
837 ParagraphList::const_iterator p = pstart;
838 Layout const & bstyle = p->layout();
839 size_t const depth = p->params().depth();
840 for (++p; p != pend; ++p) {
841 Layout const & style = p->layout();
842 // It shouldn't happen that e.g. a section command occurs inside
843 // a quotation environment, at a higher depth, but as of 6/2009,
844 // it can happen. We pretend that it's just at lowest depth.
845 if (style.latextype == LATEX_COMMAND)
848 // If depth is down, we're done
849 if (p->params().depth() < depth)
852 // If depth is up, we're not done
853 if (p->params().depth() > depth)
856 // FIXME I am not sure about the first check.
857 // Surely we *could* have different layouts that count as
858 // LATEX_PARAGRAPH, right?
859 if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
866 ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
868 OutputParams const & runparams,
870 ParagraphList::const_iterator const & pbegin,
871 ParagraphList::const_iterator const & pend)
873 ParagraphList::const_iterator const begin = text.paragraphs().begin();
874 ParagraphList::const_iterator par = pbegin;
875 for (; par != pend; ++par) {
876 Layout const & lay = par->layout();
877 if (!lay.counter.empty())
878 buf.masterBuffer()->params().
879 documentClass().counters().step(lay.counter, OutputUpdate);
880 // FIXME We should see if there's a label to be output and
881 // do something with it.
885 // If we are already in a paragraph, and this is the first one, then we
886 // do not want to open the paragraph tag.
887 // we also do not want to open it if the current layout does not permit
888 // multiple paragraphs.
889 bool const opened = runparams.html_make_pars &&
890 (par != pbegin || !runparams.html_in_par);
891 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
894 openParTag(xs, lay, par->params(),
895 make_parid ? par->magicLabel() : "");
897 docstring const deferred =
898 par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)));
900 // We want to issue the closing tag if either:
901 // (i) We opened it, and either html_in_par is false,
902 // or we're not in the last paragraph, anyway.
903 // (ii) We didn't open it and html_in_par is true,
904 // but we are in the first par, and there is a next par.
905 ParagraphList::const_iterator nextpar = par;
907 bool const needclose =
908 (opened && (!runparams.html_in_par || nextpar != pend))
909 || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
914 if (!deferred.empty()) {
915 xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
922 ParagraphList::const_iterator makeBibliography(Buffer const & buf,
924 OutputParams const & runparams,
926 ParagraphList::const_iterator const & pbegin,
927 ParagraphList::const_iterator const & pend)
930 // Use TextClass::htmlTOCLayout() to figure out how we should look.
931 xs << html::StartTag("h2", "class='bibliography'")
932 << pbegin->layout().labelstring(false)
933 << html::EndTag("h2")
935 << html::StartTag("div", "class='bibliography'")
937 makeParagraphs(buf, xs, runparams, text, pbegin, pend);
938 xs << html::EndTag("div");
943 bool isNormalEnv(Layout const & lay)
945 return lay.latextype == LATEX_ENVIRONMENT
946 || lay.latextype == LATEX_BIB_ENVIRONMENT;
950 ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
952 OutputParams const & runparams,
954 ParagraphList::const_iterator const & pbegin,
955 ParagraphList::const_iterator const & pend)
957 ParagraphList::const_iterator const begin = text.paragraphs().begin();
958 ParagraphList::const_iterator par = pbegin;
959 Layout const & bstyle = par->layout();
960 depth_type const origdepth = pbegin->params().depth();
962 // open tag for this environment
963 openParTag(xs, bstyle, pbegin->magicLabel());
966 // we will on occasion need to remember a layout from before.
967 Layout const * lastlay = 0;
969 while (par != pend) {
970 Layout const & style = par->layout();
971 // the counter only gets stepped if we're in some kind of list,
972 // or if it's the first time through.
973 // note that enum, etc, are handled automatically.
974 // FIXME There may be a bug here about user defined enumeration
975 // types. If so, then we'll need to take the counter and add "i",
976 // "ii", etc, as with enum.
977 Counters & cnts = buf.masterBuffer()->params().documentClass().counters();
978 docstring const & cntr = style.counter;
979 if (!style.counter.empty()
980 && (par == pbegin || !isNormalEnv(style))
981 && cnts.hasCounter(cntr)
983 cnts.step(cntr, OutputUpdate);
984 ParagraphList::const_iterator send;
985 // this will be positive, if we want to skip the initial word
986 // (if it's been taken for the label).
989 switch (style.latextype) {
990 case LATEX_ENVIRONMENT:
991 case LATEX_LIST_ENVIRONMENT:
992 case LATEX_ITEM_ENVIRONMENT: {
993 // There are two possiblities in this case.
994 // One is that we are still in the environment in which we
995 // started---which we will be if the depth is the same.
996 if (par->params().depth() == origdepth) {
997 LATTEST(bstyle == style);
999 closeItemTag(xs, *lastlay);
1003 bool const labelfirst = style.htmllabelfirst();
1005 openItemTag(xs, style, par->params());
1008 if (style.labeltype != LABEL_NO_LABEL &&
1009 style.htmllabeltag() != "NONE") {
1010 if (isNormalEnv(style)) {
1011 // in this case, we print the label only for the first
1012 // paragraph (as in a theorem).
1013 if (par == pbegin) {
1014 docstring const lbl =
1015 pbegin->params().labelString();
1017 openLabelTag(xs, style);
1019 closeLabelTag(xs, style);
1023 } else { // some kind of list
1024 if (style.labeltype == LABEL_MANUAL) {
1025 openLabelTag(xs, style);
1026 sep = par->firstWordLyXHTML(xs, runparams);
1027 closeLabelTag(xs, style);
1031 openLabelTag(xs, style);
1032 xs << par->params().labelString();
1033 closeLabelTag(xs, style);
1037 } // end label output
1040 openItemTag(xs, style, par->params());
1042 par->simpleLyXHTMLOnePar(buf, xs, runparams,
1043 text.outerFont(distance(begin, par)), sep);
1046 // We may not want to close the tag yet, in particular:
1047 // If we're not at the end...
1049 // and are doing items...
1050 && !isNormalEnv(style)
1051 // and if the depth has changed...
1052 && par->params().depth() != origdepth) {
1053 // then we'll save this layout for later, and close it when
1054 // we get another item.
1057 closeItemTag(xs, style);
1060 // The other possibility is that the depth has increased, in which
1061 // case we need to recurse.
1063 send = findEndOfEnvironment(par, pend);
1064 par = makeEnvironment(buf, xs, runparams, text, par, send);
1068 case LATEX_PARAGRAPH:
1069 send = findLastParagraph(par, pend);
1070 par = makeParagraphs(buf, xs, runparams, text, par, send);
1073 case LATEX_BIB_ENVIRONMENT:
1076 par = makeParagraphs(buf, xs, runparams, text, par, send);
1086 closeItemTag(xs, *lastlay);
1087 closeTag(xs, bstyle);
1093 void makeCommand(Buffer const & buf,
1095 OutputParams const & runparams,
1097 ParagraphList::const_iterator const & pbegin)
1099 Layout const & style = pbegin->layout();
1100 if (!style.counter.empty())
1101 buf.masterBuffer()->params().
1102 documentClass().counters().step(style.counter, OutputUpdate);
1104 bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
1106 openParTag(xs, style, pbegin->params(),
1107 make_parid ? pbegin->magicLabel() : "");
1109 // Label around sectioning number:
1110 // FIXME Probably need to account for LABEL_MANUAL
1111 // FIXME Probably also need now to account for labels ABOVE and CENTERED.
1112 if (style.labeltype != LABEL_NO_LABEL) {
1113 openLabelTag(xs, style);
1114 xs << pbegin->params().labelString();
1115 closeLabelTag(xs, style);
1116 // Otherwise the label might run together with the text
1117 xs << from_ascii(" ");
1120 ParagraphList::const_iterator const begin = text.paragraphs().begin();
1121 pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
1122 text.outerFont(distance(begin, pbegin)));
1123 closeTag(xs, style);
1127 } // end anonymous namespace
1130 void xhtmlParagraphs(Text const & text,
1133 OutputParams const & runparams)
1135 ParagraphList const & paragraphs = text.paragraphs();
1136 if (runparams.par_begin == runparams.par_end) {
1137 runparams.par_begin = 0;
1138 runparams.par_end = paragraphs.size();
1140 pit_type bpit = runparams.par_begin;
1141 pit_type const epit = runparams.par_end;
1142 LASSERT(bpit < epit,
1143 { xs << XHTMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
1145 OutputParams ourparams = runparams;
1146 ParagraphList::const_iterator const pend =
1147 (epit == (int) paragraphs.size()) ?
1148 paragraphs.end() : paragraphs.constIterator(epit);
1149 while (bpit < epit) {
1150 ParagraphList::const_iterator par = paragraphs.constIterator(bpit);
1151 if (par->params().startOfAppendix()) {
1152 // We want to reset the counter corresponding to toplevel sectioning
1153 Layout const & lay =
1154 buf.masterBuffer()->params().documentClass().getTOCLayout();
1155 docstring const cnt = lay.counter;
1158 buf.masterBuffer()->params().documentClass().counters();
1162 Layout const & style = par->layout();
1163 ParagraphList::const_iterator const lastpar = par;
1164 ParagraphList::const_iterator send;
1166 switch (style.latextype) {
1167 case LATEX_COMMAND: {
1168 // The files with which we are working never have more than
1169 // one paragraph in a command structure.
1171 // if (ourparams.html_in_par)
1172 // fix it so we don't get sections inside standard, e.g.
1173 // note that we may then need to make runparams not const, so we
1174 // can communicate that back.
1175 // FIXME Maybe this fix should be in the routines themselves, in case
1176 // they are called from elsewhere.
1177 makeCommand(buf, xs, ourparams, text, par);
1181 case LATEX_ENVIRONMENT:
1182 case LATEX_LIST_ENVIRONMENT:
1183 case LATEX_ITEM_ENVIRONMENT: {
1184 // FIXME Same fix here.
1185 send = findEndOfEnvironment(par, pend);
1186 par = makeEnvironment(buf, xs, ourparams, text, par, send);
1189 case LATEX_BIB_ENVIRONMENT: {
1190 // FIXME Same fix here.
1191 send = findEndOfEnvironment(par, pend);
1192 par = makeBibliography(buf, xs, ourparams, text, par, send);
1195 case LATEX_PARAGRAPH:
1196 send = findLastParagraph(par, pend);
1197 par = makeParagraphs(buf, xs, ourparams, text, par, send);
1200 bpit += distance(lastpar, par);
1205 string alignmentToCSS(LyXAlignment align)
1208 case LYX_ALIGN_BLOCK:
1209 // we are NOT going to use text-align: justify!!
1210 case LYX_ALIGN_LEFT:
1212 case LYX_ALIGN_RIGHT:
1214 case LYX_ALIGN_CENTER: