Doxygen
Loading...
Searching...
No Matches
markdown.cpp File Reference
#include <stdio.h>
#include <unordered_map>
#include <functional>
#include <atomic>
#include <array>
#include <string_view>
#include "markdown.h"
#include "debug.h"
#include "util.h"
#include "doxygen.h"
#include "commentscan.h"
#include "entry.h"
#include "config.h"
#include "message.h"
#include "portable.h"
#include "regex.h"
#include "fileinfo.h"
#include "trace.h"
#include "anchor.h"
#include "stringutil.h"
+ Include dependency graph for markdown.cpp:

Go to the source code of this file.

Classes

struct  TableCell
 
struct  Markdown::Private
 
struct  Markdown::Private::LinkRef
 
struct  MarkdownOutlineParser::Private
 

Macros

#define AUTO_TRACE(...)
 
#define AUTO_TRACE_ADD(...)
 
#define AUTO_TRACE_EXIT(...)
 
#define isIdChar(c)
 
#define extraChar(c)
 
#define isOpenEmphChar(c)
 
#define ignoreCloseEmphChar(c, cn)
 
#define isLiTag(i)
 

Enumerations

enum class  ExplicitPageResult { explicitPage , explicitMainPage , explicitDirPage , notExplicit }
 
enum  Alignment { AlignNone , AlignLeft , AlignCenter , AlignRight }
 

Functions

size_t isNewline (std::string_view data)
 
static QCString escapeDoubleQuotes (const QCString &s)
 
static QCString escapeSpecialChars (const QCString &s)
 
static Alignment markersToAlignment (bool leftMarker, bool rightMarker)
 helper function to convert presence of left and/or right alignment markers to an alignment value
 
static QCString getFilteredImageAttributes (std::string_view fmt, const QCString &attrs)
 parse the image attributes and return attributes for given format
 
static bool isBlockQuote (std::string_view data, size_t indent)
 returns true if this line starts a block quote
 
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 isHRuler (std::string_view data)
 
static bool isEmptyLine (std::string_view data)
 
static size_t computeIndentExcludingListMarkers (std::string_view data)
 
static size_t isListMarker (std::string_view data)
 
static bool isEndOfList (std::string_view data)
 
static bool isFencedCodeBlock (std::string_view data, size_t refIndent, QCString &lang, size_t &start, size_t &end, size_t &offset)
 
static bool isCodeBlock (std::string_view data, size_t offset, size_t &indent)
 
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.
 
static bool isTableBlock (std::string_view data)
 Returns TRUE iff data points to the start of a table block.
 
static bool hasLineBreak (std::string_view data)
 
bool skipOverFileAndLineCommands (std::string_view data, size_t indent, size_t &offset, std::string &location)
 
static ExplicitPageResult isExplicitPage (const QCString &docs)
 
QCString markdownFileNameToId (const QCString &fileName)
 processes string s and converts markdown into doxygen/html commands.
 

Variables

const char * g_utf8_nbsp = "\xc2\xa0"
 
const char * g_doxy_nbsp = "&_doxy_nbsp;"
 
const size_t codeBlockIndent = 4
 
static const std::unordered_map< std::string, std::string > g_quotationHeaderMap
 

Macro Definition Documentation

◆ AUTO_TRACE

#define AUTO_TRACE ( ...)
Value:
(void)0

Definition at line 61 of file markdown.cpp.

Referenced by escapeDoubleQuotes(), escapeSpecialChars(), and getFilteredImageAttributes().

◆ AUTO_TRACE_ADD

#define AUTO_TRACE_ADD ( ...)
Value:
(void)0

Definition at line 62 of file markdown.cpp.

◆ AUTO_TRACE_EXIT

#define AUTO_TRACE_EXIT ( ...)
Value:
(void)0

Definition at line 63 of file markdown.cpp.

Referenced by escapeDoubleQuotes(), escapeSpecialChars(), and getFilteredImageAttributes().

◆ extraChar

#define extraChar ( c)
Value:
(c=='-' || c=='+' || c=='!' || \
c=='?' || c=='$' || c=='@' || \
c=='&' || c=='*' || c=='%' || \
c=='[' || c=='(' || c=='.' || \
c=='>' || c==':' || c==',' || \
c==';' || c=='\'' || c=='"' || c=='`')

Definition at line 84 of file markdown.cpp.

84#define extraChar(c) \
85 (c=='-' || c=='+' || c=='!' || \
86 c=='?' || c=='$' || c=='@' || \
87 c=='&' || c=='*' || c=='%' || \
88 c=='[' || c=='(' || c=='.' || \
89 c=='>' || c==':' || c==',' || \
90 c==';' || c=='\'' || c=='"' || c=='`')

Referenced by Markdown::Private::processEmphasis().

◆ ignoreCloseEmphChar

#define ignoreCloseEmphChar ( c,
cn )
Value:
(c=='(' || c=='{' || c=='[' || (c=='<' && cn!='/') || \
c=='\\' || \
c=='@')

Definition at line 100 of file markdown.cpp.

100#define ignoreCloseEmphChar(c,cn) \
101 (c=='(' || c=='{' || c=='[' || (c=='<' && cn!='/') || \
102 c=='\\' || \
103 c=='@')

Referenced by Markdown::Private::findEmphasisChar().

◆ isIdChar

#define isIdChar ( c)
Value:
((c>='a' && c<='z') || \
(c>='A' && c<='Z') || \
(c>='0' && c<='9') || \
(static_cast<unsigned char>(c)>=0x80))

Definition at line 77 of file markdown.cpp.

77#define isIdChar(c) \
78 ((c>='a' && c<='z') || \
79 (c>='A' && c<='Z') || \
80 (c>='0' && c<='9') || \
81 (static_cast<unsigned char>(c)>=0x80)) // unicode characters

Referenced by Markdown::Private::findEmphasisChar(), reg::Ex::Private::matchAt(), Markdown::Private::processCodeSpan(), Markdown::Private::processEmphasis(), and Markdown::Private::processHtmlTagWrite().

◆ isLiTag

#define isLiTag ( i)
Value:
(data[(i)]=='<' && \
(data[(i)+1]=='l' || data[(i)+1]=='L') && \
(data[(i)+2]=='i' || data[(i)+2]=='I') && \
(data[(i)+3]=='>'))

Definition at line 2113 of file markdown.cpp.

2113#define isLiTag(i) \
2114 (data[(i)]=='<' && \
2115 (data[(i)+1]=='l' || data[(i)+1]=='L') && \
2116 (data[(i)+2]=='i' || data[(i)+2]=='I') && \
2117 (data[(i)+3]=='>'))

Referenced by computeIndentExcludingListMarkers().

◆ isOpenEmphChar

#define isOpenEmphChar ( c)
Value:
(c=='\n' || c==' ' || c=='\'' || c=='<' || \
c=='>' || c=='{' || c=='(' || c=='[' || \
c==',' || c==':' || c==';')

Definition at line 93 of file markdown.cpp.

93#define isOpenEmphChar(c) \
94 (c=='\n' || c==' ' || c=='\'' || c=='<' || \
95 c=='>' || c=='{' || c=='(' || c=='[' || \
96 c==',' || c==':' || c==';')

Referenced by Markdown::Private::processEmphasis().

Enumeration Type Documentation

◆ Alignment

enum Alignment
Enumerator
AlignNone 
AlignLeft 
AlignCenter 
AlignRight 

Definition at line 194 of file markdown.cpp.

@ AlignLeft
Definition markdown.cpp:194
@ AlignNone
Definition markdown.cpp:194
@ AlignRight
Definition markdown.cpp:194
@ AlignCenter
Definition markdown.cpp:194

◆ ExplicitPageResult

enum class ExplicitPageResult
strong
Enumerator
explicitPage 

docs start with a page command

explicitMainPage 

docs start with a mainpage command

explicitDirPage 

docs start with a dir command

notExplicit 

docs doesn't start with either page or mainpage

Definition at line 66 of file markdown.cpp.

67{
68 explicitPage, /**< docs start with a page command */
69 explicitMainPage, /**< docs start with a mainpage command */
70 explicitDirPage, /**< docs start with a dir command */
71 notExplicit /**< docs doesn't start with either page or mainpage */
72};
@ explicitDirPage
docs start with a dir command
Definition markdown.cpp:70
@ explicitMainPage
docs start with a mainpage command
Definition markdown.cpp:69
@ explicitPage
docs start with a page command
Definition markdown.cpp:68
@ notExplicit
docs doesn't start with either page or mainpage
Definition markdown.cpp:71

Function Documentation

◆ computeIndentExcludingListMarkers()

static size_t computeIndentExcludingListMarkers ( std::string_view data)
static

Definition at line 2121 of file markdown.cpp.

2122{
2123 AUTO_TRACE("data='{}'",Trace::trunc(data));
2124 size_t i=0;
2125 const size_t size=data.size();
2126 size_t indent=0;
2127 bool isDigit=FALSE;
2128 bool isLi=FALSE;
2129 bool listMarkerSkipped=FALSE;
2130 while (i<size &&
2131 (data[i]==' ' || // space
2132 (!listMarkerSkipped && // first list marker
2133 (data[i]=='+' || data[i]=='-' || data[i]=='*' || // unordered list char
2134 (data[i]=='#' && i>0 && data[i-1]=='-') || // -# item
2135 (isDigit=(data[i]>='1' && data[i]<='9')) || // ordered list marker?
2136 (isLi=(size>=3 && i+3<size && isLiTag(i))) // <li> tag
2137 )
2138 )
2139 )
2140 )
2141 {
2142 if (isDigit) // skip over ordered list marker '10. '
2143 {
2144 size_t j=i+1;
2145 while (j<size && ((data[j]>='0' && data[j]<='9') || data[j]=='.'))
2146 {
2147 if (data[j]=='.') // should be end of the list marker
2148 {
2149 if (j+1<size && data[j+1]==' ') // valid list marker
2150 {
2151 listMarkerSkipped=TRUE;
2152 indent+=j+1-i;
2153 i=j+1;
2154 break;
2155 }
2156 else // not a list marker
2157 {
2158 break;
2159 }
2160 }
2161 j++;
2162 }
2163 }
2164 else if (isLi)
2165 {
2166 i+=3; // skip over <li>
2167 indent+=3;
2168 listMarkerSkipped=TRUE;
2169 }
2170 else if (data[i]=='-' && size>=2 && i+2<size && data[i+1]=='#' && data[i+2]==' ')
2171 { // case "-# "
2172 listMarkerSkipped=TRUE; // only a single list marker is accepted
2173 i++; // skip over #
2174 indent++;
2175 }
2176 else if (data[i]!=' ' && i+1<size && data[i+1]==' ')
2177 { // case "- " or "+ " or "* "
2178 listMarkerSkipped=TRUE; // only a single list marker is accepted
2179 }
2180 if (data[i]!=' ' && !listMarkerSkipped)
2181 { // end of indent
2182 break;
2183 }
2184 indent++,i++;
2185 }
2186 AUTO_TRACE_EXIT("result={}",indent);
2187 return indent;
2188}
#define AUTO_TRACE(...)
Definition markdown.cpp:61
#define AUTO_TRACE_EXIT(...)
Definition markdown.cpp:63
#define isLiTag(i)
QCString trunc(const QCString &s, size_t numChars=15)
Definition trace.h:56
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34

References AUTO_TRACE, AUTO_TRACE_EXIT, FALSE, isLiTag, TRUE, and Trace::trunc().

Referenced by isCodeBlock(), and isListMarker().

◆ escapeDoubleQuotes()

static QCString escapeDoubleQuotes ( const QCString & s)
static

Definition at line 217 of file markdown.cpp.

218{
219 AUTO_TRACE("s={}",Trace::trunc(s));
220 if (s.isEmpty()) return s;
221 QCString result;
222 const char *p=s.data();
223 char c=0, pc='\0';
224 while ((c=*p++))
225 {
226 if (c=='"' && pc!='\\') result+='\\';
227 result+=c;
228 pc=c;
229 }
230 AUTO_TRACE_EXIT("result={}",result);
231 return result;
232}
This is an alternative implementation of QCString.
Definition qcstring.h:101
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159

References AUTO_TRACE, AUTO_TRACE_EXIT, QCString::data(), QCString::isEmpty(), and Trace::trunc().

Referenced by Markdown::Private::writeMarkdownImage().

◆ escapeSpecialChars()

static QCString escapeSpecialChars ( const QCString & s)
static

Definition at line 235 of file markdown.cpp.

236{
237 AUTO_TRACE("s={}",Trace::trunc(s));
238 if (s.isEmpty()) return s;
239 bool insideQuote=FALSE;
240 QCString result;
241 const char *p=s.data();
242 char c=0, pc='\0';
243 while ((c=*p++))
244 {
245 switch (c)
246 {
247 case '"':
248 if (pc!='\\') { insideQuote=!insideQuote; }
249 result+=c;
250 break;
251 case '<':
252 // fall through
253 case '>':
254 if (!insideQuote)
255 {
256 result+='\\';
257 result+=c;
258 if ((p[0]==':') && (p[1]==':'))
259 {
260 result+='\\';
261 result+=':';
262 p++;
263 }
264 }
265 else
266 {
267 result+=c;
268 }
269 break;
270 case '\\': if (!insideQuote) { result+='\\'; } result+='\\'; break;
271 case '@': if (!insideQuote) { result+='\\'; } result+='@'; break;
272 // commented out next line due to regression when using % to suppress a link
273 //case '%': if (!insideQuote) { result+='\\'; } result+='%'; break;
274 case '#': if (!insideQuote) { result+='\\'; } result+='#'; break;
275 case '$': if (!insideQuote) { result+='\\'; } result+='$'; break;
276 case '&': if (!insideQuote) { result+='\\'; } result+='&'; break;
277 default:
278 result+=c; break;
279 }
280 pc=c;
281 }
282 AUTO_TRACE_EXIT("result={}",result);
283 return result;
284}

References AUTO_TRACE, AUTO_TRACE_EXIT, QCString::data(), FALSE, QCString::isEmpty(), and Trace::trunc().

Referenced by Markdown::Private::processCodeSpan().

◆ findTableColumns()

static size_t findTableColumns ( std::string_view data,
size_t & start,
size_t & end,
size_t & columns )
static

Finds the location of the table's contains in the string data.

Only one line will be inspected.

Parameters
[in]datapointer to the string buffer.
[out]startoffset of the first character of the table content
[out]endoffset of the last character of the table content
[out]columnsnumber of table columns found
Returns
The offset until the next line in the buffer.

Definition at line 2406 of file markdown.cpp.

2407{
2408 AUTO_TRACE("data='{}'",Trace::trunc(data));
2409 const size_t size = data.size();
2410 size_t i=0,n=0;
2411 // find start character of the table line
2412 while (i<size && data[i]==' ') i++;
2413 if (i<size && data[i]=='|' && data[i]!='\n') i++,n++; // leading | does not count
2414 start = i;
2415
2416 // find end character of the table line
2417 size_t j = 0;
2418 while (i<size && (j = isNewline(data.substr(i)))==0) i++;
2419 size_t eol=i+j;
2420
2421 if (j>0 && i>0) i--; // move i to point before newline
2422 while (i>0 && data[i]==' ') i--;
2423 if (i>0 && data[i-1]!='\\' && data[i]=='|') i--,n++; // trailing or escaped | does not count
2424 end = i;
2425
2426 // count columns between start and end
2427 columns=0;
2428 if (end>start)
2429 {
2430 i=start;
2431 while (i<=end) // look for more column markers
2432 {
2433 if (data[i]=='|' && (i==0 || data[i-1]!='\\')) columns++;
2434 if (columns==1) columns++; // first | make a non-table into a two column table
2435 i++;
2436 }
2437 }
2438 if (n==2 && columns==0) // table row has | ... |
2439 {
2440 columns++;
2441 }
2442 AUTO_TRACE_EXIT("eol={} start={} end={} columns={}",eol,start,end,columns);
2443 return eol;
2444}
#define eol
The end of line string for this machine.
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
size_t isNewline(std::string_view data)
Definition markdown.cpp:207

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

Referenced by isTableBlock(), and Markdown::Private::writeTableBlock().

◆ getFilteredImageAttributes()

static QCString getFilteredImageAttributes ( std::string_view fmt,
const QCString & attrs )
static

parse the image attributes and return attributes for given format

Definition at line 310 of file markdown.cpp.

311{
312 AUTO_TRACE("fmt={} attrs={}",fmt,attrs);
313 StringVector attrList = split(attrs.str(),",");
314 for (const auto &attr_ : attrList)
315 {
316 QCString attr = QCString(attr_).stripWhiteSpace();
317 int i = attr.find(':');
318 if (i>0) // has format
319 {
320 QCString format = attr.left(i).stripWhiteSpace().lower();
321 if (format == fmt) // matching format
322 {
323 AUTO_TRACE_EXIT("result={}",attr.mid(i+1));
324 return attr.mid(i+1); // keep part after :
325 }
326 }
327 else // option that applies to all formats
328 {
329 AUTO_TRACE_EXIT("result={}",attr);
330 return attr;
331 }
332 }
333 return QCString();
334}
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
QCString lower() const
Definition qcstring.h:234
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:245
const std::string & str() const
Definition qcstring.h:537
QCString left(size_t len) const
Definition qcstring.h:214
std::vector< std::string > StringVector
Definition containers.h:33
Definition message.h:144
StringVector split(const std::string &s, const std::string &delimiter)
split input string s by string delimiter delimiter.
Definition util.cpp:7042

References AUTO_TRACE, AUTO_TRACE_EXIT, QCString::find(), QCString::left(), QCString::lower(), QCString::mid(), split(), QCString::str(), and QCString::stripWhiteSpace().

Referenced by Markdown::Private::writeMarkdownImage().

◆ hasLineBreak()

static bool hasLineBreak ( std::string_view data)
static

Definition at line 2687 of file markdown.cpp.

2688{
2689 AUTO_TRACE("data='{}'",Trace::trunc(data));
2690 size_t i=0;
2691 size_t j=0;
2692 // search for end of line and also check if it is not a completely blank
2693 while (i<data.size() && data[i]!='\n')
2694 {
2695 if (data[i]!=' ' && data[i]!='\t') j++; // some non whitespace
2696 i++;
2697 }
2698 if (i>=data.size()) { return 0; } // empty line
2699 if (i<2) { return 0; } // not long enough
2700 bool res = (j>0 && data[i-1]==' ' && data[i-2]==' '); // non blank line with at two spaces at the end
2701 AUTO_TRACE_EXIT("result={}",res);
2702 return res;
2703}

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

Referenced by Markdown::Private::writeOneLineHeaderOrRuler().

◆ isBlockQuote()

static bool isBlockQuote ( std::string_view data,
size_t indent )
static

returns true if this line starts a block quote

Definition at line 1850 of file markdown.cpp.

1851{
1852 AUTO_TRACE("data='{}' indent={}",Trace::trunc(data),indent);
1853 size_t i = 0;
1854 const size_t size = data.size();
1855 while (i<size && data[i]==' ') i++;
1856 if (i<indent+codeBlockIndent) // could be a quotation
1857 {
1858 // count >'s and skip spaces
1859 int level=0;
1860 while (i<size && (data[i]=='>' || data[i]==' '))
1861 {
1862 if (data[i]=='>') level++;
1863 i++;
1864 }
1865 // last characters should be a space or newline,
1866 // so a line starting with >= does not match, but only when level equals 1
1867 bool res = (level>0 && i<size && ((data[i-1]==' ') || data[i]=='\n')) || (level > 1);
1868 AUTO_TRACE_EXIT("result={}",res);
1869 return res;
1870 }
1871 else // too much indentation -> code block
1872 {
1873 AUTO_TRACE_EXIT("result=false: too much indentation");
1874 return false;
1875 }
1876}
const size_t codeBlockIndent
Definition markdown.cpp:201

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

Referenced by Markdown::Private::processQuotations().

◆ isCodeBlock()

static bool isCodeBlock ( std::string_view data,
size_t offset,
size_t & indent )
static

Definition at line 2313 of file markdown.cpp.

2314{
2315 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
2316 //printf("<isCodeBlock(offset=%d,size=%d,indent=%d)\n",offset,size,indent);
2317 // determine the indent of this line
2318 size_t i=0;
2319 size_t indent0=0;
2320 const size_t size = data.size();
2321 while (i<size && data[i]==' ') indent0++,i++;
2322
2323 if (indent0<codeBlockIndent)
2324 {
2325 AUTO_TRACE_EXIT("result={}: line is not indented enough {}<4",false,indent0);
2326 return false;
2327 }
2328 if (indent0>=size || data[indent0]=='\n') // empty line does not start a code block
2329 {
2330 AUTO_TRACE_EXIT("result={}: only spaces at the end of a comment block",false);
2331 return false;
2332 }
2333
2334 i=offset;
2335 int nl=0;
2336 int nl_pos[3];
2337 int offset_i = static_cast<int>(offset);
2338 // search back 3 lines and remember the start of lines -1 and -2
2339 while (i>0 && nl<3) // i counts down from offset to 1
2340 {
2341 int j = static_cast<int>(i)-offset_i-1; // j counts from -1 to -offset
2342 // since j can be negative we need to rewrap data in a std::string_view
2343 size_t nl_size = isNewline(std::string_view(data.data()+j,data.size()-j));
2344 if (nl_size>0)
2345 {
2346 nl_pos[nl++]=j+static_cast<int>(nl_size);
2347 }
2348 i--;
2349 }
2350
2351 // if there are only 2 preceding lines, then line -2 starts at -offset
2352 if (i==0 && nl==2) nl_pos[nl++]=-offset_i;
2353
2354 if (nl==3) // we have at least 2 preceding lines
2355 {
2356 //printf(" positions: nl_pos=[%d,%d,%d] line[-2]='%s' line[-1]='%s'\n",
2357 // nl_pos[0],nl_pos[1],nl_pos[2],
2358 // qPrint(QCString(data+nl_pos[1]).left(nl_pos[0]-nl_pos[1]-1)),
2359 // qPrint(QCString(data+nl_pos[2]).left(nl_pos[1]-nl_pos[2]-1)));
2360
2361 // check that line -1 is empty
2362 // Note that the offset is negative so we need to rewrap the string view
2363 if (!isEmptyLine(std::string_view(data.data()+nl_pos[1],nl_pos[0]-nl_pos[1]-1)))
2364 {
2365 AUTO_TRACE_EXIT("result={}",FALSE);
2366 return FALSE;
2367 }
2368
2369 // determine the indent of line -2
2370 // Note that the offset is negative so we need to rewrap the string view
2371 indent=std::max(indent,computeIndentExcludingListMarkers(
2372 std::string_view(data.data()+nl_pos[2],nl_pos[1]-nl_pos[2])));
2373
2374 //printf(">isCodeBlock local_indent %d>=%d+%d=%d\n",
2375 // indent0,indent,codeBlockIndent,indent0>=indent+codeBlockIndent);
2376 // if the difference is >4 spaces -> code block
2377 bool res = indent0>=indent+codeBlockIndent;
2378 AUTO_TRACE_EXIT("result={}: code block if indent difference >4 spaces",res);
2379 return res;
2380 }
2381 else // not enough lines to determine the relative indent, use global indent
2382 {
2383 // check that line -1 is empty
2384 // Note that the offset is negative so we need to rewrap the string view
2385 if (nl==1 && !isEmptyLine(std::string_view(data.data()-offset,offset-1)))
2386 {
2387 AUTO_TRACE_EXIT("result=false");
2388 return FALSE;
2389 }
2390 //printf(">isCodeBlock global indent %d>=%d+4=%d nl=%d\n",
2391 // indent0,indent,indent0>=indent+4,nl);
2392 bool res = indent0>=indent+codeBlockIndent;
2393 AUTO_TRACE_EXIT("result={}: code block if indent difference >4 spaces",res);
2394 return res;
2395 }
2396}
static size_t computeIndentExcludingListMarkers(std::string_view data)
static bool isEmptyLine(std::string_view data)

References AUTO_TRACE, AUTO_TRACE_EXIT, codeBlockIndent, computeIndentExcludingListMarkers(), FALSE, isEmptyLine(), isNewline(), and Trace::trunc().

Referenced by Markdown::Private::processBlocks().

◆ isEmptyLine()

static bool isEmptyLine ( std::string_view data)
static

Definition at line 2099 of file markdown.cpp.

2100{
2101 AUTO_TRACE("data='{}'",Trace::trunc(data));
2102 size_t i=0;
2103 while (i<data.size())
2104 {
2105 if (data[i]=='\n') { AUTO_TRACE_EXIT("true"); return true; }
2106 if (data[i]!=' ') { AUTO_TRACE_EXIT("false"); return false; }
2107 i++;
2108 }
2109 AUTO_TRACE_EXIT("true");
2110 return true;
2111}

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

Referenced by isCodeBlock(), Markdown::Private::processBlocks(), and Markdown::Private::processQuotations().

◆ isEndOfList()

static bool isEndOfList ( std::string_view data)
static

Definition at line 2201 of file markdown.cpp.

2202{
2203 AUTO_TRACE("data='{}'",Trace::trunc(data));
2204 int dots=0;
2205 size_t i=0;
2206 // end of list marker is an otherwise empty line with a dot.
2207 while (i<data.size())
2208 {
2209 if (data[i]=='.')
2210 {
2211 dots++;
2212 }
2213 else if (data[i]=='\n')
2214 {
2215 break;
2216 }
2217 else if (data[i]!=' ' && data[i]!='\t') // bail out if the line is not empty
2218 {
2219 AUTO_TRACE_EXIT("result=false");
2220 return false;
2221 }
2222 i++;
2223 }
2224 AUTO_TRACE_EXIT("result={}",dots==1);
2225 return dots==1;
2226}

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

Referenced by Markdown::Private::processBlocks(), and Markdown::Private::processQuotations().

◆ isExplicitPage()

static ExplicitPageResult isExplicitPage ( const QCString & docs)
static

Definition at line 3446 of file markdown.cpp.

3447{
3448 AUTO_TRACE("docs={}",Trace::trunc(docs));
3449 size_t i=0;
3450 std::string_view data(docs.str());
3451 const size_t size = data.size();
3452 if (!data.empty())
3453 {
3454 while (i<size && (data[i]==' ' || data[i]=='\n'))
3455 {
3456 i++;
3457 }
3458 if (i+5<size && data[i]=='<' && qstrncmp(&data[i],"<!--!",5)==0) // skip over <!--! marker
3459 {
3460 i+=5;
3461 while (i<size && (data[i]==' ' || data[i]=='\n')) // skip over spaces after the <!--! marker
3462 {
3463 i++;
3464 }
3465 }
3466 if (i+1<size &&
3467 (data[i]=='\\' || data[i]=='@') &&
3468 (qstrncmp(&data[i+1],"page ",5)==0 || qstrncmp(&data[i+1],"mainpage",8)==0)
3469 )
3470 {
3471 if (qstrncmp(&data[i+1],"page ",5)==0)
3472 {
3473 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitPage");
3475 }
3476 else
3477 {
3478 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitMainPage");
3480 }
3481 }
3482 else if (i+1<size &&
3483 (data[i]=='\\' || data[i]=='@') &&
3484 (qstrncmp(&data[i+1],"dir\n",4)==0 || qstrncmp(&data[i+1],"dir ",4)==0)
3485 )
3486 {
3487 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitDirPage");
3489 }
3490 }
3491 AUTO_TRACE_EXIT("result=ExplicitPageResult::notExplicit");
3493}
int qstrncmp(const char *str1, const char *str2, size_t len)
Definition qcstring.h:75

References AUTO_TRACE, AUTO_TRACE_EXIT, explicitDirPage, explicitMainPage, explicitPage, notExplicit, qstrncmp(), QCString::str(), and Trace::trunc().

Referenced by MarkdownOutlineParser::parseInput().

◆ isFencedCodeBlock()

static bool isFencedCodeBlock ( std::string_view data,
size_t refIndent,
QCString & lang,
size_t & start,
size_t & end,
size_t & offset )
static

extract python or .py from python... or .py...

Definition at line 2228 of file markdown.cpp.

2230{
2231 AUTO_TRACE("data='{}' refIndent={}",Trace::trunc(data),refIndent);
2232 const char dot = '.';
2233 auto isAlphaChar = [ ](char c) { return (c>='A' && c<='Z') || (c>='a' && c<='z'); };
2234 auto isAlphaNChar = [ ](char c) { return (c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || (c=='+'); };
2235 auto isLangChar = [&](char c) { return c==dot || isAlphaChar(c); };
2236 // rules: at least 3 ~~~, end of the block same amount of ~~~'s, otherwise
2237 // return FALSE
2238 size_t i=0;
2239 size_t indent=0;
2240 int startTildes=0;
2241 const size_t size = data.size();
2242 while (i<size && data[i]==' ') indent++,i++;
2243 if (indent>=refIndent+4)
2244 {
2245 AUTO_TRACE_EXIT("result=false: content is part of code block indent={} refIndent={}",indent,refIndent);
2246 return FALSE;
2247 } // part of code block
2248 char tildaChar='~';
2249 if (i<size && data[i]=='`') tildaChar='`';
2250 while (i<size && data[i]==tildaChar) startTildes++,i++;
2251 if (startTildes<3)
2252 {
2253 AUTO_TRACE_EXIT("result=false: no fence marker found #tildes={}",startTildes);
2254 return FALSE;
2255 } // not enough tildes
2256 if (i<size && data[i]=='{') // extract .py from ```{.py} ... ```
2257 {
2258 i++; // skip over {
2259 if (data[i] == dot) i++; // skip over initial dot
2260 size_t startLang=i;
2261 while (i<size && (data[i]!='\n' && data[i]!='}')) i++; // find matching }
2262 if (i<size && data[i]=='}')
2263 {
2264 lang = data.substr(startLang,i-startLang);
2265 i++;
2266 }
2267 else // missing closing bracket, treat `{` as part of the content
2268 {
2269 i=startLang-1;
2270 lang="";
2271 }
2272 }
2273 else if (i<size && isLangChar(data[i])) /// extract python or .py from ```python...``` or ```.py...```
2274 {
2275 if (data[i] == dot) i++; // skip over initial dot
2276 size_t startLang=i;
2277 if (i<size && isAlphaChar(data[i])) //check first character of language specifier
2278 {
2279 i++;
2280 while (i<size && isAlphaNChar(data[i])) i++; // find end of language specifier
2281 }
2282 lang = data.substr(startLang,i-startLang);
2283 }
2284 else // no language specified
2285 {
2286 lang="";
2287 }
2288
2289 start=i;
2290 while (i<size)
2291 {
2292 if (data[i]==tildaChar)
2293 {
2294 end=i;
2295 int endTildes=0;
2296 while (i<size && data[i]==tildaChar) endTildes++,i++;
2297 while (i<size && data[i]==' ') i++;
2298 {
2299 if (endTildes==startTildes)
2300 {
2301 offset=i;
2302 AUTO_TRACE_EXIT("result=true: found end marker at offset {} lang='{}'",offset,lang);
2303 return true;
2304 }
2305 }
2306 }
2307 i++;
2308 }
2309 AUTO_TRACE_EXIT("result=false: no end marker found lang={}'",lang);
2310 return false;
2311}

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

Referenced by Markdown::Private::processBlocks(), and Markdown::Private::processQuotations().

◆ isHRuler()

static bool isHRuler ( std::string_view data)
static

Definition at line 1968 of file markdown.cpp.

1969{
1970 AUTO_TRACE("data='{}'",Trace::trunc(data));
1971 size_t i=0;
1972 size_t size = data.size();
1973 if (size>0 && data[size-1]=='\n') size--; // ignore newline character
1974 while (i<size && data[i]==' ') i++;
1975 if (i>=size) { AUTO_TRACE_EXIT("result=false: empty line"); return false; } // empty line
1976 char c=data[i];
1977 if (c!='*' && c!='-' && c!='_')
1978 {
1979 AUTO_TRACE_EXIT("result=false: {} is not a hrule character",c);
1980 return false; // not a hrule character
1981 }
1982 int n=0;
1983 while (i<size)
1984 {
1985 if (data[i]==c)
1986 {
1987 n++; // count rule character
1988 }
1989 else if (data[i]!=' ')
1990 {
1991 AUTO_TRACE_EXIT("result=false: line contains non hruler characters");
1992 return false; // line contains non hruler characters
1993 }
1994 i++;
1995 }
1996 AUTO_TRACE_EXIT("result={}",n>=3);
1997 return n>=3; // at least 3 characters needed for a hruler
1998}

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

Referenced by Markdown::Private::writeBlockQuote(), and Markdown::Private::writeOneLineHeaderOrRuler().

◆ isLinkRef()

static size_t isLinkRef ( std::string_view data,
QCString & refid,
QCString & link,
QCString & title )
static

returns end of the link ref if this is indeed a link reference.

Definition at line 1879 of file markdown.cpp.

1880{
1881 AUTO_TRACE("data='{}'",Trace::trunc(data));
1882 const size_t size = data.size();
1883 // format: start with [some text]:
1884 size_t i = 0;
1885 while (i<size && data[i]==' ') i++;
1886 if (i>=size || data[i]!='[') { return 0; }
1887 i++;
1888 size_t refIdStart=i;
1889 while (i<size && data[i]!='\n' && data[i]!=']') i++;
1890 if (i>=size || data[i]!=']') { return 0; }
1891 refid = data.substr(refIdStart,i-refIdStart);
1892 if (refid.isEmpty()) { return 0; }
1893 AUTO_TRACE_ADD("refid found {}",refid);
1894 //printf(" isLinkRef: found refid='%s'\n",qPrint(refid));
1895 i++;
1896 if (i>=size || data[i]!=':') { return 0; }
1897 i++;
1898
1899 // format: whitespace* \n? whitespace* (<url> | url)
1900 while (i<size && data[i]==' ') i++;
1901 if (i<size && data[i]=='\n')
1902 {
1903 i++;
1904 while (i<size && data[i]==' ') i++;
1905 }
1906 if (i>=size) { return 0; }
1907
1908 if (i<size && data[i]=='<') i++;
1909 size_t linkStart=i;
1910 while (i<size && data[i]!=' ' && data[i]!='\n') i++;
1911 size_t linkEnd=i;
1912 if (i<size && data[i]=='>') i++;
1913 if (linkStart==linkEnd) { return 0; } // empty link
1914 link = data.substr(linkStart,linkEnd-linkStart);
1915 AUTO_TRACE_ADD("link found {}",Trace::trunc(link));
1916 if (link=="@ref" || link=="\\ref")
1917 {
1918 size_t argStart=i;
1919 while (i<size && data[i]!='\n' && data[i]!='"') i++;
1920 link+=data.substr(argStart,i-argStart);
1921 }
1922
1923 title.clear();
1924
1925 // format: (whitespace* \n? whitespace* ( 'title' | "title" | (title) ))?
1926 size_t eol=0;
1927 while (i<size && data[i]==' ') i++;
1928 if (i<size && data[i]=='\n')
1929 {
1930 eol=i;
1931 i++;
1932 while (i<size && data[i]==' ') i++;
1933 }
1934 if (i>=size)
1935 {
1936 AUTO_TRACE_EXIT("result={}: end of isLinkRef while looking for title",i);
1937 return i; // end of buffer while looking for the optional title
1938 }
1939
1940 char c = data[i];
1941 if (c=='\'' || c=='"' || c=='(') // optional title present?
1942 {
1943 //printf(" start of title found! char='%c'\n",c);
1944 i++;
1945 if (c=='(') c=')'; // replace c by end character
1946 size_t titleStart=i;
1947 // search for end of the line
1948 while (i<size && data[i]!='\n') i++;
1949 eol = i;
1950
1951 // search back to matching character
1952 size_t end=i-1;
1953 while (end>titleStart && data[end]!=c) end--;
1954 if (end>titleStart)
1955 {
1956 title = data.substr(titleStart,end-titleStart);
1957 }
1958 AUTO_TRACE_ADD("title found {}",Trace::trunc(title));
1959 }
1960 while (i<size && data[i]==' ') i++;
1961 //printf("end of isLinkRef: i=%d size=%d data[i]='%c' eol=%d\n",
1962 // i,size,data[i],eol);
1963 if (i>=size) { AUTO_TRACE_EXIT("result={}",i); return i; } // end of buffer while ref id was found
1964 else if (eol>0) { AUTO_TRACE_EXIT("result={}",eol); return eol; } // end of line while ref id was found
1965 return 0; // invalid link ref
1966}
void clear()
Definition qcstring.h:169
#define AUTO_TRACE_ADD(...)
Definition markdown.cpp:62

References AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, QCString::clear(), end(), eol, QCString::isEmpty(), and Trace::trunc().

Referenced by Markdown::Private::processBlocks().

◆ isListMarker()

static size_t isListMarker ( std::string_view data)
static

Definition at line 2190 of file markdown.cpp.

2191{
2192 AUTO_TRACE("data='{}'",Trace::trunc(data));
2193 size_t normalIndent = 0;
2194 while (normalIndent<data.size() && data[normalIndent]==' ') normalIndent++;
2195 size_t listIndent = computeIndentExcludingListMarkers(data);
2196 size_t result = listIndent>normalIndent ? listIndent : 0;
2197 AUTO_TRACE_EXIT("result={}",result);
2198 return result;
2199}

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

Referenced by Markdown::Private::processBlocks(), Markdown::Private::processQuotations(), and Markdown::Private::writeBlockQuote().

◆ isNewline()

size_t isNewline ( std::string_view data)
inline

Definition at line 207 of file markdown.cpp.

208{
209 // normal newline
210 if (data[0] == '\n') return 1;
211 // artificial new line from ^^ in ALIASES
212 if (data[0] == '\\' && qstrncmp(data.data()+1,"ilinebr ",7)==0) return data[8]==' ' ? 9 : 8;
213 return 0;
214}

References qstrncmp().

Referenced by Markdown::Private::findEndOfLine(), findTableColumns(), and isCodeBlock().

◆ isTableBlock()

static bool isTableBlock ( std::string_view data)
static

Returns TRUE iff data points to the start of a table block.

Definition at line 2447 of file markdown.cpp.

2448{
2449 AUTO_TRACE("data='{}'",Trace::trunc(data));
2450 size_t cc0=0, start=0, end=0;
2451
2452 // the first line should have at least two columns separated by '|'
2453 size_t i = findTableColumns(data,start,end,cc0);
2454 if (i>=data.size() || cc0<1)
2455 {
2456 AUTO_TRACE_EXIT("result=false: no |'s in the header");
2457 return FALSE;
2458 }
2459
2460 size_t cc1 = 0;
2461 size_t ret = findTableColumns(data.substr(i),start,end,cc1);
2462 size_t j=i+start;
2463 // separator line should consist of |, - and : and spaces only
2464 while (j<=end+i)
2465 {
2466 if (data[j]!=':' && data[j]!='-' && data[j]!='|' && data[j]!=' ')
2467 {
2468 AUTO_TRACE_EXIT("result=false: invalid character '{}'",data[j]);
2469 return FALSE; // invalid characters in table separator
2470 }
2471 j++;
2472 }
2473 if (cc1!=cc0) // number of columns should be same as previous line
2474 {
2475 AUTO_TRACE_EXIT("result=false: different number of columns as previous line {}!={}",cc1,cc0);
2476 return FALSE;
2477 }
2478
2479 i+=ret; // goto next line
2480 size_t cc2 = 0;
2481 findTableColumns(data.substr(i),start,end,cc2);
2482
2483 AUTO_TRACE_EXIT("result={}",cc1==cc2);
2484 return cc1==cc2;
2485}
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, end(), FALSE, findTableColumns(), and Trace::trunc().

Referenced by Markdown::Private::processBlocks().

◆ markdownFileNameToId()

QCString markdownFileNameToId ( const QCString & fileName)

processes string s and converts markdown into doxygen/html commands.

Definition at line 3599 of file markdown.cpp.

3600{
3601 AUTO_TRACE("fileName={}",fileName);
3602 std::string absFileName = FileInfo(fileName.str()).absFilePath();
3603 QCString baseFn = stripFromPath(absFileName.c_str());
3604 int i = baseFn.findRev('.');
3605 if (i!=-1) baseFn = baseFn.left(i);
3606 QCString baseName = escapeCharsInString(baseFn,false,false);
3607 //printf("markdownFileNameToId(%s)=md_%s\n",qPrint(fileName),qPrint(baseName));
3608 QCString res = "md_"+baseName;
3609 AUTO_TRACE_EXIT("result={}",res);
3610 return res;
3611}
Minimal replacement for QFileInfo.
Definition fileinfo.h:23
std::string absFilePath() const
Definition fileinfo.cpp:101
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:91
QCString escapeCharsInString(const QCString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:3770
static QCString stripFromPath(const QCString &p, const StringVector &l)
Definition util.cpp:309

References FileInfo::absFilePath(), AUTO_TRACE, AUTO_TRACE_EXIT, escapeCharsInString(), QCString::findRev(), QCString::left(), QCString::str(), and stripFromPath().

Referenced by DocRef::DocRef(), DocSecRefItem::parse(), and MarkdownOutlineParser::parseInput().

◆ markersToAlignment()

static Alignment markersToAlignment ( bool leftMarker,
bool rightMarker )
static

helper function to convert presence of left and/or right alignment markers to an alignment value

Definition at line 289 of file markdown.cpp.

290{
291 if (leftMarker && rightMarker)
292 {
293 return AlignCenter;
294 }
295 else if (leftMarker)
296 {
297 return AlignLeft;
298 }
299 else if (rightMarker)
300 {
301 return AlignRight;
302 }
303 else
304 {
305 return AlignNone;
306 }
307}

References AlignCenter, AlignLeft, AlignNone, and AlignRight.

Referenced by Markdown::Private::writeTableBlock().

◆ skipOverFileAndLineCommands()

bool skipOverFileAndLineCommands ( std::string_view data,
size_t indent,
size_t & offset,
std::string & location )

Definition at line 2884 of file markdown.cpp.

2885{
2886 size_t i = offset;
2887 size_t size = data.size();
2888 while (i<data.size() && data[i]==' ') i++;
2889 if (i<size+8 && data[i]=='\\' && qstrncmp(&data[i+1],"ifile \"",7)==0)
2890 {
2891 size_t locStart = i;
2892 if (i>offset) locStart--; // include the space before \ifile
2893 i+=8;
2894 bool found=false;
2895 while (i+9<size && data[i]!='\n')
2896 {
2897 if (data[i]=='\\' && qstrncmp(&data[i+1],"ilinebr ",8)==0)
2898 {
2899 found=true;
2900 break;
2901 }
2902 i++;
2903 }
2904 if (found)
2905 {
2906 i+=9;
2907 location=data.substr(locStart,i-locStart);
2908 location+='\n';
2909 while (indent>0 && i<size && data[i]==' ') i++,indent--;
2910 if (i<size && data[i]=='\n') i++;
2911 offset = i;
2912 return true;
2913 }
2914 }
2915 return false;
2916}
bool found
Definition util.cpp:984

References found, and qstrncmp().

Referenced by Markdown::Private::writeCodeBlock().

Variable Documentation

◆ codeBlockIndent

const size_t codeBlockIndent = 4

◆ g_doxy_nbsp

const char* g_doxy_nbsp = "&_doxy_nbsp;"

Definition at line 200 of file markdown.cpp.

Referenced by Markdown::Private::addStrEscapeUtf8Nbsp(), and Markdown::process().

◆ g_quotationHeaderMap

const std::unordered_map<std::string,std::string> g_quotationHeaderMap
static
Initial value:
= {
{ "[!note]", "\\note" },
{ "[!warning]", "\\warning" },
{ "[!tip]", "\\remark" },
{ "[!caution]", "\\attention" },
{ "[!important]", "\\important" }
}

Definition at line 2757 of file markdown.cpp.

2757 {
2758 // GitHub style Doxygen command
2759 { "[!note]", "\\note" },
2760 { "[!warning]", "\\warning" },
2761 { "[!tip]", "\\remark" },
2762 { "[!caution]", "\\attention" },
2763 { "[!important]", "\\important" }
2764};

Referenced by Markdown::Private::writeBlockQuote().

◆ g_utf8_nbsp

const char* g_utf8_nbsp = "\xc2\xa0"

Definition at line 199 of file markdown.cpp.

Referenced by Markdown::Private::addStrEscapeUtf8Nbsp().