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]=='>'))

Definition at line 2169 of file markdown.cpp.

2169#define isLiTag(i) \
2170 (data[(i)]=='<' && \
2171 (data[(i)+1]=='l' || data[(i)+1]=='L') && \
2172 (data[(i)+2]=='i' || data[(i)+2]=='I') && \
2173 (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 2177 of file markdown.cpp.

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

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:163
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:172

References AUTO_TRACE, AUTO_TRACE_EXIT, QCString::data(), QCString::isEmpty(), 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!='\\')
252 {
253 if (Config_getBool(MARKDOWN_STRICT))
254 {
255 result+='\\';
256 }
257 else // For Doxygen's markup style a quoted text is left untouched
258 {
259 insideQuote=!insideQuote;
260 }
261 }
262 result+=c;
263 break;
264 case '<':
265 // fall through
266 case '>':
267 if (!insideQuote)
268 {
269 result+='\\';
270 result+=c;
271 if ((p[0]==':') && (p[1]==':'))
272 {
273 result+='\\';
274 result+=':';
275 p++;
276 }
277 }
278 else
279 {
280 result+=c;
281 }
282 break;
283 case '\\': if (!insideQuote) { result+='\\'; } result+='\\'; break;
284 case '@': if (!insideQuote) { result+='\\'; } result+='@'; break;
285 // commented out next line due to regression when using % to suppress a link
286 //case '%': if (!insideQuote) { result+='\\'; } result+='%'; break;
287 case '#': if (!insideQuote) { result+='\\'; } result+='#'; break;
288 case '$': if (!insideQuote) { result+='\\'; } result+='$'; break;
289 case '&': if (!insideQuote) { result+='\\'; } result+='&'; break;
290 default:
291 result+=c; break;
292 }
293 pc=c;
294 }
295 AUTO_TRACE_EXIT("result={}",result);
296 return result;
297}
#define Config_getBool(name)
Definition config.h:33

References AUTO_TRACE, AUTO_TRACE_EXIT, Config_getBool, QCString::data(), FALSE, QCString::isEmpty(), 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 2462 of file markdown.cpp.

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

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

parse the image attributes and return attributes for given format

Definition at line 323 of file markdown.cpp.

324{
325 AUTO_TRACE("fmt={} attrs={}",fmt,attrs);
326 StringVector attrList = split(attrs.str(),",");
327 for (const auto &attr_ : attrList)
328 {
329 QCString attr = QCString(attr_).stripWhiteSpace();
330 int i = attr.find(':');
331 if (i>0) // has format
332 {
333 QCString format = attr.left(i).stripWhiteSpace().lower();
334 if (format == fmt) // matching format
335 {
336 AUTO_TRACE_EXIT("result={}",attr.mid(i+1));
337 return attr.mid(i+1); // keep part after :
338 }
339 }
340 else // option that applies to all formats
341 {
342 AUTO_TRACE_EXIT("result={}",attr);
343 return attr;
344 }
345 }
346 return QCString();
347}
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:241
QCString lower() const
Definition qcstring.h:249
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:260
const std::string & str() const
Definition qcstring.h:552
QCString left(size_t len) const
Definition qcstring.h:229
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:7135

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

bool hasLineBreak ( std::string_view data)
static

Definition at line 2743 of file markdown.cpp.

2744{
2745 AUTO_TRACE("data='{}'",Trace::trunc(data));
2746 size_t i=0;
2747 size_t j=0;
2748 // search for end of line and also check if it is not a completely blank
2749 while (i<data.size() && data[i]!='\n')
2750 {
2751 if (data[i]!=' ' && data[i]!='\t') j++; // some non whitespace
2752 i++;
2753 }
2754 if (i>=data.size()) { return 0; } // empty line
2755 if (i<2) { return 0; } // not long enough
2756 bool res = (j>0 && data[i-1]==' ' && data[i-2]==' '); // non blank line with at two spaces at the end
2757 AUTO_TRACE_EXIT("result={}",res);
2758 return res;
2759}

References AUTO_TRACE, AUTO_TRACE_EXIT, 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 1906 of file markdown.cpp.

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

References AUTO_TRACE, AUTO_TRACE_EXIT, codeBlockIndent, 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 2369 of file markdown.cpp.

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

bool isEmptyLine ( std::string_view data)
static

Definition at line 2155 of file markdown.cpp.

2156{
2157 AUTO_TRACE("data='{}'",Trace::trunc(data));
2158 size_t i=0;
2159 while (i<data.size())
2160 {
2161 if (data[i]=='\n') { AUTO_TRACE_EXIT("true"); return true; }
2162 if (data[i]!=' ') { AUTO_TRACE_EXIT("false"); return false; }
2163 i++;
2164 }
2165 AUTO_TRACE_EXIT("true");
2166 return true;
2167}

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

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

◆ isEndOfList()

bool isEndOfList ( std::string_view data)
static

Definition at line 2257 of file markdown.cpp.

2258{
2259 AUTO_TRACE("data='{}'",Trace::trunc(data));
2260 int dots=0;
2261 size_t i=0;
2262 // end of list marker is an otherwise empty line with a dot.
2263 while (i<data.size())
2264 {
2265 if (data[i]=='.')
2266 {
2267 dots++;
2268 }
2269 else if (data[i]=='\n')
2270 {
2271 break;
2272 }
2273 else if (data[i]!=' ' && data[i]!='\t') // bail out if the line is not empty
2274 {
2275 AUTO_TRACE_EXIT("result=false");
2276 return false;
2277 }
2278 i++;
2279 }
2280 AUTO_TRACE_EXIT("result={}",dots==1);
2281 return dots==1;
2282}

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

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

◆ isExplicitPage()

ExplicitPageResult isExplicitPage ( const QCString & docs)
static

Definition at line 3514 of file markdown.cpp.

3515{
3516 AUTO_TRACE("docs={}",Trace::trunc(docs));
3517 size_t i=0;
3518 std::string_view data(docs.str());
3519 const size_t size = data.size();
3520 if (!data.empty())
3521 {
3522 while (i<size && (data[i]==' ' || data[i]=='\n'))
3523 {
3524 i++;
3525 }
3526 if (literal_at(data.substr(i),"<!--!")) // skip over <!--! marker
3527 {
3528 i+=5;
3529 while (i<size && (data[i]==' ' || data[i]=='\n')) // skip over spaces after the <!--! marker
3530 {
3531 i++;
3532 }
3533 }
3534 if (i+1<size &&
3535 (data[i]=='\\' || data[i]=='@') &&
3536 (literal_at(data.substr(i+1),"page ") || literal_at(data.substr(i+1),"mainpage"))
3537 )
3538 {
3539 if (literal_at(data.substr(i+1),"page "))
3540 {
3541 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitPage");
3543 }
3544 else
3545 {
3546 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitMainPage");
3548 }
3549 }
3550 else if (i+1<size && (data[i]=='\\' || data[i]=='@') && isOtherPage(data.substr(i+1)))
3551 {
3552 AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitOtherPage");
3554 }
3555 }
3556 AUTO_TRACE_EXIT("result=ExplicitPageResult::notExplicit");
3558}
static bool isOtherPage(std::string_view data)

References AUTO_TRACE, AUTO_TRACE_EXIT, explicitMainPage, explicitOtherPage, explicitPage, isOtherPage(), literal_at(), notExplicit, 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 2284 of file markdown.cpp.

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

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

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

◆ isHRuler()

bool isHRuler ( std::string_view data)
static

Definition at line 2024 of file markdown.cpp.

2025{
2026 AUTO_TRACE("data='{}'",Trace::trunc(data));
2027 size_t i=0;
2028 size_t size = data.size();
2029 if (size>0 && data[size-1]=='\n') size--; // ignore newline character
2030 while (i<size && data[i]==' ') i++;
2031 if (i>=size) { AUTO_TRACE_EXIT("result=false: empty line"); return false; } // empty line
2032 char c=data[i];
2033 if (c!='*' && c!='-' && c!='_')
2034 {
2035 AUTO_TRACE_EXIT("result=false: {} is not a hrule character",c);
2036 return false; // not a hrule character
2037 }
2038 int n=0;
2039 while (i<size)
2040 {
2041 if (data[i]==c)
2042 {
2043 n++; // count rule character
2044 }
2045 else if (data[i]!=' ')
2046 {
2047 AUTO_TRACE_EXIT("result=false: line contains non hruler characters");
2048 return false; // line contains non hruler characters
2049 }
2050 i++;
2051 }
2052 AUTO_TRACE_EXIT("result={}",n>=3);
2053 return n>=3; // at least 3 characters needed for a hruler
2054}

References AUTO_TRACE, AUTO_TRACE_EXIT, 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 1935 of file markdown.cpp.

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

size_t isListMarker ( std::string_view data)
static

Definition at line 2246 of file markdown.cpp.

2247{
2248 AUTO_TRACE("data='{}'",Trace::trunc(data));
2249 size_t normalIndent = 0;
2250 while (normalIndent<data.size() && data[normalIndent]==' ') normalIndent++;
2251 size_t listIndent = computeIndentExcludingListMarkers(data);
2252 size_t result = listIndent>normalIndent ? listIndent : 0;
2253 AUTO_TRACE_EXIT("result={}",result);
2254 return result;
2255}

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

◆ isOtherPage()

bool isOtherPage ( std::string_view data)
static

Definition at line 3501 of file markdown.cpp.

3502{
3503#define OPC(x) if (literal_at(data,#x " ") || literal_at(data,#x "\n")) return true
3504 OPC(dir); OPC(defgroup); OPC(addtogroup); OPC(weakgroup); OPC(ingroup);
3505 OPC(fn); OPC(property); OPC(typedef); OPC(var); OPC(def);
3506 OPC(enum); OPC(namespace); OPC(class); OPC(concept); OPC(module);
3507 OPC(protocol); OPC(category); OPC(union); OPC(struct); OPC(interface);
3508 OPC(idlexcept); OPC(file);
3509#undef OPC
3510
3511 return false;
3512}
#define OPC(x)

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

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

3665{
3666 AUTO_TRACE("fileName={}",fileName);
3667 QCString absFileName = FileInfo(fileName.str()).absFilePath();
3668 QCString baseFn = stripFromPath(absFileName);
3669 int i = baseFn.findRev('.');
3670 if (i!=-1) baseFn = baseFn.left(i);
3671 QCString baseName = escapeCharsInString(baseFn,false,false);
3672 //printf("markdownFileNameToId(%s)=md_%s\n",qPrint(fileName),qPrint(baseName));
3673 QCString res = "md_"+baseName;
3674 AUTO_TRACE_EXIT("result={}",res);
3675 return res;
3676}
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:96
QCString escapeCharsInString(const QCString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:3846
static QCString stripFromPath(const QCString &p, const StringVector &l)
Definition util.cpp:310

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

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

303{
304 if (leftMarker && rightMarker)
305 {
306 return AlignCenter;
307 }
308 else if (leftMarker)
309 {
310 return AlignLeft;
311 }
312 else if (rightMarker)
313 {
314 return AlignRight;
315 }
316 else
317 {
318 return AlignNone;
319 }
320}

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

2941{
2942 size_t i = offset;
2943 size_t size = data.size();
2944 while (i<data.size() && data[i]==' ') i++;
2945 if (literal_at(data.substr(i),"\\ifile \""))
2946 {
2947 size_t locStart = i;
2948 if (i>offset) locStart--; // include the space before \ifile
2949 i+=8;
2950 bool found=false;
2951 while (i+9<size && data[i]!='\n')
2952 {
2953 if (literal_at(data.substr(i),"\\ilinebr "))
2954 {
2955 found=true;
2956 break;
2957 }
2958 i++;
2959 }
2960 if (found)
2961 {
2962 i+=9;
2963 location=data.substr(locStart,i-locStart);
2964 location+='\n';
2965 while (indent>0 && i<size && data[i]==' ') i++,indent--;
2966 if (i<size && data[i]=='\n') i++;
2967 offset = i;
2968 return true;
2969 }
2970 }
2971 return false;
2972}

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

2813 {
2814 // GitHub style Doxygen command
2815 { "[!note]", "\\note" },
2816 { "[!warning]", "\\warning" },
2817 { "[!tip]", "\\remark" },
2818 { "[!caution]", "\\attention" },
2819 { "[!important]", "\\important" }
2820};

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