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

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

References p.

◆ ~MarkdownOutlineParser()

MarkdownOutlineParser::~MarkdownOutlineParser ( )
override

Definition at line 3820 of file markdown.cpp.

3821{
3822}

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

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

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

3973{
3974 Doxygen::parserManager->getOutlineParser("*.cpp")->parsePrototype(text);
3975}
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: