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

#include <src/markdown.h>

Inheritance diagram for MarkdownOutlineParser:
Collaboration diagram for MarkdownOutlineParser:

Classes

struct  Private

Public Member Functions

 MarkdownOutlineParser ()
 ~MarkdownOutlineParser () override
void parseInput (const DString &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 DString &) 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 DString &text) override
 Callback function called by the comment block scanner.

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Definition at line 51 of file markdown.h.

Constructor & Destructor Documentation

◆ MarkdownOutlineParser()

MarkdownOutlineParser::MarkdownOutlineParser ( )

Definition at line 3820 of file markdown.cpp.

3820 : p(std::make_unique<Private>())
3821{
3822}
std::unique_ptr< Private > p
Definition markdown.h:65

References p.

◆ ~MarkdownOutlineParser()

MarkdownOutlineParser::~MarkdownOutlineParser ( )
override

Definition at line 3824 of file markdown.cpp.

3825{
3826}

Member Function Documentation

◆ needsPreprocessing()

bool MarkdownOutlineParser::needsPreprocessing ( const DString & 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 61 of file markdown.h.

61{ return false; }

◆ parseInput()

void MarkdownOutlineParser::parseInput ( const DString & 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 3828 of file markdown.cpp.

3832{
3833 std::shared_ptr<Entry> current = std::make_shared<Entry>();
3834 int prepend = 0; // number of empty lines in front
3835 current->lang = SrcLangExt::Markdown;
3836 current->fileName = fileName;
3837 current->docFile = fileName;
3838 current->docLine = 1;
3839 DString docs = stripIndentation(fileBuf);
3840 if (!docs.stripWhiteSpace().size()) return;
3841 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n{}\n",fileBuf);
3842 DString id;
3843 Markdown markdown(fileName,1,0);
3844 bool isIdGenerated = false;
3845 DString title = markdown.extractPageTitle(docs, id, prepend, isIdGenerated).stripWhiteSpace();
3846 DString generatedId;
3847 if (isIdGenerated)
3848 {
3849 generatedId = id;
3850 id = "";
3851 }
3852 int indentLevel=title.empty() ? 0 : -1;
3853 markdown.setIndentLevel(indentLevel);
3854 FileInfo fi(fileName.str());
3855 DString fn = fi.fileName();
3856 DString titleFn = stripExtensionGeneral(fn,getFileNameExtension(fn));
3857 DString mdfileAsMainPage = Config_getString(USE_MDFILE_AS_MAINPAGE);
3858 DString mdFileNameId = markdownFileNameToId(fileName);
3859 bool wasEmpty = id.empty();
3860 if (wasEmpty) id = mdFileNameId;
3861 DString relFileName = stripFromPath(fileName);
3862 bool isSubdirDocs = Config_getBool(IMPLICIT_DIR_DOCS) && relFileName.lower().endsWith("/readme.md");
3863 switch (isExplicitPage(docs))
3864 {
3866 if (!mdfileAsMainPage.empty() &&
3867 (fi.absFilePath()==FileInfo(mdfileAsMainPage.str()).absFilePath()) // file reference with path
3868 )
3869 {
3870 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3871 docs.prepend("@mainpage "+title+"\\ilinebr ");
3872 }
3873 else if (id=="mainpage" || id=="index")
3874 {
3875 if (title.empty()) title = titleFn;
3876 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3877 docs.prepend("@mainpage "+title+"\\ilinebr ");
3878 }
3879 else if (isSubdirDocs)
3880 {
3881 if (!generatedId.empty() && !title.empty())
3882 {
3883 docs.prepend("@section " + generatedId + " " + title + "\\ilinebr ");
3884 }
3885 docs.prepend("@dir\\ilinebr ");
3886 }
3887 else
3888 {
3889 if (title.empty())
3890 {
3891 title = titleFn;
3892 prepend = 0;
3893 }
3894 if (!wasEmpty)
3895 {
3896 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr @ianchor{" + relFileName + "} " + mdFileNameId + "\\ilinebr ");
3897 }
3898 else if (!generatedId.empty())
3899 {
3900 docs.prepend("@ianchor " + generatedId + "\\ilinebr ");
3901 }
3902 else if (Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB)
3903 {
3904 DString autoId = AnchorGenerator::instance().generate(title.str());
3905 docs.prepend("@ianchor{" + title + "} " + autoId + "\\ilinebr ");
3906 }
3907 docs.prepend("@page "+id+" "+title+"\\ilinebr ");
3908 }
3909 for (int i = 0; i < prepend; i++) docs.prepend("\n");
3910 break;
3912 {
3913 // look for `@page label My Title\n` and capture `label` (match[1]) and ` My Title` (match[2])
3914 static const reg::Ex re(R"([ ]*[\\@]page\s+(\a[\w-]*)(\s*[^\n]*)\n)");
3915 reg::Match match;
3916 std::string s = docs.str();
3917 if (reg::search(s,match,re))
3918 {
3919 DString orgLabel = match[1].str();
3920 DString orgTitle = match[2].str();
3921 orgTitle = orgTitle.stripWhiteSpace();
3922 DString newLabel = markdownFileNameToId(fileName);
3923 docs = docs.left(match[1].position())+ // part before label
3924 newLabel+ // new label
3925 match[2].str()+ // part between orgLabel and \n
3926 "\\ilinebr @ianchor{" + orgTitle + "} "+orgLabel+"\n"+ // add original anchor plus \n of above
3927 docs.mid(match.length()); // add remainder of docs
3928 }
3929 }
3930 break;
3932 break;
3934 break;
3935 }
3936 int lineNr=1;
3937
3938 p->commentScanner.enterFile(fileName,lineNr);
3939 Protection prot = Protection::Public;
3940 bool needsEntry = false;
3941 int position=0;
3942 GuardedSectionStack guards;
3943 DString processedDocs = markdown.process(docs,lineNr,true);
3944 while (p->commentScanner.parseCommentBlock(
3945 this,
3946 current.get(),
3947 processedDocs,
3948 fileName,
3949 lineNr,
3950 false, // isBrief
3951 false, // javadoc autobrief
3952 false, // inBodyDocs
3953 prot, // protection
3954 position,
3955 needsEntry,
3956 true,
3957 &guards
3958 ))
3959 {
3960 if (needsEntry)
3961 {
3962 DString docFile = current->docFile;
3963 root->moveToSubEntryAndRefresh(current);
3964 current->lang = SrcLangExt::Markdown;
3965 current->docFile = docFile;
3966 current->docLine = lineNr;
3967 }
3968 }
3969 if (needsEntry)
3970 {
3971 root->moveToSubEntryAndKeep(current);
3972 }
3973 p->commentScanner.leaveFile(fileName,lineNr);
3974}
static AnchorGenerator & instance()
Returns the singleton instance.
Definition anchor.cpp:41
std::string generate(const std::string &title)
generates an anchor for a section with title.
Definition anchor.cpp:56
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
DString lower() const
Definition dstring.h:326
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
size_t size() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:154
DString & prepend(const char *s)
Definition dstring.h:515
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
DString left(size_t len) const
Definition dstring.h:306
const std::string & str() const
Definition dstring.h:645
bool endsWith(const char *s) const
Definition dstring.h:617
@ Markdown
Definition debug.h:38
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78
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:76
@ explicitPage
docs start with a page command
Definition markdown.cpp:75
@ notExplicit
docs doesn't start with either page or mainpage
Definition markdown.cpp:78
@ explicitOtherPage
docs start with a dir / defgroup / addtogroup command
Definition markdown.cpp:77
static ExplicitPageResult isExplicitPage(const DString &docs)
DString markdownFileNameToId(const DString &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:850
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:861
Protection
Definition types.h:32
DString stripExtensionGeneral(const DString &fName, const DString &ext)
Definition util.cpp:3945
DString getFileNameExtension(const DString &fn)
Definition util.cpp:4210
DString stripIndentation(const DString &s, bool skipFirstLine)
Definition util.cpp:4683
DString stripFromPath(const DString &path)
Definition util.cpp:219

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

◆ parsePrototype()

void MarkdownOutlineParser::parsePrototype ( const DString & 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 3976 of file markdown.cpp.

3977{
3978 Doxygen::parserManager->getOutlineParser("*.cpp")->parsePrototype(text);
3979}
static ParserManager * parserManager
Definition doxygen.h:122
std::unique_ptr< OutlineParserInterface > getOutlineParser(const DString &extension)
Gets the interface to the parser associated with a given extension.
Definition parserintf.h:244

References ParserManager::getOutlineParser(), and Doxygen::parserManager.

Member Data Documentation

◆ p

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

Definition at line 65 of file markdown.h.

Referenced by MarkdownOutlineParser(), and parseInput().


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