Doxygen
Loading...
Searching...
No Matches
MarkdownOutlineParser Class Reference

#include <src/markdown.h>

Inheritance diagram for MarkdownOutlineParser:
Collaboration diagram for MarkdownOutlineParser:

Classes

struct  Private

Public Member Functions

 MarkdownOutlineParser ()
 ~MarkdownOutlineParser () override
void parseInput (const QCString &fileName, const char *fileBuf, const std::shared_ptr< Entry > &root, ClangTUParser *clangParser) override
 Parses a single input file with the goal to build an Entry tree.
bool needsPreprocessing (const QCString &) const override
 Returns TRUE if the language identified by extension needs the C preprocessor to be run before feed the result to the input parser.
void parsePrototype (const QCString &text) override
 Callback function called by the comment block scanner.

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Definition at line 50 of file markdown.h.

Constructor & Destructor Documentation

◆ MarkdownOutlineParser()

MarkdownOutlineParser::MarkdownOutlineParser ( )

Definition at line 3770 of file markdown.cpp.

3770 : p(std::make_unique<Private>())
3771{
3772}
std::unique_ptr< Private > p
Definition markdown.h:64

References p.

◆ ~MarkdownOutlineParser()

MarkdownOutlineParser::~MarkdownOutlineParser ( )
override

Definition at line 3774 of file markdown.cpp.

3775{
3776}

Member Function Documentation

◆ needsPreprocessing()

bool MarkdownOutlineParser::needsPreprocessing ( const QCString & extension) const
inlineoverridevirtual

Returns TRUE if the language identified by extension needs the C preprocessor to be run before feed the result to the input parser.

See also
parseInput()

Implements OutlineParserInterface.

Definition at line 60 of file markdown.h.

60{ return FALSE; }
#define FALSE
Definition qcstring.h:34

References FALSE.

◆ parseInput()

void MarkdownOutlineParser::parseInput ( const QCString & fileName,
const char * fileBuf,
const std::shared_ptr< Entry > & root,
ClangTUParser * clangParser )
overridevirtual

Parses a single input file with the goal to build an Entry tree.

Parameters
[in]fileNameThe full name of the file.
[in]fileBufThe contents of the file (zero terminated).
[in,out]rootThe root of the tree of Entry *nodes representing the information extracted from the file.
[in]clangParserThe clang translation unit parser object or nullptr if disabled.

Implements OutlineParserInterface.

Definition at line 3778 of file markdown.cpp.

3782{
3783 std::shared_ptr<Entry> current = std::make_shared<Entry>();
3784 int prepend = 0; // number of empty lines in front
3785 current->lang = SrcLangExt::Markdown;
3786 current->fileName = fileName;
3787 current->docFile = fileName;
3788 current->docLine = 1;
3789 QCString docs = stripIndentation(fileBuf);
3790 if (!docs.stripWhiteSpace().size()) return;
3791 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n{}\n",fileBuf);
3792 QCString id;
3793 Markdown markdown(fileName,1,0);
3794 bool isIdGenerated = false;
3795 QCString title = markdown.extractPageTitle(docs, id, prepend, isIdGenerated).stripWhiteSpace();
3796 QCString generatedId;
3797 if (isIdGenerated)
3798 {
3799 generatedId = id;
3800 id = "";
3801 }
3802 int indentLevel=title.isEmpty() ? 0 : -1;
3803 markdown.setIndentLevel(indentLevel);
3804 FileInfo fi(fileName.str());
3805 QCString fn = fi.fileName();
3806 QCString titleFn = stripExtensionGeneral(fn,getFileNameExtension(fn));
3807 QCString mdfileAsMainPage = Config_getString(USE_MDFILE_AS_MAINPAGE);
3808 QCString mdFileNameId = markdownFileNameToId(fileName);
3809 bool wasEmpty = id.isEmpty();
3810 if (wasEmpty) id = mdFileNameId;
3811 QCString relFileName = stripFromPath(fileName);
3812 bool isSubdirDocs = Config_getBool(IMPLICIT_DIR_DOCS) && relFileName.lower().endsWith("/readme.md");
3813 switch (isExplicitPage(docs))
3814 {
3816 if (!mdfileAsMainPage.isEmpty() &&
3817 (fi.absFilePath()==FileInfo(mdfileAsMainPage.str()).absFilePath()) // file reference with path
3818 )
3819 {
3820 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3821 docs.prepend("@mainpage "+title+"\\ilinebr ");
3822 }
3823 else if (id=="mainpage" || id=="index")
3824 {
3825 if (title.isEmpty()) title = titleFn;
3826 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3827 docs.prepend("@mainpage "+title+"\\ilinebr ");
3828 }
3829 else if (isSubdirDocs)
3830 {
3831 if (!generatedId.isEmpty() && !title.isEmpty())
3832 {
3833 docs.prepend("@section " + generatedId + " " + title + "\\ilinebr ");
3834 }
3835 docs.prepend("@dir\\ilinebr ");
3836 }
3837 else
3838 {
3839 if (title.isEmpty())
3840 {
3841 title = titleFn;
3842 prepend = 0;
3843 }
3844 if (!wasEmpty)
3845 {
3846 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr @ianchor{" + relFileName + "} " + mdFileNameId + "\\ilinebr ");
3847 }
3848 else if (!generatedId.isEmpty())
3849 {
3850 docs.prepend("@ianchor " + generatedId + "\\ilinebr ");
3851 }
3852 else if (Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB)
3853 {
3854 QCString autoId = AnchorGenerator::instance().generate(title.str());
3855 docs.prepend("@ianchor{" + title + "} " + autoId + "\\ilinebr ");
3856 }
3857 docs.prepend("@page "+id+" "+title+"\\ilinebr ");
3858 }
3859 for (int i = 0; i < prepend; i++) docs.prepend("\n");
3860 break;
3862 {
3863 // look for `@page label My Title\n` and capture `label` (match[1]) and ` My Title` (match[2])
3864 static const reg::Ex re(R"([ ]*[\\@]page\s+(\a[\w-]*)(\s*[^\n]*)\n)");
3865 reg::Match match;
3866 std::string s = docs.str();
3867 if (reg::search(s,match,re))
3868 {
3869 QCString orgLabel = match[1].str();
3870 QCString orgTitle = match[2].str();
3871 orgTitle = orgTitle.stripWhiteSpace();
3872 QCString newLabel = markdownFileNameToId(fileName);
3873 docs = docs.left(match[1].position())+ // part before label
3874 newLabel+ // new label
3875 match[2].str()+ // part between orgLabel and \n
3876 "\\ilinebr @ianchor{" + orgTitle + "} "+orgLabel+"\n"+ // add original anchor plus \n of above
3877 docs.right(docs.length()-match.length()); // add remainder of docs
3878 }
3879 }
3880 break;
3882 break;
3884 break;
3885 }
3886 int lineNr=1;
3887
3888 p->commentScanner.enterFile(fileName,lineNr);
3889 Protection prot = Protection::Public;
3890 bool needsEntry = false;
3891 int position=0;
3892 GuardedSectionStack guards;
3893 QCString processedDocs = markdown.process(docs,lineNr,true);
3894 while (p->commentScanner.parseCommentBlock(
3895 this,
3896 current.get(),
3897 processedDocs,
3898 fileName,
3899 lineNr,
3900 FALSE, // isBrief
3901 FALSE, // javadoc autobrief
3902 FALSE, // inBodyDocs
3903 prot, // protection
3904 position,
3905 needsEntry,
3906 true,
3907 &guards
3908 ))
3909 {
3910 if (needsEntry)
3911 {
3912 QCString docFile = current->docFile;
3913 root->moveToSubEntryAndRefresh(current);
3914 current->lang = SrcLangExt::Markdown;
3915 current->docFile = docFile;
3916 current->docLine = lineNr;
3917 }
3918 }
3919 if (needsEntry)
3920 {
3921 root->moveToSubEntryAndKeep(current);
3922 }
3923 p->commentScanner.leaveFile(fileName,lineNr);
3924}
static AnchorGenerator & instance()
Returns the singleton instance.
Definition anchor.cpp:38
std::string generate(const std::string &title)
generates an anchor for a section with title.
Definition anchor.cpp:53
@ Markdown
Definition debug.h:37
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:76
QCString & prepend(const char *s)
Definition qcstring.h:422
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
QCString lower() const
Definition qcstring.h:249
bool endsWith(const char *s) const
Definition qcstring.h:524
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:260
const std::string & str() const
Definition qcstring.h:552
QCString right(size_t len) const
Definition qcstring.h:234
size_t size() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:169
QCString left(size_t len) const
Definition qcstring.h:229
std::stack< GuardedSection > GuardedSectionStack
Definition commentscan.h:48
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
#define Config_getEnum(name)
Definition config.h:35
@ explicitMainPage
docs start with a mainpage command
Definition markdown.cpp:69
@ explicitPage
docs start with a page command
Definition markdown.cpp:68
@ notExplicit
docs doesn't start with either page or mainpage
Definition markdown.cpp:71
@ explicitOtherPage
docs start with a dir / defgroup / addtogroup command
Definition markdown.cpp:70
static ExplicitPageResult isExplicitPage(const QCString &docs)
QCString markdownFileNameToId(const QCString &fileName)
processes string s and converts markdown into doxygen/html commands.
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
Definition regex.cpp:844
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:855
Protection
Definition types.h:32
QCString stripIndentation(const QCString &s, bool skipFirstLine)
Definition util.cpp:5901
QCString stripExtensionGeneral(const QCString &fName, const QCString &ext)
Definition util.cpp:4875
static QCString stripFromPath(const QCString &p, const StringVector &l)
Definition util.cpp:300
QCString getFileNameExtension(const QCString &fn)
Definition util.cpp:5189

References FileInfo::absFilePath(), Config_getBool, Config_getEnum, Config_getString, QCString::endsWith(), explicitMainPage, explicitOtherPage, explicitPage, Markdown::extractPageTitle(), FALSE, FileInfo::fileName(), AnchorGenerator::generate(), getFileNameExtension(), AnchorGenerator::instance(), QCString::isEmpty(), isExplicitPage(), QCString::left(), QCString::length(), QCString::lower(), Debug::Markdown, markdownFileNameToId(), notExplicit, p, QCString::prepend(), Debug::print(), Markdown::process(), QCString::right(), reg::search(), Markdown::setIndentLevel(), QCString::size(), QCString::str(), stripExtensionGeneral(), stripFromPath(), stripIndentation(), and QCString::stripWhiteSpace().

◆ parsePrototype()

void MarkdownOutlineParser::parsePrototype ( const QCString & text)
overridevirtual

Callback function called by the comment block scanner.

It provides a string text containing the prototype of a function or variable. The parser should parse this and store the information in the Entry node that corresponds with the node for which the comment block parser was invoked.

Implements OutlineParserInterface.

Definition at line 3926 of file markdown.cpp.

3927{
3928 Doxygen::parserManager->getOutlineParser("*.cpp")->parsePrototype(text);
3929}
static ParserManager * parserManager
Definition doxygen.h:131
std::unique_ptr< OutlineParserInterface > getOutlineParser(const QCString &extension)
Gets the interface to the parser associated with a given extension.
Definition parserintf.h:209

References Doxygen::parserManager.

Member Data Documentation

◆ p

std::unique_ptr<Private> MarkdownOutlineParser::p
private

Definition at line 64 of file markdown.h.

Referenced by MarkdownOutlineParser(), and parseInput().


The documentation for this class was generated from the following files: