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