Doxygen
Loading...
Searching...
No Matches
singlecomment.cpp File Reference
#include <cstdio>
#include "singlecomment.h"
#include "docnode.h"
#include "htmldocvisitor.h"
#include "commentscan.h"
#include "commentcnv.h"
#include "markdown.h"
#include "entry.h"
#include "outputlist.h"
Include dependency graph for singlecomment.cpp:

Go to the source code of this file.

Functions

static void generateHtmlOutput (const QCString &fileName, const QCString &doc)
void generateHtmlForComment (const std::string &fn, const std::string &text)
 Helper for implemented the -c option of doxygen, which produces HTML output for a given doxygen formatted string.

Function Documentation

◆ generateHtmlForComment()

void generateHtmlForComment ( const std::string & fn,
const std::string & text )

Helper for implemented the -c option of doxygen, which produces HTML output for a given doxygen formatted string.

Definition at line 54 of file singlecomment.cpp.

55{
56 QCString fileName = "index.html";
57 std::shared_ptr<Entry> root = std::make_shared<Entry>();
58
59 // 1. Pass input through commentcnv
60 std::string convBuf;
61 convBuf.reserve(text.size()+1024);
62 convertCppComments(text,convBuf,"input.md");
63
64 // 2. Pass result through commentscan
65 MarkdownOutlineParser markdownParser;
66 CommentScanner scanner;
67 int lineNr=1;
68 scanner.enterFile(fileName,lineNr);
69 int pos=0;
70 bool needsEntry=false;
72 Markdown markdown(fileName,1,0);
73 QCString processedDocs = markdown.process(convBuf.data(),lineNr,true);
74 std::shared_ptr<Entry> current = std::make_shared<Entry>();
75 current->lang = SrcLangExt::Markdown;
76 current->fileName = fn;
77 current->docFile = fn;
78 current->docLine = 1;
79 auto prot = Protection::Public;
80 while (scanner.parseCommentBlock(&markdownParser,
81 current.get(),
82 processedDocs,
83 fileName,lineNr,
84 false, // isBrief
85 false, // isAutoBriefOn
86 false, // isInbody
87 prot,
88 pos,
89 needsEntry,
90 true, // markdownSupport
91 &guards))
92 {
93 if (needsEntry)
94 {
95 QCString docFile = current->docFile;
96 root->moveToSubEntryAndRefresh(current);
97 current->lang = SrcLangExt::Markdown;
98 current->docFile = docFile;
99 current->docLine = lineNr;
100 }
101 }
102 root->moveToSubEntryAndKeep(current);
103 scanner.leaveFile(fileName,lineNr);
104
105 // 3. Pass result through docparser
106 for (const auto &child : root->children())
107 {
108 if (!child->brief.isEmpty())
109 {
110 generateHtmlOutput(fn,child->brief);
111 }
112 if (!child->doc.isEmpty())
113 {
114 generateHtmlOutput(fn,child->doc);
115 }
116 }
117}
bool parseCommentBlock(OutlineParserInterface *parser, Entry *curEntry, const QCString &comment, const QCString &fileName, int &lineNr, bool isBrief, bool isJavadocStyle, bool isInbody, Protection &prot, int &position, bool &newEntryNeeded, bool markdownEnabled, GuardedSectionStack *guards)
Invokes the comment block parser with the request to parse a single comment block.
void enterFile(const QCString &fileName, int lineNr)
void leaveFile(const QCString &fileName, int lineNr)
Helper class to process markdown formatted text.
Definition markdown.h:32
This is an alternative implementation of QCString.
Definition qcstring.h:101
void convertCppComments(const std::string &inBuf, std::string &outBuf, const std::string &fn)
Converts the comments in a file.
std::stack< GuardedSection > GuardedSectionStack
Definition commentscan.h:48
static void generateHtmlOutput(const QCString &fileName, const QCString &doc)

References convertCppComments(), CommentScanner::enterFile(), generateHtmlOutput(), CommentScanner::leaveFile(), CommentScanner::parseCommentBlock(), and Markdown::process().

Referenced by parseInput().

◆ generateHtmlOutput()

void generateHtmlOutput ( const QCString & fileName,
const QCString & doc )
static

Definition at line 27 of file singlecomment.cpp.

28{
29 //printf("------\n%s\n------\n",qPrint(doc));
30 auto parser { createDocParser() };
31 auto ast { validatingParseDoc(*parser.get(),
32 fileName,
33 1,
34 nullptr,
35 nullptr,
36 doc,
38 .setMarkdownSupport(true)
39 .setAutolinkSupport(true))
40 };
41 const DocNodeAST *astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
42 if (astImpl)
43 {
44 TextStream t;
45 OutputCodeList codeList;
46 codeList.add<HtmlCodeGenerator>(&t);
47 HtmlDocVisitor visitor(t,codeList,nullptr,fileName);
48 std::visit(visitor,astImpl->root);
49 std::string content = t.str()+"\n";
50 fwrite(content.c_str(),content.length(),1,stdout);
51 }
52}
Class representing the abstract syntax tree of a documentation block.
Definition docnode.h:1466
DocNodeVariant root
Definition docnode.h:1491
Generator for HTML code fragments.
Definition htmlgen.h:26
Concrete visitor implementation for HTML output.
Class representing a list of different code generators.
Definition outputlist.h:165
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:195
Text streaming class that buffers data.
Definition textstream.h:36
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:229
IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf, const QCString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const QCString &input, const DocOptions &options)
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:55

References OutputCodeList::add(), createDocParser(), DocNodeAST::root, TextStream::str(), and validatingParseDoc().

Referenced by generateHtmlForComment().