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

3624 : p(std::make_unique<Private>())
3625{
3626}
std::unique_ptr< Private > p
Definition markdown.h:60

References p.

◆ ~MarkdownOutlineParser()

MarkdownOutlineParser::~MarkdownOutlineParser ( )
override

Definition at line 3628 of file markdown.cpp.

3629{
3630}

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

3636{
3637 std::shared_ptr<Entry> current = std::make_shared<Entry>();
3638 int prepend = 0; // number of empty lines in front
3639 current->lang = SrcLangExt::Markdown;
3640 current->fileName = fileName;
3641 current->docFile = fileName;
3642 current->docLine = 1;
3643 QCString docs = stripIndentation(fileBuf);
3644 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n{}\n",fileBuf);
3645 QCString id;
3646 Markdown markdown(fileName,1,0);
3647 bool isIdGenerated = false;
3648 QCString title = markdown.extractPageTitle(docs, id, prepend, isIdGenerated).stripWhiteSpace();
3649 QCString generatedId;
3650 if (isIdGenerated)
3651 {
3652 generatedId = id;
3653 id = "";
3654 }
3655 int indentLevel=title.isEmpty() ? 0 : -1;
3656 markdown.setIndentLevel(indentLevel);
3657 FileInfo fi(fileName.str());
3658 QCString fn = fi.fileName();
3659 QCString titleFn = stripExtensionGeneral(fn,getFileNameExtension(fn));
3660 QCString mdfileAsMainPage = Config_getString(USE_MDFILE_AS_MAINPAGE);
3661 QCString mdFileNameId = markdownFileNameToId(fileName);
3662 bool wasEmpty = id.isEmpty();
3663 if (wasEmpty) id = mdFileNameId;
3664 QCString relFileName = stripFromPath(fileName);
3665 bool isSubdirDocs = Config_getBool(IMPLICIT_DIR_DOCS) && relFileName.lower().endsWith("/readme.md");
3666 switch (isExplicitPage(docs))
3667 {
3669 if (!mdfileAsMainPage.isEmpty() &&
3670 (fi.absFilePath()==FileInfo(mdfileAsMainPage.str()).absFilePath()) // file reference with path
3671 )
3672 {
3673 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3674 docs.prepend("@mainpage "+title+"\\ilinebr ");
3675 }
3676 else if (id=="mainpage" || id=="index")
3677 {
3678 if (title.isEmpty()) title = titleFn;
3679 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3680 docs.prepend("@mainpage "+title+"\\ilinebr ");
3681 }
3682 else if (isSubdirDocs)
3683 {
3684 if (!generatedId.isEmpty() && !title.isEmpty())
3685 {
3686 docs.prepend("@section " + generatedId + " " + title + "\\ilinebr ");
3687 }
3688 docs.prepend("@dir\\ilinebr ");
3689 }
3690 else
3691 {
3692 if (title.isEmpty())
3693 {
3694 title = titleFn;
3695 prepend = 0;
3696 }
3697 if (!wasEmpty)
3698 {
3699 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr @ianchor{" + relFileName + "} " + mdFileNameId + "\\ilinebr ");
3700 }
3701 else if (!generatedId.isEmpty())
3702 {
3703 docs.prepend("@ianchor " + generatedId + "\\ilinebr ");
3704 }
3705 else if (Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB)
3706 {
3707 QCString autoId = AnchorGenerator::instance().generate(title.str());
3708 docs.prepend("@ianchor{" + title + "} " + autoId + "\\ilinebr ");
3709 }
3710 docs.prepend("@page "+id+" "+title+"\\ilinebr ");
3711 }
3712 for (int i = 0; i < prepend; i++) docs.prepend("\n");
3713 break;
3715 {
3716 // look for `@page label My Title\n` and capture `label` (match[1]) and ` My Title` (match[2])
3717 static const reg::Ex re(R"([ ]*[\\@]page\s+(\a[\w-]*)(\s*[^\n]*)\n)");
3718 reg::Match match;
3719 std::string s = docs.str();
3720 if (reg::search(s,match,re))
3721 {
3722 QCString orgLabel = match[1].str();
3723 QCString orgTitle = match[2].str();
3724 orgTitle = orgTitle.stripWhiteSpace();
3725 QCString newLabel = markdownFileNameToId(fileName);
3726 docs = docs.left(match[1].position())+ // part before label
3727 newLabel+ // new label
3728 match[2].str()+ // part between orgLabel and \n
3729 "\\ilinebr @ianchor{" + orgTitle + "} "+orgLabel+"\n"+ // add original anchor plus \n of above
3730 docs.right(docs.length()-match.length()); // add remainder of docs
3731 }
3732 }
3733 break;
3735 break;
3737 break;
3738 }
3739 int lineNr=1;
3740
3741 p->commentScanner.enterFile(fileName,lineNr);
3743 bool needsEntry = false;
3744 int position=0;
3745 GuardedSectionStack guards;
3746 QCString processedDocs = markdown.process(docs,lineNr,true);
3747 while (p->commentScanner.parseCommentBlock(
3748 this,
3749 current.get(),
3750 processedDocs,
3751 fileName,
3752 lineNr,
3753 FALSE, // isBrief
3754 FALSE, // javadoc autobrief
3755 FALSE, // inBodyDocs
3756 prot, // protection
3757 position,
3758 needsEntry,
3759 true,
3760 &guards
3761 ))
3762 {
3763 if (needsEntry)
3764 {
3765 QCString docFile = current->docFile;
3766 root->moveToSubEntryAndRefresh(current);
3767 current->lang = SrcLangExt::Markdown;
3768 current->docFile = docFile;
3769 current->docLine = lineNr;
3770 }
3771 }
3772 if (needsEntry)
3773 {
3774 root->moveToSubEntryAndKeep(current);
3775 }
3776 p->commentScanner.leaveFile(fileName,lineNr);
3777}
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:407
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
QCString lower() const
Definition qcstring.h:234
bool endsWith(const char *s) const
Definition qcstring.h:509
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:245
const std::string & str() const
Definition qcstring.h:537
QCString right(size_t len) const
Definition qcstring.h:219
QCString left(size_t len) const
Definition qcstring.h:214
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
@ explicitDirPage
docs start with a dir command
Definition markdown.cpp:70
@ 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
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
Protection level of members.
Definition types.h:26
@ Public
Definition types.h:26
@ Markdown
Definition types.h:57
QCString stripIndentation(const QCString &s, bool skipFirstLine)
Definition util.cpp:6438
QCString stripExtensionGeneral(const QCString &fName, const QCString &ext)
Definition util.cpp:5411
static QCString stripFromPath(const QCString &p, const StringVector &l)
Definition util.cpp:309
QCString getFileNameExtension(const QCString &fn)
Definition util.cpp:5747

References FileInfo::absFilePath(), Config_getBool, Config_getEnum, Config_getString, QCString::endsWith(), explicitDirPage, explicitMainPage, explicitPage, Markdown::extractPageTitle(), FALSE, FileInfo::fileName(), AnchorGenerator::generate(), getFileNameExtension(), AnchorGenerator::instance(), QCString::isEmpty(), isExplicitPage(), QCString::left(), QCString::length(), QCString::lower(), Debug::Markdown, Markdown, markdownFileNameToId(), notExplicit, p, QCString::prepend(), Debug::print(), Markdown::process(), Public, QCString::right(), reg::search(), Markdown::setIndentLevel(), 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 3779 of file markdown.cpp.

3780{
3781 Doxygen::parserManager->getOutlineParser("*.cpp")->parsePrototype(text);
3782}
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: