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.
 
- Public Member Functions inherited from OutlineParserInterface

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

3579 : p(std::make_unique<Private>())
3580{
3581}
std::unique_ptr< Private > p
Definition markdown.h:60

◆ ~MarkdownOutlineParser()

MarkdownOutlineParser::~MarkdownOutlineParser ( )
override

Definition at line 3583 of file markdown.cpp.

3584{
3585}

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

3591{
3592 std::shared_ptr<Entry> current = std::make_shared<Entry>();
3593 int prepend = 0; // number of empty lines in front
3594 current->lang = SrcLangExt::Markdown;
3595 current->fileName = fileName;
3596 current->docFile = fileName;
3597 current->docLine = 1;
3598 QCString docs = fileBuf;
3599 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n%s\n",qPrint(fileBuf));
3600 QCString id;
3601 Markdown markdown(fileName,1,0);
3602 bool isIdGenerated = false;
3603 QCString title = markdown.extractPageTitle(docs, id, prepend, isIdGenerated).stripWhiteSpace();
3604 QCString generatedId;
3605 if (isIdGenerated)
3606 {
3607 generatedId = id;
3608 id = "";
3609 }
3610 int indentLevel=title.isEmpty() ? 0 : -1;
3611 markdown.setIndentLevel(indentLevel);
3612 FileInfo fi(fileName.str());
3613 QCString fn = fi.fileName();
3614 QCString titleFn = stripExtensionGeneral(fn,getFileNameExtension(fn));
3615 QCString mdfileAsMainPage = Config_getString(USE_MDFILE_AS_MAINPAGE);
3616 QCString mdFileNameId = markdownFileNameToId(fileName);
3617 bool wasEmpty = id.isEmpty();
3618 if (wasEmpty) id = mdFileNameId;
3619 QCString relFileName = stripFromPath(fileName);
3620 bool isSubdirDocs = Config_getBool(IMPLICIT_DIR_DOCS) && relFileName.lower().endsWith("/readme.md");
3621 switch (isExplicitPage(docs))
3622 {
3624 if (!mdfileAsMainPage.isEmpty() &&
3625 (fi.absFilePath()==FileInfo(mdfileAsMainPage.str()).absFilePath()) // file reference with path
3626 )
3627 {
3628 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3629 docs.prepend("@mainpage "+title+"\\ilinebr ");
3630 }
3631 else if (id=="mainpage" || id=="index")
3632 {
3633 if (title.isEmpty()) title = titleFn;
3634 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr ");
3635 docs.prepend("@mainpage "+title+"\\ilinebr ");
3636 }
3637 else if (isSubdirDocs)
3638 {
3639 docs.prepend("@dir\\ilinebr ");
3640 }
3641 else
3642 {
3643 if (title.isEmpty())
3644 {
3645 title = titleFn;
3646 prepend = 0;
3647 }
3648 if (!wasEmpty)
3649 {
3650 docs.prepend("@ianchor{" + title + "} " + id + "\\ilinebr @ianchor{" + relFileName + "} " + mdFileNameId + "\\ilinebr ");
3651 }
3652 else if (!generatedId.isEmpty())
3653 {
3654 docs.prepend("@ianchor " + generatedId + "\\ilinebr ");
3655 }
3656 else if (Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB)
3657 {
3658 QCString autoId = AnchorGenerator::instance().generate(title.str());
3659 docs.prepend("@ianchor{" + title + "} " + autoId + "\\ilinebr ");
3660 }
3661 docs.prepend("@page "+id+" "+title+"\\ilinebr ");
3662 }
3663 for (int i = 0; i < prepend; i++) docs.prepend("\n");
3664 break;
3666 {
3667 // look for `@page label My Title\n` and capture `label` (match[1]) and ` My Title` (match[2])
3668 static const reg::Ex re(R"([ ]*[\\@]page\s+(\a[\w-]*)(\s*[^\n]*)\n)");
3669 reg::Match match;
3670 std::string s = docs.str();
3671 if (reg::search(s,match,re))
3672 {
3673 QCString orgLabel = match[1].str();
3674 QCString orgTitle = match[2].str();
3675 orgTitle = orgTitle.stripWhiteSpace();
3676 QCString newLabel = markdownFileNameToId(fileName);
3677 docs = docs.left(match[1].position())+ // part before label
3678 newLabel+ // new label
3679 match[2].str()+ // part between orgLabel and \n
3680 "\\ilinebr @ianchor{" + orgTitle + "} "+orgLabel+"\n"+ // add original anchor plus \n of above
3681 docs.right(docs.length()-match.length()); // add remainder of docs
3682 }
3683 }
3684 break;
3686 break;
3688 break;
3689 }
3690 int lineNr=1;
3691
3692 p->commentScanner.enterFile(fileName,lineNr);
3694 bool needsEntry = false;
3695 int position=0;
3696 GuardedSectionStack guards;
3697 QCString processedDocs = markdown.process(docs,lineNr,true);
3698 while (p->commentScanner.parseCommentBlock(
3699 this,
3700 current.get(),
3701 processedDocs,
3702 fileName,
3703 lineNr,
3704 FALSE, // isBrief
3705 FALSE, // javadoc autobrief
3706 FALSE, // inBodyDocs
3707 prot, // protection
3708 position,
3709 needsEntry,
3710 true,
3711 &guards
3712 ))
3713 {
3714 if (needsEntry)
3715 {
3716 QCString docFile = current->docFile;
3717 root->moveToSubEntryAndRefresh(current);
3718 current->lang = SrcLangExt::Markdown;
3719 current->docFile = docFile;
3720 current->docLine = lineNr;
3721 }
3722 }
3723 if (needsEntry)
3724 {
3725 root->moveToSubEntryAndKeep(current);
3726 }
3727 p->commentScanner.leaveFile(fileName,lineNr);
3728}
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:36
static void print(DebugMask mask, int prio, const char *fmt,...)
Definition debug.cpp:81
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:504
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:526
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
const char * qPrint(const char *s)
Definition qcstring.h:661
Protection
Protection level of members.
Definition types.h:26
@ Public
Definition types.h:26
@ Markdown
Definition types.h:57
QCString stripExtensionGeneral(const QCString &fName, const QCString &ext)
Definition util.cpp:5255
static QCString stripFromPath(const QCString &p, const StringVector &l)
Definition util.cpp:309
QCString getFileNameExtension(const QCString &fn)
Definition util.cpp:5591

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, qPrint(), QCString::right(), reg::search(), Markdown::setIndentLevel(), QCString::str(), stripExtensionGeneral(), stripFromPath(), 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 3730 of file markdown.cpp.

3731{
3732 Doxygen::parserManager->getOutlineParser("*.cpp")->parsePrototype(text);
3733}
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 ParserManager::getOutlineParser(), and Doxygen::parserManager.

Member Data Documentation

◆ p

std::unique_ptr<Private> MarkdownOutlineParser::p
private

Definition at line 60 of file markdown.h.

Referenced by parseInput().


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