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

2117#define isLiTag(i) \
2118 (data[(i)]=='<' && \
2119 (data[(i)+1]=='l' || data[(i)+1]=='L') && \
2120 (data[(i)+2]=='i' || data[(i)+2]=='I') && \
2121 (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 2125 of file markdown.cpp.

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

221{
222 AUTO_TRACE("s={}",Trace::trunc(s));
223 if (s.isEmpty()) return s;
224 QCString result;
225 const char *p=s.data();
226 char c=0, pc='\0';
227 while ((c=*p++))
228 {
229 if (c=='"' && pc!='\\') result+='\\';
230 result+=c;
231 pc=c;
232 }
233 AUTO_TRACE_EXIT("result={}",result);
234 return result;
235}
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 238 of file markdown.cpp.

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

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

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

314{
315 AUTO_TRACE("fmt={} attrs={}",fmt,attrs);
316 StringVector attrList = split(attrs.str(),",");
317 for (const auto &attr_ : attrList)
318 {
319 QCString attr = QCString(attr_).stripWhiteSpace();
320 int i = attr.find(':');
321 if (i>0) // has format
322 {
323 QCString format = attr.left(i).stripWhiteSpace().lower();
324 if (format == fmt) // matching format
325 {
326 AUTO_TRACE_EXIT("result={}",attr.mid(i+1));
327 return attr.mid(i+1); // keep part after :
328 }
329 }
330 else // option that applies to all formats
331 {
332 AUTO_TRACE_EXIT("result={}",attr);
333 return attr;
334 }
335 }
336 return QCString();
337}
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:7105

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

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

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

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

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

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

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

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

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

3451{
3452 AUTO_TRACE("docs={}",Trace::trunc(docs));
3453 size_t i=0;
3454 std::string_view data(docs.str());
3455 const size_t size = data.size();
3456 if (!data.empty())
3457 {
3458 while (i<size && (data[i]==' ' || data[i]=='\n'))
3459 {
3460 i++;
3461 }
3462 if (literal_at(data.substr(i),"<!--!")) // skip over <!--! marker
3463 {
3464 i+=5;
3465 while (i<size && (data[i]==' ' || data[i]=='\n')) // skip over spaces after the <!--! marker
3466 {
3467 i++;
3468 }
3469 }
3470 if (i+1<size &&
3471 (data[i]=='\\' || data[i]=='@') &&
3472 (literal_at(data.substr(i+1),"page ") || literal_at(data.substr(i+1),"mainpage"))
3473 )
3474 {
3475 if (literal_at(data.substr(i+1),"page "))
3476 {
3477 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitPage");
3479 }
3480 else
3481 {
3482 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitMainPage");
3484 }
3485 }
3486 else if (i+1<size &&
3487 (data[i]=='\\' || data[i]=='@') &&
3488 (literal_at(data.substr(i+1),"dir\n") || literal_at(data.substr(i+1),"dir "))
3489 )
3490 {
3491 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitDirPage");
3493 }
3494 }
3495 AUTO_TRACE_EXIT("result=ExplicitPageResult::notExplicit");
3497}
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, explicitDirPage, explicitMainPage, explicitPage, literal_at(), notExplicit, 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 2232 of file markdown.cpp.

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

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

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

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

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

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

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 (literal_at(data,"\\ilinebr"))
213 {
214 return (data.size()>8 && data[8]==' ') ? 9 : 8; // also count space after \ilinebr if present
215 }
216 return 0;
217}

References literal_at().

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

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

3604{
3605 AUTO_TRACE("fileName={}",fileName);
3606 std::string absFileName = FileInfo(fileName.str()).absFilePath();
3607 QCString baseFn = stripFromPath(absFileName.c_str());
3608 int i = baseFn.findRev('.');
3609 if (i!=-1) baseFn = baseFn.left(i);
3610 QCString baseName = escapeCharsInString(baseFn,false,false);
3611 //printf("markdownFileNameToId(%s)=md_%s\n",qPrint(fileName),qPrint(baseName));
3612 QCString res = "md_"+baseName;
3613 AUTO_TRACE_EXIT("result={}",res);
3614 return res;
3615}
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:3830
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 292 of file markdown.cpp.

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

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

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

References found, and literal_at().

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

2761 {
2762 // GitHub style Doxygen command
2763 { "[!note]", "\\note" },
2764 { "[!warning]", "\\warning" },
2765 { "[!tip]", "\\remark" },
2766 { "[!caution]", "\\attention" },
2767 { "[!important]", "\\important" }
2768};

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().