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

Constructor & Destructor Documentation

◆ Private()

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

Definition at line 134 of file markdown.cpp.

134: 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 1819 of file markdown.cpp.

1820{
1821 AUTO_TRACE("{}",Trace::trunc(data));
1822 if (Portable::strnstr(data.data(),g_doxy_nbsp,data.size())==nullptr) // no escape needed -> fast
1823 {
1824 out+=data;
1825 }
1826 else // escape needed -> slow
1827 {
1828 out+=substitute(QCString(data),g_doxy_nbsp,g_utf8_nbsp);
1829 }
1830}
#define AUTO_TRACE(...)
Definition docnode.cpp:48
static const char * g_doxy_nbsp
Definition markdown.cpp:220
static const char * g_utf8_nbsp
Definition markdown.cpp:219
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 2120 of file markdown.cpp.

2121{
2122 AUTO_TRACE("title={} level={}",Trace::trunc(title),level);
2123 // match e.g. '{#id-b11} ' and capture 'id-b11'
2124 static const reg::Ex r2(R"({#(\a[\w-]*)}\s*$)");
2125 reg::Match match;
2126 std::string ti = title.str();
2127 if (reg::search(ti,match,r2))
2128 {
2129 std::string id = match[1].str();
2130 title = title.left(match.position());
2131 if (AnchorGenerator::instance().reserve(id)>0)
2132 {
2133 warn(fileName, lineNr, "An automatically generated id already has the name '{}'!", id);
2134 }
2135 //printf("found match id='%s' title=%s\n",qPrint(id),qPrint(title));
2136 AUTO_TRACE_EXIT("id={}",id);
2137 return id;
2138 }
2139 if (((level>0) && (level<=Config_getInt(TOC_INCLUDE_HEADINGS))) || (Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB))
2140 {
2141 QCString id = AnchorGenerator::instance().generate(ti);
2142 if (pIsIdGenerated) *pIsIdGenerated=true;
2143 //printf("auto-generated id='%s' title='%s'\n",qPrint(id),qPrint(title));
2144 AUTO_TRACE_EXIT("id={}",id);
2145 return id;
2146 }
2147 //printf("no id found in title '%s'\n",qPrint(title));
2148 return "";
2149}
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 736 of file markdown.cpp.

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

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

3152{
3153 AUTO_TRACE("data='{}'",Trace::trunc(data));
3154 // find end of the line
3155 const size_t size = data.size();
3156 size_t nb=0, end=offset+1, j=0;
3157 while (end<=size && (j=isNewline(data.substr(end-1)))==0)
3158 {
3159 // while looking for the end of the line we might encounter a block
3160 // that needs to be passed unprocessed.
3161 if ((data[end-1]=='\\' || data[end-1]=='@') && // command
3162 (end<=1 || (data[end-2]!='\\' && data[end-2]!='@')) // not escaped
3163 )
3164 {
3165 QCString endBlockName = isBlockCommand(data.substr(end-1),end-1);
3166 end++;
3167 if (!endBlockName.isEmpty())
3168 {
3169 size_t l = endBlockName.length();
3170 for (;end+l+1<size;end++) // search for end of block marker
3171 {
3172 if ((data[end]=='\\' || data[end]=='@') &&
3173 data[end-1]!='\\' && data[end-1]!='@'
3174 )
3175 {
3176 if (qstrncmp(&data[end+1],endBlockName.data(),l)==0)
3177 {
3178 // found end marker, skip over this block
3179 //printf("feol.block out={%s}\n",qPrint(QCString(data+i).left(end+l+1-i)));
3180 end = end + l + 2;
3181 break;
3182 }
3183 }
3184 }
3185 }
3186 }
3187 else if (nb==0 && data[end-1]=='<' && size>=6 && end+6<size &&
3188 (end<=1 || (data[end-2]!='\\' && data[end-2]!='@'))
3189 )
3190 {
3191 if (tolower(data[end])=='p' && tolower(data[end+1])=='r' &&
3192 tolower(data[end+2])=='e' && (data[end+3]=='>' || data[end+3]==' ')) // <pre> tag
3193 {
3194 // skip part until including </pre>
3195 end = end + processHtmlTagWrite(data.substr(end-1),end-1,false);
3196 break;
3197 }
3198 else
3199 {
3200 end++;
3201 }
3202 }
3203 else if (nb==0 && data[end-1]=='`')
3204 {
3205 while (end <= size && data[end - 1] == '`')
3206 {
3207 end++;
3208 nb++;
3209 }
3210 }
3211 else if (nb>0 && data[end-1]=='`')
3212 {
3213 size_t enb=0;
3214 while (end <= size && data[end - 1] == '`')
3215 {
3216 end++;
3217 enb++;
3218 }
3219 if (enb==nb) nb=0;
3220 }
3221 else
3222 {
3223 end++;
3224 }
3225 }
3226 if (j>0) end+=j-1;
3227 AUTO_TRACE_EXIT("offset={} end={}",offset,end);
3228 return end;
3229}
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
size_t isNewline(std::string_view data)
Definition markdown.cpp:227
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 2152 of file markdown.cpp.

2154{
2155 AUTO_TRACE("data='{}' header={} id={} allowAdjustLevel={}",Trace::trunc(data),Trace::trunc(header),id,allowAdjustLevel);
2156 size_t i = 0;
2157 int level = 0, blanks=0;
2158 const size_t size = data.size();
2159
2160 // find start of header text and determine heading level
2161 while (i<size && data[i]==' ') i++;
2162 if (i>=size || data[i]!='#')
2163 {
2164 return 0;
2165 }
2166 while (i < size && data[i] == '#')
2167 {
2168 i++;
2169 level++;
2170 }
2171 if (level>SectionType::MaxLevel) // too many #'s -> no section
2172 {
2173 return 0;
2174 }
2175 while (i < size && data[i] == ' ')
2176 {
2177 i++;
2178 blanks++;
2179 }
2180 if (level==1 && blanks==0)
2181 {
2182 return 0; // special case to prevent #someid seen as a header (see bug 671395)
2183 }
2184
2185 // find end of header text
2186 size_t end=i;
2187 while (end<size && data[end]!='\n') end++;
2188 while (end>i && (data[end-1]=='#' || data[end-1]==' ')) end--;
2189
2190 // store result
2191 header = data.substr(i,end-i);
2192 id = extractTitleId(header, level, pIsIdGenerated);
2193 if (!id.isEmpty()) // strip #'s between title and id
2194 {
2195 int idx=static_cast<int>(header.length())-1;
2196 while (idx>=0 && (header.at(idx)=='#' || header.at(idx)==' ')) idx--;
2197 header=header.left(idx+1);
2198 }
2199
2200 if (allowAdjustLevel && level==1 && indentLevel==-1)
2201 {
2202 // in case we find a `# Section` on a markdown page that started with the same level
2203 // header, we no longer need to artificially decrease the paragraph level.
2204 // So both
2205 // -------------------
2206 // # heading 1 <-- here we set g_indentLevel to -1
2207 // # heading 2 <-- here we set g_indentLevel back to 0 such that this will be a @section
2208 // -------------------
2209 // and
2210 // -------------------
2211 // # heading 1 <-- here we set g_indentLevel to -1
2212 // ## heading 2 <-- here we keep g_indentLevel at -1 such that @subsection will be @section
2213 // -------------------
2214 // will convert to
2215 // -------------------
2216 // @page md_page Heading 1
2217 // @section autotoc_md1 Heading 2
2218 // -------------------
2219
2220 indentLevel=0;
2221 }
2222 int res = level+indentLevel;
2223 AUTO_TRACE_EXIT("result={}",res);
2224 return res;
2225}
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 390 of file markdown.cpp.

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

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

1926{
1927 AUTO_TRACE("data='{}' allowAdjustLevel",Trace::trunc(data),allowAdjustLevel);
1928 size_t i=0, c=0;
1929 const size_t size = data.size();
1930 while (i<size && data[i]==' ') i++;
1931 if (i==size) return 0;
1932
1933 // test of level 1 header
1934 if (data[i]=='=')
1935 {
1936 while (i < size && data[i] == '=')
1937 {
1938 i++;
1939 c++;
1940 }
1941 while (i<size && data[i]==' ') i++;
1942 int level = (c>1 && (i>=size || data[i]=='\n')) ? 1 : 0;
1943 if (allowAdjustLevel && level==1 && indentLevel==-1)
1944 {
1945 // In case a page starts with a header line we use it as title, promoting it to @page.
1946 // We set g_indentLevel to -1 to promoting the other sections if they have a deeper
1947 // nesting level than the page header, i.e. @section..@subsection becomes @page..@section.
1948 // In case a section at the same level is found (@section..@section) however we need
1949 // to undo this (and the result will be @page..@section).
1950 indentLevel=0;
1951 }
1952 AUTO_TRACE_EXIT("result={}",indentLevel+level);
1953 return indentLevel+level;
1954 }
1955 // test of level 2 header
1956 if (data[i]=='-')
1957 {
1958 while (i < size && data[i] == '-')
1959 {
1960 i++;
1961 c++;
1962 }
1963 while (i<size && data[i]==' ') i++;
1964 return (c>1 && (i>=size || data[i]=='\n')) ? indentLevel+2 : 0;
1965 }
1966 return 0;
1967}

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

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

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

1706{
1707 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
1708 const size_t size = data.size();
1709
1710 /* counting the number of backticks in the delimiter */
1711 size_t nb=0, end=0;
1712 while (nb<size && data[nb]=='`')
1713 {
1714 nb++;
1715 }
1716
1717 /* finding the next delimiter with the same amount of backticks */
1718 size_t i = 0;
1719 char pc = '`';
1720 bool markdownStrict = Config_getBool(MARKDOWN_STRICT);
1721 for (end=nb; end<size; end++)
1722 {
1723 //AUTO_TRACE_ADD("c={} nb={} i={} size={}",data[end],nb,i,size);
1724 if (data[end]=='`')
1725 {
1726 i++;
1727 if (nb==1) // `...`
1728 {
1729 if (end+1<size && data[end+1]=='`') // skip over `` inside `...`
1730 {
1731 AUTO_TRACE_ADD("case1.1");
1732 // skip
1733 end++;
1734 i=0;
1735 }
1736 else // normal end of `...`
1737 {
1738 AUTO_TRACE_ADD("case1.2");
1739 break;
1740 }
1741 }
1742 else if (i==nb) // ``...``
1743 {
1744 if (end+1<size && data[end+1]=='`') // do greedy match
1745 {
1746 // skip this quote and use the next one to terminate the sequence, e.g. ``X`Y```
1747 i--;
1748 AUTO_TRACE_ADD("case2.1");
1749 }
1750 else // normal end of ``...``
1751 {
1752 AUTO_TRACE_ADD("case2.2");
1753 break;
1754 }
1755 }
1756 }
1757 else if (data[end]=='\n')
1758 {
1759 // consecutive newlines
1760 if (pc == '\n')
1761 {
1762 AUTO_TRACE_EXIT("new paragraph");
1763 return 0;
1764 }
1765 pc = '\n';
1766 i = 0;
1767 }
1768 else if (!markdownStrict && data[end]=='\'' && nb==1 && (end+1==size || (end+1<size && data[end+1]!='\'' && !isIdChar(data[end+1]))))
1769 { // look for quoted strings like 'some word', but skip strings like `it's cool`
1770 out+="&lsquo;";
1771 out+=data.substr(nb,end-nb);
1772 out+="&rsquo;";
1773 AUTO_TRACE_EXIT("quoted end={}",end+1);
1774 return static_cast<int>(end+1);
1775 }
1776 else if (!markdownStrict && data[end]=='\'' && nb==2 && end+1<size && data[end+1]=='\'')
1777 { // look for '' to match a ``
1778 out+="&ldquo;";
1779 out+=data.substr(nb,end-nb);
1780 out+="&rdquo;";
1781 AUTO_TRACE_EXIT("double quoted end={}",end+1);
1782 return static_cast<int>(end+2);
1783 }
1784 else
1785 {
1786 if (data[end]!=' ') pc = data[end];
1787 i=0;
1788 }
1789 }
1790 if (i < nb && end >= size)
1791 {
1792 AUTO_TRACE_EXIT("no matching delimiter nb={} i={}",nb,i);
1793 if (nb>=3) // found ``` that is not at the start of the line, keep it as-is.
1794 {
1795 out+=data.substr(0,nb);
1796 return static_cast<int>(nb);
1797 }
1798 return 0; // no matching delimiter
1799 }
1800 while (end<size && data[end]=='`') // do greedy match in case we have more end backticks.
1801 {
1802 end++;
1803 }
1804
1805 //printf("found code span '%s'\n",qPrint(QCString(data+f_begin).left(f_end-f_begin)));
1806
1807 /* real code span */
1808 if (nb+nb < end)
1809 {
1810 QCString codeFragment = data.substr(nb, end-nb-nb);
1811 out+="<tt>";
1812 out+=escapeSpecialChars(codeFragment);
1813 out+="</tt>";
1814 }
1815 AUTO_TRACE_EXIT("result={} nb={}",end,nb);
1816 return static_cast<int>(end);
1817}
#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:258

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

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

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

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

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

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

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

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

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

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

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

1896{
1897 AUTO_TRACE("data='{}'",Trace::trunc(data));
1898 size_t i=0;
1899 size_t end=0;
1900 Action_t action;
1901 const size_t size = data.size();
1902 while (i<size)
1903 {
1904 // skip over characters that do not trigger a specific action
1905 while (end<size && ((action=Markdown::actions[static_cast<uint8_t>(data[end])])==nullptr)) end++;
1906 // and add them to the output
1907 out+=data.substr(i,end-i);
1908 if (end>=size) break;
1909 i=end;
1910 // do the action matching a special character at i
1911 int iend = action(*this,data.substr(i),i);
1912 if (iend<=0) // update end
1913 {
1914 end=i+1-iend;
1915 }
1916 else // skip until end
1917 {
1918 i+=iend;
1919 end=i;
1920 }
1921 }
1922}
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 1241 of file markdown.cpp.

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

References FileInfo::absFilePath(), AnchorGenerator::addPrefixIfNeeded(), QCString::at(), AUTO_TRACE, AUTO_TRACE_EXIT, Mappers::cmdMapper, Config_getEnum, Config_getInt, FileInfo::exists(), externalLinkTarget(), FALSE, FileInfo::fileName(), fileName, QCString::find(), findFileDef(), getLanguageFromFileName(), Doxygen::imageNameLinkedMap, Portable::isAbsolutePath(), CommentScanner::isCommand(), QCString::isEmpty(), isId(), 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(), UNKNOWN, 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 981 of file markdown.cpp.

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

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

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

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

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

1833{
1834 AUTO_TRACE("{}",Trace::trunc(data));
1835 const size_t size = data.size();
1836 size_t i=1;
1837 QCString endBlockName = isBlockCommand(data,offset);
1838 if (!endBlockName.isEmpty())
1839 {
1840 AUTO_TRACE_ADD("endBlockName={}",endBlockName);
1841 size_t l = endBlockName.length();
1842 while (i+l<size)
1843 {
1844 if ((data[i]=='\\' || data[i]=='@') && // command
1845 data[i-1]!='\\' && data[i-1]!='@') // not escaped
1846 {
1847 if (qstrncmp(&data[i+1],endBlockName.data(),l)==0)
1848 {
1849 //printf("found end at %d\n",i);
1850 addStrEscapeUtf8Nbsp(data.substr(0,i+1+l));
1851 AUTO_TRACE_EXIT("result={}",i+1+l);
1852 return static_cast<int>(i+1+l);
1853 }
1854 }
1855 i++;
1856 }
1857 }
1858 size_t endPos = isSpecialCommand(data,offset);
1859 if (endPos>0)
1860 {
1861 out+=data.substr(0,endPos);
1862 return static_cast<int>(endPos);
1863 }
1864 if (size>1 && (data[0]=='\\' || data[0]=='@')) // escaped characters
1865 {
1866 char c=data[1];
1867 if (c=='[' || c==']' || c=='*' || c=='(' || c==')' || c=='`' || c=='_')
1868 {
1869 out+=data[1];
1870 AUTO_TRACE_EXIT("2");
1871 return 2;
1872 }
1873 else if (c=='\\' || c=='@')
1874 {
1875 out+=data.substr(0,2);
1876 AUTO_TRACE_EXIT("2");
1877 return 2;
1878 }
1879 else if (c=='-' && size>3 && data[2]=='-' && data[3]=='-') // \---
1880 {
1881 out+=data.substr(1,3);
1882 AUTO_TRACE_EXIT("2");
1883 return 4;
1884 }
1885 else if (c=='-' && size>2 && data[2]=='-') // \--
1886 {
1887 out+=data.substr(1,2);
1888 AUTO_TRACE_EXIT("3");
1889 return 3;
1890 }
1891 }
1892 return 0;
1893}
size_t isSpecialCommand(std::string_view data, size_t offset)
Definition markdown.cpp:460
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 2923 of file markdown.cpp.

2924{
2925 AUTO_TRACE("data='{}'",Trace::trunc(data));
2926 size_t i=0;
2927 int curLevel=0;
2928 size_t end=0;
2929 const size_t size = data.size();
2930 std::string startCmd;
2931 int isGitHubAlert = false;
2932 int isGitHubFirst = false;
2933 while (i<size)
2934 {
2935 // find end of this line
2936 end=i+1;
2937 while (end<=size && data[end-1]!='\n') end++;
2938 size_t j=i;
2939 int level=0;
2940 size_t indent=i;
2941 // compute the quoting level
2942 while (j<end && (data[j]==' ' || data[j]=='>'))
2943 {
2944 if (data[j]=='>') { level++; indent=j+1; }
2945 else if (j>0 && data[j-1]=='>') indent=j+1;
2946 j++;
2947 }
2948 if (indent>0 && j>0 && data[j-1]=='>' &&
2949 !(j==size || data[j]=='\n')) // disqualify last > if not followed by space
2950 {
2951 indent--;
2952 level--;
2953 j--;
2954 }
2955 AUTO_TRACE_ADD("indent={} i={} j={} end={} level={} line={}",indent,i,j,end,level,Trace::trunc(&data[i]));
2956 if (level==0 && j<end-1 && !isListMarker(data.substr(j)) && !isHRuler(data.substr(j)))
2957 {
2958 level = curLevel; // lazy
2959 }
2960 if (level==1)
2961 {
2962 QCString txt = stripWhiteSpace(data.substr(indent,end-indent));
2963 auto it = g_quotationHeaderMap.find(txt.lower().str()); // TODO: in C++20 the std::string can be dropped
2964 if (it != g_quotationHeaderMap.end())
2965 {
2966 isGitHubAlert = true;
2967 isGitHubFirst = true;
2968 startCmd = it->second;
2969 }
2970 }
2971 if (level>curLevel) // quote level increased => add start markers
2972 {
2973 if (level!=1 || !isGitHubAlert) // normal block quote
2974 {
2975 for (int l=curLevel;l<level-1;l++)
2976 {
2977 out+="<blockquote>";
2978 }
2979 out += "<blockquote>&zwj;"; // empty blockquotes are also shown
2980 }
2981 else if (!startCmd.empty()) // GitHub style alert
2982 {
2983 out += startCmd + " ";
2984 }
2985 }
2986 else if (level<curLevel) // quote level decreased => add end markers
2987 {
2988 int decrLevel = curLevel;
2989 if (level==0 && isGitHubAlert)
2990 {
2991 decrLevel--;
2992 }
2993 for (int l=level;l<decrLevel;l++)
2994 {
2995 out += "</blockquote>\\ilinebr ";
2996 }
2997 }
2998 if (level==0)
2999 {
3000 curLevel=0;
3001 break; // end of quote block
3002 }
3003 // copy line without quotation marks
3004 if (curLevel!=0 || !isGitHubAlert)
3005 {
3006 std::string_view txt = data.substr(indent,end-indent);
3007 if (stripWhiteSpace(txt).empty() && !startCmd.empty())
3008 {
3009 if (!isGitHubFirst) out += "<br>";
3010 out += "<br>\n";
3011 }
3012 else
3013 {
3014 out += txt;
3015 }
3016 isGitHubFirst = false;
3017 }
3018 else // GitHub alert section
3019 {
3020 out+= "\n";
3021 }
3022 curLevel=level;
3023 // proceed with next line
3024 i=end;
3025 }
3026 // end of comment within blockquote => add end markers
3027 if (isGitHubAlert) // GitHub alert doesn't have a blockquote
3028 {
3029 curLevel--;
3030 }
3031 for (int l=0;l<curLevel;l++)
3032 {
3033 out+="</blockquote>";
3034 }
3035 AUTO_TRACE_EXIT("i={}",i);
3036 return i;
3037}
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:2286
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 3079 of file markdown.cpp.

3080{
3081 AUTO_TRACE("data='{}' refIndent={}",Trace::trunc(data),refIndent);
3082 const size_t size = data.size();
3083 size_t i=0;
3084 // no need for \ilinebr here as the previous line was empty and was skipped
3085 out+="@iverbatim\n";
3086 int emptyLines=0;
3087 std::string location;
3088 while (i<size)
3089 {
3090 // find end of this line
3091 size_t end=i+1;
3092 while (end<=size && data[end-1]!='\n') end++;
3093 size_t j=i;
3094 size_t indent=0;
3095 while (j < end && data[j] == ' ')
3096 {
3097 j++;
3098 indent++;
3099 }
3100 //printf("j=%d end=%d indent=%d refIndent=%d tabSize=%d data={%s}\n",
3101 // j,end,indent,refIndent,Config_getInt(TAB_SIZE),qPrint(QCString(data+i).left(end-i-1)));
3102 if (j==end-1) // empty line
3103 {
3104 emptyLines++;
3105 i=end;
3106 }
3107 else if (indent>=refIndent+codeBlockIndent) // enough indent to continue the code block
3108 {
3109 while (emptyLines>0) // write skipped empty lines
3110 {
3111 // add empty line
3112 out+="\n";
3113 emptyLines--;
3114 }
3115 // add code line minus the indent
3116 size_t offset = i+refIndent+codeBlockIndent;
3117 std::string lineLoc;
3118 if (skipOverFileAndLineCommands(data,codeBlockIndent,offset,lineLoc))
3119 {
3120 location = lineLoc;
3121 }
3122 out+=data.substr(offset,end-offset);
3123 i=end;
3124 }
3125 else // end of code block
3126 {
3127 break;
3128 }
3129 }
3130 out+="@endiverbatim";
3131 if (!location.empty())
3132 {
3133 out+=location;
3134 }
3135 else
3136 {
3137 out+="\\ilinebr ";
3138 }
3139 while (emptyLines>0) // write skipped empty lines
3140 {
3141 // add empty line
3142 out+="\n";
3143 emptyLines--;
3144 }
3145 AUTO_TRACE_EXIT("i={}",i);
3146 return i;
3147}
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 3231 of file markdown.cpp.

3233{
3234 AUTO_TRACE("data='{}' lang={} blockStart={} blockEnd={}",Trace::trunc(data),lang,blockStart,blockEnd);
3235 if (!lang.empty() && lang[0]=='.') lang=lang.substr(1);
3236 const size_t size=data.size();
3237 size_t i=0;
3238 while (i<size && (data[i]==' ' || data[i]=='\t'))
3239 {
3240 out+=data[i++];
3241 blockStart--;
3242 blockEnd--;
3243 }
3244 out+="@icode";
3245 if (!lang.empty())
3246 {
3247 out+="{"+lang+"}";
3248 }
3249 out+=" ";
3250 addStrEscapeUtf8Nbsp(data.substr(blockStart+i,blockEnd-blockStart));
3251 out+="@endicode ";
3252}

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

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

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

2864{
2865 AUTO_TRACE("data='{}'",Trace::trunc(data));
2866 int level=0;
2867 QCString header;
2868 QCString id;
2869 if (isHRuler(data))
2870 {
2871 out+="<hr>\n";
2872 }
2873 else if ((level=isAtxHeader(data,header,id,TRUE)))
2874 {
2875 QCString hTag;
2876 if (!id.isEmpty())
2877 {
2878 switch (level)
2879 {
2880 case SectionType::Section: out+="@section "; break;
2881 case SectionType::Subsection: out+="@subsection "; break;
2882 case SectionType::Subsubsection: out+="@subsubsection "; break;
2883 case SectionType::Paragraph: out+="@paragraph "; break;
2884 case SectionType::Subparagraph: out+="@subparagraph "; break;
2885 case SectionType::Subsubparagraph: out+="@subsubparagraph "; break;
2886 }
2887 out+=id;
2888 out+=" ";
2889 out+=header;
2890 out+="\n";
2891 }
2892 else
2893 {
2894 hTag.sprintf("h%d",level);
2895 out+="<"+hTag+">";
2896 out+=header;
2897 out+="</"+hTag+">\n";
2898 }
2899 }
2900 else if (data.size()>0) // nothing interesting -> just output the line
2901 {
2902 size_t tmpSize = data.size();
2903 if (data[data.size()-1] == '\n') tmpSize--;
2904 out+=data.substr(0,tmpSize);
2905
2906 if (hasLineBreak(data))
2907 {
2908 out+="\\ilinebr<br>";
2909 }
2910 if (tmpSize != data.size()) out+='\n';
2911 }
2912}
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 2644 of file markdown.cpp.

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

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

◆ indentLevel

int Markdown::Private::indentLevel =0

Definition at line 180 of file markdown.cpp.

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

◆ lineNr

int Markdown::Private::lineNr = 0

Definition at line 179 of file markdown.cpp.

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

◆ linkRefs

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

Definition at line 177 of file markdown.cpp.

Referenced by processBlocks(), and processLink().

◆ out


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