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 47 of file singlecomment.cpp.

48{
49 QCString fileName = "index.html";
50 std::shared_ptr<Entry> root = std::make_shared<Entry>();
51
52 // 1. Pass input through commentcnv
53 std::string convBuf;
54 convBuf.reserve(text.size()+1024);
55 convertCppComments(text,convBuf,"input.md");
56
57 // 2. Pass result through commentscan
58 MarkdownOutlineParser markdownParser;
59 CommentScanner scanner;
60 int lineNr=1;
61 scanner.enterFile(fileName,lineNr);
62 int pos=0;
63 bool needsEntry=false;
65 Markdown markdown(fileName,1,0);
66 QCString processedDocs = markdown.process(convBuf.data(),lineNr,true);
67 std::shared_ptr<Entry> current = std::make_shared<Entry>();
68 current->lang = SrcLangExt::Markdown;
69 current->fileName = fn;
70 current->docFile = fn;
71 current->docLine = 1;
72 auto prot = Protection::Public;
73 while (scanner.parseCommentBlock(&markdownParser,
74 current.get(),
75 processedDocs,
76 fileName,lineNr,
77 false, // isBrief
78 false, // isAutoBriefOn
79 false, // isInbody
80 prot,
81 pos,
82 needsEntry,
83 true, // markdownSupport
84 &guards))
85 {
86 if (needsEntry)
87 {
88 QCString docFile = current->docFile;
89 root->moveToSubEntryAndRefresh(current);
90 current->lang = SrcLangExt::Markdown;
91 current->docFile = docFile;
92 current->docLine = lineNr;
93 }
94 }
95 root->moveToSubEntryAndKeep(current);
96 scanner.leaveFile(fileName,lineNr);
97
98 // 3. Pass result through docparser
99 for (const auto &child : root->children())
100 {
101 if (!child->brief.isEmpty())
102 {
103 generateHtmlOutput(QCString(fn),child->brief);
104 }
105 if (!child->doc.isEmpty())
106 {
107 generateHtmlOutput(QCString(fn),child->doc);
108 }
109 }
110}
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)
@ Public
Definition types.h:26
@ Markdown
Definition types.h:57

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

Referenced by parseInput().

◆ generateHtmlOutput()

static 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, 1, nullptr, nullptr, doc, false, false,
33 QCString(), false, false, true) };
34 const DocNodeAST *astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
35 if (astImpl)
36 {
37 TextStream t;
38 OutputCodeList codeList;
39 codeList.add<HtmlCodeGenerator>(&t);
40 HtmlDocVisitor visitor(t,codeList,nullptr,fileName);
41 std::visit(visitor,astImpl->root);
42 std::string content = t.str()+"\n";
43 fwrite(content.c_str(),content.length(),1,stdout);
44 }
45}
Class representing the abstract syntax tree of a documentation block.
Definition docnode.h:1460
DocNodeVariant root
Definition docnode.h:1481
Generator for HTML code fragments.
Definition htmlgen.h:25
Concrete visitor implementation for HTML output.
Class representing a list of different code generators.
Definition outputlist.h:164
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:194
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
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:54
IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf, const QCString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const QCString &input, bool indexWords, bool isExample, const QCString &exampleName, bool singleLine, bool linkFromIndex, bool markdownSupport)

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

Referenced by generateHtmlForComment().