]> git.lyx.org Git - lyx.git/blob - src/output_xhtml.cpp
8eabbc19ab8246b24a8f373ec52d52efd212eda6
[lyx.git] / src / output_xhtml.cpp
1 /**
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.
5  *
6  * \author Richard Heck
7  * 
8  * This code is based upon output_docbook.cpp
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "output_xhtml.h"
16
17 #include "Buffer.h"
18 #include "buffer_funcs.h"
19 #include "BufferParams.h"
20 #include "Counters.h"
21 #include "Layout.h"
22 #include "OutputParams.h"
23 #include "Paragraph.h"
24 #include "ParagraphList.h"
25 #include "ParagraphParameters.h"
26 #include "sgml.h"
27 #include "Text.h"
28 #include "TextClass.h"
29
30 #include "support/lassert.h"
31 #include "support/debug.h"
32 #include "support/lstrings.h"
33
34 #include <vector>
35
36 using namespace std;
37 using namespace lyx::support;
38
39 namespace lyx {
40
41 namespace html {
42
43 docstring escapeChar(char_type c)
44 {
45         docstring str;
46         switch (c) {
47         case ' ':
48                 str += " ";
49                 break;
50         case '&':
51                 str += "&amp;";
52                 break;
53         case '<':
54                 str += "&lt;";
55                 break;
56         case '>':
57                 str += "&gt;";
58                 break;
59         default:
60                 str += c;
61                 break;
62         }
63         return str;
64 }
65
66
67 // escape what needs escaping
68 docstring htmlize(docstring const & str) {
69         odocstringstream d;
70         docstring::const_iterator it = str.begin();
71         docstring::const_iterator en = str.end();
72         for (; it != en; ++it)
73                 d << escapeChar(*it);
74         return d.str();
75 }
76
77
78 bool isFontTag(string const & s)
79 {
80         return s == "em" || s == "strong"; // others?
81 }
82 } // namespace html
83
84
85 docstring StartTag::asTag() const
86 {
87         string output = "<" + tag_;
88         if (!attr_.empty())
89                 output += " " + attr_;
90         output += ">";
91         return from_utf8(output);
92 }
93
94
95 docstring StartTag::asEndTag() const
96 {
97         string output = "</" + tag_ + ">";
98         return from_utf8(output);
99 }
100
101
102 docstring EndTag::asEndTag() const
103 {
104         string output = "</" + tag_ + ">";
105         return from_utf8(output);
106 }
107
108
109 docstring CompTag::asTag() const
110 {
111         string output = "<" + tag_;
112         if (!attr_.empty())
113                 output += " " + attr_;
114         output += " />";
115         return from_utf8(output);
116 }
117
118
119 ////////////////////////////////////////////////////////////////
120 ///
121 /// XHTMLStream
122 ///
123 ////////////////////////////////////////////////////////////////
124
125 XHTMLStream::XHTMLStream(odocstream & os) 
126                 :os_(os)
127 {}
128
129
130 void XHTMLStream::cr() 
131 {
132         // tabs?
133         os_ << from_ascii("\n");
134 }
135
136
137 void XHTMLStream::writeError(std::string const & s)
138 {
139         LYXERR0(s);
140         os_ << from_utf8("<!-- Output Error: " + s + " -->");
141 }
142
143
144 bool XHTMLStream::closeFontTags()
145 {
146         // first, we close any open font tags we can close
147         StartTag curtag = tag_stack_.back();
148         while (html::isFontTag(curtag.tag_)) {
149                 os_ << curtag.asEndTag();
150                 tag_stack_.pop_back();
151                 if (tag_stack_.empty())
152                         // this probably shouldn't happen, since then the
153                         // font tags weren't in any other tag. but that
154                         // problem will likely be caught elsewhere.
155                         return true;
156                 curtag = tag_stack_.back();
157         }
158         // so we've hit a non-font tag. let's see if any of the
159         // remaining tags are font tags.
160         TagStack::const_iterator it = tag_stack_.begin();
161         TagStack::const_iterator en = tag_stack_.end();
162         bool noFontTags = true;
163         for (; it != en; ++it) {
164                 if (html::isFontTag(it->tag_)) {
165                         writeError("Font tag `" + it->tag_ + "' still open in closeFontTags().");
166                         noFontTags = false;
167                 }
168         }
169         return noFontTags;
170 }
171
172
173 void XHTMLStream::clearTagDeque()
174 {
175         while (!pending_tags_.empty()) {
176                 StartTag const & tag = pending_tags_.front();
177                 // tabs?
178                 os_ << tag.asTag();
179                 tag_stack_.push_back(tag);
180                 pending_tags_.pop_front();
181         }
182 }
183
184
185 XHTMLStream & XHTMLStream::operator<<(docstring const & d)
186 {
187         clearTagDeque();
188         os_ << html::htmlize(d);
189         return *this;
190 }
191
192
193 XHTMLStream & XHTMLStream::operator<<(const char * s)
194 {
195         clearTagDeque();
196         os_ << html::htmlize(from_ascii(s));
197         return *this;
198 }
199
200
201 XHTMLStream & XHTMLStream::operator<<(char_type c)
202 {
203         clearTagDeque();
204         os_ << html::escapeChar(c);
205         return *this;
206 }
207
208
209 XHTMLStream & XHTMLStream::operator<<(StartTag const & tag) 
210 {
211         if (tag.tag_.empty())
212                 return *this;
213         pending_tags_.push_back(tag);
214         if (tag.keepempty_)
215                 clearTagDeque();
216         return *this;
217 }
218
219
220 XHTMLStream & XHTMLStream::operator<<(CompTag const & tag) 
221 {
222         if (tag.tag_.empty())
223                 return *this;
224         clearTagDeque();
225         // tabs?
226         os_ << tag.asTag();
227         return *this;
228 }
229
230
231 bool    XHTMLStream::isTagOpen(string const & stag)
232 {
233         TagStack::const_iterator sit = tag_stack_.begin();
234         TagStack::const_iterator const sen = tag_stack_.end();
235         for (; sit != sen; ++sit)
236                 // we could check for the
237                 if (sit->tag_ == stag) 
238                         return true;
239         return false;
240 }
241
242
243 // this is complicated, because we want to make sure that
244 // everything is properly nested. the code ought to make 
245 // sure of that, but we won't assert (yet) if we run into
246 // a problem. we'll just output error messages and try our
247 // best to make things work.
248 XHTMLStream & XHTMLStream::operator<<(EndTag const & etag)
249 {
250         if (etag.tag_.empty())
251                 return *this;
252         // first make sure we're not closing an empty tag
253         if (!pending_tags_.empty()) {
254                 StartTag const & stag = pending_tags_.back();
255                 if (etag.tag_ == stag.tag_)  {
256                         // we have <tag></tag>, so we discard it and remove it 
257                         // from the pending_tags_.
258                         pending_tags_.pop_back();
259                         return *this;
260                 }
261                 // there is a pending tag that isn't the one we are trying
262                 // to close. 
263                 // is this tag itself pending?
264                 // non-const iterators because we may call erase().
265                 TagDeque::iterator dit = pending_tags_.begin();
266                 TagDeque::iterator const den = pending_tags_.end();
267                 for (; dit != den; ++dit) {
268                         if (dit->tag_ == etag.tag_) {
269                                 // it was pending, so we just erase it
270                                 writeError("Tried to close pending tag `" + etag.tag_ 
271                                         + "' when other tags were pending. Tag discarded.");
272                                 pending_tags_.erase(dit);
273                                 return *this;
274                         }
275                 }
276                 // so etag isn't itself pending. is it even open?
277                 if (!isTagOpen(etag.tag_)) {
278                         writeError("Tried to close `" + etag.tag_ 
279                                  + "' when tag was not open. Tag discarded.");
280                         return *this;
281                 }
282                 // ok, so etag is open.
283                 // our strategy will be as below: we will do what we need to 
284                 // do to close this tag.
285                 string estr = "Closing tag `" + etag.tag_ 
286                         + "' when other tags are pending. Discarded pending tags:\n";
287                 for (dit = pending_tags_.begin(); dit != den; ++dit)
288                         estr += dit->tag_ + "\n";
289                 writeError(estr);
290                 // clear the pending tags...
291                 pending_tags_.clear();
292                 // ...and then just fall through.
293         }
294
295         // is the tag we are closing the last one we opened?
296         if (etag.tag_ == tag_stack_.back().tag_) {
297                 // output it...
298                 os_ << etag.asEndTag();
299                 // ...and forget about it
300                 tag_stack_.pop_back();
301                 return *this;
302         } 
303         
304         // we are trying to close a tag other than the one last opened. 
305         // let's first see if this particular tag is still open somehow.
306         if (!isTagOpen(etag.tag_)) {
307                 writeError("Tried to close `" + etag.tag_ 
308                         + "' when tag was not open. Tag discarded.");
309                 return *this;
310         }
311         
312         // so the tag was opened, but other tags have been opened since
313         // and not yet closed.
314         // if it's a font tag, though...
315         if (html::isFontTag(etag.tag_)) {
316                 // it won't be a problem if the other tags open since this one
317                 // are also font tags.
318                 TagStack::const_reverse_iterator rit = tag_stack_.rbegin();
319                 TagStack::const_reverse_iterator ren = tag_stack_.rend();
320                 for (; rit != ren; ++rit) {
321                         if (rit->tag_ == etag.tag_)
322                                 break;
323                         if (!html::isFontTag(rit->tag_)) {
324                                 // we'll just leave it and, presumably, have to close it later.
325                                 writeError("Unable to close font tag `" + etag.tag_ 
326                                         + "' due to open non-font tag `" + rit->tag_ + "'.");
327                                 return *this;
328                         }
329                 }
330                 
331                 // so we have e.g.:
332                 //    <em>this is <strong>bold
333                 // and are being asked to closed em. we want:
334                 //    <em>this is <strong>bold</strong></em><strong>
335                 // first, we close the intervening tags...
336                 StartTag curtag = tag_stack_.back();
337                 // ...remembering them in a stack.
338                 TagStack fontstack;
339                 while (curtag.tag_ != etag.tag_) {
340                         os_ << curtag.asEndTag();
341                         fontstack.push_back(curtag);
342                         tag_stack_.pop_back();
343                         curtag = tag_stack_.back();
344                 }
345                 // now close our tag...
346                 os_ << etag.asEndTag();
347                 tag_stack_.pop_back();
348
349                 // ...and restore the other tags.
350                 rit = fontstack.rbegin();
351                 ren = fontstack.rend();
352                 for (; rit != ren; ++rit)
353                         pending_tags_.push_back(*rit);
354                 return *this;
355         }
356         
357         // it wasn't a font tag.
358         // so other tags were opened before this one and not properly closed. 
359         // so we'll close them, too. that may cause other issues later, but it 
360         // at least guarantees proper nesting.
361         writeError("Closing tag `" + etag.tag_ 
362                 + "' when other tags are open, namely:");
363         StartTag curtag = tag_stack_.back();
364         while (curtag.tag_ != etag.tag_) {
365                 writeError(curtag.tag_);
366                 os_ << curtag.asEndTag();
367                 tag_stack_.pop_back();
368                 curtag = tag_stack_.back();
369         }
370         // curtag is now the one we actually want.
371         os_ << curtag.asEndTag();
372         tag_stack_.pop_back();
373         
374         return *this;
375 }
376
377 // End code for XHTMLStream
378
379 namespace {
380         
381 // convenience functions
382
383 inline void openTag(XHTMLStream & xs, Layout const & lay)
384 {
385         xs << StartTag(lay.htmltag(), lay.htmlattr());
386 }
387
388
389 inline void closeTag(XHTMLStream & xs, Layout const & lay)
390 {
391         xs << EndTag(lay.htmltag());
392 }
393
394
395 inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
396 {
397         xs << StartTag(lay.htmllabeltag(), lay.htmllabelattr());
398 }
399
400
401 inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
402 {
403         xs << EndTag(lay.htmllabeltag());
404 }
405
406
407 inline void openItemTag(XHTMLStream & xs, Layout const & lay)
408 {
409         xs << StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
410 }
411
412
413 inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
414 {
415         xs << EndTag(lay.htmlitemtag());
416 }
417
418 // end of convenience functions
419
420 ParagraphList::const_iterator searchParagraphHtml(
421         ParagraphList::const_iterator p,
422         ParagraphList::const_iterator const & pend)
423 {
424         for (++p; p != pend && p->layout().latextype == LATEX_PARAGRAPH; ++p)
425                 ;
426
427         return p;
428 }
429
430
431 ParagraphList::const_iterator searchEnvironmentHtml(
432                 ParagraphList::const_iterator const pstart,
433                 ParagraphList::const_iterator const & pend)
434 {
435         ParagraphList::const_iterator p = pstart;
436         Layout const & bstyle = p->layout();
437         size_t const depth = p->params().depth();
438         for (++p; p != pend; ++p) {
439                 Layout const & style = p->layout();
440                 // It shouldn't happen that e.g. a section command occurs inside
441                 // a quotation environment, at a higher depth, but as of 6/2009,
442                 // it can happen. We pretend that it's just at lowest depth.
443                 if (style.latextype == LATEX_COMMAND)
444                         return p;
445                 // If depth is down, we're done
446                 if (p->params().depth() < depth)
447                         return p;
448                 // If depth is up, we're not done
449                 if (p->params().depth() > depth)
450                         continue;
451                 // Now we know we are at the same depth
452                 if (style.latextype == LATEX_PARAGRAPH
453                     || style.latexname() != bstyle.latexname())
454                         return p;
455         }
456         return pend;
457 }
458
459
460 ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
461                                             XHTMLStream & xs,
462                                             OutputParams const & runparams,
463                                             Text const & text,
464                                             ParagraphList::const_iterator const & pbegin,
465                                             ParagraphList::const_iterator const & pend)
466 {
467         ParagraphList::const_iterator const begin = text.paragraphs().begin();
468         ParagraphList::const_iterator par = pbegin;
469         for (; par != pend; ++par) {
470                 Layout const & lay = par->layout();
471                 if (!lay.counter.empty())
472                         buf.params().documentClass().counters().step(lay.counter);
473                 // FIXME We should see if there's a label to be output and
474                 // do something with it.
475                 if (par != pbegin)
476                         xs.cr();
477
478                 // FIXME Should we really allow anything other than 'p' here?
479                 
480                 // If we are already in a paragraph, and this is the first one, then we
481                 // do not want to open the paragraph tag.
482                 bool const opened = 
483                         (par == pbegin && runparams.html_in_par) ? false : true;
484                 if (opened)
485                         openTag(xs, lay);
486                 docstring const deferred = 
487                         par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)));
488
489                 // We want to issue the closing tag if either:
490                 //   (i)  We opened it, and either html_in_par is false,
491                 //        or we're not in the last paragraph, anyway.
492                 //   (ii) We didn't open it and html_in_par is true, 
493                 //        but we are in the first par, and there is a next par.
494                 ParagraphList::const_iterator nextpar = par;
495                 nextpar++;
496                 bool const needclose = 
497                         (opened && (!runparams.html_in_par || nextpar != pend))
498                         || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
499                 if (needclose) {
500                         closeTag(xs, lay);
501                         xs.cr();
502                 }
503                 if (!deferred.empty()) {
504                         xs << deferred;
505                         xs.cr();
506                 }
507         }
508         return pend;
509 }
510
511
512 ParagraphList::const_iterator makeBibliography(Buffer const & buf,
513                                 XHTMLStream & xs,
514                                 OutputParams const & runparams,
515                                 Text const & text,
516                                 ParagraphList::const_iterator const & pbegin,
517                                 ParagraphList::const_iterator const & pend) 
518 {
519         xs << StartTag("h2", "class='bibliography'");
520         xs << pbegin->layout().labelstring(false);
521         xs << EndTag("h2");
522         xs.cr();
523         xs << StartTag("div", "class='bibliography'");
524         xs.cr();
525         makeParagraphs(buf, xs, runparams, text, pbegin, pend);
526         xs << EndTag("div");
527         return pend;
528 }
529
530
531 bool isNormalEnv(Layout const & lay)
532 {
533         return lay.latextype == LATEX_ENVIRONMENT;
534 }
535
536         
537 ParagraphList::const_iterator makeEnvironmentHtml(Buffer const & buf,
538                                               XHTMLStream & xs,
539                                               OutputParams const & runparams,
540                                               Text const & text,
541                                               ParagraphList::const_iterator const & pbegin,
542                                               ParagraphList::const_iterator const & pend) 
543 {
544         ParagraphList::const_iterator const begin = text.paragraphs().begin();
545         ParagraphList::const_iterator par = pbegin;
546         Layout const & bstyle = par->layout();
547         depth_type const origdepth = pbegin->params().depth();
548
549         // open tag for this environment
550         openTag(xs, bstyle);
551         xs.cr();
552
553         // we will on occasion need to remember a layout from before.
554         Layout const * lastlay = 0;
555
556         while (par != pend) {
557                 Layout const & style = par->layout();
558                 // the counter only gets stepped if we're in some kind of list,
559                 // or if it's the first time through.
560                 // note that enum, etc, are handled automatically.
561                 // FIXME There may be a bug here about user defined enumeration
562                 // types. If so, then we'll need to take the counter and add "i",
563                 // "ii", etc, as with enum.
564                 if (!style.counter.empty() && 
565                     (par == pbegin || !isNormalEnv(style))
566                     && style.latextype == LATEX_LIST_ENVIRONMENT)
567                         buf.params().documentClass().counters().step(style.counter);
568                 ParagraphList::const_iterator send;
569                 // this will be positive, if we want to skip the initial word
570                 // (if it's been taken for the label).
571                 pos_type sep = 0;
572
573                 switch (style.latextype) {
574                 case LATEX_ENVIRONMENT:
575                 case LATEX_LIST_ENVIRONMENT:
576                 case LATEX_ITEM_ENVIRONMENT: {
577                         // There are two possiblities in this case. 
578                         // One is that we are still in the environment in which we 
579                         // started---which we will be if the depth is the same.
580                         if (par->params().depth() == origdepth) {
581                                 LASSERT(bstyle == style, /* */);
582                                 if (lastlay != 0) {
583                                         closeItemTag(xs, *lastlay);
584                                         lastlay = 0;
585                                 }
586                                 bool const labelfirst = style.htmllabelfirst();
587                                 if (isNormalEnv(style)) {
588                                         // in this case, we print the label only for the first 
589                                         // paragraph (as in a theorem).
590                                         openItemTag(xs, style);
591                                         if (par == pbegin && style.htmllabeltag() != "NONE") {
592                                                 docstring const lbl = 
593                                                                 pbegin->expandLabel(style, buf.params(), false);
594                                                 if (!lbl.empty()) {
595                                                         openLabelTag(xs, style);
596                                                         xs << lbl;
597                                                         closeLabelTag(xs, style);
598                                                 }
599                                                 xs.cr();
600                                         }
601                                 }       else { // some kind of list
602                                         if (!labelfirst)
603                                                 openItemTag(xs, style);
604                                         if (style.labeltype == LABEL_MANUAL
605                                             && style.htmllabeltag() != "NONE") {
606                                                 openLabelTag(xs, style);
607 //                                              sep = par->firstWordLyXHTML(xs, runparams);
608                                                 closeLabelTag(xs, style);
609                                                 xs.cr();
610                                         }
611                                         else if (style.labeltype != LABEL_NO_LABEL
612                                                  && style.htmllabeltag() != "NONE") {
613                                                 openLabelTag(xs, style);
614                                                 xs << par->expandLabel(style, buf.params(), false);
615                                                 closeLabelTag(xs, style);
616                                                 xs.cr();
617                                         }
618                                         if (labelfirst)
619                                                 openItemTag(xs, style);
620                                         else
621                                                 // FIXME This should probalby be put into the layout file rather 
622                                                 // than hardcoded.
623                                                 xs << StartTag("span", "class='" + to_utf8(style.name()) + "_inneritem'");
624                                 }
625                                 par->simpleLyXHTMLOnePar(buf, xs, runparams, 
626                                         text.outerFont(distance(begin, par)), sep);
627                                 if (!isNormalEnv(style) && !labelfirst)
628                                         xs << EndTag("span");
629                                 ++par;
630                                 // We may not want to close the tag yet, in particular,
631                                 // if we're not at the end...
632                                 if (par != pend 
633                                         //  and are doing items...
634                                          && style.latextype == LATEX_ITEM_ENVIRONMENT
635                                          // and if the depth has changed...
636                                          && par->params().depth() != origdepth) {
637                                          // then we'll save this layout for later, and close it when
638                                          // we get another item.
639                                         lastlay = &style;
640                                 } else
641                                         closeItemTag(xs, style);
642                                 xs.cr();
643                         }
644                         // The other possibility is that the depth has increased, in which
645                         // case we need to recurse.
646                         else {
647                                 send = searchEnvironmentHtml(par, pend);
648                                 par = makeEnvironmentHtml(buf, xs, runparams, text, par, send);
649                         }
650                         break;
651                 }
652                 case LATEX_PARAGRAPH:
653                         send = searchParagraphHtml(par, pend);
654                         par = makeParagraphs(buf, xs, runparams, text, par, send);
655                         break;
656                 // Shouldn't happen
657                 case LATEX_BIB_ENVIRONMENT:
658                         send = par;
659                         ++send;
660                         par = makeParagraphs(buf, xs, runparams, text, par, send);
661                         break;
662                 // Shouldn't happen
663                 case LATEX_COMMAND:
664                         ++par;
665                         break;
666                 }
667         }
668
669         if (lastlay != 0)
670                 closeItemTag(xs, *lastlay);
671         closeTag(xs, bstyle);
672         xs.cr();
673         return pend;
674 }
675
676
677 void makeCommand(Buffer const & buf,
678                                           XHTMLStream & xs,
679                                           OutputParams const & runparams,
680                                           Text const & text,
681                                           ParagraphList::const_iterator const & pbegin)
682 {
683         Layout const & style = pbegin->layout();
684         if (!style.counter.empty())
685                 buf.params().documentClass().counters().step(style.counter);
686
687         openTag(xs, style);
688
689         // Label around sectioning number:
690         // FIXME Probably need to account for LABEL_MANUAL
691         if (style.labeltype != LABEL_NO_LABEL) {
692                 openLabelTag(xs, style);
693                 xs << pbegin->expandLabel(style, buf.params(), false);
694                 closeLabelTag(xs, style);
695                 // Otherwise the label might run together with the text
696                 xs << from_ascii(" ");
697         }
698
699         ParagraphList::const_iterator const begin = text.paragraphs().begin();
700         pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
701                         text.outerFont(distance(begin, pbegin)));
702         closeTag(xs, style);
703         xs.cr();
704 }
705
706 } // end anonymous namespace
707
708
709 void xhtmlParagraphs(Text const & text,
710                        Buffer const & buf,
711                        XHTMLStream & xs,
712                        OutputParams const & runparams)
713 {
714         ParagraphList const & paragraphs = text.paragraphs();
715         ParagraphList::const_iterator par = paragraphs.begin();
716         ParagraphList::const_iterator pend = paragraphs.end();
717
718         OutputParams ourparams = runparams;
719         while (par != pend) {
720                 Layout const & style = par->layout();
721                 ParagraphList::const_iterator lastpar = par;
722                 ParagraphList::const_iterator send;
723
724                 switch (style.latextype) {
725                 case LATEX_COMMAND: {
726                         // The files with which we are working never have more than
727                         // one paragraph in a command structure.
728                         // FIXME 
729                         // if (ourparams.html_in_par)
730                         //   fix it so we don't get sections inside standard, e.g.
731                         // note that we may then need to make runparams not const, so we
732                         // can communicate that back.
733                         // FIXME Maybe this fix should be in the routines themselves, in case
734                         // they are called from elsewhere.
735                         makeCommand(buf, xs, ourparams, text, par);
736                         ++par;
737                         break;
738                 }
739                 case LATEX_ENVIRONMENT:
740                 case LATEX_LIST_ENVIRONMENT:
741                 case LATEX_ITEM_ENVIRONMENT: {
742                         // FIXME Same fix here.
743                         send = searchEnvironmentHtml(par, pend);
744                         par = makeEnvironmentHtml(buf, xs, ourparams, text, par, send);
745                         break;
746                 }
747                 case LATEX_BIB_ENVIRONMENT: {
748                         // FIXME Same fix here.
749                         send = searchEnvironmentHtml(par, pend);
750                         par = makeBibliography(buf, xs, ourparams, text, par, send);
751                         break;
752                 }
753                 case LATEX_PARAGRAPH:
754                         send = searchParagraphHtml(par, pend);
755                         par = makeParagraphs(buf, xs, ourparams, text, par, send);
756                         break;
757                 }
758                 // FIXME??
759                 // makeEnvironment may process more than one paragraphs and bypass pend
760                 if (distance(lastpar, par) >= distance(lastpar, pend))
761                         break;
762         }
763 }
764
765
766 } // namespace lyx