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