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)
#define OPC(x)

Enumerations

enum class  ExplicitPageResult { explicitPage , explicitMainPage , explicitOtherPage , 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 bool isOtherPage (std::string_view data)
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=='"' || 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=='_' || 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]=='>'))
const char * data
Definition htmlgen.cpp:158
size_t i
Definition htmlgen.cpp:161

Definition at line 2158 of file markdown.cpp.

2158#define isLiTag(i) \
2159 (data[(i)]=='<' && \
2160 (data[(i)+1]=='l' || data[(i)+1]=='L') && \
2161 (data[(i)+2]=='i' || data[(i)+2]=='I') && \
2162 (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().

◆ OPC

#define OPC ( x)
Value:
if (literal_at(data,#x " ") || literal_at(data,#x "\n")) return true
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

Referenced by isOtherPage().

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

explicitOtherPage 

docs start with a dir / defgroup / addtogroup 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 explicitOtherPage, /**< docs start with a dir / defgroup / addtogroup command */
71 notExplicit /**< docs doesn't start with either page or mainpage */
72};
@ 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
@ explicitOtherPage
docs start with a dir / defgroup / addtogroup command
Definition markdown.cpp:70

Function Documentation

◆ computeIndentExcludingListMarkers()

size_t computeIndentExcludingListMarkers ( std::string_view data)
static

Definition at line 2166 of file markdown.cpp.

2167{
2168 AUTO_TRACE("data='{}'",Trace::trunc(data));
2169 size_t i=0;
2170 const size_t size=data.size();
2171 size_t indent=0;
2172 bool isDigit=FALSE;
2173 bool isLi=FALSE;
2174 bool listMarkerSkipped=FALSE;
2175 while (i<size &&
2176 (data[i]==' ' || // space
2177 (!listMarkerSkipped && // first list marker
2178 (data[i]=='+' || data[i]=='-' || data[i]=='*' || // unordered list char
2179 (data[i]=='#' && i>0 && data[i-1]=='-') || // -# item
2180 (isDigit=(data[i]>='1' && data[i]<='9')) || // ordered list marker?
2181 (isLi=(size>=3 && i+3<size && isLiTag(i))) // <li> tag
2182 )
2183 )
2184 )
2185 )
2186 {
2187 if (isDigit) // skip over ordered list marker '10. '
2188 {
2189 size_t j=i+1;
2190 while (j<size && ((data[j]>='0' && data[j]<='9') || data[j]=='.'))
2191 {
2192 if (data[j]=='.') // should be end of the list marker
2193 {
2194 if (j+1<size && data[j+1]==' ') // valid list marker
2195 {
2196 listMarkerSkipped=TRUE;
2197 indent+=j+1-i;
2198 i=j+1;
2199 break;
2200 }
2201 else // not a list marker
2202 {
2203 break;
2204 }
2205 }
2206 j++;
2207 }
2208 }
2209 else if (isLi)
2210 {
2211 i+=3; // skip over <li>
2212 indent+=3;
2213 listMarkerSkipped=TRUE;
2214 }
2215 else if (data[i]=='-' && size>=2 && i+2<size && data[i+1]=='#' && data[i+2]==' ')
2216 { // case "-# "
2217 listMarkerSkipped=TRUE; // only a single list marker is accepted
2218 i++; // skip over #
2219 indent++;
2220 }
2221 else if (data[i]!=' ' && i+1<size && data[i+1]==' ')
2222 { // case "- " or "+ " or "* "
2223 listMarkerSkipped=TRUE; // only a single list marker is accepted
2224 }
2225 if (data[i]!=' ' && !listMarkerSkipped)
2226 { // end of indent
2227 break;
2228 }
2229 indent++,i++;
2230 }
2231 AUTO_TRACE_EXIT("result={}",indent);
2232 return indent;
2233}
size_t size
Definition htmlgen.cpp:156
#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, data, FALSE, i, isLiTag, size, TRUE, and Trace::trunc().

Referenced by isCodeBlock(), and isListMarker().

◆ escapeDoubleQuotes()

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
QCString s
Definition htmlgen.cpp:154

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

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

◆ escapeSpecialChars()

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, FALSE, s, and Trace::trunc().

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

◆ findTableColumns()

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

2452{
2453 AUTO_TRACE("data='{}'",Trace::trunc(data));
2454 const size_t size = data.size();
2455 size_t i=0,n=0;
2456 // find start character of the table line
2457 while (i<size && data[i]==' ') i++;
2458 if (i<size && data[i]=='|' && data[i]!='\n') i++,n++; // leading | does not count
2459 start = i;
2460
2461 // find end character of the table line
2462 size_t j = 0;
2463 while (i<size && (j = isNewline(data.substr(i)))==0) i++;
2464 size_t eol=i+j;
2465
2466 if (j>0 && i>0) i--; // move i to point before newline
2467 while (i>0 && data[i]==' ') i--;
2468 if (i>0 && data[i-1]!='\\' && data[i]=='|') i--,n++; // trailing or escaped | does not count
2469 end = i;
2470
2471 // count columns between start and end
2472 columns=0;
2473 if (end>start)
2474 {
2475 i=start;
2476 while (i<=end) // look for more column markers
2477 {
2478 if (data[i]=='|' && (i==0 || data[i-1]!='\\')) columns++;
2479 if (columns==1) columns++; // first | make a non-table into a two column table
2480 i++;
2481 }
2482 }
2483 if (n==2 && columns==0) // table row has | ... |
2484 {
2485 columns++;
2486 }
2487 AUTO_TRACE_EXIT("eol={} start={} end={} columns={}",eol,start,end,columns);
2488 return eol;
2489}
#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, data, end(), eol, i, isNewline(), size, and Trace::trunc().

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

◆ getFilteredImageAttributes()

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:7130

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

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

◆ hasLineBreak()

bool hasLineBreak ( std::string_view data)
static

Definition at line 2732 of file markdown.cpp.

2733{
2734 AUTO_TRACE("data='{}'",Trace::trunc(data));
2735 size_t i=0;
2736 size_t j=0;
2737 // search for end of line and also check if it is not a completely blank
2738 while (i<data.size() && data[i]!='\n')
2739 {
2740 if (data[i]!=' ' && data[i]!='\t') j++; // some non whitespace
2741 i++;
2742 }
2743 if (i>=data.size()) { return 0; } // empty line
2744 if (i<2) { return 0; } // not long enough
2745 bool res = (j>0 && data[i-1]==' ' && data[i-2]==' '); // non blank line with at two spaces at the end
2746 AUTO_TRACE_EXIT("result={}",res);
2747 return res;
2748}

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

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

◆ isBlockQuote()

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

returns true if this line starts a block quote

Definition at line 1895 of file markdown.cpp.

1896{
1897 AUTO_TRACE("data='{}' indent={}",Trace::trunc(data),indent);
1898 size_t i = 0;
1899 const size_t size = data.size();
1900 while (i<size && data[i]==' ') i++;
1901 if (i<indent+codeBlockIndent) // could be a quotation
1902 {
1903 // count >'s and skip spaces
1904 int level=0;
1905 while (i<size && (data[i]=='>' || data[i]==' '))
1906 {
1907 if (data[i]=='>') level++;
1908 i++;
1909 }
1910 // last characters should be a space or newline,
1911 // so a line starting with >= does not match, but only when level equals 1
1912 bool res = (level>0 && i<size && ((data[i-1]==' ') || data[i]=='\n')) || (level > 1);
1913 AUTO_TRACE_EXIT("result={}",res);
1914 return res;
1915 }
1916 else // too much indentation -> code block
1917 {
1918 AUTO_TRACE_EXIT("result=false: too much indentation");
1919 return false;
1920 }
1921}
const size_t codeBlockIndent
Definition markdown.cpp:201

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

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

◆ isCodeBlock()

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

Definition at line 2358 of file markdown.cpp.

2359{
2360 AUTO_TRACE("data='{}' offset={}",Trace::trunc(data),offset);
2361 //printf("<isCodeBlock(offset=%d,size=%d,indent=%d)\n",offset,size,indent);
2362 // determine the indent of this line
2363 size_t i=0;
2364 size_t indent0=0;
2365 const size_t size = data.size();
2366 while (i<size && data[i]==' ') indent0++,i++;
2367
2368 if (indent0<codeBlockIndent)
2369 {
2370 AUTO_TRACE_EXIT("result={}: line is not indented enough {}<4",false,indent0);
2371 return false;
2372 }
2373 if (indent0>=size || data[indent0]=='\n') // empty line does not start a code block
2374 {
2375 AUTO_TRACE_EXIT("result={}: only spaces at the end of a comment block",false);
2376 return false;
2377 }
2378
2379 i=offset;
2380 int nl=0;
2381 int nl_pos[3];
2382 int offset_i = static_cast<int>(offset);
2383 // search back 3 lines and remember the start of lines -1 and -2
2384 while (i>0 && nl<3) // i counts down from offset to 1
2385 {
2386 int j = static_cast<int>(i)-offset_i-1; // j counts from -1 to -offset
2387 // since j can be negative we need to rewrap data in a std::string_view
2388 size_t nl_size = isNewline(std::string_view(data.data()+j,data.size()-j));
2389 if (nl_size>0)
2390 {
2391 nl_pos[nl++]=j+static_cast<int>(nl_size);
2392 }
2393 i--;
2394 }
2395
2396 // if there are only 2 preceding lines, then line -2 starts at -offset
2397 if (i==0 && nl==2) nl_pos[nl++]=-offset_i;
2398
2399 if (nl==3) // we have at least 2 preceding lines
2400 {
2401 //printf(" positions: nl_pos=[%d,%d,%d] line[-2]='%s' line[-1]='%s'\n",
2402 // nl_pos[0],nl_pos[1],nl_pos[2],
2403 // qPrint(QCString(data+nl_pos[1]).left(nl_pos[0]-nl_pos[1]-1)),
2404 // qPrint(QCString(data+nl_pos[2]).left(nl_pos[1]-nl_pos[2]-1)));
2405
2406 // check that line -1 is empty
2407 // Note that the offset is negative so we need to rewrap the string view
2408 if (!isEmptyLine(std::string_view(data.data()+nl_pos[1],nl_pos[0]-nl_pos[1]-1)))
2409 {
2410 AUTO_TRACE_EXIT("result={}",FALSE);
2411 return FALSE;
2412 }
2413
2414 // determine the indent of line -2
2415 // Note that the offset is negative so we need to rewrap the string view
2416 indent=std::max(indent,computeIndentExcludingListMarkers(
2417 std::string_view(data.data()+nl_pos[2],nl_pos[1]-nl_pos[2])));
2418
2419 //printf(">isCodeBlock local_indent %d>=%d+%d=%d\n",
2420 // indent0,indent,codeBlockIndent,indent0>=indent+codeBlockIndent);
2421 // if the difference is >4 spaces -> code block
2422 bool res = indent0>=indent+codeBlockIndent;
2423 AUTO_TRACE_EXIT("result={}: code block if indent difference >4 spaces",res);
2424 return res;
2425 }
2426 else // not enough lines to determine the relative indent, use global indent
2427 {
2428 // check that line -1 is empty
2429 // Note that the offset is negative so we need to rewrap the string view
2430 if (nl==1 && !isEmptyLine(std::string_view(data.data()-offset,offset-1)))
2431 {
2432 AUTO_TRACE_EXIT("result=false");
2433 return FALSE;
2434 }
2435 //printf(">isCodeBlock global indent %d>=%d+4=%d nl=%d\n",
2436 // indent0,indent,indent0>=indent+4,nl);
2437 bool res = indent0>=indent+codeBlockIndent;
2438 AUTO_TRACE_EXIT("result={}: code block if indent difference >4 spaces",res);
2439 return res;
2440 }
2441}
static size_t computeIndentExcludingListMarkers(std::string_view data)
static bool isEmptyLine(std::string_view data)

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

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

◆ isEmptyLine()

bool isEmptyLine ( std::string_view data)
static

Definition at line 2144 of file markdown.cpp.

2145{
2146 AUTO_TRACE("data='{}'",Trace::trunc(data));
2147 size_t i=0;
2148 while (i<data.size())
2149 {
2150 if (data[i]=='\n') { AUTO_TRACE_EXIT("true"); return true; }
2151 if (data[i]!=' ') { AUTO_TRACE_EXIT("false"); return false; }
2152 i++;
2153 }
2154 AUTO_TRACE_EXIT("true");
2155 return true;
2156}

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

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

◆ isEndOfList()

bool isEndOfList ( std::string_view data)
static

Definition at line 2246 of file markdown.cpp.

2247{
2248 AUTO_TRACE("data='{}'",Trace::trunc(data));
2249 int dots=0;
2250 size_t i=0;
2251 // end of list marker is an otherwise empty line with a dot.
2252 while (i<data.size())
2253 {
2254 if (data[i]=='.')
2255 {
2256 dots++;
2257 }
2258 else if (data[i]=='\n')
2259 {
2260 break;
2261 }
2262 else if (data[i]!=' ' && data[i]!='\t') // bail out if the line is not empty
2263 {
2264 AUTO_TRACE_EXIT("result=false");
2265 return false;
2266 }
2267 i++;
2268 }
2269 AUTO_TRACE_EXIT("result={}",dots==1);
2270 return dots==1;
2271}

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

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

◆ isExplicitPage()

ExplicitPageResult isExplicitPage ( const QCString & docs)
static

Definition at line 3503 of file markdown.cpp.

3504{
3505 AUTO_TRACE("docs={}",Trace::trunc(docs));
3506 size_t i=0;
3507 std::string_view data(docs.str());
3508 const size_t size = data.size();
3509 if (!data.empty())
3510 {
3511 while (i<size && (data[i]==' ' || data[i]=='\n'))
3512 {
3513 i++;
3514 }
3515 if (literal_at(data.substr(i),"<!--!")) // skip over <!--! marker
3516 {
3517 i+=5;
3518 while (i<size && (data[i]==' ' || data[i]=='\n')) // skip over spaces after the <!--! marker
3519 {
3520 i++;
3521 }
3522 }
3523 if (i+1<size &&
3524 (data[i]=='\\' || data[i]=='@') &&
3525 (literal_at(data.substr(i+1),"page ") || literal_at(data.substr(i+1),"mainpage"))
3526 )
3527 {
3528 if (literal_at(data.substr(i+1),"page "))
3529 {
3530 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitPage");
3532 }
3533 else
3534 {
3535 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitMainPage");
3537 }
3538 }
3539 else if (i+1<size && (data[i]=='\\' || data[i]=='@') && isOtherPage(data.substr(i+1)))
3540 {
3541 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitOtherPage");
3543 }
3544 }
3545 AUTO_TRACE_EXIT("result=ExplicitPageResult::notExplicit");
3547}
static bool isOtherPage(std::string_view data)

References AUTO_TRACE, AUTO_TRACE_EXIT, data, explicitMainPage, explicitOtherPage, explicitPage, i, isOtherPage(), literal_at(), notExplicit, size, QCString::str(), and Trace::trunc().

Referenced by MarkdownOutlineParser::parseInput().

◆ isFencedCodeBlock()

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

2275{
2276 AUTO_TRACE("data='{}' refIndent={}",Trace::trunc(data),refIndent);
2277 const char dot = '.';
2278 auto isAlphaChar = [ ](char c) { return (c>='A' && c<='Z') || (c>='a' && c<='z'); };
2279 auto isAlphaNChar = [ ](char c) { return (c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || (c=='+'); };
2280 auto isLangChar = [&](char c) { return c==dot || isAlphaChar(c); };
2281 // rules: at least 3 ~~~, end of the block same amount of ~~~'s, otherwise
2282 // return FALSE
2283 size_t i=0;
2284 size_t indent=0;
2285 int startTildes=0;
2286 const size_t size = data.size();
2287 while (i<size && data[i]==' ') indent++,i++;
2288 if (indent>=refIndent+4)
2289 {
2290 AUTO_TRACE_EXIT("result=false: content is part of code block indent={} refIndent={}",indent,refIndent);
2291 return FALSE;
2292 } // part of code block
2293 char tildaChar='~';
2294 if (i<size && data[i]=='`') tildaChar='`';
2295 while (i<size && data[i]==tildaChar) startTildes++,i++;
2296 if (startTildes<3)
2297 {
2298 AUTO_TRACE_EXIT("result=false: no fence marker found #tildes={}",startTildes);
2299 return FALSE;
2300 } // not enough tildes
2301 if (i<size && data[i]=='{') // extract .py from ```{.py} ... ```
2302 {
2303 i++; // skip over {
2304 if (data[i] == dot) i++; // skip over initial dot
2305 size_t startLang=i;
2306 while (i<size && (data[i]!='\n' && data[i]!='}')) i++; // find matching }
2307 if (i<size && data[i]=='}')
2308 {
2309 lang = data.substr(startLang,i-startLang);
2310 i++;
2311 }
2312 else // missing closing bracket, treat `{` as part of the content
2313 {
2314 i=startLang-1;
2315 lang="";
2316 }
2317 }
2318 else if (i<size && isLangChar(data[i])) /// extract python or .py from ```python...``` or ```.py...```
2319 {
2320 if (data[i] == dot) i++; // skip over initial dot
2321 size_t startLang=i;
2322 if (i<size && isAlphaChar(data[i])) //check first character of language specifier
2323 {
2324 i++;
2325 while (i<size && isAlphaNChar(data[i])) i++; // find end of language specifier
2326 }
2327 lang = data.substr(startLang,i-startLang);
2328 }
2329 else // no language specified
2330 {
2331 lang="";
2332 }
2333
2334 start=i;
2335 while (i<size)
2336 {
2337 if (data[i]==tildaChar)
2338 {
2339 end=i;
2340 int endTildes=0;
2341 while (i<size && data[i]==tildaChar) endTildes++,i++;
2342 while (i<size && data[i]==' ') i++;
2343 {
2344 if (endTildes==startTildes)
2345 {
2346 offset=i;
2347 AUTO_TRACE_EXIT("result=true: found end marker at offset {} lang='{}'",offset,lang);
2348 return true;
2349 }
2350 }
2351 }
2352 i++;
2353 }
2354 AUTO_TRACE_EXIT("result=false: no end marker found lang={}'",lang);
2355 return false;
2356}

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

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

◆ isHRuler()

bool isHRuler ( std::string_view data)
static

Definition at line 2013 of file markdown.cpp.

2014{
2015 AUTO_TRACE("data='{}'",Trace::trunc(data));
2016 size_t i=0;
2017 size_t size = data.size();
2018 if (size>0 && data[size-1]=='\n') size--; // ignore newline character
2019 while (i<size && data[i]==' ') i++;
2020 if (i>=size) { AUTO_TRACE_EXIT("result=false: empty line"); return false; } // empty line
2021 char c=data[i];
2022 if (c!='*' && c!='-' && c!='_')
2023 {
2024 AUTO_TRACE_EXIT("result=false: {} is not a hrule character",c);
2025 return false; // not a hrule character
2026 }
2027 int n=0;
2028 while (i<size)
2029 {
2030 if (data[i]==c)
2031 {
2032 n++; // count rule character
2033 }
2034 else if (data[i]!=' ')
2035 {
2036 AUTO_TRACE_EXIT("result=false: line contains non hruler characters");
2037 return false; // line contains non hruler characters
2038 }
2039 i++;
2040 }
2041 AUTO_TRACE_EXIT("result={}",n>=3);
2042 return n>=3; // at least 3 characters needed for a hruler
2043}

References AUTO_TRACE, AUTO_TRACE_EXIT, data, i, size, and Trace::trunc().

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

◆ isLinkRef()

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

1925{
1926 AUTO_TRACE("data='{}'",Trace::trunc(data));
1927 const size_t size = data.size();
1928 // format: start with [some text]:
1929 size_t i = 0;
1930 while (i<size && data[i]==' ') i++;
1931 if (i>=size || data[i]!='[') { return 0; }
1932 i++;
1933 size_t refIdStart=i;
1934 while (i<size && data[i]!='\n' && data[i]!=']') i++;
1935 if (i>=size || data[i]!=']') { return 0; }
1936 refid = data.substr(refIdStart,i-refIdStart);
1937 if (refid.isEmpty()) { return 0; }
1938 AUTO_TRACE_ADD("refid found {}",refid);
1939 //printf(" isLinkRef: found refid='%s'\n",qPrint(refid));
1940 i++;
1941 if (i>=size || data[i]!=':') { return 0; }
1942 i++;
1943
1944 // format: whitespace* \n? whitespace* (<url> | url)
1945 while (i<size && data[i]==' ') i++;
1946 if (i<size && data[i]=='\n')
1947 {
1948 i++;
1949 while (i<size && data[i]==' ') i++;
1950 }
1951 if (i>=size) { return 0; }
1952
1953 if (i<size && data[i]=='<') i++;
1954 size_t linkStart=i;
1955 while (i<size && data[i]!=' ' && data[i]!='\n') i++;
1956 size_t linkEnd=i;
1957 if (i<size && data[i]=='>') i++;
1958 if (linkStart==linkEnd) { return 0; } // empty link
1959 link = data.substr(linkStart,linkEnd-linkStart);
1960 AUTO_TRACE_ADD("link found {}",Trace::trunc(link));
1961 if (link=="@ref" || link=="\\ref")
1962 {
1963 size_t argStart=i;
1964 while (i<size && data[i]!='\n' && data[i]!='"') i++;
1965 link+=data.substr(argStart,i-argStart);
1966 }
1967
1968 title.clear();
1969
1970 // format: (whitespace* \n? whitespace* ( 'title' | "title" | (title) ))?
1971 size_t eol=0;
1972 while (i<size && data[i]==' ') i++;
1973 if (i<size && data[i]=='\n')
1974 {
1975 eol=i;
1976 i++;
1977 while (i<size && data[i]==' ') i++;
1978 }
1979 if (i>=size)
1980 {
1981 AUTO_TRACE_EXIT("result={}: end of isLinkRef while looking for title",i);
1982 return i; // end of buffer while looking for the optional title
1983 }
1984
1985 char c = data[i];
1986 if (c=='\'' || c=='"' || c=='(') // optional title present?
1987 {
1988 //printf(" start of title found! char='%c'\n",c);
1989 i++;
1990 if (c=='(') c=')'; // replace c by end character
1991 size_t titleStart=i;
1992 // search for end of the line
1993 while (i<size && data[i]!='\n') i++;
1994 eol = i;
1995
1996 // search back to matching character
1997 size_t end=i-1;
1998 while (end>titleStart && data[end]!=c) end--;
1999 if (end>titleStart)
2000 {
2001 title = data.substr(titleStart,end-titleStart);
2002 }
2003 AUTO_TRACE_ADD("title found {}",Trace::trunc(title));
2004 }
2005 while (i<size && data[i]==' ') i++;
2006 //printf("end of isLinkRef: i=%d size=%d data[i]='%c' eol=%d\n",
2007 // i,size,data[i],eol);
2008 if (i>=size) { AUTO_TRACE_EXIT("result={}",i); return i; } // end of buffer while ref id was found
2009 else if (eol>0) { AUTO_TRACE_EXIT("result={}",eol); return eol; } // end of line while ref id was found
2010 return 0; // invalid link ref
2011}
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
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(), data, end(), eol, i, QCString::isEmpty(), size, and Trace::trunc().

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

◆ isListMarker()

size_t isListMarker ( std::string_view data)
static

Definition at line 2235 of file markdown.cpp.

2236{
2237 AUTO_TRACE("data='{}'",Trace::trunc(data));
2238 size_t normalIndent = 0;
2239 while (normalIndent<data.size() && data[normalIndent]==' ') normalIndent++;
2240 size_t listIndent = computeIndentExcludingListMarkers(data);
2241 size_t result = listIndent>normalIndent ? listIndent : 0;
2242 AUTO_TRACE_EXIT("result={}",result);
2243 return result;
2244}

References AUTO_TRACE, AUTO_TRACE_EXIT, computeIndentExcludingListMarkers(), data, 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 data, and literal_at().

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

◆ isOtherPage()

bool isOtherPage ( std::string_view data)
static

Definition at line 3490 of file markdown.cpp.

3491{
3492#define OPC(x) if (literal_at(data,#x " ") || literal_at(data,#x "\n")) return true
3493 OPC(dir); OPC(defgroup); OPC(addtogroup); OPC(weakgroup); OPC(ingroup);
3494 OPC(fn); OPC(property); OPC(typedef); OPC(var); OPC(def);
3495 OPC(enum); OPC(namespace); OPC(class); OPC(concept); OPC(module);
3496 OPC(protocol); OPC(category); OPC(union); OPC(struct); OPC(interface);
3497 OPC(idlexcept); OPC(file);
3498#undef OPC
3499
3500 return false;
3501}
#define OPC(x)

References data, and OPC.

Referenced by isExplicitPage().

◆ isTableBlock()

bool isTableBlock ( std::string_view data)
static

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

Definition at line 2492 of file markdown.cpp.

2493{
2494 AUTO_TRACE("data='{}'",Trace::trunc(data));
2495 size_t cc0=0, start=0, end=0;
2496
2497 // the first line should have at least two columns separated by '|'
2498 size_t i = findTableColumns(data,start,end,cc0);
2499 if (i>=data.size() || cc0<1)
2500 {
2501 AUTO_TRACE_EXIT("result=false: no |'s in the header");
2502 return FALSE;
2503 }
2504
2505 size_t cc1 = 0;
2506 size_t ret = findTableColumns(data.substr(i),start,end,cc1);
2507 size_t j=i+start;
2508 // separator line should consist of |, - and : and spaces only
2509 while (j<=end+i)
2510 {
2511 if (data[j]!=':' && data[j]!='-' && data[j]!='|' && data[j]!=' ')
2512 {
2513 AUTO_TRACE_EXIT("result=false: invalid character '{}'",data[j]);
2514 return FALSE; // invalid characters in table separator
2515 }
2516 j++;
2517 }
2518 if (cc1!=cc0) // number of columns should be same as previous line
2519 {
2520 AUTO_TRACE_EXIT("result=false: different number of columns as previous line {}!={}",cc1,cc0);
2521 return FALSE;
2522 }
2523
2524 i+=ret; // goto next line
2525 size_t cc2 = 0;
2526 findTableColumns(data.substr(i),start,end,cc2);
2527
2528 AUTO_TRACE_EXIT("result={}",cc1==cc2);
2529 return cc1==cc2;
2530}
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, data, end(), FALSE, findTableColumns(), i, 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 3653 of file markdown.cpp.

3654{
3655 AUTO_TRACE("fileName={}",fileName);
3656 std::string absFileName = FileInfo(fileName.str()).absFilePath();
3657 QCString baseFn = stripFromPath(absFileName.c_str());
3658 int i = baseFn.findRev('.');
3659 if (i!=-1) baseFn = baseFn.left(i);
3660 QCString baseName = escapeCharsInString(baseFn,false,false);
3661 //printf("markdownFileNameToId(%s)=md_%s\n",qPrint(fileName),qPrint(baseName));
3662 QCString res = "md_"+baseName;
3663 AUTO_TRACE_EXIT("result={}",res);
3664 return res;
3665}
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:3844
static QCString stripFromPath(const QCString &p, const StringVector &l)
Definition util.cpp:310

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

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

◆ markersToAlignment()

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

2930{
2931 size_t i = offset;
2932 size_t size = data.size();
2933 while (i<data.size() && data[i]==' ') i++;
2934 if (literal_at(data.substr(i),"\\ifile \""))
2935 {
2936 size_t locStart = i;
2937 if (i>offset) locStart--; // include the space before \ifile
2938 i+=8;
2939 bool found=false;
2940 while (i+9<size && data[i]!='\n')
2941 {
2942 if (literal_at(data.substr(i),"\\ilinebr "))
2943 {
2944 found=true;
2945 break;
2946 }
2947 i++;
2948 }
2949 if (found)
2950 {
2951 i+=9;
2952 location=data.substr(locStart,i-locStart);
2953 location+='\n';
2954 while (indent>0 && i<size && data[i]==' ') i++,indent--;
2955 if (i<size && data[i]=='\n') i++;
2956 offset = i;
2957 return true;
2958 }
2959 }
2960 return false;
2961}

References data, i, literal_at(), and size.

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

2802 {
2803 // GitHub style Doxygen command
2804 { "[!note]", "\\note" },
2805 { "[!warning]", "\\warning" },
2806 { "[!tip]", "\\remark" },
2807 { "[!caution]", "\\attention" },
2808 { "[!important]", "\\important" }
2809};

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