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