Doxygen
Loading...
Searching...
No Matches
Markdown::Private Struct Reference
+ Collaboration diagram for Markdown::Private:

Classes

struct  LinkRef
 

Public Types

using Action_t = std::function<int(std::string_view,size_t)>
 

Public Member Functions

 Private (const QCString &fn, int line, int indent)
 
QCString processQuotations (std::string_view data, size_t refIndent)
 
QCString processBlocks (std::string_view data, size_t indent)
 
QCString isBlockCommand (std::string_view data, size_t offset)
 
size_t isSpecialCommand (std::string_view data, size_t offset)
 
size_t findEndOfLine (std::string_view data, size_t offset)
 
int processHtmlTagWrite (std::string_view data, size_t offset, bool doWrite)
 Process a HTML tag.
 
int processHtmlTag (std::string_view data, size_t offset)
 
int processEmphasis (std::string_view data, size_t offset)
 
int processEmphasis1 (std::string_view data, char c)
 process single emphasis
 
int processEmphasis2 (std::string_view data, char c)
 process double emphasis
 
int processEmphasis3 (std::string_view data, char c)
 Parsing triple emphasis.
 
int processNmdash (std::string_view data, size_t offset)
 Process ndash and mdashes.
 
int processQuoted (std::string_view data, size_t offset)
 Process quoted section "...", can contain one embedded newline.
 
int processCodeSpan (std::string_view data, size_t offset)
 ` parsing a code span (assuming codespan != 0)
 
int processSpecialCommand (std::string_view data, size_t offset)
 
int processLink (std::string_view data, size_t offset)
 
size_t findEmphasisChar (std::string_view, char c, size_t c_size)
 looks for the next emph char, skipping other constructs, and stopping when either it is found, or we are at the end of a paragraph.
 
void addStrEscapeUtf8Nbsp (std::string_view data)
 
void processInline (std::string_view data)
 
void writeMarkdownImage (std::string_view fmt, bool inline_img, bool explicitTitle, const QCString &title, const QCString &content, const QCString &link, const QCString &attributes, const FileDef *fd)
 
int isHeaderline (std::string_view data, bool allowAdjustLevel)
 returns whether the line is a setext-style hdr underline
 
int isAtxHeader (std::string_view data, QCString &header, QCString &id, bool allowAdjustLevel, bool *pIsIdGenerated=nullptr)
 
void writeOneLineHeaderOrRuler (std::string_view data)
 
void writeFencedCodeBlock (std::string_view data, std::string_view lang, size_t blockStart, size_t blockEnd)
 
size_t writeBlockQuote (std::string_view data)
 
size_t writeCodeBlock (std::string_view, size_t refIndent)
 
size_t writeTableBlock (std::string_view data)
 
QCString extractTitleId (QCString &title, int level, bool *pIsIdGenerated=nullptr)
 

Public Attributes

std::unordered_map< std::string, LinkReflinkRefs
 
QCString fileName
 
int lineNr = 0
 
int indentLevel =0
 
QCString out
 
std::array< Action_t, 256 > actions
 

Detailed Description

Definition at line 113 of file markdown.cpp.

Member Typedef Documentation

◆ Action_t

using Markdown::Private::Action_t = std::function<int(std::string_view,size_t)>

Definition at line 172 of file markdown.cpp.

Constructor & Destructor Documentation

◆ Private()

Markdown::Private::Private ( const QCString & fn,
int line,
int indent )
inline

Definition at line 115 of file markdown.cpp.

116 : fileName(fn), lineNr(line), indentLevel(indent)
117 {
118 // setup callback table for special characters
119 actions[static_cast<unsigned int>('_')] = [this](std::string_view data,size_t offset) { return processEmphasis (data,offset); };
120 actions[static_cast<unsigned int>('*')] = [this](std::string_view data,size_t offset) { return processEmphasis (data,offset); };
121 actions[static_cast<unsigned int>('~')] = [this](std::string_view data,size_t offset) { return processEmphasis (data,offset); };
122 actions[static_cast<unsigned int>('`')] = [this](std::string_view data,size_t offset) { return processCodeSpan (data,offset); };
123 actions[static_cast<unsigned int>('\\')]= [this](std::string_view data,size_t offset) { return processSpecialCommand(data,offset); };
124 actions[static_cast<unsigned int>('@')] = [this](std::string_view data,size_t offset) { return processSpecialCommand(data,offset); };
125 actions[static_cast<unsigned int>('[')] = [this](std::string_view data,size_t offset) { return processLink (data,offset); };
126 actions[static_cast<unsigned int>('!')] = [this](std::string_view data,size_t offset) { return processLink (data,offset); };
127 actions[static_cast<unsigned int>('<')] = [this](std::string_view data,size_t offset) { return processHtmlTag (data,offset); };
128 actions[static_cast<unsigned int>('-')] = [this](std::string_view data,size_t offset) { return processNmdash (data,offset); };
129 actions[static_cast<unsigned int>('"')] = [this](std::string_view data,size_t offset) { return processQuoted (data,offset); };
130 }
int processQuoted(std::string_view data, size_t offset)
Process quoted section "...", can contain one embedded newline.
Definition markdown.cpp:940
int processCodeSpan(std::string_view data, size_t offset)
` parsing a code span (assuming codespan != 0)
int processSpecialCommand(std::string_view data, size_t offset)
int processHtmlTag(std::string_view data, size_t offset)
int processEmphasis(std::string_view data, size_t offset)
int processLink(std::string_view data, size_t offset)
int processNmdash(std::string_view data, size_t offset)
Process ndash and mdashes.
Definition markdown.cpp:898
std::array< Action_t, 256 > actions
Definition markdown.cpp:179

Member Function Documentation

◆ addStrEscapeUtf8Nbsp()

void Markdown::Private::addStrEscapeUtf8Nbsp ( std::string_view data)

Definition at line 1656 of file markdown.cpp.

1657{
1658 AUTO_TRACE("{}",Trace::trunc(data));
1659 if (Portable::strnstr(data.data(),g_doxy_nbsp,data.size())==nullptr) // no escape needed -> fast
1660 {
1661 out+=data;
1662 }
1663 else // escape needed -> slow
1664 {
1665 out+=substitute(QCString(data),g_doxy_nbsp,g_utf8_nbsp);
1666 }
1667}
#define AUTO_TRACE(...)
Definition docnode.cpp:46
const char * g_doxy_nbsp
Definition markdown.cpp:200
const char * g_utf8_nbsp
Definition markdown.cpp:199
const char * strnstr(const char *haystack, const char *needle, size_t haystack_len)
Definition portable.cpp:617
QCString trunc(const QCString &s, size_t numChars=15)
Definition trace.h:56
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477

References AUTO_TRACE, g_doxy_nbsp, g_utf8_nbsp, out, Portable::strnstr(), substitute(), and Trace::trunc().

Referenced by processSpecialCommand(), and writeFencedCodeBlock().

◆ extractTitleId()

QCString Markdown::Private::extractTitleId ( QCString & title,
int level,
bool * pIsIdGenerated = nullptr )

Definition at line 1959 of file markdown.cpp.

1960{
1961 AUTO_TRACE("title={} level={}",Trace::trunc(title),level);
1962 // match e.g. '{#id-b11} ' and capture 'id-b11'
1963 static const reg::Ex r2(R"({#(\a[\w-]*)}\s*$)");
1964 reg::Match match;
1965 std::string ti = title.str();
1966 if (reg::search(ti,match,r2))
1967 {
1968 std::string id = match[1].str();
1969 title = title.left(match.position());
1970 if (AnchorGenerator::instance().reserve(id)>0)
1971 {
1972 warn(fileName, lineNr, "An automatically generated id already has the name '%s'!", id.c_str());
1973 }
1974 //printf("found match id='%s' title=%s\n",id.c_str(),qPrint(title));
1975 AUTO_TRACE_EXIT("id={}",id);
1976 return id;
1977 }
1978 if ((level>0) && (level<=Config_getInt(TOC_INCLUDE_HEADINGS)))
1979 {
1980 QCString id = AnchorGenerator::instance().generate(ti);
1981 if (pIsIdGenerated) *pIsIdGenerated=true;
1982 //printf("auto-generated id='%s' title='%s'\n",qPrint(id),qPrint(title));
1983 AUTO_TRACE_EXIT("id={}",id);
1984 return id;
1985 }
1986 //printf("no id found in title '%s'\n",qPrint(title));
1987 return "";
1988}
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
const std::string & str() const
Definition qcstring.h:537
QCString left(size_t len) const
Definition qcstring.h:214
#define Config_getInt(name)
Definition config.h:34
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:48
#define warn(file, line, fmt,...)
Definition message.h:59
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

References AUTO_TRACE, AUTO_TRACE_EXIT, Config_getInt, fileName, AnchorGenerator::generate(), AnchorGenerator::instance(), QCString::left(), lineNr, reg::search(), QCString::str(), Trace::trunc(), and warn.

Referenced by isAtxHeader(), and processBlocks().

◆ findEmphasisChar()

size_t Markdown::Private::findEmphasisChar ( std::string_view data,
char c,
size_t c_size )

looks for the next emph char, skipping other constructs, and stopping when either it is found, or we are at the end of a paragraph.

Definition at line 657 of file markdown.cpp.

658{
659 AUTO_TRACE("data='{}' c={} c_size={}",Trace::trunc(data),c,c_size);
660 size_t i = 1;
661 const size_t size = data.size();
662
663 while (i<size)
664 {
665 while (i<size && data[i]!=c &&
666 data[i]!='\\' && data[i]!='@' &&
667 !(data[i]=='/' && data[i-1]=='<') && // html end tag also ends emphasis
668 data[i]!='\n') i++;
669 // avoid overflow (unclosed emph token)
670 if (i==size)
671 {
672 return 0;
673 }
674 //printf("findEmphasisChar: data=[%s] i=%d c=%c\n",data,i,data[i]);
675
676 // not counting escaped chars or characters that are unlikely
677 // to appear as the end of the emphasis char
678 if (ignoreCloseEmphChar(data[i-1],data[i]))
679 {
680 i++;
681 continue;
682 }
683 else
684 {
685 // get length of emphasis token
686 size_t len = 0;
687 while (i+len<size && data[i+len]==c)
688 {
689 len++;
690 }
691
692 if (len>0)
693 {
694 if (len!=c_size || (i+len<size && isIdChar(data[i+len]))) // to prevent touching some_underscore_identifier
695 {
696 i+=len;
697 continue;
698 }
699 AUTO_TRACE_EXIT("result={}",i);
700 return static_cast<int>(i); // found it
701 }
702 }
703
704 // skipping a code span
705 if (data[i]=='`')
706 {
707 int snb=0;
708 while (i<size && data[i]=='`') snb++,i++;
709
710 // find same pattern to end the span
711 int enb=0;
712 while (i<size && enb<snb)
713 {
714 if (data[i]=='`') enb++;
715 if (snb==1 && data[i]=='\'') break; // ` ended by '
716 i++;
717 }
718 }
719 else if (data[i]=='@' || data[i]=='\\')
720 { // skip over blocks that should not be processed
721 QCString endBlockName = isBlockCommand(data.substr(i),i);
722 if (!endBlockName.isEmpty())
723 {
724 i++;
725 size_t l = endBlockName.length();
726 while (i+l<size)
727 {
728 if ((data[i]=='\\' || data[i]=='@') && // command
729 data[i-1]!='\\' && data[i-1]!='@') // not escaped
730 {
731 if (qstrncmp(&data[i+1],endBlockName.data(),l)==0)
732 {
733 break;
734 }
735 }
736 i++;
737 }
738 }
739 else if (i+1<size && isIdChar(data[i+1])) // @cmd, stop processing, see bug 690385
740 {
741 return 0;
742 }
743 else
744 {
745 i++;
746 }
747 }
748 else if (data[i-1]=='<' && data[i]=='/') // html end tag invalidates emphasis
749 {
750 return 0;
751 }
752 else if (data[i]=='\n') // end * or _ at paragraph boundary
753 {
754 i++;
755 while (i<size && data[i]==' ') i++;
756 if (i>=size || data[i]=='\n')
757 {
758 return 0;
759 } // empty line -> paragraph
760 }
761 else // should not get here!
762 {
763 i++;
764 }
765 }
766 return 0;
767}
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
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
#define isIdChar(c)
Definition markdown.cpp:77
#define ignoreCloseEmphChar(c, cn)
Definition markdown.cpp:100
int qstrncmp(const char *str1, const char *str2, size_t len)
Definition qcstring.h:75
QCString isBlockCommand(std::string_view data, size_t offset)
Definition markdown.cpp:357

References AUTO_TRACE, AUTO_TRACE_EXIT, QCString::data(), ignoreCloseEmphChar, isBlockCommand(), QCString::isEmpty(), isIdChar, QCString::length(), qstrncmp(), and Trace::trunc().

Referenced by processEmphasis1(), processEmphasis2(), and processEmphasis3().

◆ findEndOfLine()

size_t Markdown::Private::findEndOfLine ( std::string_view data,
size_t offset )

Definition at line 2945 of file markdown.cpp.

2946{
2947 AUTO_TRACE("data='{}'",Trace::trunc(data));
2948 // find end of the line
2949 const size_t size = data.size();
2950 size_t nb=0, end=offset+1, j=0;
2951 while (end<=size && (j=isNewline(data.data()+end-1))==0)
2952 {
2953 // while looking for the end of the line we might encounter a block
2954 // that needs to be passed unprocessed.
2955 if ((data[end-1]=='\\' || data[end-1]=='@') && // command
2956 (end<=1 || (data[end-2]!='\\' && data[end-2]!='@')) // not escaped
2957 )
2958 {
2959 QCString endBlockName = isBlockCommand(data.substr(end-1),end-1);
2960 end++;
2961 if (!endBlockName.isEmpty())
2962 {
2963 size_t l = endBlockName.length();
2964 for (;end<size-l-1;end++) // search for end of block marker
2965 {
2966 if ((data[end]=='\\' || data[end]=='@') &&
2967 data[end-1]!='\\' && data[end-1]!='@'
2968 )
2969 {
2970 if (qstrncmp(&data[end+1],endBlockName.data(),l)==0)
2971 {
2972 // found end marker, skip over this block
2973 //printf("feol.block out={%s}\n",qPrint(QCString(data+i).left(end+l+1-i)));
2974 end = end + l + 2;
2975 break;
2976 }
2977 }
2978 }
2979 }
2980 }
2981 else if (nb==0 && data[end-1]=='<' && size>=6 && end<size-6 &&
2982 (end<=1 || (data[end-2]!='\\' && data[end-2]!='@'))
2983 )
2984 {
2985 if (tolower(data[end])=='p' && tolower(data[end+1])=='r' &&
2986 tolower(data[end+2])=='e' && (data[end+3]=='>' || data[end+3]==' ')) // <pre> tag
2987 {
2988 // skip part until including </pre>
2989 end = end + processHtmlTagWrite(data.substr(end-1),end-1,false);
2990 break;
2991 }
2992 else
2993 {
2994 end++;
2995 }
2996 }
2997 else if (nb==0 && data[end-1]=='`')
2998 {
2999 while (end<=size && data[end-1]=='`') end++,nb++;
3000 }
3001 else if (nb>0 && data[end-1]=='`')
3002 {
3003 size_t enb=0;
3004 while (end<=size && data[end-1]=='`') end++,enb++;
3005 if (enb==nb) nb=0;
3006 }
3007 else
3008 {
3009 end++;
3010 }
3011 }
3012 if (j>0) end+=j-1;
3013 AUTO_TRACE_EXIT("offset={} end={}",offset,end);
3014 return end;
3015}
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
size_t isNewline(std::string_view data)
Definition markdown.cpp:207
int processHtmlTagWrite(std::string_view data, size_t offset, bool doWrite)
Process a HTML tag.
Definition markdown.cpp:964

References AUTO_TRACE, AUTO_TRACE_EXIT, QCString::data(), end(), isBlockCommand(), QCString::isEmpty(), isNewline(), QCString::length(), processHtmlTagWrite(), qstrncmp(), and Trace::trunc().

Referenced by processBlocks(), and processQuotations().

◆ isAtxHeader()

int Markdown::Private::isAtxHeader ( std::string_view data,
QCString & header,
QCString & id,
bool allowAdjustLevel,
bool * pIsIdGenerated = nullptr )

Definition at line 1991 of file markdown.cpp.

1993{
1994 AUTO_TRACE("data='{}' header={} id={} allowAdjustLevel={}",Trace::trunc(data),Trace::trunc(header),id,allowAdjustLevel);
1995 size_t i = 0;
1996 int level = 0, blanks=0;
1997 const size_t size = data.size();
1998
1999 // find start of header text and determine heading level
2000 while (i<size && data[i]==' ') i++;
2001 if (i>=size || data[i]!='#')
2002 {
2003 return 0;
2004 }
2005 while (i<size && data[i]=='#') i++,level++;
2006 if (level>SectionType::MaxLevel) // too many #'s -> no section
2007 {
2008 return 0;
2009 }
2010 while (i<size && data[i]==' ') i++,blanks++;
2011 if (level==1 && blanks==0)
2012 {
2013 return 0; // special case to prevent #someid seen as a header (see bug 671395)
2014 }
2015
2016 // find end of header text
2017 size_t end=i;
2018 while (end<size && data[end]!='\n') end++;
2019 while (end>i && (data[end-1]=='#' || data[end-1]==' ')) end--;
2020
2021 // store result
2022 header = data.substr(i,end-i);
2023 id = extractTitleId(header, level, pIsIdGenerated);
2024 if (!id.isEmpty()) // strip #'s between title and id
2025 {
2026 int idx=static_cast<int>(header.length())-1;
2027 while (idx>=0 && (header.at(idx)=='#' || header.at(idx)==' ')) idx--;
2028 header=header.left(idx+1);
2029 }
2030
2031 if (allowAdjustLevel && level==1 && indentLevel==-1)
2032 {
2033 // in case we find a `# Section` on a markdown page that started with the same level
2034 // header, we no longer need to artificially decrease the paragraph level.
2035 // So both
2036 // -------------------
2037 // # heading 1 <-- here we set g_indentLevel to -1
2038 // # heading 2 <-- here we set g_indentLevel back to 0 such that this will be a @section
2039 // -------------------
2040 // and
2041 // -------------------
2042 // # heading 1 <-- here we set g_indentLevel to -1
2043 // ## heading 2 <-- here we keep g_indentLevel at -1 such that @subsection will be @section
2044 // -------------------
2045 // will convert to
2046 // -------------------
2047 // @page md_page Heading 1
2048 // @section autotoc_md1 Heading 2
2049 // -------------------
2050
2051 indentLevel=0;
2052 }
2053 int res = level+indentLevel;
2054 AUTO_TRACE_EXIT("result={}",res);
2055 return res;
2056}
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:578
static constexpr int MaxLevel
Definition section.h:39
QCString extractTitleId(QCString &title, int level, bool *pIsIdGenerated=nullptr)

References QCString::at(), AUTO_TRACE, AUTO_TRACE_EXIT, end(), extractTitleId(), indentLevel, QCString::left(), QCString::length(), SectionType::MaxLevel, and Trace::trunc().

Referenced by writeOneLineHeaderOrRuler().

◆ isBlockCommand()

QCString Markdown::Private::isBlockCommand ( std::string_view data,
size_t offset )

Definition at line 357 of file markdown.cpp.

358{
359 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
360
361 using EndBlockFunc = QCString (*)(const std::string &,bool,char);
362
363 static const auto getEndBlock = [](const std::string &blockName,bool,char) -> QCString
364 {
365 return "end"+blockName;
366 };
367 static const auto getEndCode = [](const std::string &blockName,bool openBracket,char) -> QCString
368 {
369 return openBracket ? QCString("}") : "end"+blockName;
370 };
371 static const auto getEndUml = [](const std::string &/* blockName */,bool,char) -> QCString
372 {
373 return "enduml";
374 };
375 static const auto getEndFormula = [](const std::string &/* blockName */,bool,char nextChar) -> QCString
376 {
377 switch (nextChar)
378 {
379 case '$': return "f$";
380 case '(': return "f)";
381 case '[': return "f]";
382 case '{': return "f}";
383 }
384 return "";
385 };
386
387 // table mapping a block start command to a function that can return the matching end block string
388 static const std::unordered_map<std::string,EndBlockFunc> blockNames =
389 {
390 { "dot", getEndBlock },
391 { "code", getEndCode },
392 { "icode", getEndBlock },
393 { "msc", getEndBlock },
394 { "verbatim", getEndBlock },
395 { "iverbatim", getEndBlock },
396 { "iliteral", getEndBlock },
397 { "latexonly", getEndBlock },
398 { "htmlonly", getEndBlock },
399 { "xmlonly", getEndBlock },
400 { "rtfonly", getEndBlock },
401 { "manonly", getEndBlock },
402 { "docbookonly", getEndBlock },
403 { "startuml", getEndUml },
404 { "f", getEndFormula }
405 };
406
407 const size_t size = data.size();
408 bool openBracket = offset>0 && data.data()[-1]=='{';
409 bool isEscaped = offset>0 && (data.data()[-1]=='\\' || data.data()[-1]=='@');
410 if (isEscaped) return QCString();
411
412 size_t end=1;
413 while (end<size && (data[end]>='a' && data[end]<='z')) end++;
414 if (end==1) return QCString();
415 std::string blockName(data.substr(1,end-1));
416 auto it = blockNames.find(blockName);
417 QCString result;
418 if (it!=blockNames.end()) // there is a function assigned
419 {
420 result = it->second(blockName, openBracket, end<size ? data[end] : 0);
421 }
422 AUTO_TRACE_EXIT("result={}",result);
423 return result;
424}

References AUTO_TRACE, AUTO_TRACE_EXIT, end(), QCString::size(), and Trace::trunc().

Referenced by findEmphasisChar(), findEndOfLine(), processBlocks(), and processSpecialCommand().

◆ isHeaderline()

int Markdown::Private::isHeaderline ( std::string_view data,
bool allowAdjustLevel )

returns whether the line is a setext-style hdr underline

Definition at line 1772 of file markdown.cpp.

1773{
1774 AUTO_TRACE("data='{}' allowAdjustLevel",Trace::trunc(data),allowAdjustLevel);
1775 size_t i=0, c=0;
1776 const size_t size = data.size();
1777 while (i<size && data[i]==' ') i++;
1778 if (i==size) return 0;
1779
1780 // test of level 1 header
1781 if (data[i]=='=')
1782 {
1783 while (i<size && data[i]=='=') i++,c++;
1784 while (i<size && data[i]==' ') i++;
1785 int level = (c>1 && (i>=size || data[i]=='\n')) ? 1 : 0;
1786 if (allowAdjustLevel && level==1 && indentLevel==-1)
1787 {
1788 // In case a page starts with a header line we use it as title, promoting it to @page.
1789 // We set g_indentLevel to -1 to promoting the other sections if they have a deeper
1790 // nesting level than the page header, i.e. @section..@subsection becomes @page..@section.
1791 // In case a section at the same level is found (@section..@section) however we need
1792 // to undo this (and the result will be @page..@section).
1793 indentLevel=0;
1794 }
1795 AUTO_TRACE_EXIT("result={}",indentLevel+level);
1796 return indentLevel+level;
1797 }
1798 // test of level 2 header
1799 if (data[i]=='-')
1800 {
1801 while (i<size && data[i]=='-') i++,c++;
1802 while (i<size && data[i]==' ') i++;
1803 return (c>1 && (i>=size || data[i]=='\n')) ? indentLevel+2 : 0;
1804 }
1805 return 0;
1806}

References AUTO_TRACE, AUTO_TRACE_EXIT, indentLevel, and Trace::trunc().

Referenced by processBlocks().

◆ isSpecialCommand()

size_t Markdown::Private::isSpecialCommand ( std::string_view data,
size_t offset )

Definition at line 426 of file markdown.cpp.

427{
428 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
429
430 using EndCmdFunc = size_t (*)(std::string_view,size_t);
431
432 static const auto endOfLine = [](std::string_view data_,size_t offset_) -> size_t
433 {
434 // skip until the end of line (allowing line continuation characters)
435 char lc = 0;
436 char c = 0;
437 while (offset_<data_.size() && ((c=data_[offset_])!='\n' || lc=='\\'))
438 {
439 if (c=='\\') lc='\\'; // last character was a line continuation
440 else if (c!=' ') lc=0; // rest line continuation
441 offset_++;
442 }
443 return offset_;
444 };
445
446 static const auto endOfLabel = [](std::string_view data_,size_t offset_) -> size_t
447 {
448 if (offset_<data_.size() && data_[offset_]==' ') // we expect a space before the label
449 {
450 char c = 0;
451 offset_++;
452 // skip over spaces
453 while (offset_<data_.size() && data_[offset_]==' ') offset_++;
454 // skip over label
455 while (offset_<data_.size() && (c=data_[offset_])!=' ' && c!='\\' && c!='@' && c!='\n') offset_++;
456 return offset_;
457 }
458 return 0;
459 };
460
461 static const auto endOfLabelOpt = [](std::string_view data_,size_t offset_) -> size_t
462 {
463 size_t index=offset_;
464 if (index<data_.size() && data_[index]==' ') // skip over optional spaces
465 {
466 index++;
467 while (index<data_.size() && data_[index]==' ') index++;
468 }
469 if (index<data_.size() && data_[index]=='{') // find matching '}'
470 {
471 index++;
472 char c = 0;
473 while (index<data_.size() && (c=data_[index])!='}' && c!='\\' && c!='@' && c!='\n') index++;
474 if (index==data_.size() || data_[index]!='}') return 0; // invalid option
475 offset_=index+1; // part after {...} is the option
476 }
477 return endOfLabel(data_,offset_);
478 };
479
480 static const auto endOfParam = [](std::string_view data_,size_t offset_) -> size_t
481 {
482 size_t index=offset_;
483 if (index<data_.size() && data_[index]==' ') // skip over optional spaces
484 {
485 index++;
486 while (index<data_.size() && data_[index]==' ') index++;
487 }
488 if (index<data_.size() && data_[index]=='[') // find matching ']'
489 {
490 index++;
491 char c = 0;
492 while (index<data_.size() && (c=data_[index])!=']' && c!='\n') index++;
493 if (index==data_.size() || data_[index]!=']') return 0; // invalid parameter
494 offset_=index+1; // part after [...] is the parameter name
495 }
496 return endOfLabel(data_,offset_);
497 };
498
499 static const auto endOfFuncLike = [](std::string_view data_,size_t offset_,bool allowSpaces) -> size_t
500 {
501 if (offset_<data_.size() && data_[offset_]==' ') // we expect a space before the name
502 {
503 char c=0;
504 offset_++;
505 // skip over spaces
506 while (offset_<data_.size() && data_[offset_]==' ')
507 {
508 offset_++;
509 }
510 // skip over name (and optionally type)
511 while (offset_<data_.size() && (c=data_[offset_])!='\n' && (allowSpaces || c!=' ') && c!='(')
512 {
513 offset_++;
514 }
515 if (c=='(') // find the end of the function
516 {
517 int count=1;
518 offset_++;
519 while (offset_<data_.size() && (c=data_[offset_++]))
520 {
521 if (c=='(') count++;
522 else if (c==')') count--;
523 if (count==0) return offset_;
524 }
525 }
526 return offset_;
527 }
528 return 0;
529 };
530
531 static const auto endOfFunc = [](std::string_view data_,size_t offset_) -> size_t
532 {
533 return endOfFuncLike(data_,offset_,true);
534 };
535
536 static const auto endOfGuard = [](std::string_view data_,size_t offset_) -> size_t
537 {
538 return endOfFuncLike(data_,offset_,false);
539 };
540
541 static const std::unordered_map<std::string,EndCmdFunc> cmdNames =
542 {
543 { "a", endOfLabel },
544 { "addindex", endOfLine },
545 { "addtogroup", endOfLabel },
546 { "anchor", endOfLabel },
547 { "b", endOfLabel },
548 { "c", endOfLabel },
549 { "category", endOfLine },
550 { "cite", endOfLabel },
551 { "class", endOfLine },
552 { "concept", endOfLine },
553 { "copybrief", endOfFunc },
554 { "copydetails", endOfFunc },
555 { "copydoc", endOfFunc },
556 { "def", endOfFunc },
557 { "defgroup", endOfLabel },
558 { "diafile", endOfLine },
559 { "dir", endOfLine },
560 { "dockbookinclude",endOfLine },
561 { "dontinclude", endOfLine },
562 { "dotfile", endOfLine },
563 { "e", endOfLabel },
564 { "elseif", endOfGuard },
565 { "em", endOfLabel },
566 { "emoji", endOfLabel },
567 { "enum", endOfLabel },
568 { "example", endOfLine },
569 { "exception", endOfLine },
570 { "extends", endOfLabel },
571 { "file", endOfLine },
572 { "fn", endOfFunc },
573 { "headerfile", endOfLine },
574 { "htmlinclude", endOfLine },
575 { "ianchor", endOfLabelOpt },
576 { "idlexcept", endOfLine },
577 { "if", endOfGuard },
578 { "ifnot", endOfGuard },
579 { "image", endOfLine },
580 { "implements", endOfLine },
581 { "include", endOfLine },
582 { "includedoc", endOfLine },
583 { "includelineno", endOfLine },
584 { "ingroup", endOfLabel },
585 { "interface", endOfLine },
586 { "latexinclude", endOfLine },
587 { "maninclude", endOfLine },
588 { "memberof", endOfLabel },
589 { "mscfile", endOfLine },
590 { "namespace", endOfLabel },
591 { "noop", endOfLine },
592 { "overload", endOfLine },
593 { "p", endOfLabel },
594 { "package", endOfLabel },
595 { "page", endOfLabel },
596 { "paragraph", endOfLabel },
597 { "param", endOfParam },
598 { "property", endOfLine },
599 { "protocol", endOfLine },
600 { "qualifier", endOfLine },
601 { "ref", endOfLabel },
602 { "refitem", endOfLine },
603 { "related", endOfLabel },
604 { "relatedalso", endOfLabel },
605 { "relates", endOfLabel },
606 { "relatesalso", endOfLabel },
607 { "retval", endOfLabel },
608 { "rtfinclude", endOfLine },
609 { "section", endOfLabel },
610 { "skip", endOfLine },
611 { "skipline", endOfLine },
612 { "snippet", endOfLine },
613 { "snippetdoc", endOfLine },
614 { "snippetlineno", endOfLine },
615 { "struct", endOfLine },
616 { "subpage", endOfLabel },
617 { "subparagraph", endOfLabel },
618 { "subsubparagraph",endOfLabel },
619 { "subsection", endOfLabel },
620 { "subsubsection", endOfLabel },
621 { "throw", endOfLabel },
622 { "throws", endOfLabel },
623 { "tparam", endOfLabel },
624 { "typedef", endOfLine },
625 { "plantumlfile", endOfLine },
626 { "union", endOfLine },
627 { "until", endOfLine },
628 { "var", endOfLine },
629 { "verbinclude", endOfLine },
630 { "weakgroup", endOfLabel },
631 { "xmlinclude", endOfLine },
632 { "xrefitem", endOfLabel }
633 };
634
635 bool isEscaped = offset>0 && (data.data()[-1]=='\\' || data.data()[-1]=='@');
636 if (isEscaped) return 0;
637
638 const size_t size = data.size();
639 size_t end=1;
640 while (end<size && (data[end]>='a' && data[end]<='z')) end++;
641 if (end==1) return 0;
642 std::string cmdName(data.substr(1,end-1));
643 size_t result=0;
644 auto it = cmdNames.find(cmdName);
645 if (it!=cmdNames.end()) // command with parameters that should be ignored by markdown
646 {
647 // find the end of the parameters
648 result = it->second(data,end);
649 }
650 AUTO_TRACE_EXIT("result={}",result);
651 return result;
652}

References AUTO_TRACE, AUTO_TRACE_EXIT, end(), and Trace::trunc().

Referenced by processSpecialCommand().

◆ processBlocks()

QCString Markdown::Private::processBlocks ( std::string_view data,
size_t indent )

Definition at line 3199 of file markdown.cpp.

3200{
3201 AUTO_TRACE("data='{}' indent={}",Trace::trunc(data),indent);
3202 out.clear();
3203 size_t pi = std::string::npos;
3204 QCString id,link,title;
3205
3206#if 0 // commented out, since starting with a comment block is probably a usage error
3207 // see also http://stackoverflow.com/q/20478611/784672
3208
3209 // special case when the documentation starts with a code block
3210 // since the first line is skipped when looking for a code block later on.
3211 if (end>codeBlockIndent && isCodeBlock(data,0,end,blockIndent))
3212 {
3213 i=writeCodeBlock(out,data,size,blockIndent);
3214 end=i+1;
3215 pi=-1;
3216 }
3217#endif
3218
3219 size_t currentIndent = indent;
3220 size_t listIndent = indent;
3221 bool insideList = false;
3222 bool newBlock = false;
3223 // process each line
3224 size_t i=0;
3225 while (i<data.size())
3226 {
3227 size_t end = findEndOfLine(data,i);
3228 // line is now found at [i..end)
3229
3230 size_t lineIndent=0;
3231 int level = 0;
3232 while (lineIndent<end && data[i+lineIndent]==' ') lineIndent++;
3233 //printf("** lineIndent=%d line=(%s)\n",lineIndent,qPrint(QCString(data+i).left(end-i)));
3234
3235 if (newBlock)
3236 {
3237 //printf("** end of block\n");
3238 if (insideList && lineIndent<currentIndent) // end of list
3239 {
3240 //printf("** end of list\n");
3241 currentIndent = indent;
3242 insideList = false;
3243 }
3244 newBlock = false;
3245 }
3246
3247 if ((listIndent=isListMarker(data.substr(i,end-i)))) // see if we need to increase the indent level
3248 {
3249 if (listIndent<currentIndent+4)
3250 {
3251 //printf("** start of list\n");
3252 insideList = true;
3253 currentIndent = listIndent;
3254 }
3255 }
3256 else if (isEndOfList(data.substr(i,end-i)))
3257 {
3258 //printf("** end of list\n");
3259 insideList = false;
3260 currentIndent = listIndent;
3261 }
3262 else if (isEmptyLine(data.substr(i,end-i)))
3263 {
3264 //printf("** new block\n");
3265 newBlock = true;
3266 }
3267
3268 //printf("indent=%d listIndent=%d blockIndent=%d\n",indent,listIndent,blockIndent);
3269
3270 //printf("findEndOfLine: pi=%d i=%d end=%d\n",pi,i,end);
3271
3272 if (pi!=std::string::npos)
3273 {
3274 size_t blockStart=0, blockEnd=0, blockOffset=0;
3275 QCString lang;
3276 size_t blockIndent = currentIndent;
3277 size_t ref = 0;
3278 //printf("isHeaderLine(%s)=%d\n",QCString(data+i).left(size-i).data(),level);
3279 QCString endBlockName;
3280 if (data[i]=='@' || data[i]=='\\') endBlockName = isBlockCommand(data.substr(i),i);
3281 if (!endBlockName.isEmpty())
3282 {
3283 // handle previous line
3284 if (isLinkRef(data.substr(pi,i-pi),id,link,title))
3285 {
3286 linkRefs.emplace(id.lower().str(),LinkRef(link,title));
3287 }
3288 else
3289 {
3290 writeOneLineHeaderOrRuler(data.substr(pi,i-pi));
3291 }
3292 out+=data[i];
3293 i++;
3294 size_t l = endBlockName.length();
3295 while (i+l<data.size())
3296 {
3297 if ((data[i]=='\\' || data[i]=='@') && // command
3298 data[i-1]!='\\' && data[i-1]!='@') // not escaped
3299 {
3300 if (qstrncmp(&data[i+1],endBlockName.data(),l)==0)
3301 {
3302 out+=data[i];
3303 out+=endBlockName;
3304 i+=l+1;
3305 break;
3306 }
3307 }
3308 out+=data[i];
3309 i++;
3310 }
3311 }
3312 else if ((level=isHeaderline(data.substr(i),TRUE))>0)
3313 {
3314 //printf("Found header at %d-%d\n",i,end);
3315 while (pi<data.size() && data[pi]==' ') pi++;
3316 QCString header = data.substr(pi,i-pi-1);
3317 id = extractTitleId(header, level);
3318 //printf("header='%s' is='%s'\n",qPrint(header),qPrint(id));
3319 if (!header.isEmpty())
3320 {
3321 if (!id.isEmpty())
3322 {
3323 out+=level==1?"@section ":"@subsection ";
3324 out+=id;
3325 out+=" ";
3326 out+=header;
3327 out+="\n\n";
3328 }
3329 else
3330 {
3331 out+=level==1?"<h1>":"<h2>";
3332 out+=header;
3333 out+=level==1?"\n</h1>\n":"\n</h2>\n";
3334 }
3335 }
3336 else
3337 {
3338 out+="\n<hr>\n";
3339 }
3340 pi=std::string::npos;
3341 i=end;
3342 end=i+1;
3343 continue;
3344 }
3345 else if ((ref=isLinkRef(data.substr(pi),id,link,title)))
3346 {
3347 //printf("found link ref: id='%s' link='%s' title='%s'\n",
3348 // qPrint(id),qPrint(link),qPrint(title));
3349 linkRefs.emplace(id.lower().str(),LinkRef(link,title));
3350 i=ref+pi;
3351 end=i+1;
3352 }
3353 else if (isFencedCodeBlock(data.substr(pi),currentIndent,lang,blockStart,blockEnd,blockOffset))
3354 {
3355 //printf("Found FencedCodeBlock lang='%s' start=%d end=%d code={%s}\n",
3356 // qPrint(lang),blockStart,blockEnd,QCString(data+pi+blockStart).left(blockEnd-blockStart).data());
3357 writeFencedCodeBlock(data.substr(pi),lang.view(),blockStart,blockEnd);
3358 i=pi+blockOffset;
3359 pi=std::string::npos;
3360 end=i+1;
3361 continue;
3362 }
3363 else if (isCodeBlock(data.substr(i,end-i),i,blockIndent))
3364 {
3365 // skip previous line (it is empty anyway)
3366 i+=writeCodeBlock(data.substr(i),blockIndent);
3367 pi=std::string::npos;
3368 end=i+1;
3369 continue;
3370 }
3371 else if (isTableBlock(data.substr(pi)))
3372 {
3373 i=pi+writeTableBlock(data.substr(pi));
3374 pi=std::string::npos;
3375 end=i+1;
3376 continue;
3377 }
3378 else
3379 {
3380 writeOneLineHeaderOrRuler(data.substr(pi,i-pi));
3381 }
3382 }
3383 pi=i;
3384 i=end;
3385 }
3386 //printf("last line %d size=%d\n",i,size);
3387 if (pi!=std::string::npos && pi<data.size()) // deal with the last line
3388 {
3389 if (isLinkRef(data.substr(pi),id,link,title))
3390 {
3391 //printf("found link ref: id='%s' link='%s' title='%s'\n",
3392 // qPrint(id),qPrint(link),qPrint(title));
3393 linkRefs.emplace(id.lower().str(),LinkRef(link,title));
3394 }
3395 else
3396 {
3397 writeOneLineHeaderOrRuler(data.substr(pi));
3398 }
3399 }
3400
3401 return out;
3402}
std::string_view view() const
Definition qcstring.h:161
static size_t isLinkRef(std::string_view data, QCString &refid, QCString &link, QCString &title)
returns end of the link ref if this is indeed a link reference.
static bool isEndOfList(std::string_view data)
static bool isCodeBlock(std::string_view data, size_t offset, size_t &indent)
static bool isEmptyLine(std::string_view data)
const size_t codeBlockIndent
Definition markdown.cpp:201
static bool isFencedCodeBlock(std::string_view data, size_t refIndent, QCString &lang, size_t &start, size_t &end, size_t &offset)
static size_t isListMarker(std::string_view data)
static bool isTableBlock(std::string_view data)
Returns TRUE iff data points to the start of a table block.
#define TRUE
Definition qcstring.h:37
size_t writeTableBlock(std::string_view data)
void writeFencedCodeBlock(std::string_view data, std::string_view lang, size_t blockStart, size_t blockEnd)
int isHeaderline(std::string_view data, bool allowAdjustLevel)
returns whether the line is a setext-style hdr underline
std::unordered_map< std::string, LinkRef > linkRefs
Definition markdown.cpp:174
size_t writeCodeBlock(std::string_view, size_t refIndent)
size_t findEndOfLine(std::string_view data, size_t offset)
void writeOneLineHeaderOrRuler(std::string_view data)

References AUTO_TRACE, codeBlockIndent, QCString::data(), end(), extractTitleId(), findEndOfLine(), isBlockCommand(), isCodeBlock(), QCString::isEmpty(), isEmptyLine(), isEndOfList(), isFencedCodeBlock(), isHeaderline(), isLinkRef(), isListMarker(), isTableBlock(), QCString::length(), linkRefs, out, qstrncmp(), TRUE, Trace::trunc(), QCString::view(), writeCodeBlock(), writeFencedCodeBlock(), writeOneLineHeaderOrRuler(), and writeTableBlock().

◆ processCodeSpan()

int Markdown::Private::processCodeSpan ( std::string_view data,
size_t offset )

` parsing a code span (assuming codespan != 0)

Definition at line 1584 of file markdown.cpp.

1585{
1586 AUTO_TRACE("data='{}'",Trace::trunc(data));
1587 const size_t size = data.size();
1588
1589 /* counting the number of backticks in the delimiter */
1590 size_t nb=0, end=0;
1591 while (nb<size && data[nb]=='`')
1592 {
1593 nb++;
1594 }
1595
1596 /* finding the next delimiter */
1597 size_t i = 0;
1598 char pc = '`';
1599 for (end=nb; end<size && i<nb; end++)
1600 {
1601 if (data[end]=='`')
1602 {
1603 i++;
1604 }
1605 else if (data[end]=='\n')
1606 {
1607 // consecutive newlines
1608 if (pc == '\n') return 0;
1609 pc = '\n';
1610 i = 0;
1611 }
1612 else if (data[end]=='\'' && nb==1 && (end==size-1 || (end<size-1 && !isIdChar(data[end+1]))))
1613 { // look for quoted strings like 'some word', but skip strings like `it's cool`
1614 out+="&lsquo;";
1615 out+=data.substr(nb,end-nb);
1616 out+="&rsquo;";
1617 return static_cast<int>(end+1);
1618 }
1619 else
1620 {
1621 if (data[end]!=' ') pc = data[end];
1622 i=0;
1623 }
1624 }
1625 if (i < nb && end >= size)
1626 {
1627 return 0; // no matching delimiter
1628 }
1629
1630 // trimming outside whitespaces
1631 size_t f_begin = nb;
1632 while (f_begin < end && data[f_begin]==' ')
1633 {
1634 f_begin++;
1635 }
1636 size_t f_end = end - nb;
1637 while (f_end > nb && data[f_end-1]==' ')
1638 {
1639 f_end--;
1640 }
1641
1642 //printf("found code span '%s'\n",qPrint(QCString(data+f_begin).left(f_end-f_begin)));
1643
1644 /* real code span */
1645 if (f_begin < f_end)
1646 {
1647 QCString codeFragment = data.substr(f_begin, f_end-f_begin);
1648 out+="<tt>";
1649 out+=escapeSpecialChars(codeFragment);
1650 out+="</tt>";
1651 }
1652 AUTO_TRACE_EXIT("result={}",end);
1653 return static_cast<int>(end);
1654}
static QCString escapeSpecialChars(const QCString &s)
Definition markdown.cpp:235

References AUTO_TRACE, AUTO_TRACE_EXIT, end(), escapeSpecialChars(), isIdChar, out, and Trace::trunc().

◆ processEmphasis()

int Markdown::Private::processEmphasis ( std::string_view data,
size_t offset )

Definition at line 1060 of file markdown.cpp.

1061{
1062 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1063 const size_t size = data.size();
1064
1065 if ((offset>0 && !isOpenEmphChar(data.data()[-1])) || // invalid char before * or _
1066 (size>1 && data[0]!=data[1] && !(isIdChar(data[1]) || extraChar(data[1]))) || // invalid char after * or _
1067 (size>2 && data[0]==data[1] && !(isIdChar(data[2]) || extraChar(data[2])))) // invalid char after ** or __
1068 {
1069 AUTO_TRACE_EXIT("invalid surrounding characters");
1070 return 0;
1071 }
1072
1073 char c = data[0];
1074 int ret = 0;
1075 if (size>2 && c!='~' && data[1]!=c) // _bla or *bla
1076 {
1077 // whitespace cannot follow an opening emphasis
1078 if (data[1]==' ' || data[1]=='\n' ||
1079 (ret = processEmphasis1(data.substr(1), c)) == 0)
1080 {
1081 return 0;
1082 }
1083 AUTO_TRACE_EXIT("result={}",ret+1);
1084 return ret+1;
1085 }
1086 if (size>3 && data[1]==c && data[2]!=c) // __bla or **bla
1087 {
1088 if (data[2]==' ' || data[2]=='\n' ||
1089 (ret = processEmphasis2(data.substr(2), c)) == 0)
1090 {
1091 return 0;
1092 }
1093 AUTO_TRACE_EXIT("result={}",ret+2);
1094 return ret+2;
1095 }
1096 if (size>4 && c!='~' && data[1]==c && data[2]==c && data[3]!=c) // ___bla or ***bla
1097 {
1098 if (data[3]==' ' || data[3]=='\n' ||
1099 (ret = processEmphasis3(data.substr(3), c)) == 0)
1100 {
1101 return 0;
1102 }
1103 AUTO_TRACE_EXIT("result={}",ret+3);
1104 return ret+3;
1105 }
1106 return 0;
1107}
#define isOpenEmphChar(c)
Definition markdown.cpp:93
#define extraChar(c)
Definition markdown.cpp:84
int processEmphasis1(std::string_view data, char c)
process single emphasis
Definition markdown.cpp:770
int processEmphasis3(std::string_view data, char c)
Parsing triple emphasis.
Definition markdown.cpp:836
int processEmphasis2(std::string_view data, char c)
process double emphasis
Definition markdown.cpp:804

References AUTO_TRACE, AUTO_TRACE_EXIT, extraChar, isIdChar, isOpenEmphChar, processEmphasis1(), processEmphasis2(), processEmphasis3(), and Trace::trunc().

◆ processEmphasis1()

int Markdown::Private::processEmphasis1 ( std::string_view data,
char c )

process single emphasis

Definition at line 770 of file markdown.cpp.

771{
772 AUTO_TRACE("data='{}' c={}",Trace::trunc(data),c);
773 size_t i = 0;
774 const size_t size = data.size();
775
776 /* skipping one symbol if coming from emph3 */
777 if (size>1 && data[0]==c && data[1]==c) { i=1; }
778
779 while (i<size)
780 {
781 size_t len = findEmphasisChar(data.substr(i), c, 1);
782 if (len==0) { return 0; }
783 i+=len;
784 if (i>=size) { return 0; }
785
786 if (i+1<size && data[i+1]==c)
787 {
788 i++;
789 continue;
790 }
791 if (data[i]==c && data[i-1]!=' ' && data[i-1]!='\n')
792 {
793 out+="<em>";
794 processInline(data.substr(0,i));
795 out+="</em>";
796 AUTO_TRACE_EXIT("result={}",i+1);
797 return static_cast<int>(i+1);
798 }
799 }
800 return 0;
801}
size_t findEmphasisChar(std::string_view, char c, size_t c_size)
looks for the next emph char, skipping other constructs, and stopping when either it is found,...
Definition markdown.cpp:657
void processInline(std::string_view data)

References AUTO_TRACE, AUTO_TRACE_EXIT, findEmphasisChar(), out, processInline(), and Trace::trunc().

Referenced by processEmphasis(), and processEmphasis3().

◆ processEmphasis2()

int Markdown::Private::processEmphasis2 ( std::string_view data,
char c )

process double emphasis

Definition at line 804 of file markdown.cpp.

805{
806 AUTO_TRACE("data='{}' c={}",Trace::trunc(data),c);
807 size_t i = 0;
808 const size_t size = data.size();
809
810 while (i<size)
811 {
812 size_t len = findEmphasisChar(data.substr(i), c, 2);
813 if (len==0)
814 {
815 return 0;
816 }
817 i += len;
818 if (i+1<size && data[i]==c && data[i+1]==c && i && data[i-1]!=' ' && data[i-1]!='\n')
819 {
820 if (c == '~') out+="<strike>";
821 else out+="<strong>";
822 processInline(data.substr(0,i));
823 if (c == '~') out+="</strike>";
824 else out+="</strong>";
825 AUTO_TRACE_EXIT("result={}",i+2);
826 return static_cast<int>(i+2);
827 }
828 i++;
829 }
830 return 0;
831}

References AUTO_TRACE, AUTO_TRACE_EXIT, findEmphasisChar(), out, processInline(), and Trace::trunc().

Referenced by processEmphasis(), and processEmphasis3().

◆ processEmphasis3()

int Markdown::Private::processEmphasis3 ( std::string_view data,
char c )

Parsing triple emphasis.

Finds the first closing tag, and delegates to the other emph

Definition at line 836 of file markdown.cpp.

837{
838 AUTO_TRACE("data='{}' c={}",Trace::trunc(data),c);
839 size_t i = 0;
840 const size_t size = data.size();
841
842 while (i<size)
843 {
844 size_t len = findEmphasisChar(data.substr(i), c, 3);
845 if (len==0)
846 {
847 return 0;
848 }
849 i+=len;
850
851 /* skip whitespace preceded symbols */
852 if (data[i]!=c || data[i-1]==' ' || data[i-1]=='\n')
853 {
854 continue;
855 }
856
857 if (i+2<size && data[i+1]==c && data[i+2]==c)
858 {
859 out+="<em><strong>";
860 processInline(data.substr(0,i));
861 out+="</strong></em>";
862 AUTO_TRACE_EXIT("result={}",i+3);
863 return static_cast<int>(i+3);
864 }
865 else if (i+1<size && data[i+1]==c)
866 {
867 // double symbol found, handing over to emph1
868 len = processEmphasis1(std::string_view(data.data()-2, size+2), c);
869 if (len==0)
870 {
871 return 0;
872 }
873 else
874 {
875 AUTO_TRACE_EXIT("result={}",len-2);
876 return static_cast<int>(len - 2);
877 }
878 }
879 else
880 {
881 // single symbol found, handing over to emph2
882 len = processEmphasis2(std::string_view(data.data()-1, size+1), c);
883 if (len==0)
884 {
885 return 0;
886 }
887 else
888 {
889 AUTO_TRACE_EXIT("result={}",len-1);
890 return static_cast<int>(len - 1);
891 }
892 }
893 }
894 return 0;
895}

References AUTO_TRACE, AUTO_TRACE_EXIT, findEmphasisChar(), out, processEmphasis1(), processEmphasis2(), processInline(), and Trace::trunc().

Referenced by processEmphasis().

◆ processHtmlTag()

int Markdown::Private::processHtmlTag ( std::string_view data,
size_t offset )

Definition at line 1054 of file markdown.cpp.

1055{
1056 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1057 return processHtmlTagWrite(data,offset,true);
1058}

References AUTO_TRACE, processHtmlTagWrite(), and Trace::trunc().

◆ processHtmlTagWrite()

int Markdown::Private::processHtmlTagWrite ( std::string_view data,
size_t offset,
bool doWrite )

Process a HTML tag.

Note that

..

are treated specially, in the sense that all code inside is written unprocessed

Definition at line 964 of file markdown.cpp.

965{
966 AUTO_TRACE("data='{}' offset={} doWrite={}",Trace::trunc(data),offset,doWrite);
967 if (offset>0 && data.data()[-1]=='\\') { return 0; } // escaped <
968
969 const size_t size = data.size();
970
971 // find the end of the html tag
972 size_t i=1;
973 size_t l=0;
974 // compute length of the tag name
975 while (i<size && isIdChar(data[i])) i++,l++;
976 QCString tagName(data.substr(1,i-1));
977 if (tagName.lower()=="pre") // found <pre> tag
978 {
979 bool insideStr=FALSE;
980 while (i+6<size)
981 {
982 char c=data[i];
983 if (!insideStr && c=='<') // potential start of html tag
984 {
985 if (data[i+1]=='/' &&
986 tolower(data[i+2])=='p' && tolower(data[i+3])=='r' &&
987 tolower(data[i+4])=='e' && tolower(data[i+5])=='>')
988 { // found </pre> tag, copy from start to end of tag
989 if (doWrite) out+=data.substr(0,i+6);
990 //printf("found <pre>..</pre> [%d..%d]\n",0,i+6);
991 AUTO_TRACE_EXIT("result={}",i+6);
992 return static_cast<int>(i+6);
993 }
994 }
995 else if (insideStr && c=='"')
996 {
997 if (data[i-1]!='\\') insideStr=FALSE;
998 }
999 else if (c=='"')
1000 {
1001 insideStr=TRUE;
1002 }
1003 i++;
1004 }
1005 }
1006 else // some other html tag
1007 {
1008 if (l>0 && i<size)
1009 {
1010 if (data[i]=='/' && i<size-1 && data[i+1]=='>') // <bla/>
1011 {
1012 //printf("Found htmlTag={%s}\n",qPrint(QCString(data).left(i+2)));
1013 if (doWrite) out+=data.substr(0,i+2);
1014 AUTO_TRACE_EXIT("result={}",i+2);
1015 return static_cast<int>(i+2);
1016 }
1017 else if (data[i]=='>') // <bla>
1018 {
1019 //printf("Found htmlTag={%s}\n",qPrint(QCString(data).left(i+1)));
1020 if (doWrite) out+=data.substr(0,i+1);
1021 AUTO_TRACE_EXIT("result={}",i+1);
1022 return static_cast<int>(i+1);
1023 }
1024 else if (data[i]==' ') // <bla attr=...
1025 {
1026 i++;
1027 bool insideAttr=FALSE;
1028 while (i<size)
1029 {
1030 if (!insideAttr && data[i]=='"')
1031 {
1032 insideAttr=TRUE;
1033 }
1034 else if (data[i]=='"' && data[i-1]!='\\')
1035 {
1036 insideAttr=FALSE;
1037 }
1038 else if (!insideAttr && data[i]=='>') // found end of tag
1039 {
1040 //printf("Found htmlTag={%s}\n",qPrint(QCString(data).left(i+1)));
1041 if (doWrite) out+=data.substr(0,i+1);
1042 AUTO_TRACE_EXIT("result={}",i+1);
1043 return static_cast<int>(i+1);
1044 }
1045 i++;
1046 }
1047 }
1048 }
1049 }
1050 AUTO_TRACE_EXIT("not a valid html tag");
1051 return 0;
1052}
#define FALSE
Definition qcstring.h:34

References AUTO_TRACE, AUTO_TRACE_EXIT, FALSE, isIdChar, QCString::lower(), out, TRUE, and Trace::trunc().

Referenced by findEndOfLine(), and processHtmlTag().

◆ processInline()

void Markdown::Private::processInline ( std::string_view data)

Definition at line 1742 of file markdown.cpp.

1743{
1744 AUTO_TRACE("data='{}'",Trace::trunc(data));
1745 size_t i=0;
1746 size_t end=0;
1747 Action_t action;
1748 const size_t size = data.size();
1749 while (i<size)
1750 {
1751 // skip over characters that do not trigger a specific action
1752 while (end<size && ((action=actions[static_cast<uint8_t>(data[end])])==nullptr)) end++;
1753 // and add them to the output
1754 out+=data.substr(i,end-i);
1755 if (end>=size) break;
1756 i=end;
1757 // do the action matching a special character at i
1758 int iend = action(data.substr(i),i);
1759 if (iend<=0) // update end
1760 {
1761 end=i+1-iend;
1762 }
1763 else // skip until end
1764 {
1765 i+=iend;
1766 end=i;
1767 }
1768 }
1769}
std::function< int(std::string_view, size_t)> Action_t
Definition markdown.cpp:172

References actions, AUTO_TRACE, end(), out, and Trace::trunc().

Referenced by processEmphasis1(), processEmphasis2(), processEmphasis3(), and processLink().

◆ processLink()

int Markdown::Private::processLink ( std::string_view data,
size_t offset )

Definition at line 1152 of file markdown.cpp.

1153{
1154 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1155 const size_t size = data.size();
1156 QCString content;
1157 QCString link;
1158 QCString title;
1159 bool isImageLink = FALSE;
1160 bool isImageInline = FALSE;
1161 bool isToc = FALSE;
1162 size_t i=1;
1163 if (data[0]=='!')
1164 {
1165 isImageLink = TRUE;
1166 if (size<2 || data[1]!='[')
1167 {
1168 return 0;
1169 }
1170
1171 // if there is non-whitespace before the ![ within the scope of two new lines, the image
1172 // is considered inlined, i.e. the image is not preceded by an empty line
1173 int numNLsNeeded=2;
1174 int pos = -1;
1175 while (pos>=-static_cast<int>(offset) && numNLsNeeded>0)
1176 {
1177 if (data.data()[pos]=='\n') numNLsNeeded--;
1178 else if (data.data()[pos]!=' ') // found non-whitespace, stop searching
1179 {
1180 isImageInline=true;
1181 break;
1182 }
1183 pos--;
1184 }
1185 // skip '!['
1186 i++;
1187 }
1188 size_t contentStart=i;
1189 int level=1;
1190 int nlTotal=0;
1191 int nl=0;
1192 // find the matching ]
1193 while (i<size)
1194 {
1195 if (data[i-1]=='\\') // skip escaped characters
1196 {
1197 }
1198 else if (data[i]=='[')
1199 {
1200 level++;
1201 }
1202 else if (data[i]==']')
1203 {
1204 level--;
1205 if (level<=0) break;
1206 }
1207 else if (data[i]=='\n')
1208 {
1209 nl++;
1210 if (nl>1) { return 0; } // only allow one newline in the content
1211 }
1212 i++;
1213 }
1214 nlTotal += nl;
1215 nl = 0;
1216 if (i>=size) return 0; // premature end of comment -> no link
1217 size_t contentEnd=i;
1218 content = data.substr(contentStart,contentEnd-contentStart);
1219 //printf("processLink: content={%s}\n",qPrint(content));
1220 if (!isImageLink && content.isEmpty()) { return 0; } // no link text
1221 i++; // skip over ]
1222
1223 bool whiteSpace = false;
1224 // skip whitespace
1225 while (i<size && data[i]==' ') { whiteSpace = true; i++; }
1226 if (i<size && data[i]=='\n') // one newline allowed here
1227 {
1228 whiteSpace = true;
1229 i++;
1230 // skip more whitespace
1231 while (i<size && data[i]==' ') i++;
1232 }
1233 if (whiteSpace && i<size && (data[i]=='(' || data[i]=='[')) return 0;
1234
1235 bool explicitTitle=FALSE;
1236 if (i<size && data[i]=='(') // inline link
1237 {
1238 i++;
1239 while (i<size && data[i]==' ') i++;
1240 bool uriFormat=false;
1241 if (i<size && data[i]=='<') { i++; uriFormat=true; }
1242 size_t linkStart=i;
1243 int braceCount=1;
1244 while (i<size && data[i]!='\'' && data[i]!='"' && braceCount>0)
1245 {
1246 if (data[i]=='\n') // unexpected EOL
1247 {
1248 nl++;
1249 if (nl>1) { return 0; }
1250 }
1251 else if (data[i]=='(')
1252 {
1253 braceCount++;
1254 }
1255 else if (data[i]==')')
1256 {
1257 braceCount--;
1258 }
1259 if (braceCount>0)
1260 {
1261 i++;
1262 }
1263 }
1264 nlTotal += nl;
1265 nl = 0;
1266 if (i>=size || data[i]=='\n') { return 0; }
1267 link = data.substr(linkStart,i-linkStart);
1268 link = link.stripWhiteSpace();
1269 //printf("processLink: link={%s}\n",qPrint(link));
1270 if (link.isEmpty()) { return 0; }
1271 if (uriFormat && link.at(link.length()-1)=='>') link=link.left(link.length()-1);
1272
1273 // optional title
1274 if (data[i]=='\'' || data[i]=='"')
1275 {
1276 char c = data[i];
1277 i++;
1278 size_t titleStart=i;
1279 nl=0;
1280 while (i<size)
1281 {
1282 if (data[i]=='\n')
1283 {
1284 if (nl>1) { return 0; }
1285 nl++;
1286 }
1287 else if (data[i]=='\\') // escaped char in string
1288 {
1289 i++;
1290 }
1291 else if (data[i]==c)
1292 {
1293 i++;
1294 break;
1295 }
1296 i++;
1297 }
1298 if (i>=size)
1299 {
1300 return 0;
1301 }
1302 size_t titleEnd = i-1;
1303 // search back for closing marker
1304 while (titleEnd>titleStart && data[titleEnd]==' ') titleEnd--;
1305 if (data[titleEnd]==c) // found it
1306 {
1307 title = data.substr(titleStart,titleEnd-titleStart);
1308 explicitTitle=TRUE;
1309 while (i<size)
1310 {
1311 if (data[i]==' ')i++; // remove space after the closing quote and the closing bracket
1312 else if (data[i] == ')') break; // the end bracket
1313 else // illegal
1314 {
1315 return 0;
1316 }
1317 }
1318 }
1319 else
1320 {
1321 return 0;
1322 }
1323 }
1324 i++;
1325 }
1326 else if (i<size && data[i]=='[') // reference link
1327 {
1328 i++;
1329 size_t linkStart=i;
1330 nl=0;
1331 // find matching ]
1332 while (i<size && data[i]!=']')
1333 {
1334 if (data[i]=='\n')
1335 {
1336 nl++;
1337 if (nl>1) { return 0; }
1338 }
1339 i++;
1340 }
1341 if (i>=size) { return 0; }
1342 // extract link
1343 link = data.substr(linkStart,i-linkStart);
1344 //printf("processLink: link={%s}\n",qPrint(link));
1345 link = link.stripWhiteSpace();
1346 if (link.isEmpty()) // shortcut link
1347 {
1348 link=content;
1349 }
1350 // lookup reference
1351 QCString link_lower = link.lower();
1352 auto lr_it=linkRefs.find(link_lower.str());
1353 if (lr_it!=linkRefs.end()) // found it
1354 {
1355 link = lr_it->second.link;
1356 title = lr_it->second.title;
1357 //printf("processLink: ref: link={%s} title={%s}\n",qPrint(link),qPrint(title));
1358 }
1359 else // reference not found!
1360 {
1361 //printf("processLink: ref {%s} do not exist\n",link.qPrint(lower()));
1362 return 0;
1363 }
1364 i++;
1365 }
1366 else if (i<size && data[i]!=':' && !content.isEmpty()) // minimal link ref notation [some id]
1367 {
1368 QCString content_lower = content.lower();
1369 auto lr_it = linkRefs.find(content_lower.str());
1370 //printf("processLink: minimal link {%s} lr=%p",qPrint(content),lr);
1371 if (lr_it!=linkRefs.end()) // found it
1372 {
1373 link = lr_it->second.link;
1374 title = lr_it->second.title;
1375 explicitTitle=TRUE;
1376 i=contentEnd;
1377 }
1378 else if (content=="TOC")
1379 {
1380 isToc=TRUE;
1381 i=contentEnd;
1382 }
1383 else
1384 {
1385 return 0;
1386 }
1387 i++;
1388 }
1389 else
1390 {
1391 return 0;
1392 }
1393 nlTotal += nl;
1394
1395 // search for optional image attributes
1396 QCString attributes;
1397 if (isImageLink)
1398 {
1399 size_t j = i;
1400 // skip over whitespace
1401 while (j<size && data[j]==' ') { j++; }
1402 if (j<size && data[j]=='{') // we have attributes
1403 {
1404 i = j;
1405 // skip over '{'
1406 i++;
1407 size_t attributesStart=i;
1408 nl=0;
1409 // find the matching '}'
1410 while (i<size)
1411 {
1412 if (data[i-1]=='\\') // skip escaped characters
1413 {
1414 }
1415 else if (data[i]=='{')
1416 {
1417 level++;
1418 }
1419 else if (data[i]=='}')
1420 {
1421 level--;
1422 if (level<=0) break;
1423 }
1424 else if (data[i]=='\n')
1425 {
1426 nl++;
1427 if (nl>1) { return 0; } // only allow one newline in the content
1428 }
1429 i++;
1430 }
1431 nlTotal += nl;
1432 if (i>=size) return 0; // premature end of comment -> no attributes
1433 size_t attributesEnd=i;
1434 attributes = data.substr(attributesStart,attributesEnd-attributesStart);
1435 i++; // skip over '}'
1436 }
1437 if (!isImageInline)
1438 {
1439 // if there is non-whitespace after the image within the scope of two new lines, the image
1440 // is considered inlined, i.e. the image is not followed by an empty line
1441 int numNLsNeeded=2;
1442 size_t pos = i;
1443 while (pos<size && numNLsNeeded>0)
1444 {
1445 if (data[pos]=='\n') numNLsNeeded--;
1446 else if (data[pos]!=' ') // found non-whitespace, stop searching
1447 {
1448 isImageInline=true;
1449 break;
1450 }
1451 pos++;
1452 }
1453 }
1454 }
1455
1456 if (isToc) // special case for [TOC]
1457 {
1458 int toc_level = Config_getInt(TOC_INCLUDE_HEADINGS);
1459 if (toc_level>=SectionType::MinLevel && toc_level<=SectionType::MaxLevel)
1460 {
1461 out+="@tableofcontents{html:";
1462 out+=QCString().setNum(toc_level);
1463 out+="}";
1464 }
1465 }
1466 else if (isImageLink)
1467 {
1468 bool ambig = false;
1469 FileDef *fd=nullptr;
1470 if (link.find("@ref ")!=-1 || link.find("\\ref ")!=-1 ||
1472 // assume doxygen symbol link or local image link
1473 {
1474 // check if different handling is needed per format
1475 writeMarkdownImage("html", isImageInline, explicitTitle, title, content, link, attributes, fd);
1476 writeMarkdownImage("latex", isImageInline, explicitTitle, title, content, link, attributes, fd);
1477 writeMarkdownImage("rtf", isImageInline, explicitTitle, title, content, link, attributes, fd);
1478 writeMarkdownImage("docbook", isImageInline, explicitTitle, title, content, link, attributes, fd);
1479 writeMarkdownImage("xml", isImageInline, explicitTitle, title, content, link, attributes, fd);
1480 }
1481 else
1482 {
1483 out+="<img src=\"";
1484 out+=link;
1485 out+="\" alt=\"";
1486 out+=content;
1487 out+="\"";
1488 if (!title.isEmpty())
1489 {
1490 out+=" title=\"";
1491 out+=substitute(title.simplifyWhiteSpace(),"\"","&quot;");
1492 out+="\"";
1493 }
1494 out+="/>";
1495 }
1496 }
1497 else
1498 {
1500 int lp=-1;
1501 if ((lp=link.find("@ref "))!=-1 || (lp=link.find("\\ref "))!=-1 || (lang==SrcLangExt::Markdown && !isURL(link)))
1502 // assume doxygen symbol link
1503 {
1504 if (lp==-1) // link to markdown page
1505 {
1506 out+="@ref \"";
1507 if (!(Portable::isAbsolutePath(link) || isURL(link)))
1508 {
1509 FileInfo forg(link.str());
1510 if (forg.exists() && forg.isReadable())
1511 {
1512 link = forg.absFilePath();
1513 }
1514 else if (!(forg.exists() && forg.isReadable()))
1515 {
1516 FileInfo fi(fileName.str());
1517 QCString mdFile = fileName.left(fileName.length()-fi.fileName().length()) + link;
1518 FileInfo fmd(mdFile.str());
1519 if (fmd.exists() && fmd.isReadable())
1520 {
1521 link = fmd.absFilePath().data();
1522 }
1523 }
1524 }
1525 out+=link;
1526 out+="\"";
1527 }
1528 else
1529 {
1530 out+=link;
1531 }
1532 out+=" \"";
1533 if (explicitTitle && !title.isEmpty())
1534 {
1535 out+=substitute(title,"\"","&quot;");
1536 }
1537 else
1538 {
1539 processInline(std::string_view(substitute(content,"\"","&quot;").str()));
1540 }
1541 out+="\"";
1542 }
1543 else if ((lp=link.find('#'))!=-1 || link.find('/')!=-1 || link.find('.')!=-1)
1544 { // file/url link
1545 if (lp==0 || (lp>0 && !isURL(link) && Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB))
1546 {
1547 out+="@ref \"";
1549 out+="\" \"";
1550 out+=substitute(content.simplifyWhiteSpace(),"\"","&quot;");
1551 out+="\"";
1552 }
1553 else
1554 {
1555 out+="<a href=\"";
1556 out+=link;
1557 out+="\"";
1558 for (int ii = 0; ii < nlTotal; ii++) out+="\n";
1559 if (!title.isEmpty())
1560 {
1561 out+=" title=\"";
1562 out+=substitute(title.simplifyWhiteSpace(),"\"","&quot;");
1563 out+="\"";
1564 }
1565 out+=" ";
1567 out+=">";
1568 content = content.simplifyWhiteSpace();
1569 processInline(std::string_view(content.str()));
1570 out+="</a>";
1571 }
1572 }
1573 else // avoid link to e.g. F[x](y)
1574 {
1575 //printf("no link for '%s'\n",qPrint(link));
1576 return 0;
1577 }
1578 }
1579 AUTO_TRACE_EXIT("result={}",i);
1580 return static_cast<int>(i);
1581}
static std::string addPrefixIfNeeded(const std::string &anchor)
Definition anchor.cpp:46
static FileNameLinkedMap * imageNameLinkedMap
Definition doxygen.h:106
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
QCString lower() const
Definition qcstring.h:234
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:245
QCString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple whitespace cha...
Definition qcstring.cpp:185
static constexpr int MinLevel
Definition section.h:32
#define Config_getEnum(name)
Definition config.h:35
bool isAbsolutePath(const QCString &fileName)
Definition portable.cpp:514
void writeMarkdownImage(std::string_view fmt, bool inline_img, bool explicitTitle, const QCString &title, const QCString &content, const QCString &link, const QCString &attributes, const FileDef *fd)
SrcLangExt
Language as given by extension.
Definition types.h:42
@ Markdown
Definition types.h:57
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
Definition util.cpp:5549
bool isURL(const QCString &url)
Checks whether the given url starts with a supported protocol.
Definition util.cpp:6246
QCString externalLinkTarget(const bool parent)
Definition util.cpp:6022
FileDef * findFileDef(const FileNameLinkedMap *fnMap, const QCString &n, bool &ambig)
Definition util.cpp:3262

References FileInfo::absFilePath(), AnchorGenerator::addPrefixIfNeeded(), QCString::at(), AUTO_TRACE, AUTO_TRACE_EXIT, Config_getEnum, Config_getInt, FileInfo::exists(), externalLinkTarget(), FALSE, FileInfo::fileName(), fileName, QCString::find(), findFileDef(), getLanguageFromFileName(), Doxygen::imageNameLinkedMap, Portable::isAbsolutePath(), QCString::isEmpty(), FileInfo::isReadable(), isURL(), QCString::left(), QCString::length(), linkRefs, QCString::lower(), Markdown, SectionType::MaxLevel, QCString::mid(), SectionType::MinLevel, out, processInline(), QCString::setNum(), QCString::simplifyWhiteSpace(), QCString::str(), QCString::stripWhiteSpace(), substitute(), TRUE, Trace::trunc(), and writeMarkdownImage().

◆ processNmdash()

int Markdown::Private::processNmdash ( std::string_view data,
size_t offset )

Process ndash and mdashes.

Definition at line 898 of file markdown.cpp.

899{
900 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
901 const size_t size = data.size();
902 // precondition: data[0]=='-'
903 size_t i=1;
904 int count=1;
905 if (i<size && data[i]=='-') // found --
906 {
907 count++,i++;
908 }
909 if (i<size && data[i]=='-') // found ---
910 {
911 count++,i++;
912 }
913 if (i<size && data[i]=='-') // found ----
914 {
915 count++;
916 }
917 if (count>=2 && offset>=2 && qstrncmp(data.data()-2,"<!",2)==0)
918 { AUTO_TRACE_EXIT("result={}",1-count); return 1-count; } // start HTML comment
919 if (count==2 && size > 2 && data[2]=='>')
920 { return 0; } // end HTML comment
921 if (count==3 && size > 3 && data[3]=='>')
922 { return 0; } // end HTML comment
923 if (count==2 && (offset<8 || qstrncmp(data.data()-8,"operator",8)!=0)) // -- => ndash
924 {
925 out+="&ndash;";
926 AUTO_TRACE_EXIT("result=2");
927 return 2;
928 }
929 else if (count==3) // --- => ndash
930 {
931 out+="&mdash;";
932 AUTO_TRACE_EXIT("result=3");
933 return 3;
934 }
935 // not an ndash or mdash
936 return 0;
937}

References AUTO_TRACE, AUTO_TRACE_EXIT, out, qstrncmp(), and Trace::trunc().

◆ processQuotations()

QCString Markdown::Private::processQuotations ( std::string_view data,
size_t refIndent )

Definition at line 3040 of file markdown.cpp.

3041{
3042 AUTO_TRACE("data='{}' refIndex='{}'",Trace::trunc(data),refIndent);
3043 out.clear();
3044 size_t i=0,end=0;
3045 size_t pi=std::string::npos;
3046 bool newBlock = false;
3047 bool insideList = false;
3048 size_t currentIndent = refIndent;
3049 size_t listIndent = refIndent;
3050 const size_t size = data.size();
3051 QCString lang;
3052 while (i<size)
3053 {
3054 end = findEndOfLine(data,i);
3055 // line is now found at [i..end)
3056
3057 size_t lineIndent=0;
3058 while (lineIndent<end && data[i+lineIndent]==' ') lineIndent++;
3059 //printf("** lineIndent=%d line=(%s)\n",lineIndent,qPrint(QCString(data+i).left(end-i)));
3060
3061 if (newBlock)
3062 {
3063 //printf("** end of block\n");
3064 if (insideList && lineIndent<currentIndent) // end of list
3065 {
3066 //printf("** end of list\n");
3067 currentIndent = refIndent;
3068 insideList = false;
3069 }
3070 newBlock = false;
3071 }
3072
3073 if ((listIndent=isListMarker(data.substr(i,end-i)))) // see if we need to increase the indent level
3074 {
3075 if (listIndent<currentIndent+4)
3076 {
3077 //printf("** start of list\n");
3078 insideList = true;
3079 currentIndent = listIndent;
3080 }
3081 }
3082 else if (isEndOfList(data.substr(i,end-i)))
3083 {
3084 //printf("** end of list\n");
3085 insideList = false;
3086 currentIndent = listIndent;
3087 }
3088 else if (isEmptyLine(data.substr(i,end-i)))
3089 {
3090 //printf("** new block\n");
3091 newBlock = true;
3092 }
3093 //printf("currentIndent=%d listIndent=%d refIndent=%d\n",currentIndent,listIndent,refIndent);
3094
3095 if (pi!=std::string::npos)
3096 {
3097 size_t blockStart=0, blockEnd=0, blockOffset=0;
3098 if (isFencedCodeBlock(data.substr(pi),currentIndent,lang,blockStart,blockEnd,blockOffset))
3099 {
3100 auto addSpecialCommand = [&](const QCString &startCmd,const QCString &endCmd)
3101 {
3102 size_t cmdPos = pi+blockStart+1;
3103 QCString pl = data.substr(cmdPos,blockEnd-blockStart-1);
3104 size_t ii = 0;
3105 int nl = 1;
3106 // check for absence of start command, either @start<cmd>, or \\start<cmd>
3107 while (ii<pl.length() && qisspace(pl[ii]))
3108 {
3109 if (pl[ii]=='\n') nl++;
3110 ii++; // skip leading whitespace
3111 }
3112 bool addNewLines = false;
3113 if (ii+startCmd.length()>=pl.length() || // no room for start command
3114 (pl[ii]!='\\' && pl[ii]!='@') || // no @ or \ after whitespace
3115 qstrncmp(pl.data()+ii+1,startCmd.data(),startCmd.length())!=0) // no start command
3116 {
3117 // input: output:
3118 // ----------------------------------------------------
3119 // ```{plantuml} => @startuml
3120 // A->B A->B
3121 // ``` @enduml
3122 // ----------------------------------------------------
3123 pl = "@"+startCmd+"\n" + pl + "@"+endCmd;
3124 addNewLines = false;
3125 }
3126 else // we have a @start... command inside the code block
3127 {
3128 // input: output:
3129 // ----------------------------------------------------
3130 // ```{plantuml} \n
3131 // \n
3132 // @startuml => @startuml
3133 // A->B A->B
3134 // @enduml @enduml
3135 // ``` \n
3136 // ----------------------------------------------------
3137 addNewLines = true;
3138 }
3139 if (addNewLines) for (int j=0;j<nl;j++) out+='\n';
3140 processSpecialCommand(pl.view().substr(ii),ii);
3141 if (addNewLines) out+='\n';
3142 };
3143
3144 if (!Config_getString(PLANTUML_JAR_PATH).isEmpty() && lang=="plantuml")
3145 {
3146 addSpecialCommand("startuml","enduml");
3147 }
3148 else if (Config_getBool(HAVE_DOT) && lang=="dot")
3149 {
3150 addSpecialCommand("dot","enddot");
3151 }
3152 else if (lang=="msc") // msc is built-in
3153 {
3154 addSpecialCommand("msc","endmsc");
3155 }
3156 else // normal code block
3157 {
3158 writeFencedCodeBlock(data.substr(pi),lang.view(),blockStart,blockEnd);
3159 }
3160 i=pi+blockOffset;
3161 pi=std::string::npos;
3162 end=i+1;
3163 continue;
3164 }
3165 else if (isBlockQuote(data.substr(pi,i-pi),currentIndent))
3166 {
3167 i = pi+writeBlockQuote(data.substr(pi));
3168 pi=std::string::npos;
3169 end=i+1;
3170 continue;
3171 }
3172 else
3173 {
3174 //printf("quote out={%s}\n",QCString(data+pi).left(i-pi).data());
3175 out+=data.substr(pi,i-pi);
3176 }
3177 }
3178 pi=i;
3179 i=end;
3180 }
3181 if (pi!=std::string::npos && pi<size) // deal with the last line
3182 {
3183 if (isBlockQuote(data.substr(pi),currentIndent))
3184 {
3185 writeBlockQuote(data.substr(pi));
3186 }
3187 else
3188 {
3189 out+=data.substr(pi);
3190 }
3191 }
3192
3193 //printf("Process quotations\n---- input ----\n%s\n---- output ----\n%s\n------------\n",
3194 // qPrint(s),prv->out.get());
3195
3196 return out;
3197}
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
static bool isBlockQuote(std::string_view data, size_t indent)
returns true if this line starts a block quote
bool qisspace(char c)
Definition qcstring.h:81
size_t writeBlockQuote(std::string_view data)

References AUTO_TRACE, Config_getBool, Config_getString, QCString::data(), end(), findEndOfLine(), isBlockQuote(), isEmptyLine(), isEndOfList(), isFencedCodeBlock(), isListMarker(), QCString::length(), out, processSpecialCommand(), qisspace(), qstrncmp(), Trace::trunc(), QCString::view(), writeBlockQuote(), and writeFencedCodeBlock().

◆ processQuoted()

int Markdown::Private::processQuoted ( std::string_view data,
size_t offset )

Process quoted section "...", can contain one embedded newline.

Definition at line 940 of file markdown.cpp.

941{
942 AUTO_TRACE("data='{}'",Trace::trunc(data));
943 const size_t size = data.size();
944 size_t i=1;
945 int nl=0;
946 while (i<size && data[i]!='"' && nl<2)
947 {
948 if (data[i]=='\n') nl++;
949 i++;
950 }
951 if (i<size && data[i]=='"' && nl<2)
952 {
953 out+=data.substr(0,i+1);
954 AUTO_TRACE_EXIT("result={}",i+2);
955 return static_cast<int>(i+1);
956 }
957 // not a quoted section
958 return 0;
959}

References AUTO_TRACE, AUTO_TRACE_EXIT, out, and Trace::trunc().

◆ processSpecialCommand()

int Markdown::Private::processSpecialCommand ( std::string_view data,
size_t offset )

Definition at line 1669 of file markdown.cpp.

1670{
1671 AUTO_TRACE("{}",Trace::trunc(data));
1672 const size_t size = data.size();
1673 size_t i=1;
1674 QCString endBlockName = isBlockCommand(data,offset);
1675 if (!endBlockName.isEmpty())
1676 {
1677 AUTO_TRACE_ADD("endBlockName={}",endBlockName);
1678 size_t l = endBlockName.length();
1679 while (i+l<size)
1680 {
1681 if ((data[i]=='\\' || data[i]=='@') && // command
1682 data[i-1]!='\\' && data[i-1]!='@') // not escaped
1683 {
1684 if (qstrncmp(&data[i+1],endBlockName.data(),l)==0)
1685 {
1686 //printf("found end at %d\n",i);
1687 addStrEscapeUtf8Nbsp(data.substr(0,i+1+l));
1688 AUTO_TRACE_EXIT("result={}",i+1+l);
1689 return static_cast<int>(i+1+l);
1690 }
1691 }
1692 i++;
1693 }
1694 }
1695 size_t endPos = isSpecialCommand(data,offset);
1696 if (endPos>0)
1697 {
1698 out+=data.substr(0,endPos);
1699 return static_cast<int>(endPos);
1700 }
1701 if (size>1 && data[0]=='\\') // escaped characters
1702 {
1703 char c=data[1];
1704 if (c=='[' || c==']' || c=='*' || c=='(' || c==')' || c=='`' || c=='_')
1705 {
1706 out+=data[1];
1707 AUTO_TRACE_EXIT("2");
1708 return 2;
1709 }
1710 else if (c=='\\' || c=='@')
1711 {
1712 out+=data.substr(0,2);
1713 AUTO_TRACE_EXIT("2");
1714 return 2;
1715 }
1716 else if (c=='-' && size>3 && data[2]=='-' && data[3]=='-') // \---
1717 {
1718 out+=data.substr(1,3);
1719 AUTO_TRACE_EXIT("2");
1720 return 4;
1721 }
1722 else if (c=='-' && size>2 && data[2]=='-') // \--
1723 {
1724 out+=data.substr(1,2);
1725 AUTO_TRACE_EXIT("3");
1726 return 3;
1727 }
1728 }
1729 else if (size>1 && data[0]=='@') // escaped characters
1730 {
1731 char c=data[1];
1732 if (c=='\\' || c=='@')
1733 {
1734 out+=data.substr(0,2);
1735 AUTO_TRACE_EXIT("2");
1736 return 2;
1737 }
1738 }
1739 return 0;
1740}
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:47
size_t isSpecialCommand(std::string_view data, size_t offset)
Definition markdown.cpp:426
void addStrEscapeUtf8Nbsp(std::string_view data)

References addStrEscapeUtf8Nbsp(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, QCString::data(), isBlockCommand(), QCString::isEmpty(), isSpecialCommand(), QCString::length(), out, qstrncmp(), and Trace::trunc().

Referenced by processQuotations().

◆ writeBlockQuote()

size_t Markdown::Private::writeBlockQuote ( std::string_view data)

Definition at line 2725 of file markdown.cpp.

2726{
2727 AUTO_TRACE("data='{}'",Trace::trunc(data));
2728 size_t i=0;
2729 int curLevel=0;
2730 size_t end=0;
2731 const size_t size = data.size();
2732 std::string startCmd;
2733 int isGitHubAlert = false;
2734 int isGitHubFirst = false;
2735 while (i<size)
2736 {
2737 // find end of this line
2738 end=i+1;
2739 while (end<=size && data[end-1]!='\n') end++;
2740 size_t j=i;
2741 int level=0;
2742 size_t indent=i;
2743 // compute the quoting level
2744 while (j<end && (data[j]==' ' || data[j]=='>'))
2745 {
2746 if (data[j]=='>') { level++; indent=j+1; }
2747 else if (j>0 && data[j-1]=='>') indent=j+1;
2748 j++;
2749 }
2750 if (indent>0 && j>0 && data[j-1]=='>' &&
2751 !(j==size || data[j]=='\n')) // disqualify last > if not followed by space
2752 {
2753 indent--;
2754 level--;
2755 j--;
2756 }
2757 AUTO_TRACE_ADD("indent={} i={} j={} end={} level={} line={}",indent,i,j,end,level,Trace::trunc(&data[i]));
2758 if (level==0 && j<end-1)
2759 {
2760 level = curLevel; // lazy
2761 }
2762 if (level==1)
2763 {
2764 QCString txt = stripWhiteSpace(data.substr(indent,end-indent));
2765 auto it = g_quotationHeaderMap.find(txt.lower().str()); // TODO: in C++20 the std::string can be dropped
2766 if (it != g_quotationHeaderMap.end())
2767 {
2768 isGitHubAlert = true;
2769 isGitHubFirst = true;
2770 startCmd = it->second;
2771 }
2772 }
2773 if (level>curLevel) // quote level increased => add start markers
2774 {
2775 if (level!=1 || !isGitHubAlert) // normal block quote
2776 {
2777 for (int l=curLevel;l<level-1;l++)
2778 {
2779 out+="<blockquote>";
2780 }
2781 out += "<blockquote>&zwj;"; // empty blockquotes are also shown
2782 }
2783 else if (!startCmd.empty()) // GitHub style alert
2784 {
2785 out += startCmd + " ";
2786 }
2787 }
2788 else if (level<curLevel) // quote level decreased => add end markers
2789 {
2790 int decrLevel = curLevel;
2791 if (level==0 && isGitHubAlert)
2792 {
2793 decrLevel--;
2794 }
2795 for (int l=level;l<decrLevel;l++)
2796 {
2797 out += "</blockquote>";
2798 }
2799 }
2800 if (level==0)
2801 {
2802 curLevel=0;
2803 break; // end of quote block
2804 }
2805 // copy line without quotation marks
2806 if (curLevel!=0 || !isGitHubAlert)
2807 {
2808 std::string_view txt = data.substr(indent,end-indent);
2809 if (stripWhiteSpace(txt).empty() && !startCmd.empty())
2810 {
2811 if (!isGitHubFirst) out += "<br>";
2812 out += "<br>\n";
2813 }
2814 else
2815 {
2816 out += txt;
2817 }
2818 isGitHubFirst = false;
2819 }
2820 else // GitHub alert section
2821 {
2822 out+= "\n";
2823 }
2824 curLevel=level;
2825 // proceed with next line
2826 i=end;
2827 }
2828 // end of comment within blockquote => add end markers
2829 if (isGitHubAlert) // GitHub alert doesn't have a blockquote
2830 {
2831 curLevel--;
2832 }
2833 for (int l=0;l<curLevel;l++)
2834 {
2835 out+="</blockquote>";
2836 }
2837 AUTO_TRACE_EXIT("i={}",i);
2838 return i;
2839}
static const std::unordered_map< std::string, std::string > g_quotationHeaderMap
static void decrLevel(yyscan_t yyscanner)
Definition pre.l:2177
std::string_view stripWhiteSpace(std::string_view s)
Given a string view s, returns a new, narrower view on that string, skipping over any leading or trai...
Definition stringutil.h:72

References AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, decrLevel(), end(), g_quotationHeaderMap, QCString::lower(), out, QCString::str(), stripWhiteSpace(), and Trace::trunc().

Referenced by processQuotations().

◆ writeCodeBlock()

size_t Markdown::Private::writeCodeBlock ( std::string_view data,
size_t refIndent )

Definition at line 2877 of file markdown.cpp.

2878{
2879 AUTO_TRACE("data='{}' refIndent={}",Trace::trunc(data),refIndent);
2880 const size_t size = data.size();
2881 size_t i=0;
2882 // no need for \ilinebr here as the previous line was empty and was skipped
2883 out+="@iverbatim\n";
2884 int emptyLines=0;
2885 std::string location;
2886 while (i<size)
2887 {
2888 // find end of this line
2889 size_t end=i+1;
2890 while (end<=size && data[end-1]!='\n') end++;
2891 size_t j=i;
2892 size_t indent=0;
2893 while (j<end && data[j]==' ') j++,indent++;
2894 //printf("j=%d end=%d indent=%d refIndent=%d tabSize=%d data={%s}\n",
2895 // j,end,indent,refIndent,Config_getInt(TAB_SIZE),qPrint(QCString(data+i).left(end-i-1)));
2896 if (j==end-1) // empty line
2897 {
2898 emptyLines++;
2899 i=end;
2900 }
2901 else if (indent>=refIndent+codeBlockIndent) // enough indent to continue the code block
2902 {
2903 while (emptyLines>0) // write skipped empty lines
2904 {
2905 // add empty line
2906 out+="\n";
2907 emptyLines--;
2908 }
2909 // add code line minus the indent
2910 size_t offset = i+refIndent+codeBlockIndent;
2911 std::string lineLoc;
2912 if (skipOverFileAndLineCommands(data,codeBlockIndent,offset,lineLoc))
2913 {
2914 location = lineLoc;
2915 }
2916 out+=data.substr(offset,end-offset);
2917 i=end;
2918 }
2919 else // end of code block
2920 {
2921 break;
2922 }
2923 }
2924 out+="@endiverbatim";
2925 if (!location.empty())
2926 {
2927 out+=location;
2928 }
2929 else
2930 {
2931 out+="\\ilinebr ";
2932 }
2933 while (emptyLines>0) // write skipped empty lines
2934 {
2935 // add empty line
2936 out+="\n";
2937 emptyLines--;
2938 }
2939 AUTO_TRACE_EXIT("i={}",i);
2940 return i;
2941}
bool skipOverFileAndLineCommands(std::string_view data, size_t indent, size_t &offset, std::string &location)

References AUTO_TRACE, AUTO_TRACE_EXIT, codeBlockIndent, end(), out, skipOverFileAndLineCommands(), and Trace::trunc().

Referenced by processBlocks().

◆ writeFencedCodeBlock()

void Markdown::Private::writeFencedCodeBlock ( std::string_view data,
std::string_view lang,
size_t blockStart,
size_t blockEnd )

Definition at line 3017 of file markdown.cpp.

3019{
3020 AUTO_TRACE("data='{}' lang={} blockStart={} blockEnd={}",Trace::trunc(data),lang,blockStart,blockEnd);
3021 if (!lang.empty() && lang[0]=='.') lang=lang.substr(1);
3022 const size_t size=data.size();
3023 size_t i=0;
3024 while (i<size && (data[i]==' ' || data[i]=='\t'))
3025 {
3026 out+=data[i++];
3027 blockStart--;
3028 blockEnd--;
3029 }
3030 out+="@icode";
3031 if (!lang.empty())
3032 {
3033 out+="{"+lang+"}";
3034 }
3035 out+=" ";
3036 addStrEscapeUtf8Nbsp(data.substr(blockStart+i,blockEnd-blockStart));
3037 out+="@endicode ";
3038}

References addStrEscapeUtf8Nbsp(), AUTO_TRACE, out, and Trace::trunc().

Referenced by processBlocks(), and processQuotations().

◆ writeMarkdownImage()

void Markdown::Private::writeMarkdownImage ( std::string_view fmt,
bool inline_img,
bool explicitTitle,
const QCString & title,
const QCString & content,
const QCString & link,
const QCString & attributes,
const FileDef * fd )

Definition at line 1109 of file markdown.cpp.

1114{
1115 AUTO_TRACE("fmt={} inline_img={} explicitTitle={} title={} content={} link={} attrs={}",
1116 fmt,inline_img,explicitTitle,Trace::trunc(title),Trace::trunc(content),link,attrs);
1117 QCString attributes = getFilteredImageAttributes(fmt, attrs);
1118 out+="@image";
1119 if (inline_img)
1120 {
1121 out+="{inline}";
1122 }
1123 out+=" ";
1124 out+=fmt;
1125 out+=" ";
1126 out+=link.mid(fd ? 0 : 5);
1127 if (!explicitTitle && !content.isEmpty())
1128 {
1129 out+=" \"";
1130 out+=escapeDoubleQuotes(content);
1131 out+="\"";
1132 }
1133 else if ((content.isEmpty() || explicitTitle) && !title.isEmpty())
1134 {
1135 out+=" \"";
1136 out+=escapeDoubleQuotes(title);
1137 out+="\"";
1138 }
1139 else
1140 {
1141 out+=" ";// so the line break will not be part of the image name
1142 }
1143 if (!attributes.isEmpty())
1144 {
1145 out+=" ";
1146 out+=attributes;
1147 out+=" ";
1148 }
1149 out+="\\ilinebr ";
1150}
static QCString escapeDoubleQuotes(const QCString &s)
Definition markdown.cpp:217
static QCString getFilteredImageAttributes(std::string_view fmt, const QCString &attrs)
parse the image attributes and return attributes for given format
Definition markdown.cpp:310

References AUTO_TRACE, escapeDoubleQuotes(), getFilteredImageAttributes(), QCString::isEmpty(), QCString::mid(), out, and Trace::trunc().

Referenced by processLink().

◆ writeOneLineHeaderOrRuler()

void Markdown::Private::writeOneLineHeaderOrRuler ( std::string_view data)

Definition at line 2665 of file markdown.cpp.

2666{
2667 AUTO_TRACE("data='{}'",Trace::trunc(data));
2668 int level=0;
2669 QCString header;
2670 QCString id;
2671 if (isHRuler(data))
2672 {
2673 out+="<hr>\n";
2674 }
2675 else if ((level=isAtxHeader(data,header,id,TRUE)))
2676 {
2677 QCString hTag;
2678 if (!id.isEmpty())
2679 {
2680 switch (level)
2681 {
2682 case SectionType::Section: out+="@section "; break;
2683 case SectionType::Subsection: out+="@subsection "; break;
2684 case SectionType::Subsubsection: out+="@subsubsection "; break;
2685 case SectionType::Paragraph: out+="@paragraph "; break;
2686 case SectionType::Subparagraph: out+="@subparagraph "; break;
2687 case SectionType::Subsubparagraph: out+="@subsubparagraph "; break;
2688 }
2689 out+=id;
2690 out+=" ";
2691 out+=header;
2692 out+="\n";
2693 }
2694 else
2695 {
2696 hTag.sprintf("h%d",level);
2697 out+="<"+hTag+">";
2698 out+=header;
2699 out+="</"+hTag+">\n";
2700 }
2701 }
2702 else if (data.size()>0) // nothing interesting -> just output the line
2703 {
2704 size_t tmpSize = data.size();
2705 if (data[data.size()-1] == '\n') tmpSize--;
2706 out+=data.substr(0,tmpSize);
2707
2708 if (hasLineBreak(data))
2709 {
2710 out+="\\ilinebr<br>";
2711 }
2712 if (tmpSize != data.size()) out+='\n';
2713 }
2714}
QCString & sprintf(const char *format,...)
Definition qcstring.cpp:29
static constexpr int Section
Definition section.h:33
static constexpr int Subsection
Definition section.h:34
static constexpr int Subsubsection
Definition section.h:35
static constexpr int Paragraph
Definition section.h:36
static constexpr int Subsubparagraph
Definition section.h:38
static constexpr int Subparagraph
Definition section.h:37
static bool hasLineBreak(std::string_view data)
static bool isHRuler(std::string_view data)
int isAtxHeader(std::string_view data, QCString &header, QCString &id, bool allowAdjustLevel, bool *pIsIdGenerated=nullptr)

References AUTO_TRACE, hasLineBreak(), isAtxHeader(), isHRuler(), out, SectionType::Paragraph, SectionType::Section, QCString::sprintf(), SectionType::Subparagraph, SectionType::Subsection, SectionType::Subsubparagraph, SectionType::Subsubsection, TRUE, and Trace::trunc().

Referenced by processBlocks().

◆ writeTableBlock()

size_t Markdown::Private::writeTableBlock ( std::string_view data)

Definition at line 2446 of file markdown.cpp.

2447{
2448 AUTO_TRACE("data='{}'",Trace::trunc(data));
2449 const size_t size = data.size();
2450
2451 size_t columns=0, start=0, end=0;
2452 size_t i = findTableColumns(data,start,end,columns);
2453 size_t headerStart = start;
2454 size_t headerEnd = end;
2455
2456 // read cell alignments
2457 size_t cc = 0;
2458 size_t ret = findTableColumns(data.substr(i),start,end,cc);
2459 size_t k=0;
2460 std::vector<int> columnAlignment(columns);
2461
2462 bool leftMarker=false, rightMarker=false, startFound=false;
2463 size_t j=start+i;
2464 while (j<=end+i)
2465 {
2466 if (!startFound)
2467 {
2468 if (data[j]==':') { leftMarker=TRUE; startFound=TRUE; }
2469 if (data[j]=='-') startFound=TRUE;
2470 //printf(" data[%d]=%c startFound=%d\n",j,data[j],startFound);
2471 }
2472 if (data[j]=='-') rightMarker=FALSE;
2473 else if (data[j]==':') rightMarker=TRUE;
2474 if (j<=end+i && (data[j]=='|' && (j==0 || data[j-1]!='\\')))
2475 {
2476 if (k<columns)
2477 {
2478 columnAlignment[k] = markersToAlignment(leftMarker,rightMarker);
2479 //printf("column[%d] alignment=%d\n",k,columnAlignment[k]);
2480 leftMarker=FALSE;
2481 rightMarker=FALSE;
2482 startFound=FALSE;
2483 }
2484 k++;
2485 }
2486 j++;
2487 }
2488 if (k<columns)
2489 {
2490 columnAlignment[k] = markersToAlignment(leftMarker,rightMarker);
2491 //printf("column[%d] alignment=%d\n",k,columnAlignment[k]);
2492 }
2493 // proceed to next line
2494 i+=ret;
2495
2496 // Store the table cell information by row then column. This
2497 // allows us to handle row spanning.
2498 std::vector<std::vector<TableCell> > tableContents;
2499
2500 size_t m = headerStart;
2501 std::vector<TableCell> headerContents(columns);
2502 for (k=0;k<columns;k++)
2503 {
2504 while (m<=headerEnd && (data[m]!='|' || (m>0 && data[m-1]=='\\')))
2505 {
2506 headerContents[k].cellText += data[m++];
2507 }
2508 m++;
2509 // do the column span test before stripping white space
2510 // || is spanning columns, | | is not
2511 headerContents[k].colSpan = headerContents[k].cellText.isEmpty();
2512 headerContents[k].cellText = headerContents[k].cellText.stripWhiteSpace();
2513 }
2514 tableContents.push_back(headerContents);
2515
2516 // write table cells
2517 while (i<size)
2518 {
2519 ret = findTableColumns(data.substr(i),start,end,cc);
2520 if (cc!=columns) break; // end of table
2521
2522 j=start+i;
2523 k=0;
2524 std::vector<TableCell> rowContents(columns);
2525 while (j<=end+i)
2526 {
2527 if (j<=end+i && (data[j]=='|' && (j==0 || data[j-1]!='\\')))
2528 {
2529 // do the column span test before stripping white space
2530 // || is spanning columns, | | is not
2531 rowContents[k].colSpan = rowContents[k].cellText.isEmpty();
2532 rowContents[k].cellText = rowContents[k].cellText.stripWhiteSpace();
2533 k++;
2534 } // if (j<=end+i && (data[j]=='|' && (j==0 || data[j-1]!='\\')))
2535 else
2536 {
2537 rowContents[k].cellText += data[j];
2538 } // else { if (j<=end+i && (data[j]=='|' && (j==0 || data[j-1]!='\\'))) }
2539 j++;
2540 } // while (j<=end+i)
2541 // do the column span test before stripping white space
2542 // || is spanning columns, | | is not
2543 rowContents[k].colSpan = rowContents[k].cellText.isEmpty();
2544 rowContents[k].cellText = rowContents[k].cellText.stripWhiteSpace();
2545 tableContents.push_back(rowContents);
2546
2547 // proceed to next line
2548 i+=ret;
2549 }
2550
2551 out+="<table class=\"markdownTable\">";
2552 QCString cellTag("th"), cellClass("class=\"markdownTableHead");
2553 for (size_t row = 0; row < tableContents.size(); row++)
2554 {
2555 if (row)
2556 {
2557 if (row % 2)
2558 {
2559 out+="\n<tr class=\"markdownTableRowOdd\">";
2560 }
2561 else
2562 {
2563 out+="\n<tr class=\"markdownTableRowEven\">";
2564 }
2565 }
2566 else
2567 {
2568 out+="\n <tr class=\"markdownTableHead\">";
2569 }
2570 for (size_t c = 0; c < columns; c++)
2571 {
2572 // save the cell text for use after column span computation
2573 QCString cellText(tableContents[row][c].cellText);
2574
2575 // Row span handling. Spanning rows will contain a caret ('^').
2576 // If the current cell contains just a caret, this is part of an
2577 // earlier row's span and the cell should not be added to the
2578 // output.
2579 if (tableContents[row][c].cellText == "^")
2580 {
2581 continue;
2582 }
2583 if (tableContents[row][c].colSpan)
2584 {
2585 int cr = static_cast<int>(c);
2586 while ( cr >= 0 && tableContents[row][cr].colSpan)
2587 {
2588 cr--;
2589 };
2590 if (cr >= 0 && tableContents[row][cr].cellText == "^") continue;
2591 }
2592 size_t rowSpan = 1, spanRow = row+1;
2593 while ((spanRow < tableContents.size()) &&
2594 (tableContents[spanRow][c].cellText == "^"))
2595 {
2596 spanRow++;
2597 rowSpan++;
2598 }
2599
2600 out+=" <" + cellTag + " " + cellClass;
2601 // use appropriate alignment style
2602 switch (columnAlignment[c])
2603 {
2604 case AlignLeft: out+="Left\""; break;
2605 case AlignRight: out+="Right\""; break;
2606 case AlignCenter: out+="Center\""; break;
2607 case AlignNone: out+="None\""; break;
2608 }
2609
2610 if (rowSpan > 1)
2611 {
2612 QCString spanStr;
2613 spanStr.setNum(rowSpan);
2614 out+=" rowspan=\"" + spanStr + "\"";
2615 }
2616 // Column span handling, assumes that column spans will have
2617 // empty strings, which would indicate the sequence "||", used
2618 // to signify spanning columns.
2619 size_t colSpan = 1;
2620 while ((c+1 < columns) && tableContents[row][c+1].colSpan)
2621 {
2622 c++;
2623 colSpan++;
2624 }
2625 if (colSpan > 1)
2626 {
2627 QCString spanStr;
2628 spanStr.setNum(colSpan);
2629 out+=" colspan=\"" + spanStr + "\"";
2630 }
2631 // need at least one space on either side of the cell text in
2632 // order for doxygen to do other formatting
2633 out+="> " + cellText + " \\ilinebr </" + cellTag + ">";
2634 }
2635 cellTag = "td";
2636 cellClass = "class=\"markdownTableBody";
2637 out+=" </tr>";
2638 }
2639 out+="</table>\n";
2640
2641 AUTO_TRACE_EXIT("i={}",i);
2642 return i;
2643}
QCString & setNum(short n)
Definition qcstring.h:444
static Alignment markersToAlignment(bool leftMarker, bool rightMarker)
helper function to convert presence of left and/or right alignment markers to a alignment value
Definition markdown.cpp:289
static size_t findTableColumns(std::string_view data, size_t &start, size_t &end, size_t &columns)
Finds the location of the table's contains in the string data.
@ AlignLeft
Definition markdown.cpp:194
@ AlignNone
Definition markdown.cpp:194
@ AlignRight
Definition markdown.cpp:194
@ AlignCenter
Definition markdown.cpp:194

References AlignCenter, AlignLeft, AlignNone, AlignRight, AUTO_TRACE, AUTO_TRACE_EXIT, end(), FALSE, findTableColumns(), markersToAlignment(), out, QCString::setNum(), TRUE, and Trace::trunc().

Referenced by processBlocks().

Member Data Documentation

◆ actions

std::array<Action_t,256> Markdown::Private::actions

Definition at line 179 of file markdown.cpp.

Referenced by processInline().

◆ fileName

QCString Markdown::Private::fileName

Definition at line 175 of file markdown.cpp.

Referenced by extractTitleId(), and processLink().

◆ indentLevel

int Markdown::Private::indentLevel =0

Definition at line 177 of file markdown.cpp.

Referenced by isAtxHeader(), and isHeaderline().

◆ lineNr

int Markdown::Private::lineNr = 0

Definition at line 176 of file markdown.cpp.

Referenced by extractTitleId().

◆ linkRefs

std::unordered_map<std::string,LinkRef> Markdown::Private::linkRefs

Definition at line 174 of file markdown.cpp.

Referenced by processBlocks(), and processLink().

◆ out


The documentation for this struct was generated from the following file: