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