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#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
27static 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, 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}
46
47void generateHtmlForComment(const std::string &fn,const std::string &text)
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)
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.
Helper class to process markdown formatted text.
Definition markdown.h:32
QCString process(const QCString &input, int &startNewlines, bool fromParseInput=false)
Class representing a list of different code generators.
Definition outputlist.h:164
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:194
This is an alternative implementation of QCString.
Definition qcstring.h:101
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
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: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)
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 QCString &fileName, const QCString &doc)
@ Public
Definition types.h:26
@ Markdown
Definition types.h:57