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

Constructor & Destructor Documentation

◆ MarkdownOutlineParser()

MarkdownOutlineParser::MarkdownOutlineParser ( )

Definition at line 3685 of file markdown.cpp.

3685 : p(std::make_unique<Private>())
3686{
3687}
std::unique_ptr< Private > p
Definition markdown.h:60

References p.

◆ ~MarkdownOutlineParser()

MarkdownOutlineParser::~MarkdownOutlineParser ( )
override

Definition at line 3689 of file markdown.cpp.

3690{
3691}

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

56{ 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 3693 of file markdown.cpp.

3697{
3698 std::shared_ptr<Entry> current = std::make_shared<Entry>();
3699 int prepend = 0; // number of empty lines in front
3700 current->lang = SrcLangExt::Markdown;
3701 current->fileName = fileName;
3702 current->docFile = fileName;
3703 current->docLine = 1;
3704 QCString docs = stripIndentation(fileBuf);
3705 if (!docs.stripWhiteSpace().size()) return;
3706 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n{}\n",fileBuf);
3707 QCString id;
3708 Markdown markdown(fileName,1,0);
3709 bool isIdGenerated = false;
3710 QCString title = markdown.extractPageTitle(docs, id, prepend, isIdGenerated).stripWhiteSpace();
3711 QCString generatedId;
3712 if (isIdGenerated)
3713 {
3714 generatedId = id;
3715 id = "";
3716 }
3717 int indentLevel=title.isEmpty() ? 0 : -1;
3718 markdown.setIndentLevel(indentLevel);
3719 FileInfo fi(fileName.str());
3720 QCString fn = fi.fileName();
3721 QCString titleFn = stripExtensionGeneral(fn,getFileNameExtension(fn));
3722 QCString mdfileAsMainPage = Config_getString(USE_MDFILE_AS_MAINPAGE);
3723 QCString mdFileNameId = markdownFileNameToId(fileName);
3724 bool wasEmpty = id.isEmpty();
3725 if (wasEmpty) id = mdFileNameId;
3726 QCString relFileName = stripFromPath(fileName);
3727 bool isSubdirDocs = Config_getBool(IMPLICIT_DIR_DOCS) && relFileName.lower().endsWith("/readme.md");
3728 switch (isExplicitPage(docs))
3729 {
3731 if (!mdfileAsMainPage.isEmpty() &&
3732 (fi.absFilePath()==FileInfo(mdfileAsMainPage.str()).absFilePath()) // file reference with path
3733 )
3734 {
3735 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3736 docs.prepend("@mainpage "+title+"\\ilinebr ");
3737 }
3738 else if (id=="mainpage" || id=="index")
3739 {
3740 if (title.isEmpty()) title = titleFn;
3741 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3742 docs.prepend("@mainpage "+title+"\\ilinebr ");
3743 }
3744 else if (isSubdirDocs)
3745 {
3746 if (!generatedId.isEmpty() && !title.isEmpty())
3747 {
3748 docs.prepend("@section " + generatedId + " " + title + "\\ilinebr ");
3749 }
3750 docs.prepend("@dir\\ilinebr ");
3751 }
3752 else
3753 {
3754 if (title.isEmpty())
3755 {
3756 title = titleFn;
3757 prepend = 0;
3758 }
3759 if (!wasEmpty)
3760 {
3761 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr @ianchor{" + relFileName + "} " + mdFileNameId + "\\ilinebr ");
3762 }
3763 else if (!generatedId.isEmpty())
3764 {
3765 docs.prepend("@ianchor " + generatedId + "\\ilinebr ");
3766 }
3767 else if (Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB)
3768 {
3769 QCString autoId = AnchorGenerator::instance().generate(title.str());
3770 docs.prepend("@ianchor{" + title + "} " + autoId + "\\ilinebr ");
3771 }
3772 docs.prepend("@page "+id+" "+title+"\\ilinebr ");
3773 }
3774 for (int i = 0; i < prepend; i++) docs.prepend("\n");
3775 break;
3777 {
3778 // look for `@page label My Title\n` and capture `label` (match[1]) and ` My Title` (match[2])
3779 static const reg::Ex re(R"([ ]*[\\@]page\s+(\a[\w-]*)(\s*[^\n]*)\n)");
3780 reg::Match match;
3781 std::string s = docs.str();
3782 if (reg::search(s,match,re))
3783 {
3784 QCString orgLabel = match[1].str();
3785 QCString orgTitle = match[2].str();
3786 orgTitle = orgTitle.stripWhiteSpace();
3787 QCString newLabel = markdownFileNameToId(fileName);
3788 docs = docs.left(match[1].position())+ // part before label
3789 newLabel+ // new label
3790 match[2].str()+ // part between orgLabel and \n
3791 "\\ilinebr @ianchor{" + orgTitle + "} "+orgLabel+"\n"+ // add original anchor plus \n of above
3792 docs.right(docs.length()-match.length()); // add remainder of docs
3793 }
3794 }
3795 break;
3797 break;
3799 break;
3800 }
3801 int lineNr=1;
3802
3803 p->commentScanner.enterFile(fileName,lineNr);
3804 Protection prot = Protection::Public;
3805 bool needsEntry = false;
3806 int position=0;
3807 GuardedSectionStack guards;
3808 QCString processedDocs = markdown.process(docs,lineNr,true);
3809 while (p->commentScanner.parseCommentBlock(
3810 this,
3811 current.get(),
3812 processedDocs,
3813 fileName,
3814 lineNr,
3815 FALSE, // isBrief
3816 FALSE, // javadoc autobrief
3817 FALSE, // inBodyDocs
3818 prot, // protection
3819 position,
3820 needsEntry,
3821 true,
3822 &guards
3823 ))
3824 {
3825 if (needsEntry)
3826 {
3827 QCString docFile = current->docFile;
3828 root->moveToSubEntryAndRefresh(current);
3829 current->lang = SrcLangExt::Markdown;
3830 current->docFile = docFile;
3831 current->docLine = lineNr;
3832 }
3833 }
3834 if (needsEntry)
3835 {
3836 root->moveToSubEntryAndKeep(current);
3837 }
3838 p->commentScanner.leaveFile(fileName,lineNr);
3839}
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:59
@ 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:748
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:759
Protection
Definition types.h:32
QCString stripIndentation(const QCString &s, bool skipFirstLine)
Definition util.cpp:6468
QCString stripExtensionGeneral(const QCString &fName, const QCString &ext)
Definition util.cpp:5430
static QCString stripFromPath(const QCString &p, const StringVector &l)
Definition util.cpp:310
QCString getFileNameExtension(const QCString &fn)
Definition util.cpp:5766

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

3842{
3843 Doxygen::parserManager->getOutlineParser("*.cpp")->parsePrototype(text);
3844}
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 60 of file markdown.h.

Referenced by MarkdownOutlineParser(), and parseInput().


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