Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
singlecomment.cpp
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2024 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
* Documents produced by Doxygen are derivative works derived from the
12
* input used in their production; they are not affected by this license.
13
*
14
*/
15
16
#include <cstdio>
17
18
#include "
singlecomment.h
"
19
#include "
docnode.h
"
20
#include "
htmldocvisitor.h
"
21
#include "
commentscan.h
"
22
#include "
commentcnv.h
"
23
#include "
markdown.h
"
24
#include "
entry.h
"
25
#include "
outputlist.h
"
26
27
static
void
generateHtmlOutput
(
const
QCString
&fileName,
const
QCString
&doc)
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,
37
DocOptions
()
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
}
53
54
void
generateHtmlForComment
(
const
std::string &fn,
const
std::string &text)
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
;
71
GuardedSectionStack
guards;
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
}
CommentScanner
Definition
commentscan.h:54
CommentScanner::parseCommentBlock
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.
Definition
commentscan.l:4956
CommentScanner::enterFile
void enterFile(const QCString &fileName, int lineNr)
Definition
commentscan.l:5144
CommentScanner::leaveFile
void leaveFile(const QCString &fileName, int lineNr)
Definition
commentscan.l:5150
DocNodeAST
Class representing the abstract syntax tree of a documentation block.
Definition
docnode.h:1463
DocNodeAST::root
DocNodeVariant root
Definition
docnode.h:1488
HtmlCodeGenerator
Generator for HTML code fragments.
Definition
htmlgen.h:26
HtmlDocVisitor
Concrete visitor implementation for HTML output.
Definition
htmldocvisitor.h:30
Markdown
Helper class to process markdown formatted text.
Definition
markdown.h:32
Markdown::process
QCString process(const QCString &input, int &startNewlines, bool fromParseInput=false)
Definition
markdown.cpp:3705
MarkdownOutlineParser
Definition
markdown.h:51
OutputCodeList
Class representing a list of different code generators.
Definition
outputlist.h:165
OutputCodeList::add
void add(OutputCodeIntfPtr &&p)
Definition
outputlist.h:195
QCString
This is an alternative implementation of QCString.
Definition
qcstring.h:101
TextStream
Text streaming class that buffers data.
Definition
textstream.h:36
TextStream::str
std::string str() const
Return the contents of the buffer as a std::string object.
Definition
textstream.h:216
commentcnv.h
First pass comment processing.
convertCppComments
void convertCppComments(const std::string &inBuf, std::string &outBuf, const std::string &fn)
Converts the comments in a file.
Definition
commentcnv.l:2089
commentscan.h
Interface for the comment block scanner.
GuardedSectionStack
std::stack< GuardedSection > GuardedSectionStack
Definition
commentscan.h:48
docnode.h
validatingParseDoc
IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf, const QCString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const QCString &input, const DocOptions &options)
Definition
docparser.cpp:2005
createDocParser
IDocParserPtr createDocParser()
factory function to create a parser
Definition
docparser.cpp:55
entry.h
htmldocvisitor.h
markdown.h
outputlist.h
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 forma...
Definition
singlecomment.cpp:54
generateHtmlOutput
static void generateHtmlOutput(const QCString &fileName, const QCString &doc)
Definition
singlecomment.cpp:27
singlecomment.h
DocOptions
Definition
docoptions.h:23
src
singlecomment.cpp
Generated by
1.17.0