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< Private > p

Detailed Description

Definition at line 51 of file markdown.h.

Constructor & Destructor Documentation

◆ MarkdownOutlineParser()

MarkdownOutlineParser::MarkdownOutlineParser ( )

Definition at line 3821 of file markdown.cpp.

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

References p.

◆ ~MarkdownOutlineParser()

MarkdownOutlineParser::~MarkdownOutlineParser ( )
override

Definition at line 3825 of file markdown.cpp.

3826{
3827}

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 3829 of file markdown.cpp.

3833{
3834 std::shared_ptr<Entry> current = std::make_shared<Entry>();
3835 int prepend = 0; // number of empty lines in front
3836 current->lang = SrcLangExt::Markdown;
3837 current->fileName = fileName;
3838 current->docFile = fileName;
3839 current->docLine = 1;
3840 DString docs = stripIndentation(fileBuf);
3841 if (!docs.stripWhiteSpace().size()) return;
3842 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n{}\n",fileBuf);
3843 DString id;
3844 Markdown markdown(fileName,1,0);
3845 bool isIdGenerated = false;
3846 DString title = markdown.extractPageTitle(docs, id, prepend, isIdGenerated).stripWhiteSpace();
3847 DString generatedId;
3848 if (isIdGenerated)
3849 {
3850 generatedId = id;
3851 id = "";
3852 }
3853 int indentLevel=title.empty() ? 0 : -1;
3854 markdown.setIndentLevel(indentLevel);
3855 FileInfo fi(fileName.str());
3856 DString fn = fi.fileName();
3857 DString titleFn = stripExtensionGeneral(fn,getFileNameExtension(fn));
3858 DString mdfileAsMainPage = Config_getString(USE_MDFILE_AS_MAINPAGE);
3859 DString mdFileNameId = markdownFileNameToId(fileName);
3860 bool wasEmpty = id.empty();
3861 if (wasEmpty) id = mdFileNameId;
3862 DString relFileName = stripFromPath(fileName);
3863 bool isSubdirDocs = Config_getBool(IMPLICIT_DIR_DOCS) && relFileName.lower().endsWith("/readme.md");
3864 switch (isExplicitPage(docs))
3865 {
3867 if (!mdfileAsMainPage.empty() &&
3868 (fi.absFilePath()==FileInfo(mdfileAsMainPage.str()).absFilePath()) // file reference with path
3869 )
3870 {
3871 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3872 docs.prepend("@mainpage "+title+"\\ilinebr ");
3873 }
3874 else if (id=="mainpage" || id=="index")
3875 {
3876 if (title.empty()) title = titleFn;
3877 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3878 docs.prepend("@mainpage "+title+"\\ilinebr ");
3879 }
3880 else if (isSubdirDocs)
3881 {
3882 if (!generatedId.empty() && !title.empty())
3883 {
3884 docs.prepend("@section " + generatedId + " " + title + "\\ilinebr ");
3885 }
3886 docs.prepend("@dir\\ilinebr ");
3887 }
3888 else
3889 {
3890 if (title.empty())
3891 {
3892 title = titleFn;
3893 prepend = 0;
3894 }
3895 if (!wasEmpty)
3896 {
3897 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr @ianchor{" + relFileName + "} " + mdFileNameId + "\\ilinebr ");
3898 }
3899 else if (!generatedId.empty())
3900 {
3901 docs.prepend("@ianchor " + generatedId + "\\ilinebr ");
3902 }
3903 else if (Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB)
3904 {
3905 DString autoId = AnchorGenerator::instance().generate(title.str());
3906 docs.prepend("@ianchor{" + title + "} " + autoId + "\\ilinebr ");
3907 }
3908 docs.prepend("@page "+id+" "+title+"\\ilinebr ");
3909 }
3910 for (int i = 0; i < prepend; i++) docs.prepend("\n");
3911 break;
3913 {
3914 // look for `@page label My Title\n` and capture `label` (match[1]) and ` My Title` (match[2])
3915 static const reg::Ex re(R"([ ]*[\\@]page\s+(\a[\w-]*)(\s*[^\n]*)\n)");
3916 reg::Match match;
3917 std::string s = docs.str();
3918 if (reg::search(s,match,re))
3919 {
3920 DString orgLabel = match[1].str();
3921 DString orgTitle = match[2].str();
3922 orgTitle = orgTitle.stripWhiteSpace();
3923 DString newLabel = markdownFileNameToId(fileName);
3924 docs = docs.left(match[1].position())+ // part before label
3925 newLabel+ // new label
3926 match[2].str()+ // part between orgLabel and \n
3927 "\\ilinebr @ianchor{" + orgTitle + "} "+orgLabel+"\n"+ // add original anchor plus \n of above
3928 docs.mid(match.length()); // add remainder of docs
3929 }
3930 }
3931 break;
3933 break;
3935 break;
3936 }
3937 int lineNr=1;
3938
3939 p->commentScanner.enterFile(fileName,lineNr);
3940 Protection prot = Protection::Public;
3941 bool needsEntry = false;
3942 int position=0;
3943 GuardedSectionStack guards;
3944 DString processedDocs = markdown.process(docs,lineNr,true);
3945 while (p->commentScanner.parseCommentBlock(
3946 this,
3947 current.get(),
3948 processedDocs,
3949 fileName,
3950 lineNr,
3951 false, // isBrief
3952 false, // javadoc autobrief
3953 false, // inBodyDocs
3954 prot, // protection
3955 position,
3956 needsEntry,
3957 true,
3958 &guards
3959 ))
3960 {
3961 if (needsEntry)
3962 {
3963 DString docFile = current->docFile;
3964 root->moveToSubEntryAndRefresh(current);
3965 current->lang = SrcLangExt::Markdown;
3966 current->docFile = docFile;
3967 current->docLine = lineNr;
3968 }
3969 }
3970 if (needsEntry)
3971 {
3972 root->moveToSubEntryAndKeep(current);
3973 }
3974 p->commentScanner.leaveFile(fileName,lineNr);
3975}
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:3954
DString getFileNameExtension(const DString &fn)
Definition util.cpp:4219
DString stripIndentation(const DString &s, bool skipFirstLine)
Definition util.cpp:4696
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 3977 of file markdown.cpp.

3978{
3979 Doxygen::parserManager->getOutlineParser("*.cpp")->parsePrototype(text);
3980}
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: