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 50 of file markdown.h.

Constructor & Destructor Documentation

◆ MarkdownOutlineParser()

MarkdownOutlineParser::MarkdownOutlineParser ( )

Definition at line 3815 of file markdown.cpp.

3815 : p(std::make_unique<Private>())
3816{
3817}
std::unique_ptr< Private > p
Definition markdown.h:64

References p.

◆ ~MarkdownOutlineParser()

MarkdownOutlineParser::~MarkdownOutlineParser ( )
override

Definition at line 3819 of file markdown.cpp.

3820{
3821}

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 60 of file markdown.h.

60{ 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 3823 of file markdown.cpp.

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

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

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

References ParserManager::getOutlineParser(), and 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: