Doxygen
Loading...
Searching...
No Matches
Markdown Class Reference

Helper class to process markdown formatted text. More...

#include <src/markdown.h>

Classes

struct  Private

Public Member Functions

 Markdown (const QCString &fileName, int lineNr, int indentLevel=0)
 ~Markdown ()
QCString process (const QCString &input, int &startNewlines, bool fromParseInput=false)
QCString extractPageTitle (QCString &docs, QCString &id, int &prepend, bool &isIdGenerated)
void setIndentLevel (int level)

Private Attributes

std::unique_ptr< Privateprv

Detailed Description

Helper class to process markdown formatted text.

Definition at line 31 of file markdown.h.

Constructor & Destructor Documentation

◆ Markdown()

Markdown::Markdown ( const QCString & fileName,
int lineNr,
int indentLevel = 0 )

Definition at line 182 of file markdown.cpp.

183 : prv(std::make_unique<Private>(fileName,lineNr,indentLevel))
184{
185 using namespace std::placeholders;
186 (void)lineNr; // not used yet
187}
std::unique_ptr< Private > prv
Definition markdown.h:43

References prv.

Referenced by ~Markdown().

◆ ~Markdown()

Markdown::~Markdown ( )
default

References Markdown().

Member Function Documentation

◆ extractPageTitle()

QCString Markdown::extractPageTitle ( QCString & docs,
QCString & id,
int & prepend,
bool & isIdGenerated )

Definition at line 3549 of file markdown.cpp.

3550{
3551 AUTO_TRACE("docs={} prepend={}",Trace::trunc(docs),id,prepend);
3552 // first first non-empty line
3553 prepend = 0;
3554 QCString title;
3555 size_t i=0;
3556 QCString docs_org(docs);
3557 std::string_view data(docs_org.str());
3558 const size_t size = data.size();
3559 docs.clear();
3560 while (i<size && (data[i]==' ' || data[i]=='\n'))
3561 {
3562 if (data[i]=='\n') prepend++;
3563 i++;
3564 }
3565 if (i>=size) { return QCString(); }
3566 size_t end1=i+1;
3567 while (end1<size && data[end1-1]!='\n') end1++;
3568 //printf("i=%d end1=%d size=%d line='%s'\n",i,end1,size,docs.mid(i,end1-i).data());
3569 // first line from i..end1
3570 if (end1<size)
3571 {
3572 // second line form end1..end2
3573 size_t end2=end1+1;
3574 while (end2<size && data[end2-1]!='\n') end2++;
3575 if (prv->isHeaderline(data.substr(end1),FALSE))
3576 {
3577 title = data.substr(i,end1-i-1);
3578 docs+="\n\n"+docs_org.mid(end2);
3579 id = prv->extractTitleId(title, 0, &isIdGenerated);
3580 //printf("extractPageTitle(title='%s' docs='%s' id='%s')\n",title.data(),docs.data(),id.data());
3581 AUTO_TRACE_EXIT("result={} id={} isIdGenerated={}",Trace::trunc(title),id,isIdGenerated);
3582 return title;
3583 }
3584 }
3585 if (i<end1 && prv->isAtxHeader(data.substr(i,end1-i),title,id,FALSE,&isIdGenerated)>0)
3586 {
3587 docs+="\n";
3588 docs+=docs_org.mid(end1);
3589 }
3590 else
3591 {
3592 docs=docs_org;
3593 id = prv->extractTitleId(title, 0, &isIdGenerated);
3594 }
3595 AUTO_TRACE_EXIT("result={} id={} isIdGenerated={}",Trace::trunc(title),id,isIdGenerated);
3596 return title;
3597}
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
void clear()
Definition qcstring.h:169
#define AUTO_TRACE(...)
Definition docnode.cpp:46
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:48
size_t size
Definition htmlgen.cpp:156
const char * data
Definition htmlgen.cpp:158
size_t i
Definition htmlgen.cpp:161
QCString trunc(const QCString &s, size_t numChars=15)
Definition trace.h:56
#define FALSE
Definition qcstring.h:34

References AUTO_TRACE, AUTO_TRACE_EXIT, QCString::clear(), data, FALSE, i, QCString::mid(), prv, size, QCString::str(), and Trace::trunc().

Referenced by MarkdownOutlineParser::parseInput().

◆ process()

QCString Markdown::process ( const QCString & input,
int & startNewlines,
bool fromParseInput = false )

Definition at line 3602 of file markdown.cpp.

3603{
3604 if (input.isEmpty()) return input;
3605 size_t refIndent=0;
3606
3607 // for replace tabs by spaces
3608 QCString s = input;
3609 if (s.at(s.length()-1)!='\n') s += "\n"; // see PR #6766
3610 s = detab(s,refIndent);
3611 //printf("======== DeTab =========\n---- output -----\n%s\n---------\n",qPrint(s));
3612
3613 // then process quotation blocks (as these may contain other blocks)
3614 s = prv->processQuotations(s.view(),refIndent);
3615 //printf("======== Quotations =========\n---- output -----\n%s\n---------\n",qPrint(s));
3616
3617 // then process block items (headers, rules, and code blocks, references)
3618 s = prv->processBlocks(s.view(),refIndent);
3619 //printf("======== Blocks =========\n---- output -----\n%s\n---------\n",qPrint(s));
3620
3621 // finally process the inline markup (links, emphasis and code spans)
3622 prv->out.clear();
3623 prv->out.reserve(s.length());
3624 prv->processInline(s.view());
3625 if (fromParseInput)
3626 {
3627 Debug::print(Debug::Markdown,0,"---- output -----\n{}\n=========\n",qPrint(prv->out));
3628 }
3629 else
3630 {
3631 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n{}\n---- output -----\n{}\n=========\n",input,prv->out);
3632 }
3633
3634 // post processing
3635 QCString result = substitute(prv->out,g_doxy_nbsp,"&nbsp;");
3636 const char *p = result.data();
3637 if (p)
3638 {
3639 while (*p==' ') p++; // skip over spaces
3640 while (*p=='\n') {startNewlines++;p++;}; // skip over newlines
3641 if (literal_at(p,"<br>")) p+=4; // skip over <br>
3642 }
3643 if (p>result.data())
3644 {
3645 // strip part of the input
3646 result = result.mid(static_cast<int>(p-result.data()));
3647 }
3648 return result;
3649}
@ Markdown
Definition debug.h:37
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:76
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:578
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159
std::string_view view() const
Definition qcstring.h:161
QCString s
Definition htmlgen.cpp:154
const char * g_doxy_nbsp
Definition markdown.cpp:200
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
const char * qPrint(const char *s)
Definition qcstring.h:672
bool literal_at(const char *data, const char(&str)[N])
returns TRUE iff data points to a substring that matches string literal str
Definition stringutil.h:98
QCString detab(const QCString &s, size_t &refIndent)
Definition util.cpp:7232

References QCString::data(), detab(), g_doxy_nbsp, QCString::isEmpty(), literal_at(), Debug::Markdown, QCString::mid(), Debug::print(), prv, qPrint(), s, and substitute().

Referenced by generateHtmlForComment(), handleCommentBlock(), handleCommentBlock(), handleCommentBlock(), VHDLOutlineParser::handleCommentBlock(), handleParametersCommentBlocks(), and MarkdownOutlineParser::parseInput().

◆ setIndentLevel()

void Markdown::setIndentLevel ( int level)

Definition at line 191 of file markdown.cpp.

191{ prv->indentLevel = level; }

References prv.

Referenced by MarkdownOutlineParser::parseInput().

Member Data Documentation

◆ prv

std::unique_ptr<Private> Markdown::prv
private

Definition at line 43 of file markdown.h.

Referenced by extractPageTitle(), Markdown(), process(), and setIndentLevel().


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