Skip to main content

The Markdown Class Reference

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

Declaration

class Markdown { ... }

Included Headers

#include <src/markdown.h>

Public Constructors Index

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

Public Destructor Index

~Markdown ()

Public Member Functions Index

QCStringprocess (const QCString &input, int &startNewlines, bool fromParseInput=false)
QCStringextractPageTitle (QCString &docs, QCString &id, int &prepend, bool &isIdGenerated)
voidsetIndentLevel (int level)

Private Member Attributes Index

std::unique_ptr< Private >prv

Description

Helper class to process markdown formatted text.

Definition at line 31 of file markdown.h.

Public Constructors

Markdown()

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

Declaration at line 34 of file markdown.h, definition at line 182 of file markdown.cpp.

182Markdown::Markdown(const QCString &fileName,int lineNr,int indentLevel)
183 : prv(std::make_unique<Private>(fileName,lineNr,indentLevel))
184{
185 using namespace std::placeholders;
186 (void)lineNr; // not used yet
187}

Reference prv.

Referenced by ~Markdown.

Public Destructor

~Markdown()

Markdown::~Markdown ()

Definition at line 35 of file markdown.h.

Reference Markdown.

Public Member Functions

extractPageTitle()

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

Declaration at line 38 of file markdown.h, definition at line 3496 of file markdown.cpp.

3496QCString Markdown::extractPageTitle(QCString &docs, QCString &id, int &prepend, bool &isIdGenerated)
3497{
3498 AUTO_TRACE("docs={} prepend={}",Trace::trunc(docs),id,prepend);
3499 // first first non-empty line
3500 prepend = 0;
3501 QCString title;
3502 size_t i=0;
3503 QCString docs_org(docs);
3504 std::string_view data(docs_org.str());
3505 const size_t size = data.size();
3506 docs.clear();
3507 while (i<size && (data[i]==' ' || data[i]=='\n'))
3508 {
3509 if (data[i]=='\n') prepend++;
3510 i++;
3511 }
3512 if (i>=size) { return QCString(); }
3513 size_t end1=i+1;
3514 while (end1<size && data[end1-1]!='\n') end1++;
3515 //printf("i=%d end1=%d size=%d line='%s'\n",i,end1,size,docs.mid(i,end1-i).data());
3516 // first line from i..end1
3517 if (end1<size)
3518 {
3519 // second line form end1..end2
3520 size_t end2=end1+1;
3521 while (end2<size && data[end2-1]!='\n') end2++;
3522 if (prv->isHeaderline(data.substr(end1),FALSE))
3523 {
3524 title = data.substr(i,end1-i-1);
3525 docs+="\n\n"+docs_org.mid(end2);
3526 id = prv->extractTitleId(title, 0, &isIdGenerated);
3527 //printf("extractPageTitle(title='%s' docs='%s' id='%s')\n",title.data(),docs.data(),id.data());
3528 AUTO_TRACE_EXIT("result={} id={} isIdGenerated={}",Trace::trunc(title),id,isIdGenerated);
3529 return title;
3530 }
3531 }
3532 if (i<end1 && prv->isAtxHeader(data.substr(i,end1-i),title,id,FALSE,&isIdGenerated)>0)
3533 {
3534 docs+="\n";
3535 docs+=docs_org.mid(end1);
3536 }
3537 else
3538 {
3539 docs=docs_org;
3540 id = prv->extractTitleId(title, 0, &isIdGenerated);
3541 }
3542 AUTO_TRACE_EXIT("result={} id={} isIdGenerated={}",Trace::trunc(title),id,isIdGenerated);
3543 return title;
3544}

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)

Declaration at line 37 of file markdown.h, definition at line 3549 of file markdown.cpp.

3549QCString Markdown::process(const QCString &input, int &startNewlines, bool fromParseInput)
3550{
3551 if (input.isEmpty()) return input;
3552 size_t refIndent=0;
3553
3554 // for replace tabs by spaces
3555 QCString s = input;
3556 if (s.at(s.length()-1)!='\n') s += "\n"; // see PR #6766
3557 s = detab(s,refIndent);
3558 //printf("======== DeTab =========\n---- output -----\n%s\n---------\n",qPrint(s));
3559
3560 // then process quotation blocks (as these may contain other blocks)
3561 s = prv->processQuotations(s.view(),refIndent);
3562 //printf("======== Quotations =========\n---- output -----\n%s\n---------\n",qPrint(s));
3563
3564 // then process block items (headers, rules, and code blocks, references)
3565 s = prv->processBlocks(s.view(),refIndent);
3566 //printf("======== Blocks =========\n---- output -----\n%s\n---------\n",qPrint(s));
3567
3568 // finally process the inline markup (links, emphasis and code spans)
3569 prv->out.clear();
3570 prv->out.reserve(s.length());
3571 prv->processInline(s.view());
3572 if (fromParseInput)
3573 {
3574 Debug::print(Debug::Markdown,0,"---- output -----\n{}\n=========\n",qPrint(prv->out));
3575 }
3576 else
3577 {
3578 Debug::print(Debug::Markdown,0,"======== Markdown =========\n---- input ------- \n{}\n---- output -----\n{}\n=========\n",input,prv->out);
3579 }
3580
3581 // post processing
3582 QCString result = substitute(prv->out,g_doxy_nbsp,"&nbsp;");
3583 const char *p = result.data();
3584 if (p)
3585 {
3586 while (*p==' ') p++; // skip over spaces
3587 while (*p=='\n') {startNewlines++;p++;}; // skip over newlines
3588 if (literal_at(p,"<br>")) p+=4; // skip over <br>
3589 }
3590 if (p>result.data())
3591 {
3592 // strip part of the input
3593 result = result.mid(static_cast<int>(p-result.data()));
3594 }
3595 return result;
3596}

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

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

setIndentLevel()

void Markdown::setIndentLevel (int level)

Declaration at line 39 of file markdown.h, definition at line 191 of file markdown.cpp.

191void Markdown::setIndentLevel(int level) { prv->indentLevel = level; }

Reference prv.

Referenced by MarkdownOutlineParser::parseInput.

Private Member Attributes

prv

std::unique_ptr<Private> Markdown::prv

Definition at line 43 of file markdown.h.

43 std::unique_ptr<Private> prv;

Referenced by extractPageTitle, Markdown, process and setIndentLevel.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.