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