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

1794{
1795 AUTO_TRACE("{}",Trace::trunc(data));
1796 if (Portable::strnstr(data.data(),g_doxy_nbsp,data.size())==nullptr) // no escape needed -> fast
1797 {
1798 out+=data;
1799 }
1800 else // escape needed -> slow
1801 {
1802 out+=substitute(QCString(data),g_doxy_nbsp,g_utf8_nbsp);
1803 }
1804}
#define AUTO_TRACE(...)
Definition docnode.cpp:48
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:600
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 2094 of file markdown.cpp.

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

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

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

2128{
2129 AUTO_TRACE("data='{}' header={} id={} allowAdjustLevel={}",Trace::trunc(data),Trace::trunc(header),id,allowAdjustLevel);
2130 size_t i = 0;
2131 int level = 0, blanks=0;
2132 const size_t size = data.size();
2133
2134 // find start of header text and determine heading level
2135 while (i<size && data[i]==' ') i++;
2136 if (i>=size || data[i]!='#')
2137 {
2138 return 0;
2139 }
2140 while (i < size && data[i] == '#')
2141 {
2142 i++;
2143 level++;
2144 }
2145 if (level>SectionType::MaxLevel) // too many #'s -> no section
2146 {
2147 return 0;
2148 }
2149 while (i < size && data[i] == ' ')
2150 {
2151 i++;
2152 blanks++;
2153 }
2154 if (level==1 && blanks==0)
2155 {
2156 return 0; // special case to prevent #someid seen as a header (see bug 671395)
2157 }
2158
2159 // find end of header text
2160 size_t end=i;
2161 while (end<size && data[end]!='\n') end++;
2162 while (end>i && (data[end-1]=='#' || data[end-1]==' ')) end--;
2163
2164 // store result
2165 header = data.substr(i,end-i);
2166 id = extractTitleId(header, level, pIsIdGenerated);
2167 if (!id.isEmpty()) // strip #'s between title and id
2168 {
2169 int idx=static_cast<int>(header.length())-1;
2170 while (idx>=0 && (header.at(idx)=='#' || header.at(idx)==' ')) idx--;
2171 header=header.left(idx+1);
2172 }
2173
2174 if (allowAdjustLevel && level==1 && indentLevel==-1)
2175 {
2176 // in case we find a `# Section` on a markdown page that started with the same level
2177 // header, we no longer need to artificially decrease the paragraph level.
2178 // So both
2179 // -------------------
2180 // # heading 1 <-- here we set g_indentLevel to -1
2181 // # heading 2 <-- here we set g_indentLevel back to 0 such that this will be a @section
2182 // -------------------
2183 // and
2184 // -------------------
2185 // # heading 1 <-- here we set g_indentLevel to -1
2186 // ## heading 2 <-- here we keep g_indentLevel at -1 such that @subsection will be @section
2187 // -------------------
2188 // will convert to
2189 // -------------------
2190 // @page md_page Heading 1
2191 // @section autotoc_md1 Heading 2
2192 // -------------------
2193
2194 indentLevel=0;
2195 }
2196 int res = level+indentLevel;
2197 AUTO_TRACE_EXIT("result={}",res);
2198 return res;
2199}
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 { "mermaid", getEndBlock },
437 { "f", getEndFormula }
438 };
439
440 const size_t size = data.size();
441 bool openBracket = offset>0 && data.data()[-1]=='{';
442 bool isEscaped = offset>0 && (data.data()[-1]=='\\' || data.data()[-1]=='@');
443 if (isEscaped) return result;
444
445 size_t end=1;
446 while (end<size && (data[end]>='a' && data[end]<='z')) end++;
447 if (end==1) return result;
448 std::string blockName(data.substr(1,end-1));
449 auto it = blockNames.find(blockName);
450 if (it!=blockNames.end()) // there is a function assigned
451 {
452 result = it->second(blockName, openBracket, end<size ? data[end] : 0);
453 }
454 AUTO_TRACE_EXIT("result={}",result);
455 return result;
456}

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

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

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

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

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

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

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

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

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

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

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

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

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

1142{
1143 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1144 return processHtmlTagWrite(data,offset,true);
1145}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1201{
1202 AUTO_TRACE("fmt={} inline_img={} explicitTitle={} title={} content={} link={} attrs={}",
1203 fmt,inline_img,explicitTitle,Trace::trunc(title),Trace::trunc(content),link,attrs);
1204 QCString attributes = getFilteredImageAttributes(fmt, attrs);
1205 out+="@image";
1206 if (inline_img)
1207 {
1208 out+="{inline}";
1209 }
1210 out+=" ";
1211 out+=fmt;
1212 out+=" ";
1213 out+=link.mid(fd ? 0 : 5);
1214 if (!explicitTitle && !content.isEmpty())
1215 {
1216 out+=" \"";
1217 out+=escapeDoubleQuotes(content);
1218 out+="\"";
1219 }
1220 else if ((content.isEmpty() || explicitTitle) && !title.isEmpty())
1221 {
1222 out+=" \"";
1223 out+=escapeDoubleQuotes(title);
1224 out+="\"";
1225 }
1226 else
1227 {
1228 out+=" ";// so the line break will not be part of the image name
1229 }
1230 if (!attributes.isEmpty())
1231 {
1232 out+=" ";
1233 out+=attributes;
1234 out+=" ";
1235 }
1236 out+="\\ilinebr ";
1237}
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 2837 of file markdown.cpp.

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

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