/****************************************************************************** * * * * * Copyright (C) 1997-2002 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its * documentation under the terms of the GNU General Public License is hereby * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * * Documents produced by Doxygen are derivative works derived from the * input used in their production; they are not affected by this license. * */ #include "htmldocvisitor.h" #include "docparser.h" #include "language.h" #include "doxygen.h" #include "outputgen.h" #include "code.h" #include "dot.h" HtmlDocVisitor::HtmlDocVisitor(QTextStream &t,BaseCodeDocInterface &ci) : m_t(t), m_ci(ci), m_insidePre(FALSE), m_hide(FALSE) { } //-------------------------------------- // visitor functions for leaf nodes //-------------------------------------- void HtmlDocVisitor::HtmlDocVisitor::visit(DocWord *w) { if (m_hide) return; filter(w->word()); } void HtmlDocVisitor::HtmlDocVisitor::visit(DocLinkedWord *w) { if (m_hide) return; startLink(w->ref(),w->file(),w->anchor()); filter(w->word()); endLink(); } void HtmlDocVisitor::HtmlDocVisitor::visit(DocWhiteSpace *w) { if (m_hide) return; if (m_insidePre) { m_t << w->chars(); } else { m_t << " "; } } void HtmlDocVisitor::visit(DocSymbol *s) { if (m_hide) return; switch(s->symbol()) { case DocSymbol::BSlash: m_t << "\\"; break; case DocSymbol::At: m_t << "@"; break; case DocSymbol::Less: m_t << "<"; break; case DocSymbol::Greater: m_t << ">"; break; case DocSymbol::Amp: m_t << "&"; break; case DocSymbol::Dollar: m_t << "$"; break; case DocSymbol::Hash: m_t << "#"; break; case DocSymbol::Percent: m_t << "%"; break; case DocSymbol::Copy: m_t << "©"; break; case DocSymbol::Apos: m_t << "'"; break; case DocSymbol::Quot: m_t << "\""; break; case DocSymbol::Uml: m_t << "&" << s->letter() << "uml;"; break; case DocSymbol::Acute: m_t << "&" << s->letter() << "acute;"; break; case DocSymbol::Grave: m_t << "&" << s->letter() << "grave;"; break; case DocSymbol::Circ: m_t << "&" << s->letter() << "circ;"; break; case DocSymbol::Tilde: m_t << "&" << s->letter() << "tilde;"; break; case DocSymbol::Szlig: m_t << "ß"; break; case DocSymbol::Cedil: m_t << "&" << s->letter() << "cedul;"; break; case DocSymbol::Ring: m_t << "&" << s->letter() << "ring;"; break; case DocSymbol::Nbsp: m_t << " "; break; default: printf("Error: unknown symbol found\n"); } } void HtmlDocVisitor::visit(DocURL *u) { if (m_hide) return; m_t << "url() << "\">" << u->url() << ""; } void HtmlDocVisitor::visit(DocLineBreak *) { if (m_hide) return; m_t << "
\n"; } void HtmlDocVisitor::visit(DocHorRuler *) { if (m_hide) return; m_t << "
\n"; } void HtmlDocVisitor::visit(DocStyleChange *s) { if (m_hide) return; switch (s->style()) { case DocStyleChange::Bold: if (s->enable()) m_t << ""; else m_t << " "; break; case DocStyleChange::Italic: if (s->enable()) m_t << ""; else m_t << " "; break; case DocStyleChange::Code: if (s->enable()) m_t << ""; else m_t << " "; break; case DocStyleChange::Subscript: if (s->enable()) m_t << ""; else m_t << " "; break; case DocStyleChange::Superscript: if (s->enable()) m_t << ""; else m_t << " "; break; case DocStyleChange::Center: if (s->enable()) m_t << "
"; else m_t << "
"; break; case DocStyleChange::Small: if (s->enable()) m_t << ""; else m_t << " "; break; } } void HtmlDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; switch(s->type()) { case DocVerbatim::Code: // fall though m_t << "
"; 
      parseCode(m_ci,s->context(),s->text(),FALSE,0);
      m_t << "
"; break; case DocVerbatim::Verbatim: m_t << "
";
      filter(s->text());
      m_t << "
"; break; case DocVerbatim::HtmlOnly: m_t << s->text(); break; case DocVerbatim::LatexOnly: /* nothing */ break; } } void HtmlDocVisitor::visit(DocAnchor *) { if (m_hide) return; m_t << ""; } void HtmlDocVisitor::visit(DocInclude *inc) { if (m_hide) return; switch(inc->type()) { case DocInclude::Include: m_t << "
";
      parseCode(m_ci,inc->context(),inc->text(),FALSE,0);
      m_t << "
"; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: m_t << inc->text(); break; case DocInclude::VerbInclude: m_t << "
";
      filter(inc->text());
      m_t << "
"; break; } } void HtmlDocVisitor::visit(DocIncOperator *op) { //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n", // op->type(),op->isFirst(),op->isLast(),op->text().data()); if (op->isFirst()) { m_t << "
";
    m_hide = TRUE;
  }
  if (op->type()!=DocIncOperator::Skip) 
  {
    parseCode(m_ci,op->context(),op->text(),FALSE,0);
  }
  if (op->isLast())  
  {
    m_hide = FALSE;
    m_t << "
"; } else { m_t << endl; } } void HtmlDocVisitor::visit(DocFormula *f) { if (m_hide) return; if (f->text().at(0)=='\\') m_t << "

" << endl; m_t << "name() << ".png\">"; if (f->text().at(0)=='\\') m_t << endl << "

" << endl; else m_t << " "; } //-------------------------------------- // visitor functions for compound nodes //-------------------------------------- void HtmlDocVisitor::visitPre(DocAutoList *l) { if (l->isEnumList()) { m_t << "

    \n"; } else { m_t << "
\n"; } else { m_t << "\n"; } } void HtmlDocVisitor::visitPre(DocAutoListItem *) { m_t << "
  • "; } void HtmlDocVisitor::visitPost(DocAutoListItem *) { m_t << "
  • "; } void HtmlDocVisitor::visitPre(DocPara *) { } void HtmlDocVisitor::visitPost(DocPara *p) { if (!p->isLast() && // omit

    for last paragraph !(p->parent() && // and for parameter sections p->parent()->kind()==DocNode::Kind_ParamSect ) ) m_t << "\n

    \n"; } void HtmlDocVisitor::visitPre(DocRoot *) { //m_t << "


    New parser:

    \n"; } void HtmlDocVisitor::visitPost(DocRoot *) { //m_t << "

    Old parser:

    \n"; } void HtmlDocVisitor::visitPre(DocSimpleSect *s) { m_t << "
    "; switch(s->type()) { case DocSimpleSect::See: m_t << theTranslator->trSeeAlso(); break; case DocSimpleSect::Return: m_t << theTranslator->trReturns(); break; case DocSimpleSect::Author: m_t << theTranslator->trAuthor(TRUE,TRUE); break; case DocSimpleSect::Authors: m_t << theTranslator->trAuthor(TRUE,FALSE); break; case DocSimpleSect::Version: m_t << theTranslator->trVersion(); break; case DocSimpleSect::Since: m_t << theTranslator->trSince(); break; case DocSimpleSect::Date: m_t << theTranslator->trDate(); break; case DocSimpleSect::Note: m_t << theTranslator->trNote(); break; case DocSimpleSect::Warning: m_t << theTranslator->trWarning(); break; case DocSimpleSect::Pre: m_t << theTranslator->trPrecondition(); break; case DocSimpleSect::Post: m_t << theTranslator->trPostcondition(); break; case DocSimpleSect::Invar: m_t << theTranslator->trInvariant(); break; case DocSimpleSect::Remark: m_t << theTranslator->trRemarks(); break; case DocSimpleSect::Attention: m_t << theTranslator->trAttention(); break; case DocSimpleSect::User: break; case DocSimpleSect::Unknown: break; } // special case 1: user defined title if (s->type()!=DocSimpleSect::User) { m_t << ":
    "; } } void HtmlDocVisitor::visitPost(DocSimpleSect *) { m_t << "
    \n"; } void HtmlDocVisitor::visitPre(DocTitle *) { } void HtmlDocVisitor::visitPost(DocTitle *) { m_t << "
    "; } void HtmlDocVisitor::visitPre(DocSimpleList *) { m_t << "\n"; } void HtmlDocVisitor::visitPre(DocSimpleListItem *) { m_t << "
  • "; } void HtmlDocVisitor::visitPost(DocSimpleListItem *) { m_t << "
  • \n"; } void HtmlDocVisitor::visitPre(DocSection *s) { m_t << "level()+1 << ">"; m_t << "anchor(); filter(s->title()); m_t << "\"" << endl; m_t << "level()+1 << ">\n"; } void HtmlDocVisitor::visitPost(DocSection *) { } void HtmlDocVisitor::visitPre(DocHtmlList *s) { if (s->type()==DocHtmlList::Ordered) m_t << "
      \n"; else m_t << "
    \n"; else m_t << "\n"; } void HtmlDocVisitor::visitPre(DocHtmlListItem *) { m_t << "
  • \n"; } void HtmlDocVisitor::visitPost(DocHtmlListItem *) { m_t << "
  • \n"; } void HtmlDocVisitor::visitPre(DocHtmlPre *) { m_t << "
    \n";
      m_insidePre=TRUE;
    }
    
    void HtmlDocVisitor::visitPost(DocHtmlPre *) 
    {
      m_insidePre=FALSE;
      m_t << "
    \n"; } void HtmlDocVisitor::visitPre(DocHtmlDescList *) { m_t << "
    \n"; } void HtmlDocVisitor::visitPost(DocHtmlDescList *) { m_t << "
    \n"; } void HtmlDocVisitor::visitPre(DocHtmlDescTitle *) { m_t << "
    "; } void HtmlDocVisitor::visitPost(DocHtmlDescTitle *) { m_t << "
    \n"; } void HtmlDocVisitor::visitPre(DocHtmlDescData *) { m_t << "
    "; } void HtmlDocVisitor::visitPost(DocHtmlDescData *) { m_t << "
    \n"; } void HtmlDocVisitor::visitPre(DocHtmlTable *) { m_t << "\n"; } void HtmlDocVisitor::visitPost(DocHtmlTable *) { m_t << "
    \n"; } void HtmlDocVisitor::visitPre(DocHtmlRow *) { m_t << "\n"; } void HtmlDocVisitor::visitPost(DocHtmlRow *) { m_t << "\n"; } void HtmlDocVisitor::visitPre(DocHtmlCell *c) { if (c->isHeading()) m_t << ""; else m_t << ""; } void HtmlDocVisitor::visitPost(DocHtmlCell *c) { if (c->isHeading()) m_t << ""; else m_t << ""; } void HtmlDocVisitor::visitPre(DocHtmlCaption *) { m_t << ""; } void HtmlDocVisitor::visitPost(DocHtmlCaption *) { m_t << "\n"; } void HtmlDocVisitor::visitPre(DocIndexEntry *) { m_hide = TRUE; } void HtmlDocVisitor::visitPost(DocIndexEntry *) { m_hide = FALSE; } void HtmlDocVisitor::visitPre(DocInternal *) { m_t << "

    " << theTranslator->trForInternalUseOnly() << "

    " << endl; m_t << "

    " << endl; } void HtmlDocVisitor::visitPost(DocInternal *) { m_t << "

    " << endl; } void HtmlDocVisitor::visitPre(DocHRef *href) { m_t << "url() << "\">"; } void HtmlDocVisitor::visitPost(DocHRef *) { m_t << ""; } void HtmlDocVisitor::visitPre(DocHtmlHeader *header) { m_t << "level() << ">"; } void HtmlDocVisitor::visitPost(DocHtmlHeader *header) { m_t << "level() << ">\n"; } void HtmlDocVisitor::visitPre(DocImage *img) { if (img->type()==DocImage::Html) { QCString baseName=img->name(); int i; if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1) { baseName=baseName.right(baseName.length()-i-1); } m_t << "
    " << endl; m_t << "name() << "\" alt=\"" << baseName << "\">" << endl; if (img->hasCaption()) { m_t << "

    "; } } else // other format -> skip { m_hide=TRUE; } } void HtmlDocVisitor::visitPost(DocImage *img) { if (img->type()==DocImage::Html) { if (img->hasCaption()) { m_t << "

    "; } m_t << "
    " << endl; } else // other format { m_hide=FALSE; } } void HtmlDocVisitor::visitPre(DocDotFile *df) { QCString baseName=df->file(); int i; if ((i=baseName.findRev('/'))!=-1) { baseName=baseName.right(baseName.length()-i-1); } QCString outDir = Config_getString("HTML_OUTPUT"); writeDotGraphFromFile(df->file(),outDir,baseName,BITMAP); m_t << "
    " << endl; m_t << "\""" << endl; if (df->hasCaption()) { m_t << "

    "; } } void HtmlDocVisitor::visitPost(DocDotFile *df) { if (df->hasCaption()) { m_t << "

    " << endl; } m_t << "
    " << endl; } void HtmlDocVisitor::visitPre(DocLink *lnk) { startLink(lnk->ref(),lnk->file(),lnk->anchor()); } void HtmlDocVisitor::visitPost(DocLink *) { endLink(); } void HtmlDocVisitor::visitPre(DocRef *ref) { startLink(ref->ref(),ref->file(),ref->anchor()); if (!ref->hasLinkText()) filter(ref->targetTitle()); } void HtmlDocVisitor::visitPost(DocRef *) { endLink(); m_t << " "; } void HtmlDocVisitor::visitPre(DocSecRefItem *ref) { QCString refName=ref->file(); if (refName.right(Doxygen::htmlFileExtension.length())!=Doxygen::htmlFileExtension) { refName+=Doxygen::htmlFileExtension; } m_t << "
  • anchor() << "\">"; } void HtmlDocVisitor::visitPost(DocSecRefItem *) { m_t << " "; } void HtmlDocVisitor::visitPre(DocSecRefList *) { m_t << "" << endl; m_t << "" << endl; m_t << "" << endl; } void HtmlDocVisitor::visitPre(DocLanguage *) { } void HtmlDocVisitor::visitPost(DocLanguage *) { } void HtmlDocVisitor::visitPre(DocParamSect *s) { m_t << "
    "; switch(s->type()) { case DocParamSect::Param: m_t << theTranslator->trParameters(); break; case DocParamSect::RetVal: m_t << theTranslator->trReturnValues(); break; case DocParamSect::Exception: m_t << theTranslator->trExceptions(); break; default: ASSERT(0); } m_t << ":"; m_t << "
    " << endl; m_t << " " << endl; } void HtmlDocVisitor::visitPost(DocParamSect *) { m_t << "
    " << endl; m_t << "
    " << endl; } void HtmlDocVisitor::visitPre(DocParamList *pl) { m_t << " "; QStrListIterator li(pl->parameters()); const char *s; bool first=TRUE; for (li.toFirst();(s=li.current());++li) { if (!first) m_t << ","; else first=FALSE; m_t << s; } m_t << " "; } void HtmlDocVisitor::visitPost(DocParamList *) { m_t << "" << endl; } void HtmlDocVisitor::visitPre(DocXRefItem *x) { m_t << "
    file() << Doxygen::htmlFileExtension << "#" << x->anchor() << "\">"; filter(x->title()); m_t << ":
    "; } void HtmlDocVisitor::visitPost(DocXRefItem *) { m_t << "
    " << endl; } void HtmlDocVisitor::visitPre(DocInternalRef *ref) { startLink(0,ref->file(),ref->anchor()); } void HtmlDocVisitor::visitPost(DocInternalRef *) { endLink(); m_t << " "; } void HtmlDocVisitor::visitPre(DocCopy *) { } void HtmlDocVisitor::visitPost(DocCopy *) { } void HtmlDocVisitor::filter(const char *str) { if (str==0) return; const char *p=str; char c; while (*p) { c=*p++; switch(c) { case '<': m_t << "<"; break; case '>': m_t << ">"; break; case '&': m_t << "&"; break; default: m_t << c; } } } void HtmlDocVisitor::startLink(const QCString &ref,const QCString &file,const QCString &anchor) { QCString *dest; if (!ref.isEmpty()) // link to entity imported via tag file { m_t << ""; } void HtmlDocVisitor::endLink() { m_t << ""; }