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

Classes

struct  LinkRef

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

Detailed Description

Definition at line 130 of file markdown.cpp.

Constructor & Destructor Documentation

◆ Private()

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

Definition at line 132 of file markdown.cpp.

132: fileName(fn), lineNr(line), indentLevel(indent) { }

References fileName, indentLevel, and lineNr.

Member Function Documentation

◆ addStrEscapeUtf8Nbsp()

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

Definition at line 1781 of file markdown.cpp.

1782{
1783 AUTO_TRACE("{}",Trace::trunc(data));
1784 if (Portable::strnstr(data.data(),g_doxy_nbsp,data.size())==nullptr) // no escape needed -> fast
1785 {
1786 out+=data;
1787 }
1788 else // escape needed -> slow
1789 {
1790 out+=substitute(QCString(data),g_doxy_nbsp,g_utf8_nbsp);
1791 }
1792}
#define AUTO_TRACE(...)
Definition docnode.cpp:46
static const char * g_doxy_nbsp
Definition markdown.cpp:218
static const char * g_utf8_nbsp
Definition markdown.cpp:217
const char * strnstr(const char *haystack, const char *needle, size_t haystack_len)
Definition portable.cpp:601
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:571

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

2093{
2094 AUTO_TRACE("title={} level={}",Trace::trunc(title),level);
2095 // match e.g. '{#id-b11} ' and capture 'id-b11'
2096 static const reg::Ex r2(R"({#(\a[\w-]*)}\s*$)");
2097 reg::Match match;
2098 std::string ti = title.str();
2099 if (reg::search(ti,match,r2))
2100 {
2101 std::string id = match[1].str();
2102 title = title.left(match.position());
2103 if (AnchorGenerator::instance().reserve(id)>0)
2104 {
2105 warn(fileName, lineNr, "An automatically generated id already has the name '{}'!", id);
2106 }
2107 //printf("found match id='%s' title=%s\n",qPrint(id),qPrint(title));
2108 AUTO_TRACE_EXIT("id={}",id);
2109 return id;
2110 }
2111 if (((level>0) && (level<=Config_getInt(TOC_INCLUDE_HEADINGS))) || (Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB))
2112 {
2113 QCString id = AnchorGenerator::instance().generate(ti);
2114 if (pIsIdGenerated) *pIsIdGenerated=true;
2115 //printf("auto-generated id='%s' title='%s'\n",qPrint(id),qPrint(title));
2116 AUTO_TRACE_EXIT("id={}",id);
2117 return id;
2118 }
2119 //printf("no id found in title '%s'\n",qPrint(title));
2120 return "";
2121}
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:53
const std::string & str() const
Definition qcstring.h:552
QCString left(size_t len) const
Definition qcstring.h:229
#define Config_getInt(name)
Definition config.h:34
#define Config_getEnum(name)
Definition config.h:35
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:48
#define warn(file, line, fmt,...)
Definition message.h:97
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:844
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:855

References AUTO_TRACE, AUTO_TRACE_EXIT, Config_getEnum, 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 730 of file markdown.cpp.

731{
732 AUTO_TRACE("data='{}' c={} c_size={}",Trace::trunc(data),c,c_size);
733 size_t i = 1;
734 const size_t size = data.size();
735
736 while (i<size)
737 {
738 while (i<size && data[i]!=c &&
739 data[i]!='\\' && data[i]!='@' &&
740 !(data[i]=='/' && data[i-1]=='<') && // html end tag also ends emphasis
741 data[i]!='\n') i++;
742 // avoid overflow (unclosed emph token)
743 if (i==size)
744 {
745 return 0;
746 }
747 //printf("findEmphasisChar: data=[%s] i=%d c=%c\n",data,i,data[i]);
748
749 // not counting escaped chars or characters that are unlikely
750 // to appear as the end of the emphasis char
751 if (ignoreCloseEmphChar(data[i-1],data[i]))
752 {
753 i++;
754 continue;
755 }
756 else
757 {
758 // get length of emphasis token
759 size_t len = 0;
760 while (i+len<size && data[i+len]==c)
761 {
762 len++;
763 }
764
765 if (len>0)
766 {
767 if (len!=c_size || (i+len<size && isIdChar(data[i+len]))) // to prevent touching some_underscore_identifier
768 {
769 i+=len;
770 continue;
771 }
772 AUTO_TRACE_EXIT("result={}",i);
773 return static_cast<int>(i); // found it
774 }
775 }
776
777 // skipping a code span
778 if (data[i]=='`')
779 {
780 int snb=0;
781 while (i < size && data[i] == '`')
782 {
783 snb++;
784 i++;
785 }
786
787 // find same pattern to end the span
788 int enb=0;
789 while (i<size && enb<snb)
790 {
791 if (data[i]=='`') enb++;
792 if (snb==1 && data[i]=='\'') break; // ` ended by '
793 i++;
794 }
795 }
796 else if (data[i]=='@' || data[i]=='\\')
797 { // skip over blocks that should not be processed
798 QCString endBlockName = isBlockCommand(data.substr(i),i);
799 if (!endBlockName.isEmpty())
800 {
801 i++;
802 size_t l = endBlockName.length();
803 while (i+l<size)
804 {
805 if ((data[i]=='\\' || data[i]=='@') && // command
806 data[i-1]!='\\' && data[i-1]!='@') // not escaped
807 {
808 if (qstrncmp(&data[i+1],endBlockName.data(),l)==0)
809 {
810 break;
811 }
812 }
813 i++;
814 }
815 }
816 else if (i+1<size && isIdChar(data[i+1])) // @cmd, stop processing, see bug 690385
817 {
818 return 0;
819 }
820 else
821 {
822 i++;
823 }
824 }
825 else if (data[i-1]=='<' && data[i]=='/') // html end tag invalidates emphasis
826 {
827 return 0;
828 }
829 else if (data[i]=='\n') // end * or _ at paragraph boundary
830 {
831 i++;
832 while (i<size && data[i]==' ') i++;
833 if (i>=size || data[i]=='\n')
834 {
835 return 0;
836 } // empty line -> paragraph
837 }
838 else // should not get here!
839 {
840 i++;
841 }
842 }
843 return 0;
844}
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
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:172
static constexpr bool ignoreCloseEmphChar(char c, char cn)
Definition markdown.cpp:116
static constexpr bool isIdChar(char c)
Definition markdown.cpp:77
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:388

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

3122{
3123 AUTO_TRACE("data='{}'",Trace::trunc(data));
3124 // find end of the line
3125 const size_t size = data.size();
3126 size_t nb=0, end=offset+1, j=0;
3127 while (end<=size && (j=isNewline(data.substr(end-1)))==0)
3128 {
3129 // while looking for the end of the line we might encounter a block
3130 // that needs to be passed unprocessed.
3131 if ((data[end-1]=='\\' || data[end-1]=='@') && // command
3132 (end<=1 || (data[end-2]!='\\' && data[end-2]!='@')) // not escaped
3133 )
3134 {
3135 QCString endBlockName = isBlockCommand(data.substr(end-1),end-1);
3136 end++;
3137 if (!endBlockName.isEmpty())
3138 {
3139 size_t l = endBlockName.length();
3140 for (;end+l+1<size;end++) // search for end of block marker
3141 {
3142 if ((data[end]=='\\' || data[end]=='@') &&
3143 data[end-1]!='\\' && data[end-1]!='@'
3144 )
3145 {
3146 if (qstrncmp(&data[end+1],endBlockName.data(),l)==0)
3147 {
3148 // found end marker, skip over this block
3149 //printf("feol.block out={%s}\n",qPrint(QCString(data+i).left(end+l+1-i)));
3150 end = end + l + 2;
3151 break;
3152 }
3153 }
3154 }
3155 }
3156 }
3157 else if (nb==0 && data[end-1]=='<' && size>=6 && end+6<size &&
3158 (end<=1 || (data[end-2]!='\\' && data[end-2]!='@'))
3159 )
3160 {
3161 if (tolower(data[end])=='p' && tolower(data[end+1])=='r' &&
3162 tolower(data[end+2])=='e' && (data[end+3]=='>' || data[end+3]==' ')) // <pre> tag
3163 {
3164 // skip part until including </pre>
3165 end = end + processHtmlTagWrite(data.substr(end-1),end-1,false);
3166 break;
3167 }
3168 else
3169 {
3170 end++;
3171 }
3172 }
3173 else if (nb==0 && data[end-1]=='`')
3174 {
3175 while (end <= size && data[end - 1] == '`')
3176 {
3177 end++;
3178 nb++;
3179 }
3180 }
3181 else if (nb>0 && data[end-1]=='`')
3182 {
3183 size_t enb=0;
3184 while (end <= size && data[end - 1] == '`')
3185 {
3186 end++;
3187 enb++;
3188 }
3189 if (enb==nb) nb=0;
3190 }
3191 else
3192 {
3193 end++;
3194 }
3195 }
3196 if (j>0) end+=j-1;
3197 AUTO_TRACE_EXIT("offset={} end={}",offset,end);
3198 return end;
3199}
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
size_t isNewline(std::string_view data)
Definition markdown.cpp:225
int processHtmlTagWrite(std::string_view data, size_t offset, bool doWrite)
Process a HTML tag.

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

2126{
2127 AUTO_TRACE("data='{}' header={} id={} allowAdjustLevel={}",Trace::trunc(data),Trace::trunc(header),id,allowAdjustLevel);
2128 size_t i = 0;
2129 int level = 0, blanks=0;
2130 const size_t size = data.size();
2131
2132 // find start of header text and determine heading level
2133 while (i<size && data[i]==' ') i++;
2134 if (i>=size || data[i]!='#')
2135 {
2136 return 0;
2137 }
2138 while (i < size && data[i] == '#')
2139 {
2140 i++;
2141 level++;
2142 }
2143 if (level>SectionType::MaxLevel) // too many #'s -> no section
2144 {
2145 return 0;
2146 }
2147 while (i < size && data[i] == ' ')
2148 {
2149 i++;
2150 blanks++;
2151 }
2152 if (level==1 && blanks==0)
2153 {
2154 return 0; // special case to prevent #someid seen as a header (see bug 671395)
2155 }
2156
2157 // find end of header text
2158 size_t end=i;
2159 while (end<size && data[end]!='\n') end++;
2160 while (end>i && (data[end-1]=='#' || data[end-1]==' ')) end--;
2161
2162 // store result
2163 header = data.substr(i,end-i);
2164 id = extractTitleId(header, level, pIsIdGenerated);
2165 if (!id.isEmpty()) // strip #'s between title and id
2166 {
2167 int idx=static_cast<int>(header.length())-1;
2168 while (idx>=0 && (header.at(idx)=='#' || header.at(idx)==' ')) idx--;
2169 header=header.left(idx+1);
2170 }
2171
2172 if (allowAdjustLevel && level==1 && indentLevel==-1)
2173 {
2174 // in case we find a `# Section` on a markdown page that started with the same level
2175 // header, we no longer need to artificially decrease the paragraph level.
2176 // So both
2177 // -------------------
2178 // # heading 1 <-- here we set g_indentLevel to -1
2179 // # heading 2 <-- here we set g_indentLevel back to 0 such that this will be a @section
2180 // -------------------
2181 // and
2182 // -------------------
2183 // # heading 1 <-- here we set g_indentLevel to -1
2184 // ## heading 2 <-- here we keep g_indentLevel at -1 such that @subsection will be @section
2185 // -------------------
2186 // will convert to
2187 // -------------------
2188 // @page md_page Heading 1
2189 // @section autotoc_md1 Heading 2
2190 // -------------------
2191
2192 indentLevel=0;
2193 }
2194 int res = level+indentLevel;
2195 AUTO_TRACE_EXIT("result={}",res);
2196 return res;
2197}
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:593
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 388 of file markdown.cpp.

389{
390 QCString result;
391 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
392
393 using EndBlockFunc = QCString (*)(const std::string &,bool,char);
394
395 static constexpr auto getEndBlock = [](const std::string &blockName,bool,char) -> QCString
396 {
397 return "end"+blockName;
398 };
399 static constexpr auto getEndCode = [](const std::string &blockName,bool openBracket,char) -> QCString
400 {
401 return openBracket ? QCString("}") : "end"+blockName;
402 };
403 static constexpr auto getEndUml = [](const std::string &/* blockName */,bool,char) -> QCString
404 {
405 return "enduml";
406 };
407 static constexpr auto getEndFormula = [](const std::string &/* blockName */,bool,char nextChar) -> QCString
408 {
409 switch (nextChar)
410 {
411 case '$': return "f$";
412 case '(': return "f)";
413 case '[': return "f]";
414 case '{': return "f}";
415 }
416 return "";
417 };
418
419 // table mapping a block start command to a function that can return the matching end block string
420 static const std::unordered_map<std::string,EndBlockFunc> blockNames =
421 {
422 { "dot", getEndBlock },
423 { "code", getEndCode },
424 { "icode", getEndBlock },
425 { "msc", getEndBlock },
426 { "verbatim", getEndBlock },
427 { "iverbatim", getEndBlock },
428 { "iliteral", getEndBlock },
429 { "latexonly", getEndBlock },
430 { "htmlonly", getEndBlock },
431 { "xmlonly", getEndBlock },
432 { "rtfonly", getEndBlock },
433 { "manonly", getEndBlock },
434 { "docbookonly", getEndBlock },
435 { "startuml", getEndUml },
436 { "f", getEndFormula }
437 };
438
439 const size_t size = data.size();
440 bool openBracket = offset>0 && data.data()[-1]=='{';
441 bool isEscaped = offset>0 && (data.data()[-1]=='\\' || data.data()[-1]=='@');
442 if (isEscaped) return result;
443
444 size_t end=1;
445 while (end<size && (data[end]>='a' && data[end]<='z')) end++;
446 if (end==1) return result;
447 std::string blockName(data.substr(1,end-1));
448 auto it = blockNames.find(blockName);
449 if (it!=blockNames.end()) // there is a function assigned
450 {
451 result = it->second(blockName, openBracket, end<size ? data[end] : 0);
452 }
453 AUTO_TRACE_EXIT("result={}",result);
454 return result;
455}

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

1898{
1899 AUTO_TRACE("data='{}' allowAdjustLevel",Trace::trunc(data),allowAdjustLevel);
1900 size_t i=0, c=0;
1901 const size_t size = data.size();
1902 while (i<size && data[i]==' ') i++;
1903 if (i==size) return 0;
1904
1905 // test of level 1 header
1906 if (data[i]=='=')
1907 {
1908 while (i < size && data[i] == '=')
1909 {
1910 i++;
1911 c++;
1912 }
1913 while (i<size && data[i]==' ') i++;
1914 int level = (c>1 && (i>=size || data[i]=='\n')) ? 1 : 0;
1915 if (allowAdjustLevel && level==1 && indentLevel==-1)
1916 {
1917 // In case a page starts with a header line we use it as title, promoting it to @page.
1918 // We set g_indentLevel to -1 to promoting the other sections if they have a deeper
1919 // nesting level than the page header, i.e. @section..@subsection becomes @page..@section.
1920 // In case a section at the same level is found (@section..@section) however we need
1921 // to undo this (and the result will be @page..@section).
1922 indentLevel=0;
1923 }
1924 AUTO_TRACE_EXIT("result={}",indentLevel+level);
1925 return indentLevel+level;
1926 }
1927 // test of level 2 header
1928 if (data[i]=='-')
1929 {
1930 while (i < size && data[i] == '-')
1931 {
1932 i++;
1933 c++;
1934 }
1935 while (i<size && data[i]==' ') i++;
1936 return (c>1 && (i>=size || data[i]=='\n')) ? indentLevel+2 : 0;
1937 }
1938 return 0;
1939}

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

458{
459 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
460
461 using EndCmdFunc = size_t (*)(std::string_view,size_t);
462
463 static constexpr auto endOfLine = [](std::string_view data_,size_t offset_) -> size_t
464 {
465 // skip until the end of line (allowing line continuation characters)
466 char lc = 0;
467 char c = 0;
468 while (offset_<data_.size() && ((c=data_[offset_])!='\n' || lc=='\\'))
469 {
470 if (c=='\\') lc='\\'; // last character was a line continuation
471 else if (c!=' ') lc=0; // rest line continuation
472 offset_++;
473 }
474 return offset_;
475 };
476
477 static constexpr auto endOfLabels = [](std::string_view data_,size_t offset_,bool multi_) -> size_t
478 {
479 if (offset_<data_.size() && data_[offset_]==' ') // we expect a space before the label
480 {
481 char c = 0;
482 offset_++;
483 bool done=false;
484 while (!done)
485 {
486 // skip over spaces
487 while (offset_<data_.size() && data_[offset_]==' ')
488 {
489 offset_++;
490 }
491 // skip over label
492 while (offset_<data_.size() && (c=data_[offset_])!=' ' && c!=',' && c!='\\' && c!='@' && c!='\n')
493 {
494 offset_++;
495 }
496 // optionally skip over a comma separated list of labels
497 if (multi_ && offset_<data_.size() && (data_[offset_]==',' || data_[offset_]==' '))
498 {
499 size_t off = offset_;
500 while (off<data_.size() && data_[off]==' ')
501 {
502 off++;
503 }
504 if (off<data_.size() && data_[off]==',')
505 {
506 offset_ = ++off;
507 }
508 else // no next label found
509 {
510 done=true;
511 }
512 }
513 else
514 {
515 done=true;
516 }
517 }
518 return offset_;
519 }
520 return 0;
521 };
522
523 static constexpr auto endOfLabel = [](std::string_view data_,size_t offset_) -> size_t
524 {
525 return endOfLabels(data_,offset_,false);
526 };
527
528 static constexpr auto endOfLabelOpt = [](std::string_view data_,size_t offset_) -> size_t
529 {
530 size_t index=offset_;
531 if (index<data_.size() && data_[index]==' ') // skip over optional spaces
532 {
533 index++;
534 while (index<data_.size() && data_[index]==' ') index++;
535 }
536 if (index<data_.size() && data_[index]=='{') // find matching '}'
537 {
538 index++;
539 char c = 0;
540 while (index<data_.size() && (c=data_[index])!='}' && c!='\\' && c!='@' && c!='\n') index++;
541 if (index==data_.size() || data_[index]!='}') return 0; // invalid option
542 offset_=index+1; // part after {...} is the option
543 }
544 return endOfLabel(data_,offset_);
545 };
546
547 static constexpr auto endOfParam = [](std::string_view data_,size_t offset_) -> size_t
548 {
549 size_t index=offset_;
550 if (index<data_.size() && data_[index]==' ') // skip over optional spaces
551 {
552 index++;
553 while (index<data_.size() && data_[index]==' ') index++;
554 }
555 if (index<data_.size() && data_[index]=='[') // find matching ']'
556 {
557 index++;
558 char c = 0;
559 while (index<data_.size() && (c=data_[index])!=']' && c!='\n') index++;
560 if (index==data_.size() || data_[index]!=']') return 0; // invalid parameter
561 offset_=index+1; // part after [...] is the parameter name
562 }
563 return endOfLabels(data_,offset_,true);
564 };
565
566 static constexpr auto endOfRetVal = [](std::string_view data_,size_t offset_) -> size_t
567 {
568 return endOfLabels(data_,offset_,true);
569 };
570
571 static constexpr auto endOfFuncLike = [](std::string_view data_,size_t offset_,bool allowSpaces) -> size_t
572 {
573 if (offset_<data_.size() && data_[offset_]==' ') // we expect a space before the name
574 {
575 char c=0;
576 offset_++;
577 // skip over spaces
578 while (offset_<data_.size() && data_[offset_]==' ')
579 {
580 offset_++;
581 }
582 // skip over name (and optionally type)
583 while (offset_<data_.size() && (c=data_[offset_])!='\n' && (allowSpaces || c!=' ') && c!='(')
584 {
585 if (literal_at(data_.substr(offset_),"\\ilinebr ")) break;
586 offset_++;
587 }
588 if (c=='(') // find the end of the function
589 {
590 int count=1;
591 offset_++;
592 while (offset_<data_.size() && (c=data_[offset_++]))
593 {
594 if (c=='(') count++;
595 else if (c==')') count--;
596 if (count==0) return offset_;
597 }
598 }
599 return offset_;
600 }
601 return 0;
602 };
603
604 static constexpr auto endOfFunc = [](std::string_view data_,size_t offset_) -> size_t
605 {
606 return endOfFuncLike(data_,offset_,true);
607 };
608
609 static constexpr auto endOfGuard = [](std::string_view data_,size_t offset_) -> size_t
610 {
611 return endOfFuncLike(data_,offset_,false);
612 };
613
614 static const std::unordered_map<std::string,EndCmdFunc> cmdNames =
615 {
616 { "a", endOfLabel },
617 { "addindex", endOfLine },
618 { "addtogroup", endOfLabel },
619 { "anchor", endOfLabel },
620 { "b", endOfLabel },
621 { "c", endOfLabel },
622 { "category", endOfLine },
623 { "cite", endOfLabel },
624 { "class", endOfLine },
625 { "concept", endOfLine },
626 { "copybrief", endOfFunc },
627 { "copydetails", endOfFunc },
628 { "copydoc", endOfFunc },
629 { "def", endOfFunc },
630 { "defgroup", endOfLabel },
631 { "diafile", endOfLine },
632 { "dir", endOfLine },
633 { "dockbookinclude",endOfLine },
634 { "dontinclude", endOfLine },
635 { "dotfile", endOfLine },
636 { "e", endOfLabel },
637 { "elseif", endOfGuard },
638 { "em", endOfLabel },
639 { "emoji", endOfLabel },
640 { "enum", endOfLabel },
641 { "example", endOfLine },
642 { "exception", endOfLine },
643 { "extends", endOfLabel },
644 { "file", endOfLine },
645 { "fn", endOfFunc },
646 { "headerfile", endOfLine },
647 { "htmlinclude", endOfLine },
648 { "ianchor", endOfLabelOpt },
649 { "idlexcept", endOfLine },
650 { "if", endOfGuard },
651 { "ifnot", endOfGuard },
652 { "image", endOfLine },
653 { "implements", endOfLine },
654 { "include", endOfLine },
655 { "includedoc", endOfLine },
656 { "includelineno", endOfLine },
657 { "ingroup", endOfLabel },
658 { "interface", endOfLine },
659 { "latexinclude", endOfLine },
660 { "maninclude", endOfLine },
661 { "memberof", endOfLabel },
662 { "mscfile", endOfLine },
663 { "namespace", endOfLabel },
664 { "noop", endOfLine },
665 { "overload", endOfLine },
666 { "p", endOfLabel },
667 { "package", endOfLabel },
668 { "page", endOfLabel },
669 { "paragraph", endOfLabel },
670 { "param", endOfParam },
671 { "property", endOfLine },
672 { "protocol", endOfLine },
673 { "qualifier", endOfLine },
674 { "ref", endOfLabel },
675 { "refitem", endOfLine },
676 { "related", endOfLabel },
677 { "relatedalso", endOfLabel },
678 { "relates", endOfLabel },
679 { "relatesalso", endOfLabel },
680 { "retval", endOfRetVal},
681 { "rtfinclude", endOfLine },
682 { "section", endOfLabel },
683 { "skip", endOfLine },
684 { "skipline", endOfLine },
685 { "snippet", endOfLine },
686 { "snippetdoc", endOfLine },
687 { "snippetlineno", endOfLine },
688 { "struct", endOfLine },
689 { "subpage", endOfLabel },
690 { "subparagraph", endOfLabel },
691 { "subsubparagraph",endOfLabel },
692 { "subsection", endOfLabel },
693 { "subsubsection", endOfLabel },
694 { "throw", endOfLabel },
695 { "throws", endOfLabel },
696 { "tparam", endOfLabel },
697 { "typedef", endOfLine },
698 { "plantumlfile", endOfLine },
699 { "union", endOfLine },
700 { "until", endOfLine },
701 { "var", endOfLine },
702 { "verbinclude", endOfLine },
703 { "weakgroup", endOfLabel },
704 { "xmlinclude", endOfLine },
705 { "xrefitem", endOfLabel }
706 };
707
708 bool isEscaped = offset>0 && (data.data()[-1]=='\\' || data.data()[-1]=='@');
709 if (isEscaped) return 0;
710
711 const size_t size = data.size();
712 size_t end=1;
713 while (end<size && (data[end]>='a' && data[end]<='z')) end++;
714 if (end==1) return 0;
715 std::string cmdName(data.substr(1,end-1));
716 size_t result=0;
717 auto it = cmdNames.find(cmdName);
718 if (it!=cmdNames.end()) // command with parameters that should be ignored by markdown
719 {
720 // find the end of the parameters
721 result = it->second(data,end);
722 }
723 AUTO_TRACE_EXIT("result={}",result);
724 return result;
725}
bool literal_at(const char *data, const char(&str)[N])
returns TRUE iff data points to a substring that matches string literal str
Definition stringutil.h:98

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

Referenced by processSpecialCommand().

◆ processBlocks()

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

Definition at line 3387 of file markdown.cpp.

3388{
3389 AUTO_TRACE("data='{}' indent={}",Trace::trunc(data),indent);
3390 out.clear();
3391 size_t pi = std::string::npos;
3392 QCString id,link,title;
3393
3394#if 0 // commented out, since starting with a comment block is probably a usage error
3395 // see also http://stackoverflow.com/q/20478611/784672
3396
3397 // special case when the documentation starts with a code block
3398 // since the first line is skipped when looking for a code block later on.
3399 if (end>codeBlockIndent && isCodeBlock(data,0,end,blockIndent))
3400 {
3401 i=writeCodeBlock(out,data,size,blockIndent);
3402 end=i+1;
3403 pi=-1;
3404 }
3405#endif
3406
3407 size_t currentIndent = indent;
3408 size_t listIndent = indent;
3409 bool insideList = false;
3410 bool newBlock = false;
3411 // process each line
3412 size_t i=0;
3413 while (i<data.size())
3414 {
3415 size_t end = findEndOfLine(data,i);
3416 // line is now found at [i..end)
3417
3418 size_t lineIndent=0;
3419 int level = 0;
3420 while (lineIndent<end && data[i+lineIndent]==' ') lineIndent++;
3421 //printf("** lineIndent=%d line=(%s)\n",lineIndent,qPrint(QCString(data+i).left(end-i)));
3422
3423 if (newBlock)
3424 {
3425 //printf("** end of block\n");
3426 if (insideList && lineIndent<currentIndent) // end of list
3427 {
3428 //printf("** end of list\n");
3429 currentIndent = indent;
3430 insideList = false;
3431 }
3432 newBlock = false;
3433 }
3434
3435 if ((listIndent=isListMarker(data.substr(i,end-i)))) // see if we need to increase the indent level
3436 {
3437 if (listIndent<currentIndent+4)
3438 {
3439 //printf("** start of list\n");
3440 insideList = true;
3441 currentIndent = listIndent;
3442 }
3443 }
3444 else if (isEndOfList(data.substr(i,end-i)))
3445 {
3446 //printf("** end of list\n");
3447 insideList = false;
3448 currentIndent = listIndent;
3449 }
3450 else if (isEmptyLine(data.substr(i,end-i)))
3451 {
3452 //printf("** new block\n");
3453 newBlock = true;
3454 }
3455
3456 //printf("indent=%d listIndent=%d blockIndent=%d\n",indent,listIndent,blockIndent);
3457
3458 //printf("findEndOfLine: pi=%d i=%d end=%d\n",pi,i,end);
3459
3460 if (pi!=std::string::npos)
3461 {
3462 size_t blockStart=0, blockEnd=0, blockOffset=0;
3463 QCString lang;
3464 size_t blockIndent = currentIndent;
3465 size_t ref = 0;
3466 //printf("isHeaderLine(%s)=%d\n",QCString(data+i).left(size-i).data(),level);
3467 QCString endBlockName;
3468 if (data[i]=='@' || data[i]=='\\') endBlockName = isBlockCommand(data.substr(i),i);
3469 if (!endBlockName.isEmpty())
3470 {
3471 // handle previous line
3472 if (isLinkRef(data.substr(pi,i-pi),id,link,title))
3473 {
3474 linkRefs.emplace(id.lower().str(),LinkRef(link,title));
3475 }
3476 else
3477 {
3478 writeOneLineHeaderOrRuler(data.substr(pi,i-pi));
3479 }
3480 out+=data[i];
3481 i++;
3482 size_t l = endBlockName.length();
3483 while (i+l<data.size())
3484 {
3485 if ((data[i]=='\\' || data[i]=='@') && // command
3486 data[i-1]!='\\' && data[i-1]!='@') // not escaped
3487 {
3488 if (qstrncmp(&data[i+1],endBlockName.data(),l)==0)
3489 {
3490 out+=data[i];
3491 out+=endBlockName;
3492 i+=l+1;
3493 break;
3494 }
3495 }
3496 out+=data[i];
3497 i++;
3498 }
3499 }
3500 else if ((level=isHeaderline(data.substr(i),TRUE))>0)
3501 {
3502 //printf("Found header at %d-%d\n",i,end);
3503 while (pi<data.size() && data[pi]==' ') pi++;
3504 QCString header = data.substr(pi,i-pi-1);
3505 id = extractTitleId(header, level);
3506 //printf("header='%s' is='%s'\n",qPrint(header),qPrint(id));
3507 if (!header.isEmpty())
3508 {
3509 if (!id.isEmpty())
3510 {
3511 out+=level==1?"@section ":"@subsection ";
3512 out+=id;
3513 out+=" ";
3514 out+=header;
3515 out+="\n\n";
3516 }
3517 else
3518 {
3519 out+=level==1?"<h1>":"<h2>";
3520 out+=header;
3521 out+=level==1?"\n</h1>\n":"\n</h2>\n";
3522 }
3523 }
3524 else
3525 {
3526 out+="\n<hr>\n";
3527 }
3528 pi=std::string::npos;
3529 i=end;
3530 end=i+1;
3531 continue;
3532 }
3533 else if ((ref=isLinkRef(data.substr(pi),id,link,title)))
3534 {
3535 //printf("found link ref: id='%s' link='%s' title='%s'\n",
3536 // qPrint(id),qPrint(link),qPrint(title));
3537 linkRefs.emplace(id.lower().str(),LinkRef(link,title));
3538 i=ref+pi;
3539 end=i+1;
3540 }
3541 else if (isFencedCodeBlock(data.substr(pi),currentIndent,lang,blockStart,blockEnd,blockOffset,fileName,lineNr))
3542 {
3543 //printf("Found FencedCodeBlock lang='%s' start=%d end=%d code={%s}\n",
3544 // qPrint(lang),blockStart,blockEnd,QCString(data+pi+blockStart).left(blockEnd-blockStart).data());
3545 writeFencedCodeBlock(data.substr(pi),lang.view(),blockStart,blockEnd);
3546 i=pi+blockOffset;
3547 pi=std::string::npos;
3548 end=i+1;
3549 continue;
3550 }
3551 else if (isCodeBlock(data.substr(i,end-i),i,blockIndent))
3552 {
3553 // skip previous line (it is empty anyway)
3554 i+=writeCodeBlock(data.substr(i),blockIndent);
3555 pi=std::string::npos;
3556 end=i+1;
3557 continue;
3558 }
3559 else if (isTableBlock(data.substr(pi)))
3560 {
3561 i=pi+writeTableBlock(data.substr(pi));
3562 pi=std::string::npos;
3563 end=i+1;
3564 continue;
3565 }
3566 else
3567 {
3568 writeOneLineHeaderOrRuler(data.substr(pi,i-pi));
3569 }
3570 }
3571 pi=i;
3572 i=end;
3573 }
3574 //printf("last line %d size=%d\n",i,size);
3575 if (pi!=std::string::npos && pi<data.size()) // deal with the last line
3576 {
3577 if (isLinkRef(data.substr(pi),id,link,title))
3578 {
3579 //printf("found link ref: id='%s' link='%s' title='%s'\n",
3580 // qPrint(id),qPrint(link),qPrint(title));
3581 linkRefs.emplace(id.lower().str(),LinkRef(link,title));
3582 }
3583 else
3584 {
3585 writeOneLineHeaderOrRuler(data.substr(pi));
3586 }
3587 }
3588
3589 return out;
3590}
std::string_view view() const
Definition qcstring.h:174
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)
static const size_t codeBlockIndent
Definition markdown.cpp:219
static bool isFencedCodeBlock(std::string_view data, size_t refIndent, QCString &lang, size_t &start, size_t &end, size_t &offset, QCString &fileName, int lineNr)
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:175
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(), fileName, findEndOfLine(), isBlockCommand(), isCodeBlock(), QCString::isEmpty(), isEmptyLine(), isEndOfList(), isFencedCodeBlock(), isHeaderline(), isLinkRef(), isListMarker(), isTableBlock(), QCString::length(), lineNr, 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 1667 of file markdown.cpp.

1668{
1669 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1670 const size_t size = data.size();
1671
1672 /* counting the number of backticks in the delimiter */
1673 size_t nb=0, end=0;
1674 while (nb<size && data[nb]=='`')
1675 {
1676 nb++;
1677 }
1678
1679 /* finding the next delimiter with the same amount of backticks */
1680 size_t i = 0;
1681 char pc = '`';
1682 bool markdownStrict = Config_getBool(MARKDOWN_STRICT);
1683 for (end=nb; end<size; end++)
1684 {
1685 //AUTO_TRACE_ADD("c={} nb={} i={} size={}",data[end],nb,i,size);
1686 if (data[end]=='`')
1687 {
1688 i++;
1689 if (nb==1) // `...`
1690 {
1691 if (end+1<size && data[end+1]=='`') // skip over `` inside `...`
1692 {
1693 AUTO_TRACE_ADD("case1.1");
1694 // skip
1695 end++;
1696 i=0;
1697 }
1698 else // normal end of `...`
1699 {
1700 AUTO_TRACE_ADD("case1.2");
1701 break;
1702 }
1703 }
1704 else if (i==nb) // ``...``
1705 {
1706 if (end+1<size && data[end+1]=='`') // do greedy match
1707 {
1708 // skip this quote and use the next one to terminate the sequence, e.g. ``X`Y```
1709 i--;
1710 AUTO_TRACE_ADD("case2.1");
1711 }
1712 else // normal end of ``...``
1713 {
1714 AUTO_TRACE_ADD("case2.2");
1715 break;
1716 }
1717 }
1718 }
1719 else if (data[end]=='\n')
1720 {
1721 // consecutive newlines
1722 if (pc == '\n')
1723 {
1724 AUTO_TRACE_EXIT("new paragraph");
1725 return 0;
1726 }
1727 pc = '\n';
1728 i = 0;
1729 }
1730 else if (!markdownStrict && data[end]=='\'' && nb==1 && (end+1==size || (end+1<size && data[end+1]!='\'' && !isIdChar(data[end+1]))))
1731 { // look for quoted strings like 'some word', but skip strings like `it's cool`
1732 out+="&lsquo;";
1733 out+=data.substr(nb,end-nb);
1734 out+="&rsquo;";
1735 AUTO_TRACE_EXIT("quoted end={}",end+1);
1736 return static_cast<int>(end+1);
1737 }
1738 else if (!markdownStrict && data[end]=='\'' && nb==2 && end+1<size && data[end+1]=='\'')
1739 { // look for '' to match a ``
1740 out+="&ldquo;";
1741 out+=data.substr(nb,end-nb);
1742 out+="&rdquo;";
1743 AUTO_TRACE_EXIT("double quoted end={}",end+1);
1744 return static_cast<int>(end+2);
1745 }
1746 else
1747 {
1748 if (data[end]!=' ') pc = data[end];
1749 i=0;
1750 }
1751 }
1752 if (i < nb && end >= size)
1753 {
1754 AUTO_TRACE_EXIT("no matching delimiter nb={} i={}",nb,i);
1755 if (nb>=3) // found ``` that is not at the start of the line, keep it as-is.
1756 {
1757 out+=data.substr(0,nb);
1758 return static_cast<int>(nb);
1759 }
1760 return 0; // no matching delimiter
1761 }
1762 while (end<size && data[end]=='`') // do greedy match in case we have more end backticks.
1763 {
1764 end++;
1765 }
1766
1767 //printf("found code span '%s'\n",qPrint(QCString(data+f_begin).left(f_end-f_begin)));
1768
1769 /* real code span */
1770 if (nb+nb < end)
1771 {
1772 QCString codeFragment = data.substr(nb, end-nb-nb);
1773 out+="<tt>";
1774 out+=escapeSpecialChars(codeFragment);
1775 out+="</tt>";
1776 }
1777 AUTO_TRACE_EXIT("result={} nb={}",end,nb);
1778 return static_cast<int>(end);
1779}
#define Config_getBool(name)
Definition config.h:33
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:47
static QCString escapeSpecialChars(const QCString &s)
Definition markdown.cpp:256

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

Referenced by Markdown::fill_table().

◆ processEmphasis()

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

Definition at line 1143 of file markdown.cpp.

1144{
1145 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1146 const size_t size = data.size();
1147
1148 if (isAllowedEmphStr(data,offset) || // invalid char before * or _
1149 (size>1 && data[0]!=data[1] && !(isIdChar(data[1]) || extraChar(data[1]))) || // invalid char after * or _
1150 (size>2 && data[0]==data[1] && !(isIdChar(data[2]) || extraChar(data[2])))) // invalid char after ** or __
1151 {
1152 AUTO_TRACE_EXIT("invalid surrounding characters");
1153 return 0;
1154 }
1155
1156 char c = data[0];
1157 int ret = 0;
1158 if (size>2 && c!='~' && data[1]!=c) // _bla or *bla
1159 {
1160 // whitespace cannot follow an opening emphasis
1161 if (data[1]==' ' || data[1]=='\n' ||
1162 (ret = processEmphasis1(data.substr(1), c)) == 0)
1163 {
1164 return 0;
1165 }
1166 AUTO_TRACE_EXIT("result={}",ret+1);
1167 return ret+1;
1168 }
1169 if (size>3 && data[1]==c && data[2]!=c) // __bla or **bla
1170 {
1171 if (data[2]==' ' || data[2]=='\n' ||
1172 (ret = processEmphasis2(data.substr(2), c)) == 0)
1173 {
1174 return 0;
1175 }
1176 AUTO_TRACE_EXIT("result={}",ret+2);
1177 return ret+2;
1178 }
1179 if (size>4 && c!='~' && data[1]==c && data[2]==c && data[3]!=c) // ___bla or ***bla
1180 {
1181 if (data[3]==' ' || data[3]=='\n' ||
1182 (ret = processEmphasis3(data.substr(3), c)) == 0)
1183 {
1184 return 0;
1185 }
1186 AUTO_TRACE_EXIT("result={}",ret+3);
1187 return ret+3;
1188 }
1189 return 0;
1190}
static constexpr bool isAllowedEmphStr(const std::string_view &data, size_t offset)
Definition markdown.cpp:108
static constexpr bool extraChar(char c)
Definition markdown.cpp:86
int processEmphasis1(std::string_view data, char c)
process single emphasis
Definition markdown.cpp:847
int processEmphasis3(std::string_view data, char c)
Parsing triple emphasis.
Definition markdown.cpp:913
int processEmphasis2(std::string_view data, char c)
process double emphasis
Definition markdown.cpp:881

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

Referenced by Markdown::fill_table().

◆ processEmphasis1()

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

process single emphasis

Definition at line 847 of file markdown.cpp.

848{
849 AUTO_TRACE("data='{}' c={}",Trace::trunc(data),c);
850 size_t i = 0;
851 const size_t size = data.size();
852
853 /* skipping one symbol if coming from emph3 */
854 if (size>1 && data[0]==c && data[1]==c) { i=1; }
855
856 while (i<size)
857 {
858 size_t len = findEmphasisChar(data.substr(i), c, 1);
859 if (len==0) { return 0; }
860 i+=len;
861 if (i>=size) { return 0; }
862
863 if (i+1<size && data[i+1]==c)
864 {
865 i++;
866 continue;
867 }
868 if (data[i]==c && data[i-1]!=' ' && data[i-1]!='\n')
869 {
870 out+="<em>";
871 processInline(data.substr(0,i));
872 out+="</em>";
873 AUTO_TRACE_EXIT("result={}",i+1);
874 return static_cast<int>(i+1);
875 }
876 }
877 return 0;
878}
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:730
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 881 of file markdown.cpp.

882{
883 AUTO_TRACE("data='{}' c={}",Trace::trunc(data),c);
884 size_t i = 0;
885 const size_t size = data.size();
886
887 while (i<size)
888 {
889 size_t len = findEmphasisChar(data.substr(i), c, 2);
890 if (len==0)
891 {
892 return 0;
893 }
894 i += len;
895 if (i+1<size && data[i]==c && data[i+1]==c && i && data[i-1]!=' ' && data[i-1]!='\n')
896 {
897 if (c == '~') out+="<strike>";
898 else out+="<strong>";
899 processInline(data.substr(0,i));
900 if (c == '~') out+="</strike>";
901 else out+="</strong>";
902 AUTO_TRACE_EXIT("result={}",i+2);
903 return static_cast<int>(i+2);
904 }
905 i++;
906 }
907 return 0;
908}

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

914{
915 AUTO_TRACE("data='{}' c={}",Trace::trunc(data),c);
916 size_t i = 0;
917 const size_t size = data.size();
918
919 while (i<size)
920 {
921 size_t len = findEmphasisChar(data.substr(i), c, 3);
922 if (len==0)
923 {
924 return 0;
925 }
926 i+=len;
927
928 /* skip whitespace preceded symbols */
929 if (data[i]!=c || data[i-1]==' ' || data[i-1]=='\n')
930 {
931 continue;
932 }
933
934 if (i+2<size && data[i+1]==c && data[i+2]==c)
935 {
936 out+="<em><strong>";
937 processInline(data.substr(0,i));
938 out+="</strong></em>";
939 AUTO_TRACE_EXIT("result={}",i+3);
940 return static_cast<int>(i+3);
941 }
942 else if (i+1<size && data[i+1]==c)
943 {
944 // double symbol found, handing over to emph1
945 len = processEmphasis1(std::string_view(data.data()-2, size+2), c);
946 if (len==0)
947 {
948 return 0;
949 }
950 else
951 {
952 AUTO_TRACE_EXIT("result={}",len-2);
953 return static_cast<int>(len - 2);
954 }
955 }
956 else
957 {
958 // single symbol found, handing over to emph2
959 len = processEmphasis2(std::string_view(data.data()-1, size+1), c);
960 if (len==0)
961 {
962 return 0;
963 }
964 else
965 {
966 AUTO_TRACE_EXIT("result={}",len-1);
967 return static_cast<int>(len - 1);
968 }
969 }
970 }
971 return 0;
972}

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

1138{
1139 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1140 return processHtmlTagWrite(data,offset,true);
1141}

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

Referenced by Markdown::fill_table().

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

1044{
1045 AUTO_TRACE("data='{}' offset={} doWrite={}",Trace::trunc(data),offset,doWrite);
1046 if (offset>0 && data.data()[-1]=='\\') { return 0; } // escaped <
1047
1048 const size_t size = data.size();
1049
1050 // find the end of the html tag
1051 size_t i=1;
1052 size_t l=0;
1053 // compute length of the tag name
1054 while (i < size && isIdChar(data[i]))
1055 {
1056 i++;
1057 l++;
1058 }
1059 QCString tagName(data.substr(1,i-1));
1060 if (tagName.lower()=="pre") // found <pre> tag
1061 {
1062 bool insideStr=FALSE;
1063 while (i+6<size)
1064 {
1065 char c=data[i];
1066 if (!insideStr && c=='<') // potential start of html tag
1067 {
1068 if (data[i+1]=='/' &&
1069 tolower(data[i+2])=='p' && tolower(data[i+3])=='r' &&
1070 tolower(data[i+4])=='e' && tolower(data[i+5])=='>')
1071 { // found </pre> tag, copy from start to end of tag
1072 if (doWrite) out+=data.substr(0,i+6);
1073 //printf("found <pre>..</pre> [%d..%d]\n",0,i+6);
1074 AUTO_TRACE_EXIT("result={}",i+6);
1075 return static_cast<int>(i+6);
1076 }
1077 }
1078 else if (insideStr && c=='"')
1079 {
1080 if (data[i-1]!='\\') insideStr=FALSE;
1081 }
1082 else if (c=='"')
1083 {
1084 insideStr=TRUE;
1085 }
1086 i++;
1087 }
1088 }
1089 else // some other html tag
1090 {
1091 if (l>0 && i<size)
1092 {
1093 if (data[i]=='/' && i+1<size && data[i+1]=='>') // <bla/>
1094 {
1095 //printf("Found htmlTag={%s}\n",qPrint(QCString(data).left(i+2)));
1096 if (doWrite) out+=data.substr(0,i+2);
1097 AUTO_TRACE_EXIT("result={}",i+2);
1098 return static_cast<int>(i+2);
1099 }
1100 else if (data[i]=='>') // <bla>
1101 {
1102 //printf("Found htmlTag={%s}\n",qPrint(QCString(data).left(i+1)));
1103 if (doWrite) out+=data.substr(0,i+1);
1104 AUTO_TRACE_EXIT("result={}",i+1);
1105 return static_cast<int>(i+1);
1106 }
1107 else if (data[i]==' ') // <bla attr=...
1108 {
1109 i++;
1110 bool insideAttr=FALSE;
1111 while (i<size)
1112 {
1113 if (!insideAttr && data[i]=='"')
1114 {
1115 insideAttr=TRUE;
1116 }
1117 else if (data[i]=='"' && data[i-1]!='\\')
1118 {
1119 insideAttr=FALSE;
1120 }
1121 else if (!insideAttr && data[i]=='>') // found end of tag
1122 {
1123 //printf("Found htmlTag={%s}\n",qPrint(QCString(data).left(i+1)));
1124 if (doWrite) out+=data.substr(0,i+1);
1125 AUTO_TRACE_EXIT("result={}",i+1);
1126 return static_cast<int>(i+1);
1127 }
1128 i++;
1129 }
1130 }
1131 }
1132 }
1133 AUTO_TRACE_EXIT("not a valid html tag");
1134 return 0;
1135}
#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 1867 of file markdown.cpp.

1868{
1869 AUTO_TRACE("data='{}'",Trace::trunc(data));
1870 size_t i=0;
1871 size_t end=0;
1872 Action_t action;
1873 const size_t size = data.size();
1874 while (i<size)
1875 {
1876 // skip over characters that do not trigger a specific action
1877 while (end<size && ((action=Markdown::actions[static_cast<uint8_t>(data[end])])==nullptr)) end++;
1878 // and add them to the output
1879 out+=data.substr(i,end-i);
1880 if (end>=size) break;
1881 i=end;
1882 // do the action matching a special character at i
1883 int iend = action(*this,data.substr(i),i);
1884 if (iend<=0) // update end
1885 {
1886 end=i+1-iend;
1887 }
1888 else // skip until end
1889 {
1890 i+=iend;
1891 end=i;
1892 }
1893 }
1894}
static ActionTable_t actions
Definition markdown.h:47
std::function< int(Private &, std::string_view, size_t)> Action_t
Definition markdown.h:44

References Markdown::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 1235 of file markdown.cpp.

1236{
1237 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1238 const size_t size = data.size();
1239 QCString content;
1240 QCString link;
1241 QCString title;
1242 bool isImageLink = FALSE;
1243 bool isImageInline = FALSE;
1244 bool isToc = FALSE;
1245 size_t i=1;
1246 if (data[0]=='!')
1247 {
1248 isImageLink = TRUE;
1249 if (size<2 || data[1]!='[')
1250 {
1251 return 0;
1252 }
1253
1254 // if there is non-whitespace before the ![ within the scope of two new lines, the image
1255 // is considered inlined, i.e. the image is not preceded by an empty line
1256 int numNLsNeeded=2;
1257 int pos = -1;
1258 while (pos>=-static_cast<int>(offset) && numNLsNeeded>0)
1259 {
1260 if (data.data()[pos]=='\n') numNLsNeeded--;
1261 else if (data.data()[pos]!=' ') // found non-whitespace, stop searching
1262 {
1263 isImageInline=true;
1264 break;
1265 }
1266 pos--;
1267 }
1268 // skip '!['
1269 i++;
1270 }
1271 size_t contentStart=i;
1272 int level=1;
1273 int nlTotal=0;
1274 int nl=0;
1275 // find the matching ]
1276 while (i<size)
1277 {
1278 if (data[i-1]=='\\') // skip escaped characters
1279 {
1280 }
1281 else if (data[i]=='[')
1282 {
1283 level++;
1284 }
1285 else if (data[i]==']')
1286 {
1287 level--;
1288 if (level<=0) break;
1289 }
1290 else if (data[i]=='\n')
1291 {
1292 nl++;
1293 if (nl>1) { return 0; } // only allow one newline in the content
1294 }
1295 i++;
1296 }
1297 nlTotal += nl;
1298 nl = 0;
1299 if (i>=size) return 0; // premature end of comment -> no link
1300 size_t contentEnd=i;
1301 content = data.substr(contentStart,contentEnd-contentStart);
1302 //printf("processLink: content={%s}\n",qPrint(content));
1303 if (!isImageLink && content.isEmpty()) { return 0; } // no link text
1304 i++; // skip over ]
1305
1306 bool whiteSpace = false;
1307 // skip whitespace
1308 while (i<size && data[i]==' ') { whiteSpace = true; i++; }
1309 if (i<size && data[i]=='\n') // one newline allowed here
1310 {
1311 whiteSpace = true;
1312 i++;
1313 // skip more whitespace
1314 while (i<size && data[i]==' ') i++;
1315 }
1316 if (whiteSpace && i<size && (data[i]=='(' || data[i]=='[')) return 0;
1317
1318 bool explicitTitle=FALSE;
1319 if (i<size && data[i]=='(') // inline link
1320 {
1321 i++;
1322 while (i<size && data[i]==' ') i++;
1323 bool uriFormat=false;
1324 if (i<size && data[i]=='<') { i++; uriFormat=true; }
1325 size_t linkStart=i;
1326 int braceCount=1;
1327 while (i<size && data[i]!='\'' && data[i]!='"' && braceCount>0)
1328 {
1329 if (data[i]=='\n') // unexpected EOL
1330 {
1331 nl++;
1332 if (nl>1) { return 0; }
1333 }
1334 else if (data[i]=='(')
1335 {
1336 braceCount++;
1337 }
1338 else if (data[i]==')')
1339 {
1340 braceCount--;
1341 }
1342 if (braceCount>0)
1343 {
1344 i++;
1345 }
1346 }
1347 nlTotal += nl;
1348 nl = 0;
1349 if (i>=size || data[i]=='\n') { return 0; }
1350 link = data.substr(linkStart,i-linkStart);
1351 link = link.stripWhiteSpace();
1352 //printf("processLink: link={%s}\n",qPrint(link));
1353 if (link.isEmpty()) { return 0; }
1354 if (uriFormat && link.at(link.length()-1)=='>') link=link.left(link.length()-1);
1355
1356 // optional title
1357 if (data[i]=='\'' || data[i]=='"')
1358 {
1359 char c = data[i];
1360 i++;
1361 size_t titleStart=i;
1362 nl=0;
1363 while (i<size)
1364 {
1365 if (data[i]=='\n')
1366 {
1367 if (nl>1) { return 0; }
1368 nl++;
1369 }
1370 else if (data[i]=='\\') // escaped char in string
1371 {
1372 i++;
1373 }
1374 else if (data[i]==c)
1375 {
1376 i++;
1377 break;
1378 }
1379 i++;
1380 }
1381 if (i>=size)
1382 {
1383 return 0;
1384 }
1385 size_t titleEnd = i-1;
1386 // search back for closing marker
1387 while (titleEnd>titleStart && data[titleEnd]==' ') titleEnd--;
1388 if (data[titleEnd]==c) // found it
1389 {
1390 title = data.substr(titleStart,titleEnd-titleStart);
1391 explicitTitle=TRUE;
1392 while (i<size)
1393 {
1394 if (data[i]==' ')i++; // remove space after the closing quote and the closing bracket
1395 else if (data[i] == ')') break; // the end bracket
1396 else // illegal
1397 {
1398 return 0;
1399 }
1400 }
1401 }
1402 else
1403 {
1404 return 0;
1405 }
1406 }
1407 i++;
1408 }
1409 else if (i<size && data[i]=='[') // reference link
1410 {
1411 i++;
1412 size_t linkStart=i;
1413 nl=0;
1414 // find matching ]
1415 while (i<size && data[i]!=']')
1416 {
1417 if (data[i]=='\n')
1418 {
1419 nl++;
1420 if (nl>1) { return 0; }
1421 }
1422 i++;
1423 }
1424 if (i>=size) { return 0; }
1425 // extract link
1426 link = data.substr(linkStart,i-linkStart);
1427 //printf("processLink: link={%s}\n",qPrint(link));
1428 link = link.stripWhiteSpace();
1429 if (link.isEmpty()) // shortcut link
1430 {
1431 link=content;
1432 }
1433 // lookup reference
1434 QCString link_lower = link.lower();
1435 auto lr_it=linkRefs.find(link_lower.str());
1436 if (lr_it!=linkRefs.end()) // found it
1437 {
1438 link = lr_it->second.link;
1439 title = lr_it->second.title;
1440 //printf("processLink: ref: link={%s} title={%s}\n",qPrint(link),qPrint(title));
1441 }
1442 else // reference not found!
1443 {
1444 //printf("processLink: ref {%s} do not exist\n",link.qPrint(lower()));
1445 return 0;
1446 }
1447 i++;
1448 }
1449 else if (i<size && data[i]!=':' && !content.isEmpty()) // minimal link ref notation [some id]
1450 {
1451 QCString content_lower = content.lower();
1452 auto lr_it = linkRefs.find(content_lower.str());
1453 //printf("processLink: minimal link {%s} lr=%p",qPrint(content),lr);
1454 if (lr_it!=linkRefs.end()) // found it
1455 {
1456 link = lr_it->second.link;
1457 title = lr_it->second.title;
1458 explicitTitle=TRUE;
1459 i=contentEnd;
1460 }
1461 else if (content=="TOC")
1462 {
1463 isToc=TRUE;
1464 i=contentEnd;
1465 }
1466 else
1467 {
1468 return 0;
1469 }
1470 i++;
1471 }
1472 else
1473 {
1474 return 0;
1475 }
1476 nlTotal += nl;
1477
1478 // search for optional image attributes
1479 QCString attributes;
1480 if (isImageLink)
1481 {
1482 size_t j = i;
1483 // skip over whitespace
1484 while (j<size && data[j]==' ') { j++; }
1485 if (j<size && data[j]=='{') // we have attributes
1486 {
1487 i = j;
1488 // skip over '{'
1489 i++;
1490 size_t attributesStart=i;
1491 nl=0;
1492 // find the matching '}'
1493 while (i<size)
1494 {
1495 if (data[i-1]=='\\') // skip escaped characters
1496 {
1497 }
1498 else if (data[i]=='{')
1499 {
1500 level++;
1501 }
1502 else if (data[i]=='}')
1503 {
1504 level--;
1505 if (level<=0) break;
1506 }
1507 else if (data[i]=='\n')
1508 {
1509 nl++;
1510 if (nl>1) { return 0; } // only allow one newline in the content
1511 }
1512 i++;
1513 }
1514 nlTotal += nl;
1515 if (i>=size) return 0; // premature end of comment -> no attributes
1516 size_t attributesEnd=i;
1517 attributes = data.substr(attributesStart,attributesEnd-attributesStart);
1518 i++; // skip over '}'
1519 }
1520 if (!isImageInline)
1521 {
1522 // if there is non-whitespace after the image within the scope of two new lines, the image
1523 // is considered inlined, i.e. the image is not followed by an empty line
1524 int numNLsNeeded=2;
1525 size_t pos = i;
1526 while (pos<size && numNLsNeeded>0)
1527 {
1528 if (data[pos]=='\n') numNLsNeeded--;
1529 else if (data[pos]!=' ') // found non-whitespace, stop searching
1530 {
1531 isImageInline=true;
1532 break;
1533 }
1534 pos++;
1535 }
1536 }
1537 }
1538
1539 if (isToc) // special case for [TOC]
1540 {
1541 int toc_level = Config_getInt(TOC_INCLUDE_HEADINGS);
1542 if (toc_level>=SectionType::MinLevel && toc_level<=SectionType::MaxLevel)
1543 {
1544 out+="@tableofcontents{html:";
1545 out+=QCString().setNum(toc_level);
1546 out+="}";
1547 }
1548 }
1549 else if (isImageLink)
1550 {
1551 bool ambig = false;
1552 FileDef *fd=nullptr;
1553 if (link.find("@ref ")!=-1 || link.find("\\ref ")!=-1 ||
1555 // assume doxygen symbol link or local image link
1556 {
1557 // check if different handling is needed per format
1558 writeMarkdownImage("html", isImageInline, explicitTitle, title, content, link, attributes, fd);
1559 writeMarkdownImage("latex", isImageInline, explicitTitle, title, content, link, attributes, fd);
1560 writeMarkdownImage("rtf", isImageInline, explicitTitle, title, content, link, attributes, fd);
1561 writeMarkdownImage("docbook", isImageInline, explicitTitle, title, content, link, attributes, fd);
1562 writeMarkdownImage("xml", isImageInline, explicitTitle, title, content, link, attributes, fd);
1563 }
1564 else
1565 {
1566 out+="<img src=\"";
1567 out+=link;
1568 out+="\" alt=\"";
1569 out+=content;
1570 out+="\"";
1571 if (!title.isEmpty())
1572 {
1573 out+=" title=\"";
1574 out+=substitute(title.simplifyWhiteSpace(),"\"","&quot;");
1575 out+="\"";
1576 }
1577 out+="/>";
1578 }
1579 }
1580 else
1581 {
1583 int lp=-1;
1584 if ((lp=link.find("@ref "))!=-1 || (lp=link.find("\\ref "))!=-1 || (lang==SrcLangExt::Markdown && !isURL(link)))
1585 // assume doxygen symbol link
1586 {
1587 if (lp==-1) // link to markdown page
1588 {
1589 out+="@ref \"";
1590 if (!(Portable::isAbsolutePath(link) || isURL(link)))
1591 {
1592 FileInfo forg(link.str());
1593 if (forg.exists() && forg.isReadable())
1594 {
1595 link = forg.absFilePath();
1596 }
1597 else if (!(forg.exists() && forg.isReadable()))
1598 {
1599 FileInfo fi(fileName.str());
1600 QCString mdFile = fileName.left(fileName.length()-fi.fileName().length()) + link;
1601 FileInfo fmd(mdFile.str());
1602 if (fmd.exists() && fmd.isReadable())
1603 {
1604 link = fmd.absFilePath().data();
1605 }
1606 }
1607 }
1608 out+=link;
1609 out+="\"";
1610 }
1611 else
1612 {
1613 out+=link;
1614 }
1615 out+=" \"";
1616 if (explicitTitle && !title.isEmpty())
1617 {
1618 out+=substitute(title,"\"","&quot;");
1619 }
1620 else
1621 {
1622 processInline(std::string_view(substitute(content,"\"","&quot;").str()));
1623 }
1624 out+="\"";
1625 }
1626 else if ((lp=link.find('#'))!=-1 || link.find('/')!=-1 || link.find('.')!=-1)
1627 { // file/url link
1628 if (lp==0 || (lp>0 && !isURL(link) && Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB))
1629 {
1630 out+="@ref \"";
1632 out+="\" \"";
1633 out+=substitute(content.simplifyWhiteSpace(),"\"","&quot;");
1634 out+="\"";
1635 }
1636 else
1637 {
1638 out+="<a href=\"";
1639 out+=link;
1640 out+="\"";
1641 for (int ii = 0; ii < nlTotal; ii++) out+="\n";
1642 if (!title.isEmpty())
1643 {
1644 out+=" title=\"";
1645 out+=substitute(title.simplifyWhiteSpace(),"\"","&quot;");
1646 out+="\"";
1647 }
1648 out+=" ";
1650 out+=">";
1651 content = content.simplifyWhiteSpace();
1652 processInline(std::string_view(content.str()));
1653 out+="</a>";
1654 }
1655 }
1656 else // avoid link to e.g. F[x](y)
1657 {
1658 //printf("no link for '%s'\n",qPrint(link));
1659 return 0;
1660 }
1661 }
1662 AUTO_TRACE_EXIT("result={}",i);
1663 return static_cast<int>(i);
1664}
static std::string addPrefixIfNeeded(const std::string &anchor)
Definition anchor.cpp:46
static FileNameLinkedMap * imageNameLinkedMap
Definition doxygen.h:105
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:241
QCString lower() const
Definition qcstring.h:249
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:260
QCString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple whitespace cha...
Definition qcstring.cpp:190
static constexpr int MinLevel
Definition section.h:32
bool isAbsolutePath(const QCString &fileName)
Definition portable.cpp:498
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
Definition types.h:207
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
Definition util.cpp:5147
bool isURL(const QCString &url)
Checks whether the given url starts with a supported protocol.
Definition util.cpp:5865
QCString externalLinkTarget(const bool parent)
Definition util.cpp:5661
FileDef * findFileDef(const FileNameLinkedMap *fnMap, const QCString &n, bool &ambig)
Definition util.cpp:2838

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(), SectionType::MaxLevel, QCString::mid(), SectionType::MinLevel, out, processInline(), QCString::setNum(), QCString::simplifyWhiteSpace(), QCString::str(), QCString::stripWhiteSpace(), substitute(), TRUE, Trace::trunc(), and writeMarkdownImage().

Referenced by Markdown::fill_table().

◆ processNmdash()

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

Process ndash and mdashes.

Definition at line 975 of file markdown.cpp.

976{
977 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
978 const size_t size = data.size();
979 // precondition: data[0]=='-'
980 size_t i=1;
981 int count=1;
982 if (i<size && data[i]=='-') // found --
983 {
984 count++;
985 i++;
986 }
987 if (i<size && data[i]=='-') // found ---
988 {
989 count++;
990 i++;
991 }
992 if (i<size && data[i]=='-') // found ----
993 {
994 count++;
995 }
996 if (count>=2 && offset>=2 && literal_at(data.data()-2,"<!"))
997 { AUTO_TRACE_EXIT("result={}",1-count); return 1-count; } // start HTML comment
998 if (count==2 && size > 2 && data[2]=='>')
999 { return 0; } // end HTML comment
1000 if (count==3 && size > 3 && data[3]=='>')
1001 { return 0; } // end HTML comment
1002 if (count==2 && (offset<8 || !literal_at(data.data()-8,"operator"))) // -- => ndash
1003 {
1004 out+="&ndash;";
1005 AUTO_TRACE_EXIT("result=2");
1006 return 2;
1007 }
1008 else if (count==3) // --- => ndash
1009 {
1010 out+="&mdash;";
1011 AUTO_TRACE_EXIT("result=3");
1012 return 3;
1013 }
1014 // not an ndash or mdash
1015 return 0;
1016}

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

Referenced by Markdown::fill_table().

◆ processQuotations()

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

Definition at line 3224 of file markdown.cpp.

3225{
3226 AUTO_TRACE("data='{}' refIndex='{}'",Trace::trunc(data),refIndent);
3227 out.clear();
3228 size_t i=0,end=0;
3229 size_t pi=std::string::npos;
3230 bool newBlock = false;
3231 bool insideList = false;
3232 size_t currentIndent = refIndent;
3233 size_t listIndent = refIndent;
3234 const size_t size = data.size();
3235 QCString lang;
3236 while (i<size)
3237 {
3238 end = findEndOfLine(data,i);
3239 // line is now found at [i..end)
3240
3241 size_t lineIndent=0;
3242 while (lineIndent<end && data[i+lineIndent]==' ') lineIndent++;
3243 //printf("** lineIndent=%d line=(%s)\n",lineIndent,qPrint(QCString(data+i).left(end-i)));
3244
3245 if (newBlock)
3246 {
3247 //printf("** end of block\n");
3248 if (insideList && lineIndent<currentIndent) // end of list
3249 {
3250 //printf("** end of list\n");
3251 currentIndent = refIndent;
3252 insideList = false;
3253 }
3254 newBlock = false;
3255 }
3256
3257 if ((listIndent=isListMarker(data.substr(i,end-i)))) // see if we need to increase the indent level
3258 {
3259 if (listIndent<currentIndent+4)
3260 {
3261 //printf("** start of list\n");
3262 insideList = true;
3263 currentIndent = listIndent;
3264 }
3265 }
3266 else if (isEndOfList(data.substr(i,end-i)))
3267 {
3268 //printf("** end of list\n");
3269 insideList = false;
3270 currentIndent = listIndent;
3271 }
3272 else if (isEmptyLine(data.substr(i,end-i)))
3273 {
3274 //printf("** new block\n");
3275 newBlock = true;
3276 }
3277 //printf("currentIndent=%d listIndent=%d refIndent=%d\n",currentIndent,listIndent,refIndent);
3278
3279 if (pi!=std::string::npos)
3280 {
3281 size_t blockStart=0, blockEnd=0, blockOffset=0;
3282 if (isFencedCodeBlock(data.substr(pi),currentIndent,lang,blockStart,blockEnd,blockOffset,fileName,lineNr))
3283 {
3284 auto addSpecialCommand = [&](const QCString &startCmd,const QCString &endCmd)
3285 {
3286 size_t cmdPos = pi+blockStart+1;
3287 QCString pl = data.substr(cmdPos,blockEnd-blockStart-1);
3288 size_t ii = 0;
3289 int nl = 1;
3290 // check for absence of start command, either @start<cmd>, or \\start<cmd>
3291 while (ii<pl.length() && qisspace(pl[ii]))
3292 {
3293 if (pl[ii]=='\n') nl++;
3294 ii++; // skip leading whitespace
3295 }
3296 bool addNewLines = false;
3297 if (ii+startCmd.length()>=pl.length() || // no room for start command
3298 (pl[ii]!='\\' && pl[ii]!='@') || // no @ or \ after whitespace
3299 qstrncmp(pl.data()+ii+1,startCmd.data(),startCmd.length())!=0) // no start command
3300 {
3301 // input: output:
3302 // ----------------------------------------------------
3303 // ```{plantuml} => @startuml
3304 // A->B A->B
3305 // ``` @enduml
3306 // ----------------------------------------------------
3307 pl = "@"+startCmd+"\n" + pl + "@"+endCmd;
3308 addNewLines = false;
3309 }
3310 else // we have a @start... command inside the code block
3311 {
3312 // input: output:
3313 // ----------------------------------------------------
3314 // ```{plantuml} \n
3315 // \n
3316 // @startuml => @startuml
3317 // A->B A->B
3318 // @enduml @enduml
3319 // ``` \n
3320 // ----------------------------------------------------
3321 addNewLines = true;
3322 }
3323 if (addNewLines) for (int j=0;j<nl;j++) out+='\n';
3324 processSpecialCommand(pl.view().substr(ii),ii);
3325 if (addNewLines) out+='\n';
3326 };
3327
3328 if (!Config_getString(PLANTUML_JAR_PATH).isEmpty() && lang=="plantuml")
3329 {
3330 addSpecialCommand("startuml","enduml");
3331 }
3332 else if (Config_getBool(HAVE_DOT) && lang=="dot")
3333 {
3334 addSpecialCommand("dot","enddot");
3335 }
3336 else if (lang=="msc") // msc is built-in
3337 {
3338 addSpecialCommand("msc","endmsc");
3339 }
3340 else // normal code block
3341 {
3342 writeFencedCodeBlock(data.substr(pi),lang.view(),blockStart,blockEnd);
3343 }
3344 i=pi+blockOffset;
3345 pi=std::string::npos;
3346 end=i+1;
3347 continue;
3348 }
3349 else if (isBlockQuote(data.substr(pi,i-pi),currentIndent))
3350 {
3351 i = pi+writeBlockQuote(data.substr(pi));
3352 pi=std::string::npos;
3353 end=i+1;
3354 continue;
3355 }
3356 else
3357 {
3358 //printf("quote out={%s}\n",QCString(data+pi).left(i-pi).data());
3359 out+=data.substr(pi,i-pi);
3360 }
3361 }
3362 pi=i;
3363 i=end;
3364 }
3365 if (pi!=std::string::npos && pi<size) // deal with the last line
3366 {
3367 if (isBlockQuote(data.substr(pi),currentIndent))
3368 {
3369 writeBlockQuote(data.substr(pi));
3370 }
3371 else
3372 {
3373 if (QCString(data.substr(pi)).startsWith("```") || QCString(data.substr(pi)).startsWith("~~~"))
3374 {
3375 warn(fileName, lineNr, "Ending inside a fenced code block. Maybe the end marker for the block is missing?");
3376 }
3377 out+=data.substr(pi);
3378 }
3379 }
3380
3381 //printf("Process quotations\n---- input ----\n%s\n---- output ----\n%s\n------------\n",
3382 // qPrint(s),prv->out.get());
3383
3384 return out;
3385}
#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)
int processSpecialCommand(std::string_view data, size_t offset)

References AUTO_TRACE, Config_getBool, Config_getString, QCString::data(), end(), fileName, findEndOfLine(), isBlockQuote(), isEmptyLine(), isEndOfList(), isFencedCodeBlock(), isListMarker(), QCString::length(), lineNr, out, processSpecialCommand(), qisspace(), qstrncmp(), QCString::startsWith(), Trace::trunc(), QCString::view(), warn, 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 1019 of file markdown.cpp.

1020{
1021 AUTO_TRACE("data='{}'",Trace::trunc(data));
1022 const size_t size = data.size();
1023 size_t i=1;
1024 int nl=0;
1025 while (i<size && data[i]!='"' && nl<2)
1026 {
1027 if (data[i]=='\n') nl++;
1028 i++;
1029 }
1030 if (i<size && data[i]=='"' && nl<2)
1031 {
1032 out+=data.substr(0,i+1);
1033 AUTO_TRACE_EXIT("result={}",i+2);
1034 return static_cast<int>(i+1);
1035 }
1036 // not a quoted section
1037 return 0;
1038}

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

Referenced by Markdown::fill_table().

◆ processSpecialCommand()

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

Definition at line 1794 of file markdown.cpp.

1795{
1796 AUTO_TRACE("{}",Trace::trunc(data));
1797 const size_t size = data.size();
1798 size_t i=1;
1799 QCString endBlockName = isBlockCommand(data,offset);
1800 if (!endBlockName.isEmpty())
1801 {
1802 AUTO_TRACE_ADD("endBlockName={}",endBlockName);
1803 size_t l = endBlockName.length();
1804 while (i+l<size)
1805 {
1806 if ((data[i]=='\\' || data[i]=='@') && // command
1807 data[i-1]!='\\' && data[i-1]!='@') // not escaped
1808 {
1809 if (qstrncmp(&data[i+1],endBlockName.data(),l)==0)
1810 {
1811 //printf("found end at %d\n",i);
1812 addStrEscapeUtf8Nbsp(data.substr(0,i+1+l));
1813 AUTO_TRACE_EXIT("result={}",i+1+l);
1814 return static_cast<int>(i+1+l);
1815 }
1816 }
1817 i++;
1818 }
1819 }
1820 size_t endPos = isSpecialCommand(data,offset);
1821 if (endPos>0)
1822 {
1823 out+=data.substr(0,endPos);
1824 return static_cast<int>(endPos);
1825 }
1826 if (size>1 && data[0]=='\\') // escaped characters
1827 {
1828 char c=data[1];
1829 if (c=='[' || c==']' || c=='*' || c=='(' || c==')' || c=='`' || c=='_')
1830 {
1831 out+=data[1];
1832 AUTO_TRACE_EXIT("2");
1833 return 2;
1834 }
1835 else if (c=='\\' || c=='@')
1836 {
1837 out+=data.substr(0,2);
1838 AUTO_TRACE_EXIT("2");
1839 return 2;
1840 }
1841 else if (c=='-' && size>3 && data[2]=='-' && data[3]=='-') // \---
1842 {
1843 out+=data.substr(1,3);
1844 AUTO_TRACE_EXIT("2");
1845 return 4;
1846 }
1847 else if (c=='-' && size>2 && data[2]=='-') // \--
1848 {
1849 out+=data.substr(1,2);
1850 AUTO_TRACE_EXIT("3");
1851 return 3;
1852 }
1853 }
1854 else if (size>1 && data[0]=='@') // escaped characters
1855 {
1856 char c=data[1];
1857 if (c=='\\' || c=='@')
1858 {
1859 out+=data.substr(0,2);
1860 AUTO_TRACE_EXIT("2");
1861 return 2;
1862 }
1863 }
1864 return 0;
1865}
size_t isSpecialCommand(std::string_view data, size_t offset)
Definition markdown.cpp:457
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 Markdown::fill_table(), and processQuotations().

◆ writeBlockQuote()

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

Definition at line 2893 of file markdown.cpp.

2894{
2895 AUTO_TRACE("data='{}'",Trace::trunc(data));
2896 size_t i=0;
2897 int curLevel=0;
2898 size_t end=0;
2899 const size_t size = data.size();
2900 std::string startCmd;
2901 int isGitHubAlert = false;
2902 int isGitHubFirst = false;
2903 while (i<size)
2904 {
2905 // find end of this line
2906 end=i+1;
2907 while (end<=size && data[end-1]!='\n') end++;
2908 size_t j=i;
2909 int level=0;
2910 size_t indent=i;
2911 // compute the quoting level
2912 while (j<end && (data[j]==' ' || data[j]=='>'))
2913 {
2914 if (data[j]=='>') { level++; indent=j+1; }
2915 else if (j>0 && data[j-1]=='>') indent=j+1;
2916 j++;
2917 }
2918 if (indent>0 && j>0 && data[j-1]=='>' &&
2919 !(j==size || data[j]=='\n')) // disqualify last > if not followed by space
2920 {
2921 indent--;
2922 level--;
2923 j--;
2924 }
2925 AUTO_TRACE_ADD("indent={} i={} j={} end={} level={} line={}",indent,i,j,end,level,Trace::trunc(&data[i]));
2926 if (level==0 && j<end-1 && !isListMarker(data.substr(j)) && !isHRuler(data.substr(j)))
2927 {
2928 level = curLevel; // lazy
2929 }
2930 if (level==1)
2931 {
2932 QCString txt = stripWhiteSpace(data.substr(indent,end-indent));
2933 auto it = g_quotationHeaderMap.find(txt.lower().str()); // TODO: in C++20 the std::string can be dropped
2934 if (it != g_quotationHeaderMap.end())
2935 {
2936 isGitHubAlert = true;
2937 isGitHubFirst = true;
2938 startCmd = it->second;
2939 }
2940 }
2941 if (level>curLevel) // quote level increased => add start markers
2942 {
2943 if (level!=1 || !isGitHubAlert) // normal block quote
2944 {
2945 for (int l=curLevel;l<level-1;l++)
2946 {
2947 out+="<blockquote>";
2948 }
2949 out += "<blockquote>&zwj;"; // empty blockquotes are also shown
2950 }
2951 else if (!startCmd.empty()) // GitHub style alert
2952 {
2953 out += startCmd + " ";
2954 }
2955 }
2956 else if (level<curLevel) // quote level decreased => add end markers
2957 {
2958 int decrLevel = curLevel;
2959 if (level==0 && isGitHubAlert)
2960 {
2961 decrLevel--;
2962 }
2963 for (int l=level;l<decrLevel;l++)
2964 {
2965 out += "</blockquote>\\ilinebr ";
2966 }
2967 }
2968 if (level==0)
2969 {
2970 curLevel=0;
2971 break; // end of quote block
2972 }
2973 // copy line without quotation marks
2974 if (curLevel!=0 || !isGitHubAlert)
2975 {
2976 std::string_view txt = data.substr(indent,end-indent);
2977 if (stripWhiteSpace(txt).empty() && !startCmd.empty())
2978 {
2979 if (!isGitHubFirst) out += "<br>";
2980 out += "<br>\n";
2981 }
2982 else
2983 {
2984 out += txt;
2985 }
2986 isGitHubFirst = false;
2987 }
2988 else // GitHub alert section
2989 {
2990 out+= "\n";
2991 }
2992 curLevel=level;
2993 // proceed with next line
2994 i=end;
2995 }
2996 // end of comment within blockquote => add end markers
2997 if (isGitHubAlert) // GitHub alert doesn't have a blockquote
2998 {
2999 curLevel--;
3000 }
3001 for (int l=0;l<curLevel;l++)
3002 {
3003 out+="</blockquote>";
3004 }
3005 AUTO_TRACE_EXIT("i={}",i);
3006 return i;
3007}
static const std::unordered_map< std::string, std::string > g_quotationHeaderMap
static bool isHRuler(std::string_view data)
static void decrLevel(yyscan_t yyscanner)
Definition pre.l:2251
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, isHRuler(), isListMarker(), 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 3049 of file markdown.cpp.

3050{
3051 AUTO_TRACE("data='{}' refIndent={}",Trace::trunc(data),refIndent);
3052 const size_t size = data.size();
3053 size_t i=0;
3054 // no need for \ilinebr here as the previous line was empty and was skipped
3055 out+="@iverbatim\n";
3056 int emptyLines=0;
3057 std::string location;
3058 while (i<size)
3059 {
3060 // find end of this line
3061 size_t end=i+1;
3062 while (end<=size && data[end-1]!='\n') end++;
3063 size_t j=i;
3064 size_t indent=0;
3065 while (j < end && data[j] == ' ')
3066 {
3067 j++;
3068 indent++;
3069 }
3070 //printf("j=%d end=%d indent=%d refIndent=%d tabSize=%d data={%s}\n",
3071 // j,end,indent,refIndent,Config_getInt(TAB_SIZE),qPrint(QCString(data+i).left(end-i-1)));
3072 if (j==end-1) // empty line
3073 {
3074 emptyLines++;
3075 i=end;
3076 }
3077 else if (indent>=refIndent+codeBlockIndent) // enough indent to continue the code block
3078 {
3079 while (emptyLines>0) // write skipped empty lines
3080 {
3081 // add empty line
3082 out+="\n";
3083 emptyLines--;
3084 }
3085 // add code line minus the indent
3086 size_t offset = i+refIndent+codeBlockIndent;
3087 std::string lineLoc;
3088 if (skipOverFileAndLineCommands(data,codeBlockIndent,offset,lineLoc))
3089 {
3090 location = lineLoc;
3091 }
3092 out+=data.substr(offset,end-offset);
3093 i=end;
3094 }
3095 else // end of code block
3096 {
3097 break;
3098 }
3099 }
3100 out+="@endiverbatim";
3101 if (!location.empty())
3102 {
3103 out+=location;
3104 }
3105 else
3106 {
3107 out+="\\ilinebr ";
3108 }
3109 while (emptyLines>0) // write skipped empty lines
3110 {
3111 // add empty line
3112 out+="\n";
3113 emptyLines--;
3114 }
3115 AUTO_TRACE_EXIT("i={}",i);
3116 return i;
3117}
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 3201 of file markdown.cpp.

3203{
3204 AUTO_TRACE("data='{}' lang={} blockStart={} blockEnd={}",Trace::trunc(data),lang,blockStart,blockEnd);
3205 if (!lang.empty() && lang[0]=='.') lang=lang.substr(1);
3206 const size_t size=data.size();
3207 size_t i=0;
3208 while (i<size && (data[i]==' ' || data[i]=='\t'))
3209 {
3210 out+=data[i++];
3211 blockStart--;
3212 blockEnd--;
3213 }
3214 out+="@icode";
3215 if (!lang.empty())
3216 {
3217 out+="{"+lang+"}";
3218 }
3219 out+=" ";
3220 addStrEscapeUtf8Nbsp(data.substr(blockStart+i,blockEnd-blockStart));
3221 out+="@endicode ";
3222}

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

1197{
1198 AUTO_TRACE("fmt={} inline_img={} explicitTitle={} title={} content={} link={} attrs={}",
1199 fmt,inline_img,explicitTitle,Trace::trunc(title),Trace::trunc(content),link,attrs);
1200 QCString attributes = getFilteredImageAttributes(fmt, attrs);
1201 out+="@image";
1202 if (inline_img)
1203 {
1204 out+="{inline}";
1205 }
1206 out+=" ";
1207 out+=fmt;
1208 out+=" ";
1209 out+=link.mid(fd ? 0 : 5);
1210 if (!explicitTitle && !content.isEmpty())
1211 {
1212 out+=" \"";
1213 out+=escapeDoubleQuotes(content);
1214 out+="\"";
1215 }
1216 else if ((content.isEmpty() || explicitTitle) && !title.isEmpty())
1217 {
1218 out+=" \"";
1219 out+=escapeDoubleQuotes(title);
1220 out+="\"";
1221 }
1222 else
1223 {
1224 out+=" ";// so the line break will not be part of the image name
1225 }
1226 if (!attributes.isEmpty())
1227 {
1228 out+=" ";
1229 out+=attributes;
1230 out+=" ";
1231 }
1232 out+="\\ilinebr ";
1233}
static QCString escapeDoubleQuotes(const QCString &s)
Definition markdown.cpp:238
static QCString getFilteredImageAttributes(std::string_view fmt, const QCString &attrs)
parse the image attributes and return attributes for given format
Definition markdown.cpp:341

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

2834{
2835 AUTO_TRACE("data='{}'",Trace::trunc(data));
2836 int level=0;
2837 QCString header;
2838 QCString id;
2839 if (isHRuler(data))
2840 {
2841 out+="<hr>\n";
2842 }
2843 else if ((level=isAtxHeader(data,header,id,TRUE)))
2844 {
2845 QCString hTag;
2846 if (!id.isEmpty())
2847 {
2848 switch (level)
2849 {
2850 case SectionType::Section: out+="@section "; break;
2851 case SectionType::Subsection: out+="@subsection "; break;
2852 case SectionType::Subsubsection: out+="@subsubsection "; break;
2853 case SectionType::Paragraph: out+="@paragraph "; break;
2854 case SectionType::Subparagraph: out+="@subparagraph "; break;
2855 case SectionType::Subsubparagraph: out+="@subsubparagraph "; break;
2856 }
2857 out+=id;
2858 out+=" ";
2859 out+=header;
2860 out+="\n";
2861 }
2862 else
2863 {
2864 hTag.sprintf("h%d",level);
2865 out+="<"+hTag+">";
2866 out+=header;
2867 out+="</"+hTag+">\n";
2868 }
2869 }
2870 else if (data.size()>0) // nothing interesting -> just output the line
2871 {
2872 size_t tmpSize = data.size();
2873 if (data[data.size()-1] == '\n') tmpSize--;
2874 out+=data.substr(0,tmpSize);
2875
2876 if (hasLineBreak(data))
2877 {
2878 out+="\\ilinebr<br>";
2879 }
2880 if (tmpSize != data.size()) out+='\n';
2881 }
2882}
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)
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 2614 of file markdown.cpp.

2615{
2616 AUTO_TRACE("data='{}'",Trace::trunc(data));
2617 const size_t size = data.size();
2618
2619 size_t columns=0, start=0, end=0;
2620 size_t i = findTableColumns(data,start,end,columns);
2621 size_t headerStart = start;
2622 size_t headerEnd = end;
2623
2624 // read cell alignments
2625 size_t cc = 0;
2626 size_t ret = findTableColumns(data.substr(i),start,end,cc);
2627 size_t k=0;
2628 std::vector<Alignment> columnAlignment(columns);
2629
2630 bool leftMarker=false, rightMarker=false, startFound=false;
2631 size_t j=start+i;
2632 while (j<=end+i)
2633 {
2634 if (!startFound)
2635 {
2636 if (data[j]==':') { leftMarker=TRUE; startFound=TRUE; }
2637 if (data[j]=='-') startFound=TRUE;
2638 //printf(" data[%d]=%c startFound=%d\n",j,data[j],startFound);
2639 }
2640 if (data[j]=='-') rightMarker=FALSE;
2641 else if (data[j]==':') rightMarker=TRUE;
2642 if (j<=end+i && (data[j]=='|' && (j==0 || data[j-1]!='\\')))
2643 {
2644 if (k<columns)
2645 {
2646 columnAlignment[k] = markersToAlignment(leftMarker,rightMarker);
2647 //printf("column[%d] alignment=%d\n",k,columnAlignment[k]);
2648 leftMarker=FALSE;
2649 rightMarker=FALSE;
2650 startFound=FALSE;
2651 }
2652 k++;
2653 }
2654 j++;
2655 }
2656 if (k<columns)
2657 {
2658 columnAlignment[k] = markersToAlignment(leftMarker,rightMarker);
2659 //printf("column[%d] alignment=%d\n",k,columnAlignment[k]);
2660 }
2661 // proceed to next line
2662 i+=ret;
2663
2664 // Store the table cell information by row then column. This
2665 // allows us to handle row spanning.
2666 std::vector<std::vector<TableCell> > tableContents;
2667
2668 size_t m = headerStart;
2669 std::vector<TableCell> headerContents(columns);
2670 for (k=0;k<columns;k++)
2671 {
2672 while (m<=headerEnd && (data[m]!='|' || (m>0 && data[m-1]=='\\')))
2673 {
2674 headerContents[k].cellText += data[m++];
2675 }
2676 m++;
2677 // do the column span test before stripping white space
2678 // || is spanning columns, | | is not
2679 headerContents[k].colSpan = headerContents[k].cellText.isEmpty();
2680 headerContents[k].cellText = headerContents[k].cellText.stripWhiteSpace();
2681 }
2682 tableContents.push_back(headerContents);
2683
2684 // write table cells
2685 while (i<size)
2686 {
2687 ret = findTableColumns(data.substr(i),start,end,cc);
2688 if (cc!=columns) break; // end of table
2689
2690 j=start+i;
2691 k=0;
2692 std::vector<TableCell> rowContents(columns);
2693 while (j<=end+i)
2694 {
2695 if (j<=end+i && (data[j]=='|' && (j==0 || data[j-1]!='\\')))
2696 {
2697 // do the column span test before stripping white space
2698 // || is spanning columns, | | is not
2699 rowContents[k].colSpan = rowContents[k].cellText.isEmpty();
2700 rowContents[k].cellText = rowContents[k].cellText.stripWhiteSpace();
2701 k++;
2702 } // if (j<=end+i && (data[j]=='|' && (j==0 || data[j-1]!='\\')))
2703 else
2704 {
2705 rowContents[k].cellText += data[j];
2706 } // else { if (j<=end+i && (data[j]=='|' && (j==0 || data[j-1]!='\\'))) }
2707 j++;
2708 } // while (j<=end+i)
2709 // do the column span test before stripping white space
2710 // || is spanning columns, | | is not
2711 rowContents[k].colSpan = rowContents[k].cellText.isEmpty();
2712 rowContents[k].cellText = rowContents[k].cellText.stripWhiteSpace();
2713 tableContents.push_back(rowContents);
2714
2715 // proceed to next line
2716 i+=ret;
2717 }
2718
2719 out+="<table class=\"markdownTable\">";
2720 QCString cellTag("th"), cellClass("class=\"markdownTableHead");
2721 for (size_t row = 0; row < tableContents.size(); row++)
2722 {
2723 if (row)
2724 {
2725 if (row % 2)
2726 {
2727 out+="\n<tr class=\"markdownTableRowOdd\">";
2728 }
2729 else
2730 {
2731 out+="\n<tr class=\"markdownTableRowEven\">";
2732 }
2733 }
2734 else
2735 {
2736 out+="\n <tr class=\"markdownTableHead\">";
2737 }
2738 for (size_t c = 0; c < columns; c++)
2739 {
2740 // save the cell text for use after column span computation
2741 QCString cellText(tableContents[row][c].cellText);
2742
2743 // Row span handling. Spanning rows will contain a caret ('^').
2744 // If the current cell contains just a caret, this is part of an
2745 // earlier row's span and the cell should not be added to the
2746 // output.
2747 if (tableContents[row][c].cellText == "^")
2748 {
2749 continue;
2750 }
2751 if (tableContents[row][c].colSpan)
2752 {
2753 int cr = static_cast<int>(c);
2754 while ( cr >= 0 && tableContents[row][cr].colSpan)
2755 {
2756 cr--;
2757 };
2758 if (cr >= 0 && tableContents[row][cr].cellText == "^") continue;
2759 }
2760 size_t rowSpan = 1, spanRow = row+1;
2761 while ((spanRow < tableContents.size()) &&
2762 (tableContents[spanRow][c].cellText == "^"))
2763 {
2764 spanRow++;
2765 rowSpan++;
2766 }
2767
2768 out+=" <" + cellTag + " " + cellClass;
2769 // use appropriate alignment style
2770 switch (columnAlignment[c])
2771 {
2772 case Alignment::Left: out+="Left\""; break;
2773 case Alignment::Right: out+="Right\""; break;
2774 case Alignment::Center: out+="Center\""; break;
2775 case Alignment::None: out+="None\""; break;
2776 }
2777
2778 if (rowSpan > 1)
2779 {
2780 QCString spanStr;
2781 spanStr.setNum(rowSpan);
2782 out+=" rowspan=\"" + spanStr + "\"";
2783 }
2784 // Column span handling, assumes that column spans will have
2785 // empty strings, which would indicate the sequence "||", used
2786 // to signify spanning columns.
2787 size_t colSpan = 1;
2788 while ((c+1 < columns) && tableContents[row][c+1].colSpan)
2789 {
2790 c++;
2791 colSpan++;
2792 }
2793 if (colSpan > 1)
2794 {
2795 QCString spanStr;
2796 spanStr.setNum(colSpan);
2797 out+=" colspan=\"" + spanStr + "\"";
2798 }
2799 // need at least one space on either side of the cell text in
2800 // order for doxygen to do other formatting
2801 out+="> " + cellText + " \\ilinebr </" + cellTag + ">";
2802 }
2803 cellTag = "td";
2804 cellClass = "class=\"markdownTableBody";
2805 out+=" </tr>";
2806 }
2807 out+="</table>\n";
2808
2809 AUTO_TRACE_EXIT("i={}",i);
2810 return i;
2811}
QCString & setNum(short n)
Definition qcstring.h:459
static constexpr Alignment markersToAlignment(bool leftMarker, bool rightMarker)
helper function to convert presence of left and/or right alignment markers to an alignment value
Definition markdown.cpp:320
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.

References AUTO_TRACE, AUTO_TRACE_EXIT, Center, end(), FALSE, findTableColumns(), Left, markersToAlignment(), None, out, Right, QCString::setNum(), TRUE, and Trace::trunc().

Referenced by processBlocks().

Member Data Documentation

◆ fileName

QCString Markdown::Private::fileName

Definition at line 176 of file markdown.cpp.

Referenced by extractTitleId(), Private(), processBlocks(), processLink(), and processQuotations().

◆ indentLevel

int Markdown::Private::indentLevel =0

Definition at line 178 of file markdown.cpp.

Referenced by isAtxHeader(), isHeaderline(), and Private().

◆ lineNr

int Markdown::Private::lineNr = 0

Definition at line 177 of file markdown.cpp.

Referenced by extractTitleId(), Private(), processBlocks(), and processQuotations().

◆ linkRefs

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

Definition at line 175 of file markdown.cpp.

Referenced by processBlocks(), and processLink().

◆ out


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