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

177 : prv(std::make_unique<Private>(fileName,lineNr,indentLevel))
178{
179 using namespace std::placeholders;
180 (void)lineNr; // not used yet
181}
std::unique_ptr< Private > prv
Definition markdown.h:43

◆ ~Markdown()

Markdown::~Markdown ( )
default

Member Function Documentation

◆ extractPageTitle()

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

Definition at line 3343 of file markdown.cpp.

3344{
3345 AUTO_TRACE("docs={} prepend={}",Trace::trunc(docs),id,prepend);
3346 // first first non-empty line
3347 prepend = 0;
3348 QCString title;
3349 size_t i=0;
3350 QCString docs_org(docs);
3351 std::string_view data(docs_org.str());
3352 const size_t size = data.size();
3353 docs.clear();
3354 while (i<size && (data[i]==' ' || data[i]=='\n'))
3355 {
3356 if (data[i]=='\n') prepend++;
3357 i++;
3358 }
3359 if (i>=size) { return QCString(); }
3360 size_t end1=i+1;
3361 while (end1<size && data[end1-1]!='\n') end1++;
3362 //printf("i=%d end1=%d size=%d line='%s'\n",i,end1,size,docs.mid(i,end1-i).data());
3363 // first line from i..end1
3364 if (end1<size)
3365 {
3366 // second line form end1..end2
3367 size_t end2=end1+1;
3368 while (end2<size && data[end2-1]!='\n') end2++;
3369 if (prv->isHeaderline(data.substr(end1),FALSE))
3370 {
3371 title = data.substr(i,end1-i-1);
3372 docs+="\n\n"+docs_org.mid(end2);
3373 id = prv->extractTitleId(title, 0, &isIdGenerated);
3374 //printf("extractPageTitle(title='%s' docs='%s' id='%s')\n",title.data(),docs.data(),id.data());
3375 AUTO_TRACE_EXIT("result={} id={} isIdGenerated={}",Trace::trunc(title),id,isIdGenerated);
3376 return title;
3377 }
3378 }
3379 if (i<end1 && prv->isAtxHeader(data.substr(i,end1-i),title,id,FALSE,&isIdGenerated)>0)
3380 {
3381 docs+="\n";
3382 docs+=docs_org.mid(end1);
3383 }
3384 else
3385 {
3386 docs=docs_org;
3387 id = prv->extractTitleId(title, 0, &isIdGenerated);
3388 }
3389 AUTO_TRACE_EXIT("result={} id={} isIdGenerated={}",Trace::trunc(title),id,isIdGenerated);
3390 return title;
3391}
This is an alternative implementation of QCString.
Definition qcstring.h:94
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:219
void clear()
Definition qcstring.h:162
#define AUTO_TRACE(...)
Definition docnode.cpp:46
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:48
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(), FALSE, QCString::mid(), prv, QCString::str(), and Trace::trunc().

Referenced by MarkdownOutlineParser::parseInput().

◆ process()

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

Definition at line 3396 of file markdown.cpp.

3397{
3398 if (input.isEmpty()) return input;
3399 size_t refIndent=0;
3400
3401 // for replace tabs by spaces
3402 QCString s = input;
3403 if (s.at(s.length()-1)!='\n') s += "\n"; // see PR #6766
3404 s = detab(s,refIndent);
3405 //printf("======== DeTab =========\n---- output -----\n%s\n---------\n",qPrint(s));
3406
3407 // then process quotation blocks (as these may contain other blocks)
3408 s = prv->processQuotations(s.view(),refIndent);
3409 //printf("======== Quotations =========\n---- output -----\n%s\n---------\n",qPrint(s));
3410
3411 // then process block items (headers, rules, and code blocks, references)
3412 s = prv->processBlocks(s.view(),refIndent);
3413 //printf("======== Blocks =========\n---- output -----\n%s\n---------\n",qPrint(s));
3414
3415 // finally process the inline markup (links, emphasis and code spans)
3416 prv->out.clear();
3417 prv->out.reserve(s.length());
3418 prv->processInline(s.view());
3419 if (fromParseInput)
3420 {
3421 Debug::print(Debug::Markdown,0,"---- output -----\n%s\n=========\n",qPrint(prv->out));
3422 }
3423 else
3424 {
3425 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n%s\n---- output -----\n%s\n=========\n",qPrint(input),qPrint(prv->out));
3426 }
3427
3428 // post processing
3429 QCString result = substitute(prv->out,g_doxy_nbsp,"&nbsp;");
3430 const char *p = result.data();
3431 if (p)
3432 {
3433 while (*p==' ') p++; // skip over spaces
3434 while (*p=='\n') {startNewlines++;p++;}; // skip over newlines
3435 if (qstrncmp(p,"<br>",4)==0) p+=4; // skip over <br>
3436 }
3437 if (p>result.data())
3438 {
3439 // strip part of the input
3440 result = result.mid(static_cast<int>(p-result.data()));
3441 }
3442 return result;
3443}
@ Markdown
Definition debug.h:36
static void print(DebugMask mask, int prio, const char *fmt,...)
Definition debug.cpp:80
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:146
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:558
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:143
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:152
std::string_view view() const
Definition qcstring.h:154
const char * g_doxy_nbsp
Definition markdown.cpp:194
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
int qstrncmp(const char *str1, const char *str2, size_t len)
Definition qcstring.h:75
const char * qPrint(const char *s)
Definition qcstring.h:652
QCString detab(const QCString &s, size_t &refIndent)
Definition util.cpp:7070

References QCString::at(), QCString::clear(), QCString::data(), detab(), g_doxy_nbsp, QCString::isEmpty(), QCString::length(), Debug::Markdown, QCString::mid(), Debug::print(), prv, qPrint(), qstrncmp(), substitute(), and QCString::view().

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

◆ setIndentLevel()

void Markdown::setIndentLevel ( int level)

Definition at line 185 of file markdown.cpp.

185{ 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(), process(), and setIndentLevel().


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