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