Imported Upstream version 1.8.15
[platform/upstream/doxygen.git] / src / htmldocvisitor.cpp
1 /******************************************************************************
2  *
3  * 
4  *
5  *
6  * Copyright (C) 1997-2015 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby 
10  * granted. No representations are made about the suitability of this software 
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18
19 #include <qdir.h>
20 #include "htmldocvisitor.h"
21 #include "docparser.h"
22 #include "language.h"
23 #include "doxygen.h"
24 #include "outputgen.h"
25 #include "dot.h"
26 #include "message.h"
27 #include "config.h"
28 #include "htmlgen.h"
29 #include "parserintf.h"
30 #include "msc.h"
31 #include "dia.h"
32 #include "util.h"
33 #include "vhdldocgen.h"
34 #include "filedef.h"
35 #include "memberdef.h"
36 #include "htmlentity.h"
37 #include "emoji.h"
38 #include "plantuml.h"
39
40 static const int NUM_HTML_LIST_TYPES = 4;
41 static const char types[][NUM_HTML_LIST_TYPES] = {"1", "a", "i", "A"};
42 enum contexts_t
43 {
44     NONE,      // 0
45     STARTLI,   // 1
46     STARTDD,   // 2
47     ENDLI,     // 3
48     ENDDD,     // 4
49     STARTTD,   // 5
50     ENDTD,     // 6
51     INTERLI,   // 7
52     INTERDD,   // 8
53     INTERTD    // 9
54 };
55 static const char *contexts[10] = 
56 { "",          // 0
57   "startli",   // 1
58   "startdd",   // 2
59   "endli",     // 3
60   "enddd",     // 4
61   "starttd",   // 5
62   "endtd",     // 6
63   "interli",   // 7
64   "interdd",   // 8
65   "intertd"    // 9
66 };
67
68 static QCString convertIndexWordToAnchor(const QString &word)
69 {
70   static char hex[] = "0123456789abcdef";
71   static int cnt = 0;
72   QCString result="a";
73   QCString cntStr;
74   result += cntStr.setNum(cnt);
75   result += "_";
76   cnt++;
77   const char *str = word.data();
78   unsigned char c;
79   if (str)
80   {
81     while ((c = *str++))
82     {
83       if ((c >= 'a' && c <= 'z') || // ALPHA
84           (c >= 'A' && c <= 'Z') || // ALPHA
85           (c >= '0' && c <= '9') || // DIGIT
86           c == '-' ||
87           c == '.' ||
88           c == '_'
89          )
90       {
91         result += c;
92       }
93       else
94       {
95         char enc[4];
96         enc[0] = ':';
97         enc[1] = hex[(c & 0xf0) >> 4];
98         enc[2] = hex[c & 0xf];
99         enc[3] = 0;
100         result += enc;
101       }
102     }
103   }
104   return result;
105 }
106
107 static bool mustBeOutsideParagraph(DocNode *n)
108 {
109   switch (n->kind())
110   {
111           /* <ul> */
112         case DocNode::Kind_HtmlList:
113         case DocNode::Kind_SimpleList:
114         case DocNode::Kind_AutoList:
115           /* <dl> */
116         case DocNode::Kind_SimpleSect:
117         case DocNode::Kind_ParamSect:
118         case DocNode::Kind_HtmlDescList:
119         case DocNode::Kind_XRefItem:
120           /* <table> */
121         case DocNode::Kind_HtmlTable:
122           /* <h?> */
123         case DocNode::Kind_Section:
124         case DocNode::Kind_HtmlHeader:
125           /* \internal */
126         case DocNode::Kind_Internal:
127           /* <div> */
128         case DocNode::Kind_Include:
129         case DocNode::Kind_Image:
130         case DocNode::Kind_SecRefList:
131           /* <hr> */
132         case DocNode::Kind_HorRuler:
133           /* CopyDoc gets paragraph markers from the wrapping DocPara node,
134            * but needs to insert them for all documentation being copied to
135            * preserve formatting.
136            */
137         case DocNode::Kind_Copy:
138           /* <blockquote> */
139         case DocNode::Kind_HtmlBlockQuote:
140           /* \parblock */
141         case DocNode::Kind_ParBlock:
142         case DocNode::Kind_IncOperator:
143           return TRUE;
144         case DocNode::Kind_Verbatim:
145           {
146             DocVerbatim *dv = (DocVerbatim*)n;
147             return dv->type()!=DocVerbatim::HtmlOnly || dv->isBlock();
148           }
149         case DocNode::Kind_StyleChange:
150           return ((DocStyleChange*)n)->style()==DocStyleChange::Preformatted ||
151                  ((DocStyleChange*)n)->style()==DocStyleChange::Div ||
152                  ((DocStyleChange*)n)->style()==DocStyleChange::Center;
153         case DocNode::Kind_Formula:
154           return !((DocFormula*)n)->isInline();
155         default:
156           break;
157   }
158   return FALSE;
159 }
160
161 static bool isDocVerbatimVisible(DocVerbatim *s)
162 {
163   switch(s->type())
164   {
165     case DocVerbatim::ManOnly:
166     case DocVerbatim::LatexOnly:
167     case DocVerbatim::XmlOnly:
168     case DocVerbatim::RtfOnly:
169     case DocVerbatim::DocbookOnly:
170       return FALSE;
171     default:
172       return TRUE;
173   }
174 }
175
176 static bool isDocIncludeVisible(DocInclude *s)
177 {
178   switch (s->type())
179   {
180     case DocInclude::DontInclude:
181     case DocInclude::LatexInclude:
182       return FALSE;
183     default:
184       return TRUE;
185   }
186 }
187
188 static bool isDocIncOperatorVisible(DocIncOperator *s)
189 {
190   switch (s->type())
191   {
192     case DocIncOperator::Skip:
193       return FALSE;
194     default:
195       return TRUE;
196   }
197 }
198
199 static bool isInvisibleNode(DocNode *node)
200 {
201   return (node->kind()==DocNode::Kind_WhiteSpace)
202       || // skip over image nodes that are not for HTML output
203          (node->kind()==DocNode::Kind_Image && ((DocImage*)node)->type()!=DocImage::Html)
204       || // skip over verbatim nodes that are not visible in the HTML output
205          (node->kind()==DocNode::Kind_Verbatim && !isDocVerbatimVisible((DocVerbatim*)node))
206       || // skip over include nodes that are not visible in the HTML output
207          (node->kind()==DocNode::Kind_Include && !isDocIncludeVisible((DocInclude*)node))
208       || // skip over include operator nodes that are not visible in the HTML output
209          (node->kind()==DocNode::Kind_IncOperator && !isDocIncOperatorVisible((DocIncOperator*)node))
210       ;
211 }
212
213 static QString htmlAttribsToString(const HtmlAttribList &attribs, bool img_tag = FALSE)
214 {
215   QString result;
216   HtmlAttribListIterator li(attribs);
217   HtmlAttrib *att;
218   bool alt_set = FALSE;
219
220   for (li.toFirst();(att=li.current());++li)
221   {
222     if (!att->value.isEmpty())  // ignore attribute without values as they
223                                 // are not XHTML compliant, with the exception
224                                 // of the alt attribute with the img tag
225     {
226       result+=" ";
227       result+=att->name;
228       result+="=\""+convertToXML(att->value)+"\"";
229       if (att->name == "alt") alt_set = TRUE;
230     }
231   }
232   if (!alt_set && img_tag)
233   {
234       result+=" alt=\"\"";
235   }
236   return result;
237 }
238
239 //-------------------------------------------------------------------------
240
241 HtmlDocVisitor::HtmlDocVisitor(FTextStream &t,CodeOutputInterface &ci,
242                                Definition *ctx) 
243   : DocVisitor(DocVisitor_Html), m_t(t), m_ci(ci), m_insidePre(FALSE), 
244                                  m_hide(FALSE), m_ctx(ctx)
245 {
246   if (ctx) m_langExt=ctx->getDefFileExtension();
247 }
248
249   //--------------------------------------
250   // visitor functions for leaf nodes
251   //--------------------------------------
252
253 void HtmlDocVisitor::visit(DocWord *w)
254 {
255   //printf("word: %s\n",w->word().data());
256   if (m_hide) return;
257   filter(w->word());
258 }
259
260 void HtmlDocVisitor::visit(DocLinkedWord *w)
261 {
262   if (m_hide) return;
263   //printf("linked word: %s\n",w->word().data());
264   startLink(w->ref(),w->file(),w->relPath(),w->anchor(),w->tooltip());
265   filter(w->word());
266   endLink();
267 }
268
269 void HtmlDocVisitor::visit(DocWhiteSpace *w)
270 {
271   if (m_hide) return;
272   if (m_insidePre)
273   {
274     m_t << w->chars();
275   }
276   else
277   {
278     m_t << " ";
279   }
280 }
281
282 void HtmlDocVisitor::visit(DocSymbol *s)
283 {
284   if (m_hide) return;
285   const char *res = HtmlEntityMapper::instance()->html(s->symbol());
286   if (res)
287   {
288     m_t << res;
289   }
290   else
291   {
292     err("HTML: non supported HTML-entity found: %s\n",HtmlEntityMapper::instance()->html(s->symbol(),TRUE));
293   }
294 }
295
296 void HtmlDocVisitor::visit(DocEmoji *s)
297 {
298   if (m_hide) return;
299   const char *res = EmojiEntityMapper::instance()->unicode(s->index());
300   if (res)
301   {
302     m_t << res;
303   }
304   else
305   {
306     m_t << s->name();
307   }
308 }
309
310 void HtmlDocVisitor::writeObfuscatedMailAddress(const QCString &url)
311 {
312   m_t << "<a href=\"#\" onclick=\"location.href='mai'+'lto:'";
313   uint i;
314   int size=3;
315   for (i=0;i<url.length();)
316   {
317     m_t << "+'" << url.mid(i,size) << "'";
318     i+=size;
319     if (size==3) size=2; else size=3;
320   }
321   m_t << "; return false;\">";
322 }
323
324 void HtmlDocVisitor::visit(DocURL *u)
325 {
326   if (m_hide) return;
327   if (u->isEmail()) // mail address
328   {
329     QCString url = u->url();
330     writeObfuscatedMailAddress(url);
331     uint size=5,i;
332     for (i=0;i<url.length();)
333     {
334       filter(url.mid(i,size));
335       if (i<url.length()-size) m_t << "<span style=\"display: none;\">.nosp@m.</span>";
336       i+=size;
337       if (size==5) size=4; else size=5;
338     }
339     m_t << "</a>";
340   }
341   else // web address
342   {
343     m_t << "<a href=\"";
344     m_t << u->url() << "\">";
345     filter(u->url());
346     m_t << "</a>";
347   }
348 }
349
350 void HtmlDocVisitor::visit(DocLineBreak *)
351 {
352   if (m_hide) return;
353   m_t << "<br />\n";
354 }
355
356 void HtmlDocVisitor::visit(DocHorRuler *hr)
357 {
358   if (m_hide) return;
359   forceEndParagraph(hr);
360   m_t << "<hr/>\n";
361   forceStartParagraph(hr);
362 }
363
364 void HtmlDocVisitor::visit(DocStyleChange *s)
365 {
366   if (m_hide) return;
367   switch (s->style())
368   {
369     case DocStyleChange::Bold:
370       if (s->enable()) m_t << "<b" << htmlAttribsToString(s->attribs()) << ">";      else m_t << "</b>";
371       break;
372     case DocStyleChange::Strike:
373       if (s->enable()) m_t << "<strike" << htmlAttribsToString(s->attribs()) << ">";      else m_t << "</strike>";
374       break;
375     case DocStyleChange::Underline:
376       if (s->enable()) m_t << "<u" << htmlAttribsToString(s->attribs()) << ">";      else m_t << "</u>";
377       break;
378     case DocStyleChange::Italic:
379       if (s->enable()) m_t << "<em" << htmlAttribsToString(s->attribs()) << ">";     else m_t << "</em>";
380       break;
381     case DocStyleChange::Code:
382       if (s->enable()) m_t << "<code" << htmlAttribsToString(s->attribs()) << ">";   else m_t << "</code>";
383       break;
384     case DocStyleChange::Subscript:
385       if (s->enable()) m_t << "<sub" << htmlAttribsToString(s->attribs()) << ">";    else m_t << "</sub>";
386       break;
387     case DocStyleChange::Superscript:
388       if (s->enable()) m_t << "<sup" << htmlAttribsToString(s->attribs()) << ">";    else m_t << "</sup>";
389       break;
390     case DocStyleChange::Center:
391       if (s->enable()) 
392       {
393         forceEndParagraph(s);
394         m_t << "<center" << htmlAttribsToString(s->attribs()) << ">"; 
395       }
396       else 
397       {
398         m_t << "</center>";
399         forceStartParagraph(s);
400       }
401       break;
402     case DocStyleChange::Small:
403       if (s->enable()) m_t << "<small" << htmlAttribsToString(s->attribs()) << ">";  else m_t << "</small>";
404       break;
405     case DocStyleChange::Preformatted:
406       if (s->enable())
407       {
408         forceEndParagraph(s);
409         m_t << "<pre" << htmlAttribsToString(s->attribs()) << ">";
410         m_insidePre=TRUE;
411       }
412       else
413       {
414         m_insidePre=FALSE;
415         m_t << "</pre>";
416         forceStartParagraph(s);
417       }
418       break;
419     case DocStyleChange::Div:
420       if (s->enable()) 
421       {
422         forceEndParagraph(s);
423         m_t << "<div" << htmlAttribsToString(s->attribs()) << ">";  
424       }
425       else 
426       {
427         m_t << "</div>";
428         forceStartParagraph(s);
429       }
430       break;
431     case DocStyleChange::Span:
432       if (s->enable()) m_t << "<span" << htmlAttribsToString(s->attribs()) << ">";  else m_t << "</span>";
433       break;
434
435   }
436 }
437
438
439 static void visitPreCaption(FTextStream &t, DocVerbatim *s)
440 {
441   if (s->hasCaption())
442   { 
443     t << "<div class=\"caption\">" << endl;
444   }
445 }
446
447
448 static void visitPostCaption(FTextStream &t, DocVerbatim *s)
449 {
450   if (s->hasCaption())
451   {
452     t << "</div>" << endl;
453   }
454 }
455
456
457 static void visitCaption(HtmlDocVisitor *parent, QList<DocNode> children)
458 {
459   QListIterator<DocNode> cli(children);
460   DocNode *n;
461   for (cli.toFirst();(n=cli.current());++cli) n->accept(parent);
462 }
463
464 void HtmlDocVisitor::visit(DocVerbatim *s)
465 {
466   if (m_hide) return;
467   QCString lang = m_langExt;
468   if (!s->language().isEmpty()) // explicit language setting
469   {
470     lang = s->language();
471   }
472   SrcLangExt langExt = getLanguageFromFileName(lang);
473   switch(s->type())
474   {
475     case DocVerbatim::Code: 
476       forceEndParagraph(s);
477       m_t << PREFRAG_START;
478       Doxygen::parserManager->getParser(lang)
479                             ->parseCode(m_ci,
480                                         s->context(),
481                                         s->text(),
482                                         langExt,
483                                         s->isExample(),
484                                         s->exampleFile(),
485                                         0,     // fileDef
486                                         -1,    // startLine
487                                         -1,    // endLine
488                                         FALSE, // inlineFragment
489                                         0,     // memberDef
490                                         TRUE,  // show line numbers
491                                         m_ctx  // search context
492                                        );
493       m_t << PREFRAG_END;
494       forceStartParagraph(s);
495       break;
496     case DocVerbatim::Verbatim: 
497       forceEndParagraph(s);
498       m_t << /*PREFRAG_START <<*/ "<pre class=\"fragment\">";
499       filter(s->text());
500       m_t << "</pre>" /*<< PREFRAG_END*/;
501       forceStartParagraph(s);
502       break;
503     case DocVerbatim::HtmlOnly:
504       {
505         if (s->isBlock()) forceEndParagraph(s);
506         m_t << s->text();
507         if (s->isBlock()) forceStartParagraph(s);
508       }
509       break;
510     case DocVerbatim::ManOnly: 
511     case DocVerbatim::LatexOnly: 
512     case DocVerbatim::XmlOnly: 
513     case DocVerbatim::RtfOnly:
514     case DocVerbatim::DocbookOnly:
515       /* nothing */ 
516       break;
517
518     case DocVerbatim::Dot:
519       {
520         static int dotindex = 1;
521         QCString fileName(4096);
522
523         forceEndParagraph(s);
524         fileName.sprintf("%s%d%s", 
525             (Config_getString(HTML_OUTPUT)+"/inline_dotgraph_").data(), 
526             dotindex++,
527             ".dot"
528            );
529         QFile file(fileName);
530         if (!file.open(IO_WriteOnly))
531         {
532           err("Could not open file %s for writing\n",fileName.data());
533         }
534         else
535         {
536           file.writeBlock( s->text(), s->text().length() );
537           file.close();
538
539           m_t << "<div class=\"dotgraph\">" << endl;
540           writeDotFile(fileName,s->relPath(),s->context());
541           visitPreCaption(m_t, s);
542           visitCaption(this, s->children());
543           visitPostCaption(m_t, s);
544           m_t << "</div>" << endl;
545
546           if (Config_getBool(DOT_CLEANUP)) file.remove();
547         }
548         forceStartParagraph(s);
549       }
550       break;
551     case DocVerbatim::Msc:
552       {
553         forceEndParagraph(s);
554
555         static int mscindex = 1;
556         QCString baseName(4096);
557
558         baseName.sprintf("%s%d", 
559             (Config_getString(HTML_OUTPUT)+"/inline_mscgraph_").data(), 
560             mscindex++
561             );
562         QFile file(baseName+".msc");
563         if (!file.open(IO_WriteOnly))
564         {
565           err("Could not open file %s.msc for writing\n",baseName.data());
566         }
567         else
568         {
569           QCString text = "msc {";
570           text+=s->text();
571           text+="}";
572
573           file.writeBlock( text, text.length() );
574           file.close();
575
576           m_t << "<div class=\"mscgraph\">" << endl;
577           writeMscFile(baseName+".msc",s->relPath(),s->context());
578           visitPreCaption(m_t, s);
579           visitCaption(this, s->children());
580           visitPostCaption(m_t, s);
581           m_t << "</div>" << endl;
582
583           if (Config_getBool(DOT_CLEANUP)) file.remove();
584         }
585         forceStartParagraph(s);
586       }
587       break;
588     case DocVerbatim::PlantUML:
589       {
590         forceEndParagraph(s);
591
592         static QCString htmlOutput = Config_getString(HTML_OUTPUT);
593         QCString baseName = writePlantUMLSource(htmlOutput,s->exampleFile(),s->text());
594         m_t << "<div class=\"plantumlgraph\">" << endl;
595         writePlantUMLFile(baseName,s->relPath(),s->context());
596         visitPreCaption(m_t, s);
597         visitCaption(this, s->children());
598         visitPostCaption(m_t, s);
599         m_t << "</div>" << endl;
600         forceStartParagraph(s);
601       }
602       break;
603   }
604 }
605
606 void HtmlDocVisitor::visit(DocAnchor *anc)
607 {
608   if (m_hide) return;
609   m_t << "<a class=\"anchor\" id=\"" << anc->anchor() << "\"></a>";
610 }
611
612 void HtmlDocVisitor::visit(DocInclude *inc)
613 {
614   if (m_hide) return;
615   SrcLangExt langExt = getLanguageFromFileName(inc->extension());
616   switch(inc->type())
617   {
618     case DocInclude::Include: 
619       forceEndParagraph(inc);
620       m_t << PREFRAG_START;
621       Doxygen::parserManager->getParser(inc->extension())
622                             ->parseCode(m_ci,                 
623                                         inc->context(),
624                                         inc->text(),
625                                         langExt,
626                                         inc->isExample(),
627                                         inc->exampleFile(),
628                                         0,     // fileDef
629                                         -1,    // startLine
630                                         -1,    // endLine
631                                         TRUE,  // inlineFragment
632                                         0,     // memberDef
633                                         FALSE, // show line numbers
634                                         m_ctx  // search context 
635                                        );
636       m_t << PREFRAG_END;
637       forceStartParagraph(inc);
638       break;
639     case DocInclude::IncWithLines:
640       { 
641          forceEndParagraph(inc);
642          m_t << PREFRAG_START;
643          QFileInfo cfi( inc->file() );
644          FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() );
645          Doxygen::parserManager->getParser(inc->extension())
646                                ->parseCode(m_ci,
647                                            inc->context(),
648                                            inc->text(),
649                                            langExt,
650                                            inc->isExample(),
651                                            inc->exampleFile(), 
652                                            &fd,   // fileDef,
653                                            -1,    // start line
654                                            -1,    // end line
655                                            FALSE, // inline fragment
656                                            0,     // memberDef
657                                            TRUE,  // show line numbers
658                                            m_ctx  // search context
659                                            );
660          m_t << PREFRAG_END;
661          forceStartParagraph(inc);
662       }
663       break;
664     case DocInclude::DontInclude: 
665       break;
666     case DocInclude::HtmlInclude:
667       {
668         if (inc->isBlock()) forceEndParagraph(inc);
669         m_t << inc->text();
670         if (inc->isBlock()) forceStartParagraph(inc);
671       }
672       break;
673     case DocInclude::LatexInclude:
674       break;
675     case DocInclude::VerbInclude: 
676       forceEndParagraph(inc);
677       m_t << /*PREFRAG_START <<*/ "<pre class=\"fragment\">";
678       filter(inc->text());
679       m_t << "</pre>" /*<< PREFRAG_END*/;
680       forceStartParagraph(inc);
681       break;
682     case DocInclude::Snippet:
683       {
684          forceEndParagraph(inc);
685          m_t << PREFRAG_START;
686          Doxygen::parserManager->getParser(inc->extension())
687                                ->parseCode(m_ci,
688                                            inc->context(),
689                                            extractBlock(inc->text(),inc->blockId()),
690                                            langExt,
691                                            inc->isExample(),
692                                            inc->exampleFile(), 
693                                            0,
694                                            -1,    // startLine
695                                            -1,    // endLine
696                                            TRUE,  // inlineFragment
697                                            0,     // memberDef
698                                            FALSE, // show line number
699                                            m_ctx  // search context
700                                           );
701          m_t << PREFRAG_END;
702          forceStartParagraph(inc);
703       }
704       break;
705     case DocInclude::SnipWithLines:
706       {
707          forceEndParagraph(inc);
708          m_t << PREFRAG_START;
709          QFileInfo cfi( inc->file() );
710          FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() );
711          Doxygen::parserManager->getParser(inc->extension())
712                                ->parseCode(m_ci,
713                                            inc->context(),
714                                            extractBlock(inc->text(),inc->blockId()),
715                                            langExt,
716                                            inc->isExample(),
717                                            inc->exampleFile(), 
718                                            &fd,
719                                            lineBlock(inc->text(),inc->blockId()),
720                                            -1,    // endLine
721                                            FALSE, // inlineFragment
722                                            0,     // memberDef
723                                            TRUE,  // show line number
724                                            m_ctx  // search context
725                                           );
726          m_t << PREFRAG_END;
727          forceStartParagraph(inc);
728       }
729       break;
730     case DocInclude::SnippetDoc: 
731     case DocInclude::IncludeDoc: 
732       err("Internal inconsistency: found switch SnippetDoc / IncludeDoc in file: %s"
733           "Please create a bug report\n",__FILE__);
734       break;
735   }
736 }
737
738 void HtmlDocVisitor::visit(DocIncOperator *op)
739 {
740   //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n",
741   //    op->type(),op->isFirst(),op->isLast(),op->text().data());
742   if (op->isFirst()) 
743   {
744     forceEndParagraph(op);
745     if (!m_hide) m_t << PREFRAG_START;
746     pushEnabled();
747     m_hide=TRUE;
748   }
749   SrcLangExt langExt = getLanguageFromFileName(m_langExt);
750   if (op->type()!=DocIncOperator::Skip) 
751   {
752     popEnabled();
753     if (!m_hide) 
754     {
755       Doxygen::parserManager->getParser(m_langExt)
756                             ->parseCode(
757                                 m_ci,
758                                 op->context(),
759                                 op->text(),
760                                 langExt,
761                                 op->isExample(),
762                                 op->exampleFile(),
763                                 0,     // fileDef
764                                 -1,    // startLine
765                                 -1,    // endLine
766                                 FALSE, // inline fragment
767                                 0,     // memberDef
768                                 TRUE,  // show line numbers
769                                 m_ctx  // search context
770                                );
771     }
772     pushEnabled();
773     m_hide=TRUE;
774   }
775   if (op->isLast())  
776   {
777     popEnabled();
778     if (!m_hide) m_t << PREFRAG_END;
779     forceStartParagraph(op);
780   }
781   else
782   {
783     if (!m_hide) m_t << endl;
784   }
785 }
786
787 void HtmlDocVisitor::visit(DocFormula *f)
788 {
789   if (m_hide) return;
790   bool bDisplay = !f->isInline();
791   if (bDisplay) 
792   {
793     forceEndParagraph(f);
794     m_t << "<p class=\"formulaDsp\">" << endl;
795   }
796
797   if (Config_getBool(USE_MATHJAX))
798   {
799     QCString text = f->text();
800     bool closeInline = FALSE;
801     if (!bDisplay && !text.isEmpty() && text.at(0)=='$' && 
802                       text.at(text.length()-1)=='$')
803     {
804       closeInline=TRUE;
805       text = text.mid(1,text.length()-2);
806       m_t << "\\(";
807     }
808     m_t << convertToHtml(text);
809     if (closeInline)
810     {
811       m_t << "\\)";
812     }
813   }
814   else
815   {
816     m_t << "<img class=\"formula" 
817       << (bDisplay ? "Dsp" : "Inl");
818     m_t << "\" alt=\"";
819     filterQuotedCdataAttr(f->text());
820     m_t << "\"";
821     // TODO: cache image dimensions on formula generation and give height/width
822     // for faster preloading and better rendering of the page
823     m_t << " src=\"" << f->relPath() << f->name() << ".png\"/>";
824
825   }
826   if (bDisplay)
827   {
828     m_t << endl << "</p>" << endl;
829     forceStartParagraph(f);
830   }
831 }
832
833 void HtmlDocVisitor::visit(DocIndexEntry *e)
834 {
835   QCString anchor = convertIndexWordToAnchor(e->entry());
836   if (e->member()) 
837   {
838     anchor.prepend(e->member()->anchor()+"_");
839   }
840   m_t << "<a name=\"" << anchor << "\"></a>";
841   //printf("*** DocIndexEntry: word='%s' scope='%s' member='%s'\n",
842   //       e->entry().data(),
843   //       e->scope()  ? e->scope()->name().data()  : "<null>",
844   //       e->member() ? e->member()->name().data() : "<null>"
845   //      );
846   Doxygen::indexList->addIndexItem(e->scope(),e->member(),anchor,e->entry());
847 }
848
849 void HtmlDocVisitor::visit(DocSimpleSectSep *)
850 {
851   m_t << "</dd>" << endl;
852   m_t << "<dd>" << endl;
853 }
854
855 void HtmlDocVisitor::visit(DocCite *cite)
856 {
857   if (m_hide) return;
858   if (!cite->file().isEmpty()) 
859   {
860     startLink(cite->ref(),cite->file(),cite->relPath(),cite->anchor());
861   }
862   else
863   {
864     m_t << "<b>[";
865   }
866   filter(cite->text());
867   if (!cite->file().isEmpty()) 
868   {
869     endLink();
870   }
871   else
872   {
873     m_t << "]</b>";
874   }
875 }
876
877
878 //--------------------------------------
879 // visitor functions for compound nodes
880 //--------------------------------------
881
882
883 void HtmlDocVisitor::visitPre(DocAutoList *l)
884 {
885   //printf("DocAutoList::visitPre\n");
886   if (m_hide) return;
887   forceEndParagraph(l);
888   if (l->isEnumList())
889   {
890     //
891     // Do list type based on depth:
892     // 1.
893     //   a.
894     //     i.
895     //       A. 
896     //         1. (repeat)...
897     //
898     m_t << "<ol type=\"" << types[l->depth() % NUM_HTML_LIST_TYPES] << "\"";
899   }
900   else
901   {
902     m_t << "<ul";
903   }
904   m_t << getDirHtmlClassOfNode(getTextDirByConfig(l)) << ">";
905   if (!l->isPreformatted()) m_t << "\n";
906 }
907
908 void HtmlDocVisitor::visitPost(DocAutoList *l)
909 {
910   //printf("DocAutoList::visitPost\n");
911   if (m_hide) return;
912   if (l->isEnumList())
913   {
914     m_t << "</ol>";
915   }
916   else
917   {
918     m_t << "</ul>";
919   }
920   if (!l->isPreformatted()) m_t << "\n";
921   forceStartParagraph(l);
922 }
923
924 void HtmlDocVisitor::visitPre(DocAutoListItem *)
925 {
926   if (m_hide) return;
927   m_t << "<li>";
928 }
929
930 void HtmlDocVisitor::visitPost(DocAutoListItem *li) 
931 {
932   if (m_hide) return;
933   m_t << "</li>";
934   if (!li->isPreformatted()) m_t << "\n";
935 }
936
937 template<class T> 
938 bool isFirstChildNode(T *parent, DocNode *node)
939 {
940    return parent->children().getFirst()==node;
941 }
942
943 template<class T> 
944 bool isLastChildNode(T *parent, DocNode *node)
945 {
946    return parent->children().getLast()==node;
947 }
948
949 bool isSeparatedParagraph(DocSimpleSect *parent,DocPara *par)
950 {
951   QList<DocNode> nodes = parent->children();
952   int i = nodes.findRef(par);
953   if (i==-1) return FALSE;
954   int count = parent->children().count();
955   if (count>1 && i==0) // first node
956   {
957     if (nodes.at(i+1)->kind()==DocNode::Kind_SimpleSectSep)
958     {
959       return TRUE;
960     }
961   }
962   else if (count>1 && i==count-1) // last node
963   {
964     if (nodes.at(i-1)->kind()==DocNode::Kind_SimpleSectSep)
965     {
966       return TRUE;
967     }
968   }
969   else if (count>2 && i>0 && i<count-1) // intermediate node
970   {
971     if (nodes.at(i-1)->kind()==DocNode::Kind_SimpleSectSep &&
972         nodes.at(i+1)->kind()==DocNode::Kind_SimpleSectSep)
973     {
974       return TRUE;
975     }
976   }
977   return FALSE;
978 }
979
980 static int getParagraphContext(DocPara *p,bool &isFirst,bool &isLast)
981 {
982   int t=0;
983   isFirst=FALSE;
984   isLast=FALSE;
985   if (p && p->parent())
986   {
987     switch (p->parent()->kind()) 
988     {
989       case DocNode::Kind_ParBlock:
990         { // hierarchy: node N -> para -> parblock -> para
991           // adapt return value to kind of N
992           DocNode::Kind kind = DocNode::Kind_Para;
993           if ( p->parent()->parent() && p->parent()->parent()->parent() )
994           {
995             kind = p->parent()->parent()->parent()->kind();
996           }
997           isFirst=isFirstChildNode((DocParBlock*)p->parent(),p);
998           isLast =isLastChildNode ((DocParBlock*)p->parent(),p);
999           t=NONE;
1000           if (isFirst)
1001           {
1002             if (kind==DocNode::Kind_HtmlListItem ||
1003                 kind==DocNode::Kind_SecRefItem)
1004             {
1005               t=STARTLI;
1006             }
1007             else if (kind==DocNode::Kind_HtmlDescData ||
1008                      kind==DocNode::Kind_XRefItem ||
1009                      kind==DocNode::Kind_SimpleSect)
1010             {
1011               t=STARTDD;
1012             }
1013             else if (kind==DocNode::Kind_HtmlCell ||
1014                      kind==DocNode::Kind_ParamList)
1015             {
1016               t=STARTTD;
1017             }
1018           }
1019           if (isLast)
1020           {
1021             if (kind==DocNode::Kind_HtmlListItem ||
1022                 kind==DocNode::Kind_SecRefItem)
1023             {
1024               t=ENDLI;
1025             }
1026             else if (kind==DocNode::Kind_HtmlDescData ||
1027                      kind==DocNode::Kind_XRefItem ||
1028                      kind==DocNode::Kind_SimpleSect)
1029             {
1030               t=ENDDD;
1031             }
1032             else if (kind==DocNode::Kind_HtmlCell ||
1033                      kind==DocNode::Kind_ParamList)
1034             {
1035               t=ENDTD;
1036             }
1037           }
1038           if (!isFirst && !isLast)
1039           {
1040             if (kind==DocNode::Kind_HtmlListItem ||
1041                 kind==DocNode::Kind_SecRefItem)
1042             {
1043               t=INTERLI;
1044             }
1045             else if (kind==DocNode::Kind_HtmlDescData ||
1046                      kind==DocNode::Kind_XRefItem ||
1047                      kind==DocNode::Kind_SimpleSect)
1048             {
1049               t=INTERDD;
1050             }
1051             else if (kind==DocNode::Kind_HtmlCell ||
1052                      kind==DocNode::Kind_ParamList)
1053             {
1054               t=INTERTD;
1055             }
1056           }
1057           break;
1058         }
1059       case DocNode::Kind_AutoListItem:
1060         isFirst=isFirstChildNode((DocAutoListItem*)p->parent(),p);
1061         isLast =isLastChildNode ((DocAutoListItem*)p->parent(),p);
1062         t=STARTLI; // not used
1063         break;
1064       case DocNode::Kind_SimpleListItem:
1065         isFirst=TRUE;
1066         isLast =TRUE;
1067         t=STARTLI; // not used
1068         break;
1069       case DocNode::Kind_ParamList:
1070         isFirst=TRUE;
1071         isLast =TRUE;
1072         t=STARTLI; // not used
1073         break;
1074       case DocNode::Kind_HtmlListItem:
1075         isFirst=isFirstChildNode((DocHtmlListItem*)p->parent(),p);
1076         isLast =isLastChildNode ((DocHtmlListItem*)p->parent(),p);
1077         if (isFirst) t=STARTLI;
1078         if (isLast)  t=ENDLI;
1079         if (!isFirst && !isLast) t = INTERLI;
1080         break;
1081       case DocNode::Kind_SecRefItem:
1082         isFirst=isFirstChildNode((DocSecRefItem*)p->parent(),p);
1083         isLast =isLastChildNode ((DocSecRefItem*)p->parent(),p);
1084         if (isFirst) t=STARTLI;
1085         if (isLast)  t=ENDLI;
1086         if (!isFirst && !isLast) t = INTERLI;
1087         break;
1088       case DocNode::Kind_HtmlDescData:
1089         isFirst=isFirstChildNode((DocHtmlDescData*)p->parent(),p);
1090         isLast =isLastChildNode ((DocHtmlDescData*)p->parent(),p);
1091         if (isFirst) t=STARTDD;
1092         if (isLast)  t=ENDDD;
1093         if (!isFirst && !isLast) t = INTERDD;
1094         break;
1095       case DocNode::Kind_XRefItem:
1096         isFirst=isFirstChildNode((DocXRefItem*)p->parent(),p);
1097         isLast =isLastChildNode ((DocXRefItem*)p->parent(),p);
1098         if (isFirst) t=STARTDD;
1099         if (isLast)  t=ENDDD;
1100         if (!isFirst && !isLast) t = INTERDD;
1101         break;
1102       case DocNode::Kind_SimpleSect:
1103         isFirst=isFirstChildNode((DocSimpleSect*)p->parent(),p);
1104         isLast =isLastChildNode ((DocSimpleSect*)p->parent(),p);
1105         if (isFirst) t=STARTDD;
1106         if (isLast)  t=ENDDD;
1107         if (isSeparatedParagraph((DocSimpleSect*)p->parent(),p))
1108           // if the paragraph is enclosed with separators it will
1109           // be included in <dd>..</dd> so avoid addition paragraph
1110           // markers
1111         {
1112           isFirst=isLast=TRUE;
1113         }
1114         if (!isFirst && !isLast) t = INTERDD;
1115         break;
1116       case DocNode::Kind_HtmlCell:
1117         isFirst=isFirstChildNode((DocHtmlCell*)p->parent(),p);
1118         isLast =isLastChildNode ((DocHtmlCell*)p->parent(),p);
1119         if (isFirst) t=STARTTD;
1120         if (isLast)  t=ENDTD;
1121         if (!isFirst && !isLast) t = INTERTD;
1122         break;
1123       default:
1124         break;
1125     }
1126     //printf("para=%p parent()->kind=%d isFirst=%d isLast=%d t=%d\n",
1127     //    p,p->parent()->kind(),isFirst,isLast,t);
1128   }
1129   return t;
1130 }
1131
1132 void HtmlDocVisitor::visitPre(DocPara *p) 
1133 {
1134   if (m_hide) return;
1135
1136   //printf("DocPara::visitPre: parent of kind %d ",
1137   //       p->parent() ? p->parent()->kind() : -1);
1138
1139   bool needsTag = FALSE;
1140   if (p && p->parent()) 
1141   {
1142     switch (p->parent()->kind()) 
1143     {
1144       case DocNode::Kind_Section:
1145       case DocNode::Kind_Internal:
1146       case DocNode::Kind_HtmlListItem:
1147       case DocNode::Kind_HtmlDescData:
1148       case DocNode::Kind_HtmlCell:
1149       case DocNode::Kind_SimpleListItem:
1150       case DocNode::Kind_AutoListItem:
1151       case DocNode::Kind_SimpleSect:
1152       case DocNode::Kind_XRefItem:
1153       case DocNode::Kind_Copy:
1154       case DocNode::Kind_HtmlBlockQuote:
1155       case DocNode::Kind_ParBlock:
1156         needsTag = TRUE;
1157         break;
1158       case DocNode::Kind_Root:
1159         needsTag = !((DocRoot*)p->parent())->singleLine();
1160         break;
1161       default:
1162         needsTag = FALSE;
1163     }
1164   }
1165
1166   // if the first element of a paragraph is something that should be outside of
1167   // the paragraph (<ul>,<dl>,<table>,..) then that will already started the 
1168   // paragraph and we don't need to do it here
1169   bool paragraphAlreadyStarted = false;
1170   uint nodeIndex = 0;
1171   if (p && nodeIndex<p->children().count())
1172   {
1173     while (nodeIndex<p->children().count() && isInvisibleNode(p->children().at(nodeIndex)))
1174     {
1175       nodeIndex++;
1176     }
1177     if (nodeIndex<p->children().count())
1178     {
1179       DocNode *n = p->children().at(nodeIndex);
1180       if (mustBeOutsideParagraph(n))
1181       {
1182         paragraphAlreadyStarted = true;
1183         needsTag = FALSE;
1184       }
1185     }
1186   }
1187
1188   // check if this paragraph is the first or last or intermediate child of a <li> or <dd>.
1189   // this allows us to mark the tag with a special class so we can
1190   // fix the otherwise ugly spacing.
1191   int t;
1192   bool isFirst;
1193   bool isLast;
1194   t = getParagraphContext(p,isFirst,isLast);
1195   //printf("startPara first=%d last=%d\n",isFirst,isLast);
1196   if (isFirst && isLast) needsTag=FALSE;
1197
1198   //printf("  needsTag=%d\n",needsTag);
1199   // write the paragraph tag (if needed)
1200   if (needsTag)
1201     m_t << "<p" << getDirHtmlClassOfNode(getTextDirByConfig(p), contexts[t]) << ">";
1202   else if(!paragraphAlreadyStarted)
1203     m_t << getHtmlDirEmbedingChar(getTextDirByConfig(p));
1204 }
1205
1206 void HtmlDocVisitor::visitPost(DocPara *p)
1207 {
1208   bool needsTag = FALSE;
1209   if (p->parent()) 
1210   {
1211     switch (p->parent()->kind()) 
1212     {
1213       case DocNode::Kind_Section:
1214       case DocNode::Kind_Internal:
1215       case DocNode::Kind_HtmlListItem:
1216       case DocNode::Kind_HtmlDescData:
1217       case DocNode::Kind_HtmlCell:
1218       case DocNode::Kind_SimpleListItem:
1219       case DocNode::Kind_AutoListItem:
1220       case DocNode::Kind_SimpleSect:
1221       case DocNode::Kind_XRefItem:
1222       case DocNode::Kind_Copy:
1223       case DocNode::Kind_HtmlBlockQuote:
1224       case DocNode::Kind_ParBlock:
1225         needsTag = TRUE;
1226         break;
1227       case DocNode::Kind_Root:
1228         needsTag = !((DocRoot*)p->parent())->singleLine();
1229         break;
1230       default:
1231         needsTag = FALSE;
1232     }
1233   }
1234
1235   // if the last element of a paragraph is something that should be outside of
1236   // the paragraph (<ul>,<dl>,<table>) then that will already have ended the 
1237   // paragraph and we don't need to do it here
1238   int nodeIndex = p->children().count()-1;
1239   if (nodeIndex>=0)
1240   {
1241     while (nodeIndex>=0 && isInvisibleNode(p->children().at(nodeIndex)))
1242     {
1243       nodeIndex--;
1244     }
1245     if (nodeIndex>=0)
1246     {
1247       DocNode *n = p->children().at(nodeIndex);
1248       if (mustBeOutsideParagraph(n))
1249       {
1250         needsTag = FALSE;
1251       }
1252     }
1253   }
1254
1255   bool isFirst;
1256   bool isLast;
1257   getParagraphContext(p,isFirst,isLast);
1258   //printf("endPara first=%d last=%d\n",isFirst,isLast);
1259   if (isFirst && isLast) needsTag=FALSE;
1260
1261   //printf("DocPara::visitPost needsTag=%d\n",needsTag);
1262
1263   if (needsTag) m_t << "</p>\n";
1264
1265 }
1266
1267 void HtmlDocVisitor::visitPre(DocRoot *)
1268 {
1269 }
1270
1271 void HtmlDocVisitor::visitPost(DocRoot *)
1272 {
1273 }
1274
1275 void HtmlDocVisitor::visitPre(DocSimpleSect *s)
1276 {
1277   if (m_hide) return;
1278   forceEndParagraph(s);
1279   if (s->type() != DocSimpleSect::Return)
1280     m_t << "<dl" << getDirHtmlClassOfNode(getTextDirByConfig(s), "section " + s->typeString()) << "><dt>";
1281   else
1282     m_t << "<dl class=\"section " << s->typeString() << "\"><dt>";
1283   switch(s->type())
1284   {
1285     case DocSimpleSect::See: 
1286       m_t << theTranslator->trSeeAlso(); break;
1287     case DocSimpleSect::Return: 
1288       m_t << theTranslator->trReturns(); break;
1289     case DocSimpleSect::Author: 
1290       m_t << theTranslator->trAuthor(TRUE,TRUE); break;
1291     case DocSimpleSect::Authors: 
1292       m_t << theTranslator->trAuthor(TRUE,FALSE); break;
1293     case DocSimpleSect::Version: 
1294       m_t << theTranslator->trVersion(); break;
1295     case DocSimpleSect::Since: 
1296       m_t << theTranslator->trSince(); break;
1297     case DocSimpleSect::Date: 
1298       m_t << theTranslator->trDate(); break;
1299     case DocSimpleSect::Note: 
1300       m_t << theTranslator->trNote(); break;
1301     case DocSimpleSect::Warning:
1302       m_t << theTranslator->trWarning(); break;
1303     case DocSimpleSect::Pre:
1304       m_t << theTranslator->trPrecondition(); break;
1305     case DocSimpleSect::Post:
1306       m_t << theTranslator->trPostcondition(); break;
1307     case DocSimpleSect::Copyright:
1308       m_t << theTranslator->trCopyright(); break;
1309     case DocSimpleSect::Invar:
1310       m_t << theTranslator->trInvariant(); break;
1311     case DocSimpleSect::Remark:
1312       m_t << theTranslator->trRemarks(); break;
1313     case DocSimpleSect::Attention:
1314       m_t << theTranslator->trAttention(); break;
1315     case DocSimpleSect::User: break;
1316     case DocSimpleSect::Rcs: break;
1317     case DocSimpleSect::Unknown:  break;
1318   }
1319
1320   // special case 1: user defined title
1321   if (s->type()!=DocSimpleSect::User && s->type()!=DocSimpleSect::Rcs)
1322   {
1323     m_t << "</dt><dd>";
1324   }
1325 }
1326
1327 void HtmlDocVisitor::visitPost(DocSimpleSect *s)
1328 {
1329   if (m_hide) return;
1330   m_t << "</dd></dl>\n";
1331   forceStartParagraph(s);
1332 }
1333
1334 void HtmlDocVisitor::visitPre(DocTitle *)
1335 {
1336 }
1337
1338 void HtmlDocVisitor::visitPost(DocTitle *)
1339 {
1340   if (m_hide) return;
1341   m_t << "</dt><dd>";
1342 }
1343
1344 void HtmlDocVisitor::visitPre(DocSimpleList *sl)
1345 {
1346   if (m_hide) return;
1347   forceEndParagraph(sl);
1348   m_t << "<ul>";
1349   if (!sl->isPreformatted()) m_t << "\n";
1350
1351 }
1352
1353 void HtmlDocVisitor::visitPost(DocSimpleList *sl)
1354 {
1355   if (m_hide) return;
1356   m_t << "</ul>";
1357   if (!sl->isPreformatted()) m_t << "\n";
1358   forceStartParagraph(sl);
1359 }
1360
1361 void HtmlDocVisitor::visitPre(DocSimpleListItem *)
1362 {
1363   if (m_hide) return;
1364   m_t << "<li>";
1365 }
1366
1367 void HtmlDocVisitor::visitPost(DocSimpleListItem *li) 
1368 {
1369   if (m_hide) return;
1370   m_t << "</li>";
1371   if (!li->isPreformatted()) m_t << "\n";
1372 }
1373
1374 void HtmlDocVisitor::visitPre(DocSection *s)
1375 {
1376   if (m_hide) return;
1377   forceEndParagraph(s);
1378   m_t << "<h" << s->level() << getDirHtmlClassOfNode(getTextDirByConfig(s->title())) << ">";
1379   m_t << "<a class=\"anchor\" id=\"" << s->anchor();
1380   m_t << "\"></a>" << endl;
1381   filter(convertCharEntitiesToUTF8(s->title().data()));
1382   m_t << "</h" << s->level() << ">\n";
1383 }
1384
1385 void HtmlDocVisitor::visitPost(DocSection *s) 
1386 {
1387   forceStartParagraph(s);
1388 }
1389
1390 void HtmlDocVisitor::visitPre(DocHtmlList *s)
1391 {
1392   if (m_hide) return;
1393   forceEndParagraph(s);
1394   if (s->type()==DocHtmlList::Ordered) 
1395   {
1396     m_t << "<ol" << htmlAttribsToString(s->attribs()); 
1397   }
1398   else 
1399   {
1400     m_t << "<ul" << htmlAttribsToString(s->attribs());
1401   }
1402   m_t << getDirHtmlClassOfNode(getTextDirByConfig(s)) << ">\n";
1403 }
1404
1405 void HtmlDocVisitor::visitPost(DocHtmlList *s) 
1406 {
1407   if (m_hide) return;
1408   if (s->type()==DocHtmlList::Ordered) 
1409   {
1410     m_t << "</ol>"; 
1411   }
1412   else
1413   { 
1414     m_t << "</ul>";
1415   }
1416   if (!s->isPreformatted()) m_t << "\n";
1417   forceStartParagraph(s);
1418 }
1419
1420 void HtmlDocVisitor::visitPre(DocHtmlListItem *i)
1421 {
1422   if (m_hide) return;
1423   m_t << "<li" << htmlAttribsToString(i->attribs()) << ">";
1424   if (!i->isPreformatted()) m_t << "\n";
1425 }
1426
1427 void HtmlDocVisitor::visitPost(DocHtmlListItem *) 
1428 {
1429   if (m_hide) return;
1430   m_t << "</li>\n";
1431 }
1432
1433 void HtmlDocVisitor::visitPre(DocHtmlDescList *dl)
1434 {
1435   if (m_hide) return;
1436   forceEndParagraph(dl);
1437   m_t << "<dl" << htmlAttribsToString(dl->attribs()) << ">\n";
1438 }
1439
1440 void HtmlDocVisitor::visitPost(DocHtmlDescList *dl) 
1441 {
1442   if (m_hide) return;
1443   m_t << "</dl>\n";
1444   forceStartParagraph(dl);
1445 }
1446
1447 void HtmlDocVisitor::visitPre(DocHtmlDescTitle *dt)
1448 {
1449   if (m_hide) return;
1450   m_t << "<dt" << htmlAttribsToString(dt->attribs())
1451     << getDirHtmlClassOfNode(getTextDirByConfig(dt))
1452     << ">";
1453 }
1454
1455 void HtmlDocVisitor::visitPost(DocHtmlDescTitle *) 
1456 {
1457   if (m_hide) return;
1458   m_t << "</dt>\n";
1459 }
1460
1461 void HtmlDocVisitor::visitPre(DocHtmlDescData *dd)
1462 {
1463   if (m_hide) return;
1464   m_t << "<dd" << htmlAttribsToString(dd->attribs()) 
1465     << getDirHtmlClassOfNode(getTextDirByConfig(dd))
1466     << ">";
1467 }
1468
1469 void HtmlDocVisitor::visitPost(DocHtmlDescData *) 
1470 {
1471   if (m_hide) return;
1472   m_t << "</dd>\n";
1473 }
1474
1475 void HtmlDocVisitor::visitPre(DocHtmlTable *t)
1476 {
1477   if (m_hide) return;
1478
1479   forceEndParagraph(t);
1480
1481   if (t->hasCaption())
1482   {
1483     m_t << "<a class=\"anchor\" id=\"" << t->caption()->anchor() << "\"></a>\n";
1484   }
1485
1486   QString attrs = htmlAttribsToString(t->attribs());
1487   if (attrs.isEmpty())
1488   {
1489     m_t << "<table";
1490     if(t->hasCaption())
1491       m_t << getDirHtmlClassOfNode(getTextDirByConfig(t->caption()), "doxtable");
1492     else
1493       m_t << getDirHtmlClassOfNode(getTextDirByConfig(t), "doxtable");
1494     m_t << ">\n";
1495   }
1496   else
1497   {
1498     m_t << "<table";
1499     if (t->hasCaption())
1500       m_t << getDirHtmlClassOfNode(getTextDirByConfig(t->caption()));
1501     else
1502       m_t << getDirHtmlClassOfNode(getTextDirByConfig(t));
1503     m_t << htmlAttribsToString(t->attribs()) << ">\n";
1504   }
1505 }
1506
1507 void HtmlDocVisitor::visitPost(DocHtmlTable *t) 
1508 {
1509   if (m_hide) return;
1510   m_t << "</table>\n";
1511   forceStartParagraph(t);
1512 }
1513
1514 void HtmlDocVisitor::visitPre(DocHtmlRow *tr)
1515 {
1516   if (m_hide) return;
1517   m_t << "<tr" << htmlAttribsToString(tr->attribs()) << ">\n";
1518 }
1519
1520 void HtmlDocVisitor::visitPost(DocHtmlRow *) 
1521 {
1522   if (m_hide) return;
1523   m_t << "</tr>\n";
1524 }
1525
1526 void HtmlDocVisitor::visitPre(DocHtmlCell *c)
1527 {
1528   if (m_hide) return;
1529   if (c->isHeading()) 
1530   {
1531     m_t << "<th" << htmlAttribsToString(c->attribs()) << ">"; 
1532   }
1533   else 
1534   {
1535     m_t << "<td" << htmlAttribsToString(c->attribs()) << ">";
1536   }
1537 }
1538
1539 void HtmlDocVisitor::visitPost(DocHtmlCell *c) 
1540 {
1541   if (m_hide) return;
1542   if (c->isHeading()) m_t << "</th>"; else m_t << "</td>";
1543 }
1544
1545 void HtmlDocVisitor::visitPre(DocHtmlCaption *c)
1546 {
1547   if (m_hide) return;
1548   m_t << "<caption" << htmlAttribsToString(c->attribs()) << ">";
1549 }
1550
1551 void HtmlDocVisitor::visitPost(DocHtmlCaption *) 
1552 {
1553   if (m_hide) return;
1554   m_t << "</caption>\n";
1555 }
1556
1557 void HtmlDocVisitor::visitPre(DocInternal *)
1558 {
1559   if (m_hide) return;
1560   //forceEndParagraph(i);
1561   //m_t << "<p><b>" << theTranslator->trForInternalUseOnly() << "</b></p>" << endl;
1562 }
1563
1564 void HtmlDocVisitor::visitPost(DocInternal *) 
1565 {
1566   if (m_hide) return;
1567   //forceStartParagraph(i);
1568 }
1569
1570 void HtmlDocVisitor::visitPre(DocHRef *href)
1571 {
1572   if (m_hide) return;
1573   if (href->url().left(7)=="mailto:")
1574   {
1575     writeObfuscatedMailAddress(href->url().mid(7));
1576   }
1577   else
1578   {
1579     QCString url = correctURL(href->url(),href->relPath());
1580     m_t << "<a href=\"" << convertToXML(url)  << "\""
1581         << htmlAttribsToString(href->attribs()) << ">";
1582   }
1583 }
1584
1585 void HtmlDocVisitor::visitPost(DocHRef *) 
1586 {
1587   if (m_hide) return;
1588   m_t << "</a>";
1589 }
1590
1591 void HtmlDocVisitor::visitPre(DocHtmlHeader *header)
1592 {
1593   if (m_hide) return;
1594   forceEndParagraph(header);
1595   m_t << "<h" << header->level() 
1596       << htmlAttribsToString(header->attribs()) 
1597       << getDirHtmlClassOfNode(getTextDirByConfig(header))
1598       << ">";
1599 }
1600
1601 void HtmlDocVisitor::visitPost(DocHtmlHeader *header) 
1602 {
1603   if (m_hide) return;
1604   m_t << "</h" << header->level() << ">\n";
1605   forceStartParagraph(header);
1606 }
1607
1608 void HtmlDocVisitor::visitPre(DocImage *img)
1609 {
1610   if (img->type()==DocImage::Html)
1611   {
1612     bool inlineImage = img->isInlineImage();
1613     bool typeSVG = FALSE;
1614
1615     QCString url = img->url();
1616     if (url.isEmpty())
1617     {
1618       typeSVG = (img->name().right(4)==".svg");
1619     }
1620     else
1621     {
1622       typeSVG = (url.right(4)==".svg");
1623     }
1624     if (!inlineImage)
1625     {
1626       forceEndParagraph(img);
1627     }
1628     if (m_hide) return;
1629     QString baseName=img->name();
1630     int i;
1631     if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1)
1632     {
1633       baseName=baseName.right(baseName.length()-i-1);
1634     }
1635     if (!inlineImage) m_t << "<div class=\"image\">" << endl;
1636     QCString sizeAttribs;
1637     if (!img->width().isEmpty())
1638     {
1639       sizeAttribs+=" width=\""+img->width()+"\"";
1640     }
1641     if (!img->height().isEmpty()) // link to local file
1642     {
1643       sizeAttribs+=" height=\""+img->height()+"\"";
1644     }
1645     if (url.isEmpty())
1646     {
1647       if (typeSVG)
1648       {
1649         m_t << "<object type=\"image/svg+xml\" data=\"" << img->relPath() << img->name()
1650             << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()) << ">" << baseName
1651             << "</object>" << endl;
1652       }
1653       else
1654       {
1655         m_t << "<img src=\"" << img->relPath() << img->name() << "\" alt=\""
1656             << baseName << "\"" << sizeAttribs << htmlAttribsToString(img->attribs())
1657             << (inlineImage ? " class=\"inline\"" : "/>\n");
1658       }
1659     }
1660     else // link to URL
1661     {
1662       if (typeSVG)
1663       {
1664         m_t << "<object type=\"image/svg+xml\" data=\"" << correctURL(url,img->relPath())
1665             << "\"" << sizeAttribs << htmlAttribsToString(img->attribs())
1666             << "></object>" << endl;
1667       }
1668       else
1669       {
1670         m_t << "<img src=\"" << correctURL(url,img->relPath()) << "\""
1671             << sizeAttribs << htmlAttribsToString(img->attribs(), TRUE)
1672             << (inlineImage ? " class=\"inline\"" : "/>\n");
1673       }
1674     }
1675     if (img->hasCaption())
1676     {
1677       if (inlineImage)
1678       {
1679        m_t << " title=\"";
1680       }
1681       else
1682       {
1683         m_t << "<div class=\"caption\">" << endl;
1684         m_t << getHtmlDirEmbedingChar(getTextDirByConfig(img));
1685       }
1686     }
1687     else if (inlineImage)
1688     {
1689       m_t << "/>" << endl;
1690     }
1691   }
1692   else // other format -> skip
1693   {
1694     pushEnabled();
1695     m_hide=TRUE;
1696   }
1697 }
1698
1699 void HtmlDocVisitor::visitPost(DocImage *img)
1700 {
1701   if (img->type()==DocImage::Html)
1702   {
1703     if (m_hide) return;
1704     bool inlineImage = img->isInlineImage();
1705     if (img->hasCaption())
1706     {
1707       if (inlineImage)
1708         m_t << "\"/>\n ";
1709       else
1710         m_t << "</div>";
1711     }
1712     if (!inlineImage)
1713     {
1714       m_t << "</div>" << endl;
1715       forceStartParagraph(img);
1716     }
1717   }
1718   else // other format
1719   {
1720     popEnabled();
1721   }
1722 }
1723
1724 void HtmlDocVisitor::visitPre(DocDotFile *df)
1725 {
1726   if (m_hide) return;
1727   m_t << "<div class=\"dotgraph\">" << endl;
1728   writeDotFile(df->file(),df->relPath(),df->context());
1729   if (df->hasCaption())
1730   { 
1731     m_t << "<div class=\"caption\">" << endl;
1732   }
1733 }
1734
1735 void HtmlDocVisitor::visitPost(DocDotFile *df) 
1736 {
1737   if (m_hide) return;
1738   if (df->hasCaption())
1739   {
1740     m_t << "</div>" << endl;
1741   }
1742   m_t << "</div>" << endl;
1743 }
1744
1745 void HtmlDocVisitor::visitPre(DocMscFile *df)
1746 {
1747   if (m_hide) return;
1748   m_t << "<div class=\"mscgraph\">" << endl;
1749   writeMscFile(df->file(),df->relPath(),df->context());
1750   if (df->hasCaption())
1751   { 
1752     m_t << "<div class=\"caption\">" << endl;
1753   }
1754 }
1755 void HtmlDocVisitor::visitPost(DocMscFile *df) 
1756 {
1757   if (m_hide) return;
1758   if (df->hasCaption())
1759   {
1760     m_t << "</div>" << endl;
1761   }
1762   m_t << "</div>" << endl;
1763 }
1764
1765 void HtmlDocVisitor::visitPre(DocDiaFile *df)
1766 {
1767   if (m_hide) return;
1768   m_t << "<div class=\"diagraph\">" << endl;
1769   writeDiaFile(df->file(),df->relPath(),df->context());
1770   if (df->hasCaption())
1771   {
1772     m_t << "<div class=\"caption\">" << endl;
1773   }
1774 }
1775 void HtmlDocVisitor::visitPost(DocDiaFile *df)
1776 {
1777   if (m_hide) return;
1778   if (df->hasCaption())
1779   {
1780     m_t << "</div>" << endl;
1781   }
1782   m_t << "</div>" << endl;
1783 }
1784
1785 void HtmlDocVisitor::visitPre(DocLink *lnk)
1786 {
1787   if (m_hide) return;
1788   startLink(lnk->ref(),lnk->file(),lnk->relPath(),lnk->anchor());
1789 }
1790
1791 void HtmlDocVisitor::visitPost(DocLink *) 
1792 {
1793   if (m_hide) return;
1794   endLink();
1795 }
1796
1797 void HtmlDocVisitor::visitPre(DocRef *ref)
1798 {
1799   if (m_hide) return;
1800   if (!ref->file().isEmpty()) 
1801   {
1802     // when ref->isSubPage()==TRUE we use ref->file() for HTML and
1803     // ref->anchor() for LaTeX/RTF
1804     startLink(ref->ref(),ref->file(),ref->relPath(),ref->isSubPage() ? QCString() : ref->anchor());
1805   }
1806   if (!ref->hasLinkText()) filter(ref->targetTitle());
1807 }
1808
1809 void HtmlDocVisitor::visitPost(DocRef *ref) 
1810 {
1811   if (m_hide) return;
1812   if (!ref->file().isEmpty()) endLink();
1813   //m_t << " ";
1814 }
1815
1816 void HtmlDocVisitor::visitPre(DocSecRefItem *ref)
1817 {
1818   if (m_hide) return;
1819   QString refName=ref->file();
1820   if (refName.right(Doxygen::htmlFileExtension.length())!=
1821       QString(Doxygen::htmlFileExtension))
1822   {
1823     refName+=Doxygen::htmlFileExtension;
1824   }
1825   m_t << "<li><a href=\"" << refName << "#" << ref->anchor() << "\">";
1826
1827 }
1828
1829 void HtmlDocVisitor::visitPost(DocSecRefItem *) 
1830 {
1831   if (m_hide) return;
1832   m_t << "</a></li>\n";
1833 }
1834
1835 void HtmlDocVisitor::visitPre(DocSecRefList *s)
1836 {
1837   if (m_hide) return;
1838   forceEndParagraph(s);
1839   m_t << "<div class=\"multicol\">" << endl;
1840   m_t << "<ul>" << endl;
1841 }
1842
1843 void HtmlDocVisitor::visitPost(DocSecRefList *s) 
1844 {
1845   if (m_hide) return;
1846   m_t << "</ul>" << endl;
1847   m_t << "</div>" << endl;
1848   forceStartParagraph(s);
1849 }
1850
1851 //void HtmlDocVisitor::visitPre(DocLanguage *l)
1852 //{
1853 //  QString langId = Config_getEnum(OUTPUT_LANGUAGE);
1854 //  if (l->id().lower()!=langId.lower())
1855 //  {
1856 //    pushEnabled();
1857 //    m_hide = TRUE;
1858 //  }
1859 //}
1860 //
1861 //void HtmlDocVisitor::visitPost(DocLanguage *l) 
1862 //{
1863 //  QString langId = Config_getEnum(OUTPUT_LANGUAGE);
1864 //  if (l->id().lower()!=langId.lower())
1865 //  {
1866 //    popEnabled();
1867 //  }
1868 //}
1869
1870 void HtmlDocVisitor::visitPre(DocParamSect *s)
1871 {
1872   if (m_hide) return;
1873   forceEndParagraph(s);
1874   QCString className;
1875   QCString heading;
1876   switch(s->type())
1877   {
1878     case DocParamSect::Param: 
1879       heading=theTranslator->trParameters(); 
1880       className="params";
1881       break;
1882     case DocParamSect::RetVal: 
1883       heading=theTranslator->trReturnValues(); 
1884       className="retval";
1885       break;
1886     case DocParamSect::Exception: 
1887       heading=theTranslator->trExceptions(); 
1888       className="exception";
1889       break;
1890     case DocParamSect::TemplateParam: 
1891       heading=theTranslator->trTemplateParameters();
1892       className="tparams";
1893       break;
1894     default:
1895       ASSERT(0);
1896   }
1897   m_t << "<dl class=\"" << className << "\"><dt>";
1898   m_t << heading;
1899   m_t << "</dt><dd>" << endl;
1900   m_t << "  <table class=\"" << className << "\">" << endl;
1901 }
1902
1903 void HtmlDocVisitor::visitPost(DocParamSect *s)
1904 {
1905   if (m_hide) return;
1906   m_t << "  </table>" << endl;
1907   m_t << "  </dd>" << endl;
1908   m_t << "</dl>" << endl;
1909   forceStartParagraph(s);
1910 }
1911
1912 void HtmlDocVisitor::visitPre(DocParamList *pl)
1913 {
1914   //printf("DocParamList::visitPre\n");
1915   if (m_hide) return;
1916   m_t << "    <tr>";
1917   DocParamSect *sect = 0;
1918   if (pl->parent()->kind()==DocNode::Kind_ParamSect)
1919   {
1920     sect=(DocParamSect*)pl->parent();
1921   }
1922   if (sect && sect->hasInOutSpecifier())
1923   {
1924     m_t << "<td class=\"paramdir\">";
1925     if (pl->direction()!=DocParamSect::Unspecified)
1926     {
1927       m_t << "[";
1928       if (pl->direction()==DocParamSect::In)
1929       {
1930         m_t << "in";
1931       }
1932       else if (pl->direction()==DocParamSect::Out)
1933       {
1934         m_t << "out";
1935       }
1936       else if (pl->direction()==DocParamSect::InOut)
1937       {
1938         m_t << "in,out";
1939       }
1940       m_t << "]";
1941     }
1942     m_t << "</td>";
1943   }
1944   if (sect && sect->hasTypeSpecifier())
1945   {
1946     m_t << "<td class=\"paramtype\">";
1947     QListIterator<DocNode> li(pl->paramTypes());
1948     DocNode *type;
1949     bool first=TRUE;
1950     for (li.toFirst();(type=li.current());++li)
1951     {
1952       if (!first) m_t << "&#160;|&#160;"; else first=FALSE;
1953       if (type->kind()==DocNode::Kind_Word)
1954       {
1955         visit((DocWord*)type); 
1956       }
1957       else if (type->kind()==DocNode::Kind_LinkedWord)
1958       {
1959         visit((DocLinkedWord*)type); 
1960       }
1961     }
1962     m_t << "</td>";
1963   }
1964   m_t << "<td class=\"paramname\">";
1965   //QStrListIterator li(pl->parameters());
1966   //const char *s;
1967   QListIterator<DocNode> li(pl->parameters());
1968   DocNode *param;
1969   bool first=TRUE;
1970   for (li.toFirst();(param=li.current());++li)
1971   {
1972     if (!first) m_t << ","; else first=FALSE;
1973     if (param->kind()==DocNode::Kind_Word)
1974     {
1975       visit((DocWord*)param); 
1976     }
1977     else if (param->kind()==DocNode::Kind_LinkedWord)
1978     {
1979       visit((DocLinkedWord*)param); 
1980     }
1981   }
1982   m_t << "</td><td>";
1983 }
1984
1985 void HtmlDocVisitor::visitPost(DocParamList *)
1986 {
1987   //printf("DocParamList::visitPost\n");
1988   if (m_hide) return;
1989   m_t << "</td></tr>" << endl;
1990 }
1991
1992 void HtmlDocVisitor::visitPre(DocXRefItem *x)
1993 {
1994   if (m_hide) return;
1995   if (x->title().isEmpty()) return;
1996
1997   forceEndParagraph(x);
1998   bool anonymousEnum = x->file()=="@";
1999   if (!anonymousEnum)
2000   {
2001     m_t << "<dl" << getDirHtmlClassOfNode(getTextDirByConfig(x), x->key())  
2002         << "><dt><b><a class=\"el\" href=\""
2003         << x->relPath() << x->file() << Doxygen::htmlFileExtension 
2004         << "#" << x->anchor() << "\">";
2005   }
2006   else 
2007   {
2008     m_t << "<dl class=\"" << x->key() << "\"><dt><b>";
2009   }
2010   filter(x->title());
2011   m_t << ":";
2012   if (!anonymousEnum) m_t << "</a>";
2013   m_t << "</b></dt><dd>";
2014 }
2015
2016 void HtmlDocVisitor::visitPost(DocXRefItem *x)
2017 {
2018   if (m_hide) return;
2019   if (x->title().isEmpty()) return;
2020   m_t << "</dd></dl>" << endl;
2021   forceStartParagraph(x);
2022 }
2023
2024 void HtmlDocVisitor::visitPre(DocInternalRef *ref)
2025 {
2026   if (m_hide) return;
2027   startLink(0,ref->file(),ref->relPath(),ref->anchor());
2028 }
2029
2030 void HtmlDocVisitor::visitPost(DocInternalRef *) 
2031 {
2032   if (m_hide) return;
2033   endLink();
2034   m_t << " ";
2035 }
2036
2037 void HtmlDocVisitor::visitPre(DocCopy *)
2038 {
2039 }
2040
2041 void HtmlDocVisitor::visitPost(DocCopy *)
2042 {
2043 }
2044
2045 void HtmlDocVisitor::visitPre(DocText *)
2046 {
2047 }
2048
2049 void HtmlDocVisitor::visitPost(DocText *)
2050 {
2051 }
2052
2053 void HtmlDocVisitor::visitPre(DocHtmlBlockQuote *b)
2054 {
2055   if (m_hide) return;
2056   forceEndParagraph(b);
2057   QString attrs = htmlAttribsToString(b->attribs());
2058   if (attrs.isEmpty())
2059   {
2060     m_t << "<blockquote" << getDirHtmlClassOfNode(getTextDirByConfig(b), "doxtable")
2061       << ">\n";
2062   }
2063   else
2064   {
2065     m_t << "<blockquote" << getDirHtmlClassOfNode(getTextDirByConfig(b))
2066       << htmlAttribsToString(b->attribs()) << ">\n";
2067   }
2068 }
2069
2070 void HtmlDocVisitor::visitPost(DocHtmlBlockQuote *b)
2071 {
2072   if (m_hide) return;
2073   m_t << "</blockquote>" << endl;
2074   forceStartParagraph(b);
2075 }
2076
2077 void HtmlDocVisitor::visitPre(DocVhdlFlow *vf)
2078 {
2079   if (m_hide) return;
2080   if (VhdlDocGen::getFlowMember()) // use VHDL flow chart creator
2081   {
2082     forceEndParagraph(vf);
2083     QCString fname=FlowChart::convertNameToFileName();
2084     m_t << "<p>";
2085     m_t << "flowchart: " ; // TODO: translate me
2086     m_t << "<a href=\"";
2087     m_t << fname.data(); 
2088     m_t << ".svg\">";
2089     m_t << VhdlDocGen::getFlowMember()->name().data();
2090     m_t << "</a>";
2091     if (vf->hasCaption())
2092     {
2093       m_t << "<br />";
2094     }
2095   }
2096 }
2097
2098 void HtmlDocVisitor::visitPost(DocVhdlFlow *vf)
2099 {
2100   if (m_hide) return;
2101   if (VhdlDocGen::getFlowMember()) // use VHDL flow chart creator
2102   {
2103     m_t << "</p>";
2104     forceStartParagraph(vf);
2105   }
2106 }
2107
2108 void HtmlDocVisitor::visitPre(DocParBlock *)
2109 {
2110   if (m_hide) return;
2111 }
2112
2113 void HtmlDocVisitor::visitPost(DocParBlock *)
2114 {
2115   if (m_hide) return;
2116 }
2117
2118
2119
2120 void HtmlDocVisitor::filter(const char *str)
2121
2122   if (str==0) return;
2123   const char *p=str;
2124   char c;
2125   while (*p)
2126   {
2127     c=*p++;
2128     switch(c)
2129     {
2130       case '<':  m_t << "&lt;"; break;
2131       case '>':  m_t << "&gt;"; break;
2132       case '&':  m_t << "&amp;"; break;
2133       default:   m_t << c;
2134     }
2135   }
2136 }
2137
2138 /// Escape basic entities to produce a valid CDATA attribute value,
2139 /// assume that the outer quoting will be using the double quote &quot;
2140 void HtmlDocVisitor::filterQuotedCdataAttr(const char* str)
2141 {
2142   if (str==0) return;
2143   const char *p=str;
2144   char c;
2145   while (*p)
2146   {
2147     c=*p++;
2148     switch(c)
2149     {
2150       case '&':  m_t << "&amp;"; break;
2151       case '"':  m_t << "&quot;"; break;
2152       case '<':  m_t << "&lt;"; break;
2153       case '>':  m_t << "&gt;"; break;
2154       default:   m_t << c;
2155     }
2156   }
2157 }
2158
2159 void HtmlDocVisitor::startLink(const QCString &ref,const QCString &file,
2160                                const QCString &relPath,const QCString &anchor,
2161                                const QCString &tooltip)
2162 {
2163   //printf("HtmlDocVisitor: file=%s anchor=%s\n",file.data(),anchor.data());
2164   if (!ref.isEmpty()) // link to entity imported via tag file
2165   {
2166     m_t << "<a class=\"elRef\" ";
2167     m_t << externalLinkTarget() << externalRef(relPath,ref,FALSE);
2168   }
2169   else // local link
2170   {
2171     m_t << "<a class=\"el\" ";
2172   }
2173   m_t << "href=\"";
2174   m_t << externalRef(relPath,ref,TRUE);
2175   if (!file.isEmpty()) m_t << file << Doxygen::htmlFileExtension;
2176   if (!anchor.isEmpty()) m_t << "#" << anchor;
2177   m_t << "\"";
2178   if (!tooltip.isEmpty()) m_t << " title=\"" << convertToHtml(tooltip) << "\"";
2179   m_t << ">";
2180 }
2181
2182 void HtmlDocVisitor::endLink()
2183 {
2184   m_t << "</a>";
2185 }
2186
2187 void HtmlDocVisitor::pushEnabled()
2188 {
2189   m_enabled.push(new bool(m_hide));
2190 }
2191
2192 void HtmlDocVisitor::popEnabled()
2193 {
2194   bool *v=m_enabled.pop();
2195   ASSERT(v!=0);
2196   m_hide = *v;
2197   delete v;
2198 }
2199
2200 void HtmlDocVisitor::writeDotFile(const QCString &fn,const QCString &relPath,
2201                                   const QCString &context)
2202 {
2203   QCString baseName=fn;
2204   int i;
2205   if ((i=baseName.findRev('/'))!=-1)
2206   {
2207     baseName=baseName.right(baseName.length()-i-1);
2208   }
2209   if ((i=baseName.find('.'))!=-1) // strip extension
2210   {
2211     baseName=baseName.left(i);
2212   }
2213   baseName.prepend("dot_");
2214   QCString outDir = Config_getString(HTML_OUTPUT);
2215   writeDotGraphFromFile(fn,outDir,baseName,GOF_BITMAP);
2216   writeDotImageMapFromFile(m_t,fn,outDir,relPath,baseName,context);
2217 }
2218
2219 void HtmlDocVisitor::writeMscFile(const QCString &fileName,
2220                                   const QCString &relPath,
2221                                   const QCString &context)
2222 {
2223   QCString baseName=fileName;
2224   int i;
2225   if ((i=baseName.findRev('/'))!=-1) // strip path
2226   {
2227     baseName=baseName.right(baseName.length()-i-1);
2228   }
2229   if ((i=baseName.find('.'))!=-1) // strip extension
2230   {
2231     baseName=baseName.left(i);
2232   }
2233   baseName.prepend("msc_");
2234   QCString outDir = Config_getString(HTML_OUTPUT);
2235   QCString imgExt = getDotImageExtension();
2236   MscOutputFormat mscFormat = MSC_BITMAP;
2237   if ("svg" == imgExt)
2238     mscFormat = MSC_SVG;
2239   writeMscGraphFromFile(fileName,outDir,baseName,mscFormat);
2240   writeMscImageMapFromFile(m_t,fileName,outDir,relPath,baseName,context,mscFormat);
2241 }
2242
2243 void HtmlDocVisitor::writeDiaFile(const QCString &fileName,
2244                                   const QCString &relPath,
2245                                   const QCString &)
2246 {
2247   QCString baseName=fileName;
2248   int i;
2249   if ((i=baseName.findRev('/'))!=-1) // strip path
2250   {
2251     baseName=baseName.right(baseName.length()-i-1);
2252   }
2253   if ((i=baseName.find('.'))!=-1) // strip extension
2254   {
2255     baseName=baseName.left(i);
2256   }
2257   baseName.prepend("dia_");
2258   QCString outDir = Config_getString(HTML_OUTPUT);
2259   writeDiaGraphFromFile(fileName,outDir,baseName,DIA_BITMAP);
2260
2261   m_t << "<img src=\"" << relPath << baseName << ".png" << "\" />" << endl;
2262 }
2263
2264 void HtmlDocVisitor::writePlantUMLFile(const QCString &fileName,
2265                                        const QCString &relPath,
2266                                        const QCString &)
2267 {
2268   QCString baseName=fileName;
2269   int i;
2270   if ((i=baseName.findRev('/'))!=-1) // strip path
2271   {
2272     baseName=baseName.right(baseName.length()-i-1);
2273   }
2274   if ((i=baseName.findRev('.'))!=-1) // strip extension
2275   {
2276     baseName=baseName.left(i);
2277   }
2278   static QCString outDir = Config_getString(HTML_OUTPUT);
2279   QCString imgExt = getDotImageExtension();
2280   if (imgExt=="svg")
2281   {
2282     generatePlantUMLOutput(fileName,outDir,PUML_SVG);
2283     //m_t << "<iframe scrolling=\"no\" frameborder=\"0\" src=\"" << relPath << baseName << ".svg" << "\" />" << endl;
2284     //m_t << "<p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p>";
2285     //m_t << "</iframe>" << endl;
2286     m_t << "<object type=\"image/svg+xml\" data=\"" << relPath << baseName << ".svg\"></object>" << endl;
2287   }
2288   else
2289   {
2290     generatePlantUMLOutput(fileName,outDir,PUML_BITMAP);
2291     m_t << "<img src=\"" << relPath << baseName << ".png" << "\" />" << endl;
2292   }
2293 }
2294
2295 /** Returns TRUE if the child nodes in paragraph \a para until \a nodeIndex
2296     contain a style change node that is still active and that style change is one that
2297     must be located outside of a paragraph, i.e. it is a center, div, or pre tag.
2298     See also bug746162.
2299  */
2300 static bool insideStyleChangeThatIsOutsideParagraph(DocPara *para,int nodeIndex)
2301 {
2302   //printf("insideStyleChangeThatIsOutputParagraph(index=%d)\n",nodeIndex);
2303   int styleMask=0;
2304   bool styleOutsideParagraph=FALSE;
2305   while (nodeIndex>=0 && !styleOutsideParagraph)
2306   {
2307     DocNode *n = para->children().at(nodeIndex);
2308     if (n->kind()==DocNode::Kind_StyleChange)
2309     {
2310       DocStyleChange *sc = (DocStyleChange*)n;
2311       if (!sc->enable()) // remember styles that has been closed already
2312       {
2313         styleMask|=(int)sc->style();
2314       }
2315       bool paraStyle = sc->style()==DocStyleChange::Center ||
2316                        sc->style()==DocStyleChange::Div    ||
2317                        sc->style()==DocStyleChange::Preformatted;
2318       //printf("Found style change %s enabled=%d\n",sc->styleString(),sc->enable());
2319       if (sc->enable() && (styleMask&(int)sc->style())==0 && // style change that is still active
2320           paraStyle
2321          )
2322       {
2323         styleOutsideParagraph=TRUE;
2324       }
2325     }
2326     nodeIndex--;
2327   }
2328   return styleOutsideParagraph;
2329 }
2330
2331 /** Used for items found inside a paragraph, which due to XHTML restrictions
2332  *  have to be outside of the paragraph. This method will forcefully end
2333  *  the current paragraph and forceStartParagraph() will restart it.
2334  */
2335 void HtmlDocVisitor::forceEndParagraph(DocNode *n)
2336 {
2337   //printf("forceEndParagraph(%p) %d\n",n,n->kind());
2338   if (n->parent() && n->parent()->kind()==DocNode::Kind_Para)
2339   {
2340     DocPara *para = (DocPara*)n->parent();
2341     int nodeIndex = para->children().findRef(n);
2342     nodeIndex--;
2343     if (nodeIndex<0) return; // first node
2344     while (nodeIndex>=0 && isInvisibleNode(para->children().at(nodeIndex)))
2345     {
2346         nodeIndex--;
2347     }
2348     if (nodeIndex>=0)
2349     {
2350       DocNode *n = para->children().at(nodeIndex);
2351       if (mustBeOutsideParagraph(n)) return;
2352     }
2353     nodeIndex--;
2354     bool styleOutsideParagraph=insideStyleChangeThatIsOutsideParagraph(para,nodeIndex);
2355     bool isFirst;
2356     bool isLast;
2357     getParagraphContext(para,isFirst,isLast);
2358     //printf("forceEnd first=%d last=%d styleOutsideParagraph=%d\n",isFirst,isLast,styleOutsideParagraph);
2359     if (isFirst && isLast) return;
2360     if (styleOutsideParagraph) return;
2361
2362     m_t << "</p>";
2363   }
2364 }
2365
2366 /** Used for items found inside a paragraph, which due to XHTML restrictions
2367  *  have to be outside of the paragraph. This method will forcefully start
2368  *  the paragraph, that was previously ended by forceEndParagraph().
2369  */
2370 void HtmlDocVisitor::forceStartParagraph(DocNode *n)
2371 {
2372   //printf("forceStartParagraph(%p) %d\n",n,n->kind());
2373   if (n->parent() && n->parent()->kind()==DocNode::Kind_Para) // if we are inside a paragraph
2374   {
2375     DocPara *para = (DocPara*)n->parent();
2376     int nodeIndex = para->children().findRef(n);
2377     int numNodes  = para->children().count();
2378     bool styleOutsideParagraph=insideStyleChangeThatIsOutsideParagraph(para,nodeIndex);
2379     if (styleOutsideParagraph) return;
2380     nodeIndex++;
2381     if (nodeIndex==numNodes) return; // last node
2382     while (nodeIndex<numNodes && isInvisibleNode(para->children().at(nodeIndex)))
2383     {
2384       nodeIndex++;
2385     }
2386     if (nodeIndex<numNodes)
2387     {
2388       DocNode *n = para->children().at(nodeIndex);
2389       if (mustBeOutsideParagraph(n)) return; // next element also outside paragraph
2390     }
2391     else
2392     {
2393       return; // only whitespace at the end!
2394     }
2395
2396     bool needsTag = TRUE;
2397     bool isFirst;
2398     bool isLast;
2399     getParagraphContext(para,isFirst,isLast);
2400     if (isFirst && isLast) needsTag = FALSE;
2401     //printf("forceStart first=%d last=%d needsTag=%d\n",isFirst,isLast,needsTag);
2402
2403     if (needsTag)
2404       m_t << "<p" << getDirHtmlClassOfNode(getTextDirByConfig(para, nodeIndex)) << ">";
2405     else
2406       m_t << getHtmlDirEmbedingChar(getTextDirByConfig(para, nodeIndex));
2407   }
2408 }
2409