Doxygen
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// own includes
17#include "singlecomment.h"
18
19// other includes
20#include "commentcnv.h"
21#include "commentscan.h"
22#include "docnode.h"
23#include "entry.h"
24#include "htmldocvisitor.h"
25#include "markdown.h"
26#include "outputlist.h"
27
28static void generateHtmlOutput(const DString &fileName,const DString &doc)
29{
30 //printf("------\n%s\n------\n",qPrint(doc));
31 auto parser { createDocParser() };
32 auto ast { validatingParseDoc(*parser.get(),
33 fileName,
34 1,
35 nullptr,
36 nullptr,
37 doc,
39 .setMarkdownSupport(true)
40 .setAutolinkSupport(true))
41 };
42 const DocNodeAST *astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
43 if (astImpl)
44 {
45 TextStream t;
46 OutputCodeList codeList;
47 codeList.add<HtmlCodeGenerator>(&t);
48 HtmlDocVisitor visitor(t,codeList,nullptr,fileName);
49 std::visit(visitor,astImpl->root);
50 std::string content = t.str()+"\n";
51 fwrite(content.c_str(),content.length(),1,stdout);
52 }
53}
54
55void generateHtmlForComment(const std::string &fn,const std::string &text)
56{
57 DString fileName = "index.html";
58 std::shared_ptr<Entry> root = std::make_shared<Entry>();
59
60 // 1. Pass input through commentcnv
61 std::string convBuf;
62 convBuf.reserve(text.size()+1024);
63 convertCppComments(text,convBuf,"input.md");
64
65 // 2. Pass result through commentscan
66 MarkdownOutlineParser markdownParser;
67 CommentScanner scanner;
68 int lineNr=1;
69 scanner.enterFile(fileName,lineNr);
70 int pos=0;
71 bool needsEntry=false;
73 Markdown markdown(fileName,1,0);
74 DString processedDocs = markdown.process(convBuf.data(),lineNr,true);
75 std::shared_ptr<Entry> current = std::make_shared<Entry>();
76 current->lang = SrcLangExt::Markdown;
77 current->fileName = fn;
78 current->docFile = fn;
79 current->docLine = 1;
80 auto prot = Protection::Public;
81 while (scanner.parseCommentBlock(&markdownParser,
82 current.get(),
83 processedDocs,
84 fileName,lineNr,
85 false, // isBrief
86 false, // isAutoBriefOn
87 false, // isInbody
88 prot,
89 pos,
90 needsEntry,
91 true, // markdownSupport
92 &guards))
93 {
94 if (needsEntry)
95 {
96 DString docFile = current->docFile;
97 root->moveToSubEntryAndRefresh(current);
98 current->lang = SrcLangExt::Markdown;
99 current->docFile = docFile;
100 current->docLine = lineNr;
101 }
102 }
103 root->moveToSubEntryAndKeep(current);
104 scanner.leaveFile(fileName,lineNr);
105
106 // 3. Pass result through docparser
107 for (const auto &child : root->children())
108 {
109 if (!child->brief.empty())
110 {
111 generateHtmlOutput(fn,child->brief);
112 }
113 if (!child->doc.empty())
114 {
115 generateHtmlOutput(fn,child->doc);
116 }
117 }
118}
void enterFile(const DString &fileName, int lineNr)
void leaveFile(const DString &fileName, int lineNr)
bool parseCommentBlock(OutlineParserInterface *parser, Entry *curEntry, const DString &comment, const DString &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.
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
Class representing the abstract syntax tree of a documentation block.
Definition docnode.h:1471
DocNodeVariant root
Definition docnode.h:1496
Generator for HTML code fragments.
Definition htmlgen.h:23
Concrete visitor implementation for HTML output.
Helper class to process markdown formatted text.
Definition markdown.h:33
DString process(const DString &input, int &startNewlines, bool fromParseInput=false)
Class representing a list of different code generators.
Definition outputlist.h:162
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:192
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:232
First pass comment processing.
void convertCppComments(const std::string &inBuf, std::string &outBuf, const std::string &fn)
Converts the comments in a file.
Interface for the comment block scanner.
std::stack< GuardedSection > GuardedSectionStack
Definition commentscan.h:48
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:59
IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf, const DString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const DString &input, const DocOptions &options)
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...
static void generateHtmlOutput(const DString &fileName, const DString &doc)
Helper class to pass options when calling OutputList::generateDoc().
Definition docoptions.h:24