41#include <unordered_map>
64#if !ENABLE_MARKDOWN_TRACING
68#define AUTO_TRACE(...) (void)0
69#define AUTO_TRACE_ADD(...) (void)0
70#define AUTO_TRACE_EXIT(...) (void)0
86 return (c>=
'a' && c<=
'z') ||
89 (
static_cast<unsigned char>(c)>=0x80);
95 return c==
'-' || c==
'+' || c==
'!' || c==
'?' || c==
'$' || c==
'@' ||
96 c==
'&' || c==
'*' || c==
'_' || c==
'%' || c==
'[' || c==
'(' ||
97 c==
'.' || c==
'>' || c==
':' || c==
',' || c==
';' || c==
'\'' ||
98 c==
'"' || c==
'`' || c==
'\\';
104 return c==
'\n' || c==
' ' || c==
'\'' || c==
'<' ||
105 c==
'>' || c==
'{' || c==
'(' || c==
'[' ||
106 c==
',' || c==
':' || c==
';';
112 return c1==
static_cast<char>(0xc2) && c2==
static_cast<char>(0xa0);
118 (offset>1 && !
isUtf8Nbsp(data.data()[-2],data.data()[-1])));
125 return c==
'(' || c==
'{' || c==
'[' || (c==
'<' && cn!=
'/') || c==
'\\' || c==
'@';
156 int processLink(std::string_view data,
size_t offset);
164 int isHeaderline(std::string_view data,
bool allowAdjustLevel);
166 bool *pIsIdGenerated=
nullptr);
169 size_t blockStart,
size_t blockEnd);
198 a[
static_cast<unsigned int>(
'[')] = [](
Markdown::Private &obj,std::string_view data,
size_t offset) {
return obj.
processLink (data,offset); };
199 a[
static_cast<unsigned int>(
'!')] = [](
Markdown::Private &obj,std::string_view data,
size_t offset) {
return obj.
processLink (data,offset); };
209 :
prv(
std::make_unique<
Private>(fileName,lineNr,indentLevel))
211 using namespace std::placeholders;
235 if (data[0] ==
'\n')
return 1;
239 return (data.size()>8 && data[8]==
' ') ? 9 : 8;
248 if (s.
empty())
return s;
250 const char *p=s.
data();
254 if (c==
'"' && pc!=
'\\') result+=
'\\';
266 if (s.
empty())
return s;
267 bool insideQuote=
false;
269 const char *p=s.
data();
284 insideQuote=!insideQuote;
296 if ((p[0]==
':') && (p[1]==
':'))
308 case '\\':
if (!insideQuote) { result+=
'\\'; } result+=
'\\';
break;
309 case '@':
if (!insideQuote) { result+=
'\\'; } result+=
'@';
break;
312 case '#':
if (!insideQuote) { result+=
'\\'; } result+=
'#';
break;
313 case '$':
if (!insideQuote) { result+=
'\\'; } result+=
'$';
break;
314 case '&':
if (!insideQuote) { result+=
'\\'; } result+=
'&';
break;
329 if (leftMarker && rightMarker)
337 else if (rightMarker)
352 for (
const auto &attr_ : attrList)
361 return attr.
mid(i+1);
400 using EndBlockFunc =
DString (*)(
const std::string &,bool,char);
402 static constexpr auto getEndBlock = [](
const std::string &blockName,bool,char) ->
DString
404 return "end"+blockName;
406 static constexpr auto getEndCode = [](
const std::string &blockName,
bool openBracket,char) ->
DString
408 return openBracket ?
DString(
"}") :
"end"+blockName;
410 static constexpr auto getEndUml = [](
const std::string &,bool,char) ->
DString
414 static constexpr auto getEndFormula = [](
const std::string &,bool,
char nextChar) ->
DString
418 case '$':
return "f$";
419 case '(':
return "f)";
420 case '[':
return "f]";
421 case '{':
return "f}";
427 static const std::unordered_map<std::string,EndBlockFunc> blockNames =
429 {
"dot", getEndBlock },
430 {
"code", getEndCode },
431 {
"icode", getEndBlock },
432 {
"msc", getEndBlock },
433 {
"verbatim", getEndBlock },
434 {
"iverbatim", getEndBlock },
435 {
"iliteral", getEndBlock },
436 {
"latexonly", getEndBlock },
437 {
"htmlonly", getEndBlock },
438 {
"xmlonly", getEndBlock },
439 {
"rtfonly", getEndBlock },
440 {
"manonly", getEndBlock },
441 {
"docbookonly", getEndBlock },
442 {
"startuml", getEndUml },
443 {
"mermaid", getEndBlock },
444 {
"f", getEndFormula }
447 const size_t size = data.
size();
448 bool openBracket = offset>0 && data.data()[-1]==
'{';
449 bool isEscaped = offset>0 && (data.data()[-1]==
'\\' || data.data()[-1]==
'@');
450 if (isEscaped)
return result;
453 while (
end<size && (data[
end]>=
'a' && data[
end]<=
'z'))
end++;
454 if (
end==1)
return result;
455 std::string blockName(data.substr(1,
end-1));
456 auto it = blockNames.find(blockName);
457 if (it!=blockNames.end())
459 result = it->second(blockName, openBracket,
end<size ? data[
end] : 0);
469 using EndCmdFunc = size_t (*)(std::string_view,size_t);
471 static constexpr auto endOfLine = [](std::string_view data_,
size_t offset_) ->
size_t
476 while (offset_<data_.size() && ((c=data_[offset_])!=
'\n' || lc==
'\\'))
478 if (c==
'\\') lc=
'\\';
479 else if (c!=
' ') lc=0;
485 static constexpr auto endOfLabels = [](std::string_view data_,
size_t offset_,
bool multi_) ->
size_t
487 if (offset_<data_.size() && data_[offset_]==
' ')
495 while (offset_<data_.size() && data_[offset_]==
' ')
500 while (offset_<data_.size() && (c=data_[offset_])!=
' ' && c!=
',' && c!=
'\\' && c!=
'@' && c!=
'\n')
505 if (multi_ && offset_<data_.size() && (data_[offset_]==
',' || data_[offset_]==
' '))
507 size_t off = offset_;
508 while (off<data_.size() && data_[off]==
' ')
512 if (off<data_.size() && data_[off]==
',')
531 static constexpr auto endOfLabel = [](std::string_view data_,
size_t offset_) ->
size_t
533 return endOfLabels(data_,offset_,
false);
536 static constexpr auto endOfLabelOpt = [](std::string_view data_,
size_t offset_) ->
size_t
538 size_t index=offset_;
539 if (index<data_.size() && data_[index]==
' ')
542 while (index<data_.size() && data_[index]==
' ') index++;
544 if (index<data_.size() && data_[index]==
'{')
548 while (index<data_.size() && (c=data_[index])!=
'}' && c!=
'\\' && c!=
'@' && c!=
'\n') index++;
549 if (index==data_.size() || data_[index]!=
'}')
return 0;
552 return endOfLabel(data_,offset_);
555 static constexpr auto endOfParam = [](std::string_view data_,
size_t offset_) ->
size_t
557 size_t index=offset_;
558 if (index<data_.size() && data_[index]==
' ')
561 while (index<data_.size() && data_[index]==
' ') index++;
563 if (index<data_.size() && data_[index]==
'[')
567 while (index<data_.size() && (c=data_[index])!=
']' && c!=
'\n') index++;
568 if (index==data_.size() || data_[index]!=
']')
return 0;
571 return endOfLabels(data_,offset_,
true);
574 static constexpr auto endOfRetVal = [](std::string_view data_,
size_t offset_) ->
size_t
576 return endOfLabels(data_,offset_,
true);
579 static constexpr auto endOfFuncLike = [](std::string_view data_,
size_t offset_,
bool allowSpaces) ->
size_t
581 if (offset_<data_.size() && data_[offset_]==
' ')
586 while (offset_<data_.size() && data_[offset_]==
' ')
591 while (offset_<data_.size() && (c=data_[offset_])!=
'\n' && (allowSpaces || c!=
' ') && c!=
'(')
593 if (
literal_at(data_.substr(offset_),
"\\ilinebr "))
break;
600 while (offset_<data_.size() && (c=data_[offset_++]))
603 else if (c==
')') count--;
604 if (count==0)
return offset_;
612 static constexpr auto endOfFunc = [](std::string_view data_,
size_t offset_) ->
size_t
614 return endOfFuncLike(data_,offset_,
true);
617 static constexpr auto endOfGuard = [](std::string_view data_,
size_t offset_) ->
size_t
619 return endOfFuncLike(data_,offset_,
false);
622 static const std::unordered_map<std::string,EndCmdFunc> cmdNames =
625 {
"addindex", endOfLine },
626 {
"addtogroup", endOfLabel },
627 {
"anchor", endOfLabel },
630 {
"category", endOfLine },
631 {
"cite", endOfLabelOpt },
632 {
"class", endOfLine },
633 {
"concept", endOfLine },
634 {
"copybrief", endOfFunc },
635 {
"copydetails", endOfFunc },
636 {
"copydoc", endOfFunc },
637 {
"def", endOfFunc },
638 {
"defgroup", endOfLabel },
639 {
"diafile", endOfLine },
640 {
"dir", endOfLine },
641 {
"dockbookinclude",endOfLine },
642 {
"dontinclude", endOfLine },
643 {
"dotfile", endOfLine },
645 {
"elseif", endOfGuard },
646 {
"em", endOfLabel },
647 {
"emoji", endOfLabel },
648 {
"enum", endOfLabel },
649 {
"example", endOfLine },
650 {
"exception", endOfLabel },
651 {
"extends", endOfLabel },
652 {
"file", endOfLine },
654 {
"headerfile", endOfLine },
655 {
"htmlinclude", endOfLine },
656 {
"ianchor", endOfLabelOpt },
657 {
"idlexcept", endOfLine },
658 {
"if", endOfGuard },
659 {
"ifnot", endOfGuard },
660 {
"image", endOfLine },
661 {
"implements", endOfLine },
662 {
"include", endOfLine },
663 {
"includedoc", endOfLine },
664 {
"includelineno", endOfLine },
665 {
"ingroup", endOfLabel },
666 {
"interface", endOfLine },
667 {
"latexinclude", endOfLine },
668 {
"maninclude", endOfLine },
669 {
"field", endOfLabel },
670 {
"memberof", endOfLabel },
671 {
"mermaidfile", endOfLine },
672 {
"mscfile", endOfLine },
673 {
"namespace", endOfLabel },
674 {
"noop", endOfLine },
675 {
"overload", endOfLine },
677 {
"package", endOfLabel },
678 {
"page", endOfLabel },
679 {
"paragraph", endOfLabel },
680 {
"param", endOfParam },
681 {
"property", endOfLine },
682 {
"protocol", endOfLine },
683 {
"qualifier", endOfLine },
684 {
"record", endOfLine },
685 {
"ref", endOfLabel },
686 {
"refitem", endOfLine },
687 {
"related", endOfLabel },
688 {
"relatedalso", endOfLabel },
689 {
"relates", endOfLabel },
690 {
"relatesalso", endOfLabel },
691 {
"requirement", endOfLabel },
692 {
"retval", endOfRetVal},
693 {
"rtfinclude", endOfLine },
694 {
"section", endOfLabel },
695 {
"skip", endOfLine },
696 {
"skipline", endOfLine },
697 {
"snippet", endOfLine },
698 {
"snippetdoc", endOfLine },
699 {
"snippetlineno", endOfLine },
700 {
"struct", endOfLine },
701 {
"satisfies", endOfLabel },
702 {
"subpage", endOfLabel },
703 {
"subparagraph", endOfLabel },
704 {
"subsubparagraph",endOfLabel },
705 {
"subsection", endOfLabel },
706 {
"subsubsection", endOfLabel },
707 {
"throw", endOfLabel },
708 {
"throws", endOfLabel },
709 {
"tparam", endOfLabel },
710 {
"typedef", endOfLine },
711 {
"plantumlfile", endOfLine },
712 {
"union", endOfLine },
713 {
"until", endOfLine },
714 {
"var", endOfLine },
715 {
"verbinclude", endOfLine },
716 {
"verifies", endOfLabel },
717 {
"weakgroup", endOfLabel },
718 {
"xmlinclude", endOfLine },
719 {
"xrefitem", endOfLabel }
722 bool isEscaped = offset>0 && (data.data()[-1]==
'\\' || data.data()[-1]==
'@');
723 if (isEscaped)
return 0;
725 const size_t size = data.size();
727 while (
end<size && (data[
end]>=
'a' && data[
end]<=
'z'))
end++;
728 if (
end==1)
return 0;
729 std::string cmdName(data.substr(1,
end-1));
731 auto it = cmdNames.find(cmdName);
732 if (it!=cmdNames.end())
735 result = it->second(data,
end);
748 const size_t size = data.size();
752 while (i<size && data[i]!=c &&
753 data[i]!=
'\\' && data[i]!=
'@' &&
754 !(data[i]==
'/' && data[i-1]==
'<') &&
774 while (i+len<size && data[i+len]==c)
781 if (len!=c_size || (i+len<size &&
isIdChar(data[i+len])))
787 return static_cast<int>(i);
795 while (i < size && data[i] ==
'`')
803 while (i<size && enb<snb)
805 if (data[i]==
'`') enb++;
806 if (snb==1 && data[i]==
'\'')
break;
810 else if (data[i]==
'@' || data[i]==
'\\')
813 if (!endBlockName.
empty())
816 size_t l = endBlockName.
length();
819 if ((data[i]==
'\\' || data[i]==
'@') &&
820 data[i-1]!=
'\\' && data[i-1]!=
'@')
830 else if (i+1<size &&
isIdChar(data[i+1]))
839 else if (data[i-1]==
'<' && data[i]==
'/')
843 else if (data[i]==
'\n')
846 while (i<size && data[i]==
' ') i++;
847 if (i>=size || data[i]==
'\n')
865 const size_t size = data.size();
868 if (size>1 && data[0]==c && data[1]==c) { i=1; }
873 if (len==0) {
return 0; }
875 if (i>=size) {
return 0; }
877 if (i+1<size && data[i+1]==c)
882 if (data[i]==c && data[i-1]!=
' ' && data[i-1]!=
'\n')
888 return static_cast<int>(i+1);
899 const size_t size = data.size();
909 if (i+1<size && data[i]==c && data[i+1]==c && i && data[i-1]!=
' ' && data[i-1]!=
'\n')
911 if (c ==
'~')
out+=
"<strike>";
912 else out+=
"<strong>";
914 if (c ==
'~')
out+=
"</strike>";
915 else out+=
"</strong>";
917 return static_cast<int>(i+2);
931 const size_t size = data.size();
943 if (data[i]!=c || data[i-1]==
' ' || data[i-1]==
'\n')
948 if (i+2<size && data[i+1]==c && data[i+2]==c)
952 out+=
"</strong></em>";
954 return static_cast<int>(i+3);
956 else if (i+1<size && data[i+1]==c)
967 return static_cast<int>(len - 2);
981 return static_cast<int>(len - 1);
992 const size_t size = data.size();
996 if (i<size && data[i]==
'-')
1001 if (i<size && data[i]==
'-')
1006 if (i<size && data[i]==
'-')
1010 if (count>=2 && offset>=2 &&
literal_at(data.data()-2,
"<!"))
1012 if (count==2 && size > 2 && data[2]==
'>')
1014 if (count==3 && size > 3 && data[3]==
'>')
1016 if (count==2 && (offset<8 || !
literal_at(data.data()-8,
"operator")))
1036 const size_t size = data.size();
1039 while (i<size && data[i]!=
'"' && nl<2)
1041 if (data[i]==
'\n') nl++;
1044 if (i<size && data[i]==
'"' && nl<2)
1046 out+=data.substr(0,i+1);
1048 return static_cast<int>(i+1);
1060 if (offset>0 && data.data()[-1]==
'\\') {
return 0; }
1062 const size_t size = data.size();
1068 while (i < size &&
isIdChar(data[i]))
1073 DString tagName(data.substr(1,i-1));
1074 if (tagName.
lower()==
"pre")
1076 bool insideStr=
false;
1080 if (!insideStr && c==
'<')
1082 if (data[i+1]==
'/' &&
1083 tolower(data[i+2])==
'p' && tolower(data[i+3])==
'r' &&
1084 tolower(data[i+4])==
'e' && tolower(data[i+5])==
'>')
1086 if (doWrite)
out+=data.substr(0,i+6);
1089 return static_cast<int>(i+6);
1092 else if (insideStr && c==
'"')
1094 if (data[i-1]!=
'\\') insideStr=
false;
1107 if (data[i]==
'/' && i+1<size && data[i+1]==
'>')
1110 if (doWrite)
out+=data.substr(0,i+2);
1112 return static_cast<int>(i+2);
1114 else if (data[i]==
'>')
1117 if (doWrite)
out+=data.substr(0,i+1);
1119 return static_cast<int>(i+1);
1121 else if (data[i]==
' ')
1124 bool insideAttr=
false;
1127 if (!insideAttr && data[i]==
'"')
1131 else if (data[i]==
'"' && data[i-1]!=
'\\')
1135 else if (!insideAttr && data[i]==
'>')
1138 if (doWrite)
out+=data.substr(0,i+1);
1140 return static_cast<int>(i+1);
1160 const size_t size = data.size();
1172 if (size>2 && c!=
'~' && data[1]!=c)
1175 if (data[1]==
' ' || data[1]==
'\n' ||
1183 if (size>3 && data[1]==c && data[2]!=c)
1185 if (data[2]==
' ' || data[2]==
'\n' ||
1193 if (size>4 && c!=
'~' && data[1]==c && data[2]==c && data[3]!=c)
1195 if (data[3]==
' ' || data[3]==
'\n' ||
1207 std::string_view
fmt,
bool inline_img,
bool explicitTitle,
1212 AUTO_TRACE(
"fmt={} inline_img={} explicitTitle={} title={} content={} link={} attrs={}",
1223 out+=link.
mid(fd ? 0 : 5);
1224 if (!explicitTitle && !content.
empty())
1230 else if ((content.
empty() || explicitTitle) && !title.
empty())
1240 if (!attributes.
empty())
1252 const size_t size = data.size();
1257 bool isImageLink =
false;
1258 bool isImageInline =
false;
1264 if (size<2 || data[1]!=
'[')
1273 while (pos>=-
static_cast<int>(offset) && numNLsNeeded>0)
1275 if (data.data()[pos]==
'\n') numNLsNeeded--;
1276 else if (data.data()[pos]!=
' ')
1286 size_t contentStart=i;
1293 if (data[i-1]==
'\\')
1296 else if (data[i]==
'[')
1300 else if (data[i]==
']')
1303 if (level<=0)
break;
1305 else if (data[i]==
'\n')
1308 if (nl>1) {
return 0; }
1314 if (i>=size)
return 0;
1315 size_t contentEnd=i;
1316 content = data.
substr(contentStart,contentEnd-contentStart);
1318 if (!isImageLink && content.
empty()) {
return 0; }
1321 bool whiteSpace =
false;
1323 while (i<size && data[i]==
' ') { whiteSpace =
true; i++; }
1324 if (i<size && data[i]==
'\n')
1329 while (i<size && data[i]==
' ') i++;
1331 if (whiteSpace && i<size && (data[i]==
'(' || data[i]==
'['))
return 0;
1333 bool explicitTitle=
false;
1334 if (i<size && data[i]==
'(')
1337 while (i<size && data[i]==
' ') i++;
1338 bool uriFormat=
false;
1339 if (i<size && data[i]==
'<') { i++; uriFormat=
true; }
1343 while (i<size && data[i]!=
'\'' && data[i]!=
'"' && braceCount>0)
1349 if (nlConsec>1) {
return 0; }
1351 else if (data[i]==
'(')
1356 else if (data[i]==
')')
1361 else if (data[i]!=
' ')
1372 if (i>=size || data[i]==
'\n') {
return 0; }
1373 link = data.
substr(linkStart,i-linkStart);
1376 if (link.
empty()) {
return 0; }
1380 if (data[i]==
'\'' || data[i]==
'"')
1384 size_t titleStart=i;
1390 if (nl>1) {
return 0; }
1393 else if (data[i]==
'\\')
1397 else if (data[i]==c)
1408 size_t titleEnd = i-1;
1410 while (titleEnd>titleStart && data[titleEnd]==
' ') titleEnd--;
1411 if (data[titleEnd]==c)
1413 title = data.
substr(titleStart,titleEnd-titleStart);
1417 if (data[i]==
' ')i++;
1418 else if (data[i] ==
')')
break;
1432 else if (i<size && data[i]==
'[')
1438 while (i<size && data[i]!=
']')
1443 if (nl>1) {
return 0; }
1447 if (i>=size) {
return 0; }
1449 link = data.
substr(linkStart,i-linkStart);
1461 link = lr_it->second.link;
1462 title = lr_it->second.title;
1472 else if (i<size && data[i]!=
':' && !content.
empty())
1479 link = lr_it->second.link;
1480 title = lr_it->second.title;
1484 else if (content==
"TOC")
1507 while (j<size && data[j]==
' ') { j++; }
1508 if (j<size && data[j]==
'{')
1513 size_t attributesStart=i;
1518 if (data[i-1]==
'\\')
1521 else if (data[i]==
'{')
1525 else if (data[i]==
'}')
1528 if (level<=0)
break;
1530 else if (data[i]==
'\n')
1533 if (nl>1) {
return 0; }
1538 if (i>=size)
return 0;
1539 size_t attributesEnd=i;
1540 attributes = data.
substr(attributesStart,attributesEnd-attributesStart);
1549 while (pos<size && numNLsNeeded>0)
1551 if (data[pos]==
'\n') numNLsNeeded--;
1552 else if (data[pos]!=
' ')
1567 out+=
"@tableofcontents{html:";
1572 else if (isImageLink)
1581 writeMarkdownImage(
"html", isImageInline, explicitTitle, title, content, link, attributes, fd);
1582 writeMarkdownImage(
"latex", isImageInline, explicitTitle, title, content, link, attributes, fd);
1583 writeMarkdownImage(
"rtf", isImageInline, explicitTitle, title, content, link, attributes, fd);
1584 writeMarkdownImage(
"docbook", isImageInline, explicitTitle, title, content, link, attributes, fd);
1585 writeMarkdownImage(
"xml", isImageInline, explicitTitle, title, content, link, attributes, fd);
1609 (lang==SrcLangExt::Markdown && !
isURL(link)))
1641 if (explicitTitle && !title.
empty())
1670 for (
int ii = 0; ii < nlTotal; ii++)
out+=
"\n";
1683 bool foundNameRef =
false;
1684 if (!content.
empty() && (content.
at(0)==
'#' || content.
at(0)==
'@'))
1687 while (endOfId<content.
length() &&
isId(content.
at(endOfId))) endOfId++;
1694 foundNameRef =
true;
1713 return static_cast<int>(i);
1720 const size_t size = data.size();
1724 while (nb<size && data[nb]==
'`')
1741 if (
end+1<size && data[
end+1]==
'`')
1756 if (
end+1<size && data[
end+1]==
'`')
1769 else if (data[
end]==
'\n')
1780 else if (!markdownStrict && data[
end]==
'\'' && nb==1 && (
end+1==size || (
end+1<size && data[
end+1]!=
'\'' && !
isIdChar(data[
end+1]))))
1783 out+=data.substr(nb,
end-nb);
1786 return static_cast<int>(
end+1);
1788 else if (!markdownStrict && data[
end]==
'\'' && nb==2 &&
end+1<size && data[
end+1]==
'\'')
1791 out+=data.substr(nb,
end-nb);
1794 return static_cast<int>(
end+2);
1798 if (data[
end]!=
' ') pc = data[
end];
1802 if (i < nb && end >= size)
1807 out+=data.substr(0,nb);
1808 return static_cast<int>(nb);
1812 while (
end<size && data[
end]==
'`')
1828 return static_cast<int>(
end);
1847 const size_t size = data.size();
1850 if (!endBlockName.
empty())
1853 size_t l = endBlockName.
length();
1856 if ((data[i]==
'\\' || data[i]==
'@') &&
1857 data[i-1]!=
'\\' && data[i-1]!=
'@')
1864 return static_cast<int>(i+1+l);
1873 out+=data.substr(0,endPos);
1874 return static_cast<int>(endPos);
1876 if (size>1 && (data[0]==
'\\' || data[0]==
'@'))
1879 if (c==
'[' || c==
']' || c==
'*' || c==
'(' || c==
')' || c==
'`' || c==
'_')
1885 else if (c==
'\\' || c==
'@')
1887 out+=data.substr(0,2);
1891 else if (c==
'-' && size>3 && data[2]==
'-' && data[3]==
'-')
1893 out+=data.substr(1,3);
1897 else if (c==
'-' && size>2 && data[2]==
'-')
1899 out+=data.substr(1,2);
1913 const size_t size = data.size();
1919 out+=data.substr(i,
end-i);
1920 if (
end>=size)
break;
1923 int iend = action(*
this,data.substr(i),i);
1941 const size_t size = data.size();
1942 while (i<size && data[i]==
' ') i++;
1943 if (i==size)
return 0;
1948 while (i < size && data[i] ==
'=')
1953 while (i<size && data[i]==
' ') i++;
1954 int level = (c>1 && (i>=size || data[i]==
'\n')) ? 1 : 0;
1955 if (allowAdjustLevel && level==1 &&
indentLevel==-1)
1970 while (i < size && data[i] ==
'-')
1975 while (i<size && data[i]==
' ') i++;
1976 return (c>1 && (i>=size || data[i]==
'\n')) ?
indentLevel+2 : 0;
1986 const size_t size = data.size();
1987 while (i<size && data[i]==
' ') i++;
1992 while (i<size && (data[i]==
'>' || data[i]==
' '))
1994 if (data[i]==
'>') level++;
1999 bool res = (level>0 && i<size && ((data[i-1]==
' ') || data[i]==
'\n')) || (level > 1);
2014 const size_t size = data.size();
2017 while (i<size && data[i]==
' ') i++;
2018 if (i>=size || data[i]!=
'[') {
return 0; }
2020 size_t refIdStart=i;
2021 while (i<size && data[i]!=
'\n' && data[i]!=
']') i++;
2022 if (i>=size || data[i]!=
']') {
return 0; }
2023 refid = data.
substr(refIdStart,i-refIdStart);
2024 if (refid.
empty()) {
return 0; }
2028 if (i>=size || data[i]!=
':') {
return 0; }
2032 while (i<size && data[i]==
' ') i++;
2033 if (i<size && data[i]==
'\n')
2036 while (i<size && data[i]==
' ') i++;
2038 if (i>=size) {
return 0; }
2040 if (i<size && data[i]==
'<') i++;
2042 while (i<size && data[i]!=
' ' && data[i]!=
'\n') i++;
2044 if (i<size && data[i]==
'>') i++;
2045 if (linkStart==linkEnd) {
return 0; }
2046 link = data.
substr(linkStart,linkEnd-linkStart);
2048 if (link==
"@ref" || link==
"\\ref")
2051 while (i<size && data[i]!=
'\n' && data[i]!=
'"') i++;
2052 link+=data.
substr(argStart,i-argStart);
2059 while (i<size && data[i]==
' ') i++;
2060 if (i<size && data[i]==
'\n')
2064 while (i<size && data[i]==
' ') i++;
2068 AUTO_TRACE_EXIT(
"result={}: end of isLinkRef while looking for title",i);
2073 if (c==
'\'' || c==
'"' || c==
'(')
2078 size_t titleStart=i;
2080 while (i<size && data[i]!=
'\n') i++;
2085 while (
end>titleStart && data[
end]!=c)
end--;
2088 title = data.
substr(titleStart,
end-titleStart);
2092 while (i<size && data[i]==
' ') i++;
2104 size_t size = data.size();
2105 if (size>0 && data[size-1]==
'\n') size--;
2106 while (i<size && data[i]==
' ') i++;
2107 if (i>=size) {
AUTO_TRACE_EXIT(
"result=false: empty line");
return false; }
2109 if (c!=
'*' && c!=
'-' && c!=
'_')
2121 else if (data[i]!=
' ')
2136 static const reg::Ex r2(R
"({#(\a[\w-]*)}\s*$)");
2138 std::string ti = title.str();
2141 std::string
id = match[1].str();
2142 title = title.
left(match.position());
2145 warn(
fileName,
lineNr,
"An automatically generated id already has the name '{}'!",
id);
2151 if (((level>0) && (level<=
Config_getInt(TOC_INCLUDE_HEADINGS))) || (
Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB))
2154 if (pIsIdGenerated) *pIsIdGenerated=
true;
2165 DString &header,
DString &
id,
bool allowAdjustLevel,
bool *pIsIdGenerated)
2169 int level = 0, blanks=0;
2170 const size_t size = data.size();
2173 while (i<size && data[i]==
' ') i++;
2174 if (i>=size || data[i]!=
'#')
2178 while (i < size && data[i] ==
'#')
2187 while (i < size && data[i] ==
' ')
2192 if (level==1 && blanks==0)
2199 while (
end<size && data[
end]!=
'\n')
end++;
2200 while (
end>i && (data[
end-1]==
'#' || data[
end-1]==
' '))
end--;
2207 int idx=
static_cast<int>(header.
length())-1;
2208 while (idx>=0 && (header.
at(idx)==
'#' || header.
at(idx)==
' ')) idx--;
2209 header=header.
left(idx+1);
2212 if (allowAdjustLevel && level==1 &&
indentLevel==-1)
2243 while (i<data.size())
2254 (data[(i)]=='<' && \
2255 (data[(i)+1]=='l' || data[(i)+1]=='L') && \
2256 (data[(i)+2]=='i' || data[(i)+2]=='I') && \
2265 const size_t size=data.size();
2269 bool listMarkerSkipped=
false;
2272 (!listMarkerSkipped &&
2273 (data[i]==
'+' || data[i]==
'-' || data[i]==
'*' ||
2274 (data[i]==
'#' && i>0 && data[i-1]==
'-') ||
2275 (isDigit=(data[i]>=
'1' && data[i]<=
'9')) ||
2276 (isLi=(size>=3 && i+3<size &&
isLiTag(i)))
2285 while (j<size && ((data[j]>=
'0' && data[j]<=
'9') || data[j]==
'.'))
2289 if (j+1<size && data[j+1]==
' ')
2291 listMarkerSkipped=
true;
2308 listMarkerSkipped=
true;
2310 else if (data[i]==
'-' && size>=2 && i+2<size && data[i+1]==
'#' && data[i+2]==
' ')
2312 listMarkerSkipped=
true;
2316 else if (data[i]!=
' ' && i+1<size && data[i+1]==
' ')
2318 listMarkerSkipped=
true;
2320 if (data[i]!=
' ' && !listMarkerSkipped)
2334 size_t normalIndent = 0;
2335 while (normalIndent<data.size() && data[normalIndent]==
' ') normalIndent++;
2337 size_t result = listIndent>normalIndent ? listIndent : 0;
2348 while (i<data.size())
2354 else if (data[i]==
'\n')
2358 else if (data[i]!=
' ' && data[i]!=
'\t')
2370 DString &lang,
size_t &start,
size_t &
end,
size_t &offset,
2374 const char dot =
'.';
2375 auto isAlphaChar = [ ](
char c) {
return (c>=
'A' && c<=
'Z') || (c>=
'a' && c<=
'z'); };
2376 auto isAlphaNChar = [ ](
char c) {
return (c>=
'A' && c<=
'Z') || (c>=
'a' && c<=
'z') || (c>=
'0' && c<=
'9') || (c==
'+'); };
2377 auto isLangChar = [&](
char c) {
return c==dot || isAlphaChar(c); };
2383 const size_t size = data.size();
2384 while (i < size && data[i] ==
' ')
2389 if (indent>=refIndent+4)
2391 AUTO_TRACE_EXIT(
"result=false: content is part of code block indent={} refIndent={}",indent,refIndent);
2395 if (i<size && data[i]==
'`') tildaChar=
'`';
2396 while (i < size && data[i] == tildaChar)
2403 AUTO_TRACE_EXIT(
"result=false: no fence marker found #tildes={}",startTildes);
2407 while (i<size && data[i]==
' ') { i++; }
2408 if (i<size && data[i]==
'{')
2411 if (data[i] == dot) i++;
2413 while (i<size && (data[i]!=
'\n' && data[i]!=
'}')) i++;
2414 if (i<size && data[i]==
'}')
2416 lang = data.
substr(startLang,i-startLang);
2425 else if (i<size && isLangChar(data[i]))
2427 if (data[i] == dot) i++;
2429 if (i<size && isAlphaChar(data[i]))
2432 while (i<size && isAlphaNChar(data[i])) i++;
2434 lang = data.
substr(startLang,i-startLang);
2444 if (data[i]==tildaChar)
2448 while (i < size && data[i] == tildaChar)
2453 while (i<size && data[i]==
' ') i++;
2455 if (endTildes==startTildes)
2458 AUTO_TRACE_EXIT(
"result=true: found end marker at offset {} lang='{}'",offset,lang);
2465 warn(fileName, lineNr,
"Ending Inside a fenced code block. Maybe the end marker for the block is missing?");
2470static bool isCodeBlock(std::string_view data,
size_t offset,
size_t &indent)
2477 const size_t size = data.size();
2478 while (i < size && data[i] ==
' ')
2486 AUTO_TRACE_EXIT(
"result={}: line is not indented enough {}<4",
false,indent0);
2489 if (indent0>=size || data[indent0]==
'\n')
2491 AUTO_TRACE_EXIT(
"result={}: only spaces at the end of a comment block",
false);
2498 int offset_i =
static_cast<int>(offset);
2502 int j =
static_cast<int>(i)-offset_i-1;
2504 size_t nl_size =
isNewline(std::string_view(data.data()+j,data.size()-j));
2507 nl_pos[nl++]=j+
static_cast<int>(nl_size);
2513 if (i==0 && nl==2) nl_pos[nl++]=-offset_i;
2524 if (!
isEmptyLine(std::string_view(data.data()+nl_pos[1],nl_pos[0]-nl_pos[1]-1)))
2533 std::string_view(data.data()+nl_pos[2],nl_pos[1]-nl_pos[2])));
2539 AUTO_TRACE_EXIT(
"result={}: code block if indent difference >4 spaces",res);
2546 if (nl==1 && !
isEmptyLine(std::string_view(data.data()-offset,offset-1)))
2554 AUTO_TRACE_EXIT(
"result={}: code block if indent difference >4 spaces",res);
2570 const size_t size = data.size();
2573 while (i<size && data[i]==
' ') i++;
2574 if (i < size && data[i] ==
'|' && data[i] !=
'\n')
2583 while (i<size && (j =
isNewline(data.substr(i)))==0) i++;
2586 if (j>0 && i>0) i--;
2587 while (i>0 && data[i]==
' ') i--;
2588 if (i > 0 && data[i - 1] !=
'\\' && data[i] ==
'|')
2602 if (data[i]==
'|' && (i==0 || data[i-1]!=
'\\')) columns++;
2603 if (columns==1) columns++;
2607 if (n==2 && columns==0)
2619 size_t cc0=0, start=0,
end=0;
2623 if (i>=data.size() || cc0<1)
2635 if (data[j]!=
':' && data[j]!=
'-' && data[j]!=
'|' && data[j]!=
' ')
2644 AUTO_TRACE_EXIT(
"result=false: different number of columns as previous line {}!={}",cc1,cc0);
2659 const size_t size = data.size();
2661 size_t columns=0, start=0,
end=0;
2663 size_t headerStart = start;
2664 size_t headerEnd =
end;
2670 std::vector<Alignment> columnAlignment(columns);
2672 bool leftMarker=
false, rightMarker=
false, startFound=
false;
2678 if (data[j]==
':') { leftMarker=
true; startFound=
true; }
2679 if (data[j]==
'-') startFound=
true;
2682 if (data[j]==
'-') rightMarker=
false;
2683 else if (data[j]==
':') rightMarker=
true;
2684 if (j<=
end+i && (data[j]==
'|' && (j==0 || data[j-1]!=
'\\')))
2708 std::vector<std::vector<TableCell> > tableContents;
2710 size_t m = headerStart;
2711 std::vector<TableCell> headerContents(columns);
2712 for (k=0;k<columns;k++)
2714 while (m<=headerEnd && (data[m]!=
'|' || (m>0 && data[m-1]==
'\\')))
2716 headerContents[k].cellText += data[m++];
2721 headerContents[k].colSpan = headerContents[k].cellText.empty();
2722 headerContents[k].cellText = headerContents[k].cellText.stripWhiteSpace();
2724 tableContents.push_back(headerContents);
2730 if (cc!=columns)
break;
2734 std::vector<TableCell> rowContents(columns);
2737 if (j<=
end+i && (data[j]==
'|' && (j==0 || data[j-1]!=
'\\')))
2741 rowContents[k].colSpan = rowContents[k].cellText.empty();
2742 rowContents[k].cellText = rowContents[k].cellText.stripWhiteSpace();
2747 rowContents[k].cellText += data[j];
2753 rowContents[k].colSpan = rowContents[k].cellText.empty();
2754 rowContents[k].cellText = rowContents[k].cellText.stripWhiteSpace();
2755 tableContents.push_back(rowContents);
2761 out+=
"<table class=\"markdownTable\">";
2762 DString cellTag(
"th"), cellClass(
"class=\"markdownTableHead");
2763 for (
size_t row = 0; row < tableContents.size(); row++)
2769 out+=
"\n<tr class=\"markdownTableRowOdd\">";
2773 out+=
"\n<tr class=\"markdownTableRowEven\">";
2778 out+=
"\n <tr class=\"markdownTableHead\">";
2780 for (
size_t c = 0; c < columns; c++)
2783 DString cellText(tableContents[row][c].cellText);
2789 if (tableContents[row][c].cellText ==
"^")
2793 if (tableContents[row][c].colSpan)
2795 int cr =
static_cast<int>(c);
2796 while ( cr >= 0 && tableContents[row][cr].colSpan)
2800 if (cr >= 0 && tableContents[row][cr].cellText ==
"^")
continue;
2802 size_t rowSpan = 1, spanRow = row+1;
2803 while ((spanRow < tableContents.size()) &&
2804 (tableContents[spanRow][c].cellText ==
"^"))
2810 out+=
" <" + cellTag +
" " + cellClass;
2812 switch (columnAlignment[c])
2824 out+=
" rowspan=\"" + spanStr +
"\"";
2830 while ((c+1 < columns) && tableContents[row][c+1].colSpan)
2839 out+=
" colspan=\"" + spanStr +
"\"";
2843 out+=
"> " + cellText +
" \\ilinebr </" + cellTag +
">";
2846 cellClass =
"class=\"markdownTableBody";
2862 while (i<data.size() && data[i]!=
'\n')
2864 if (data[i]!=
' ' && data[i]!=
'\t') j++;
2867 if (i>=data.size()) {
return 0; }
2868 if (i<2) {
return 0; }
2869 bool res = (j>0 && data[i-1]==
' ' && data[i-2]==
' ');
2885 else if ((level=
isAtxHeader(data,header,
id,
true)))
2909 out+=
"</"+hTag+
">\n";
2912 else if (data.size()>0)
2914 size_t tmpSize = data.size();
2915 if (data[data.size()-1] ==
'\n') tmpSize--;
2916 out+=data.substr(0,tmpSize);
2920 out+=
"\\ilinebr<br>";
2922 if (tmpSize != data.size())
out+=
'\n';
2928 {
"[!note]",
"\\note" },
2929 {
"[!warning]",
"\\warning" },
2930 {
"[!tip]",
"\\remark" },
2931 {
"[!caution]",
"\\attention" },
2932 {
"[!important]",
"\\important" }
2941 const size_t size = data.size();
2942 std::string startCmd;
2943 int isGitHubAlert =
false;
2944 int isGitHubFirst =
false;
2949 while (
end<=size && data[
end-1]!=
'\n')
end++;
2954 while (j<
end && (data[j]==
' ' || data[j]==
'>'))
2956 if (data[j]==
'>') { level++; indent=j+1; }
2957 else if (j>0 && data[j-1]==
'>') indent=j+1;
2960 if (indent>0 && j>0 && data[j-1]==
'>' &&
2961 !(j==size || data[j]==
'\n'))
2978 isGitHubAlert =
true;
2979 isGitHubFirst =
true;
2980 startCmd = it->second;
2985 if (level!=1 || !isGitHubAlert)
2987 for (
int l=curLevel;l<level-1;l++)
2989 out+=
"<blockquote>";
2991 out +=
"<blockquote>‍";
2993 else if (!startCmd.empty())
2995 out += startCmd +
" ";
2998 else if (level<curLevel)
3000 int decrLevel = curLevel;
3001 if (level==0 && isGitHubAlert)
3005 for (
int l=level;l<decrLevel;l++)
3007 out +=
"</blockquote>\\ilinebr ";
3016 if (curLevel!=0 || !isGitHubAlert)
3018 std::string_view txt = data.substr(indent,
end-indent);
3021 if (!isGitHubFirst)
out +=
"<br>";
3028 isGitHubFirst =
false;
3043 for (
int l=0;l<curLevel;l++)
3045 out+=
"</blockquote>";
3056 size_t size = data.size();
3057 while (i<data.size() && data[i]==
' ') i++;
3060 size_t locStart = i;
3061 if (i>offset) locStart--;
3064 while (i+9<size && data[i]!=
'\n')
3076 location=data.substr(locStart,i-locStart);
3078 while (indent > 0 && i < size && data[i] ==
' ')
3083 if (i<size && data[i]==
'\n') i++;
3094 const size_t size = data.size();
3097 out+=
"@iverbatim\n";
3099 std::string location;
3104 while (
end<=size && data[
end-1]!=
'\n')
end++;
3107 while (j <
end && data[j] ==
' ')
3121 while (emptyLines>0)
3129 std::string lineLoc;
3134 out+=data.substr(offset,
end-offset);
3142 out+=
"@endiverbatim";
3143 if (!location.empty())
3151 while (emptyLines>0)
3167 const size_t size = data.size();
3168 size_t nb=0,
end=offset+1, j=0;
3173 if ((data[
end-1]==
'\\' || data[
end-1]==
'@') &&
3174 (
end<=1 || (data[
end-2]!=
'\\' && data[
end-2]!=
'@'))
3179 if (!endBlockName.
empty())
3181 size_t l = endBlockName.
length();
3182 for (;
end+l+1<size;
end++)
3184 if ((data[
end]==
'\\' || data[
end]==
'@') &&
3185 data[
end-1]!=
'\\' && data[
end-1]!=
'@'
3199 else if (nb==0 && data[
end-1]==
'<' && size>=6 &&
end+6<size &&
3200 (
end<=1 || (data[
end-2]!=
'\\' && data[
end-2]!=
'@'))
3203 if (tolower(data[
end])==
'p' && tolower(data[
end+1])==
'r' &&
3204 tolower(data[
end+2])==
'e' && (data[
end+3]==
'>' || data[
end+3]==
' '))
3215 else if (nb==0 && data[
end-1]==
'`')
3217 while (
end <= size && data[
end - 1] ==
'`')
3223 else if (nb>0 && data[
end-1]==
'`')
3226 while (
end <= size && data[
end - 1] ==
'`')
3244 size_t blockStart,
size_t blockEnd)
3247 if (!lang.empty() && lang[0]==
'.') lang=lang.substr(1);
3248 const size_t size=data.size();
3250 while (i<size && (data[i]==
' ' || data[i]==
'\t'))
3271 size_t pi=std::string::npos;
3272 bool newBlock =
false;
3273 bool insideList =
false;
3274 size_t currentIndent = refIndent;
3275 size_t listIndent = refIndent;
3276 const size_t size = data.size();
3283 size_t lineIndent=0;
3284 while (lineIndent<
end && data[i+lineIndent]==
' ') lineIndent++;
3290 if (insideList && lineIndent<currentIndent)
3293 currentIndent = refIndent;
3301 if (lineIndent<currentIndent+4)
3305 currentIndent = listIndent;
3312 currentIndent = listIndent;
3321 if (pi!=std::string::npos)
3323 size_t blockStart=0, blockEnd=0, blockOffset=0;
3326 auto addSpecialCommand = [&](
const DString &startCmd,
const DString &endCmd)
3328 size_t cmdPos = pi+blockStart+1;
3335 if (pl[ii]==
'\n') nl++;
3338 bool addNewLines =
false;
3340 (pl[ii]!=
'\\' && pl[ii]!=
'@') ||
3349 pl =
"@"+startCmd+
"\n" + pl +
"@"+endCmd;
3351 addNewLines =
false;
3366 if (addNewLines)
for (
int j=0;j<nl;j++)
out+=
'\n';
3368 if (addNewLines)
out+=
'\n';
3373 addSpecialCommand(
"startuml",
"enduml");
3377 addSpecialCommand(
"dot",
"enddot");
3379 else if (lang==
"msc")
3381 addSpecialCommand(
"msc",
"endmsc");
3383 else if (lang==
"mermaid")
3385 addSpecialCommand(
"mermaid",
"endmermaid");
3392 pi=std::string::npos;
3396 else if (
isBlockQuote(data.substr(pi,i-pi),currentIndent))
3399 pi=std::string::npos;
3406 out+=data.substr(pi,i-pi);
3412 if (pi!=std::string::npos && pi<size)
3422 warn(
fileName,
lineNr,
"Ending inside a fenced code block. Maybe the end marker for the block is missing?");
3424 out+=data.substr(pi);
3438 size_t pi = std::string::npos;
3454 size_t currentIndent = indent;
3455 size_t listIndent = indent;
3456 bool insideList =
false;
3457 bool newBlock =
false;
3460 while (i<data.size())
3465 size_t lineIndent=0;
3467 while (lineIndent<
end && data[i+lineIndent]==
' ') lineIndent++;
3473 if (insideList && lineIndent<currentIndent)
3476 currentIndent = indent;
3484 if (lineIndent<currentIndent+4)
3488 currentIndent = listIndent;
3495 currentIndent = listIndent;
3507 if (pi!=std::string::npos)
3509 size_t blockStart=0, blockEnd=0, blockOffset=0;
3511 size_t blockIndent = currentIndent;
3515 if (data[i]==
'@' || data[i]==
'\\') endBlockName =
isBlockCommand(data.substr(i),i);
3516 if (!endBlockName.
empty())
3519 if (
isLinkRef(data.substr(pi,i-pi),
id,link,title))
3529 size_t l = endBlockName.
length();
3530 while (i+l<data.size())
3532 if ((data[i]==
'\\' || data[i]==
'@') &&
3533 data[i-1]!=
'\\' && data[i-1]!=
'@')
3550 while (pi<data.size() && data[pi]==
' ') pi++;
3554 if (!header.
empty())
3558 out+=level==1?
"@section ":
"@subsection ";
3566 out+=level==1?
"<h1>":
"<h2>";
3568 out+=level==1?
"\n</h1>\n":
"\n</h2>\n";
3575 pi=std::string::npos;
3580 else if ((ref=
isLinkRef(data.substr(pi),
id,link,title)))
3594 pi=std::string::npos;
3602 pi=std::string::npos;
3609 pi=std::string::npos;
3622 if (pi!=std::string::npos && pi<data.size())
3624 if (
isLinkRef(data.substr(pi),
id,link,title))
3641#define OPC(x) if (literal_at(data,#x " ") || literal_at(data,#x "\n")) return true
3642 OPC(dir);
OPC(defgroup);
OPC(addtogroup);
OPC(weakgroup);
OPC(ingroup);
3645 OPC(protocol);
OPC(category);
OPC(
union);
OPC(
struct);
OPC(interface);
3656 std::string_view data(docs.
str());
3657 const size_t size = data.size();
3660 while (i<size && (data[i]==
' ' || data[i]==
'\n'))
3667 while (i<size && (data[i]==
' ' || data[i]==
'\n'))
3673 (data[i]==
'\\' || data[i]==
'@') &&
3688 else if (i+1<size && (data[i]==
'\\' || data[i]==
'@') &&
isOtherPage(data.substr(i+1)))
3706 std::string_view data(docs_org.
str());
3707 const size_t size = data.size();
3709 while (i<size && (data[i]==
' ' || data[i]==
'\n'))
3711 if (data[i]==
'\n') prepend++;
3714 if (i>=size) {
return DString(); }
3716 while (end1<size && data[end1-1]!=
'\n') end1++;
3723 while (end2<size && data[end2-1]!=
'\n') end2++;
3724 if (
prv->isHeaderline(data.substr(end1),
false))
3726 title = data.
substr(i,end1-i-1);
3727 docs+=
"\n\n"+docs_org.
mid(end2);
3728 id =
prv->extractTitleId(title, 0, &isIdGenerated);
3734 if (i<end1 && prv->isAtxHeader(data.substr(i,end1-i),title,
id,
false,&isIdGenerated)>0)
3737 docs+=docs_org.
mid(end1);
3742 id =
prv->extractTitleId(title, 0, &isIdGenerated);
3753 if (input.
empty())
return input;
3758 if (s.
at(s.
length()-1)!=
'\n') s +=
"\n";
3759 s =
detab(s,refIndent);
3763 s =
prv->processQuotations(s.
view(),refIndent);
3767 s =
prv->processBlocks(s.
view(),refIndent);
3785 const char *p = result.
data();
3788 while (*p==
' ') p++;
3789 while (*p==
'\n') {startNewlines++;p++;};
3792 if (p>result.
data())
3795 result = result.
mid(
static_cast<int>(p-result.
data()));
3831 const char *fileBuf,
3832 const std::shared_ptr<Entry> &root,
3835 std::shared_ptr<Entry> current = std::make_shared<Entry>();
3837 current->lang = SrcLangExt::Markdown;
3838 current->fileName = fileName;
3839 current->docFile = fileName;
3840 current->docLine = 1;
3846 bool isIdGenerated =
false;
3854 int indentLevel=title.
empty() ? 0 : -1;
3861 bool wasEmpty =
id.empty();
3862 if (wasEmpty)
id = mdFileNameId;
3868 if (!mdfileAsMainPage.
empty() &&
3872 docs.
prepend(
"@ianchor{" + title +
"} " +
id +
"\\ilinebr ");
3873 docs.
prepend(
"@mainpage "+title+
"\\ilinebr ");
3875 else if (
id==
"mainpage" ||
id==
"index")
3877 if (title.
empty()) title = titleFn;
3878 docs.
prepend(
"@ianchor{" + title +
"} " +
id +
"\\ilinebr ");
3879 docs.
prepend(
"@mainpage "+title+
"\\ilinebr ");
3881 else if (isSubdirDocs)
3885 docs.
prepend(
"@section " + generatedId +
" " + title +
"\\ilinebr ");
3887 docs.
prepend(
"@dir\\ilinebr ");
3898 docs.
prepend(
"@ianchor{" + title +
"} " +
id +
"\\ilinebr @ianchor{" + relFileName +
"} " + mdFileNameId +
"\\ilinebr ");
3900 else if (!generatedId.
empty())
3902 docs.
prepend(
"@ianchor " + generatedId +
"\\ilinebr ");
3904 else if (
Config_getEnum(MARKDOWN_ID_STYLE)==MARKDOWN_ID_STYLE_t::GITHUB)
3907 docs.
prepend(
"@ianchor{" + title +
"} " + autoId +
"\\ilinebr ");
3909 docs.
prepend(
"@page "+
id+
" "+title+
"\\ilinebr ");
3911 for (
int i = 0; i < prepend; i++) docs.
prepend(
"\n");
3916 static const reg::Ex re(R
"([ ]*[\\@]page\s+(\a[\w-]*)(\s*[^\n]*)\n)");
3918 std::string s = docs.str();
3921 DString orgLabel = match[1].str();
3922 DString orgTitle = match[2].str();
3925 docs = docs.
left(match[1].position())+
3928 "\\ilinebr @ianchor{" + orgTitle +
"} "+orgLabel+
"\n"+
3929 docs.
mid(match.length());
3940 p->commentScanner.enterFile(fileName,lineNr);
3942 bool needsEntry =
false;
3946 while (
p->commentScanner.parseCommentBlock(
3964 DString docFile = current->docFile;
3965 root->moveToSubEntryAndRefresh(current);
3966 current->lang = SrcLangExt::Markdown;
3967 current->docFile = docFile;
3968 current->docLine = lineNr;
3973 root->moveToSubEntryAndKeep(current);
3975 p->commentScanner.leaveFile(fileName,lineNr);
#define eol
The end of line string for this machine.
static AnchorGenerator & instance()
Returns the singleton instance.
static std::string addPrefixIfNeeded(const std::string &anchor)
std::string generate(const std::string &title)
generates an anchor for a section with title.
Clang parser object for a single translation unit, which consists of a source file and the directly o...
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
DString & setNum(short n)
size_t rfind(char c, size_t pos=npos) const
DString mid(size_t index, size_t len=npos) const
DString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple internal white...
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
DString substr(size_t pos=0, size_t count=npos) const
Returns a substring of length count starting at pos.
std::string_view view() const
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
char & at(size_t i)
Returns a reference to the character at index i.
size_t size() const
Returns the length of the string, not counting the 0-terminator.
DString & prepend(const char *s)
size_t find(char c, size_t pos=0) const
DString & sprintf(const char *format,...)
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
DString left(size_t len) const
const std::string & str() const
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
bool startsWith(const char *s) const
bool endsWith(const char *s) const
size_t length() const
Returns the length of the string, not counting the 0-terminator.
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
static ParserManager * parserManager
static FileNameLinkedMap * imageNameLinkedMap
A model of a file symbol.
Minimal replacement for QFileInfo.
std::string fileName() const
std::string absFilePath() const
FileDef * findFileDef(const DString &n, bool &ambig) const
Returns the file definition in fnMap that matches the file name n.
Helper class to process markdown formatted text.
DString process(const DString &input, int &startNewlines, bool fromParseInput=false)
static ActionTable_t fill_table()
std::array< Action_t, 256 > ActionTable_t
std::unique_ptr< Private > prv
DString extractPageTitle(DString &docs, DString &id, int &prepend, bool &isIdGenerated)
static ActionTable_t actions
void setIndentLevel(int level)
std::function< int(Private &, std::string_view, size_t)> Action_t
Markdown(const DString &fileName, int lineNr, int indentLevel=0)
void parseInput(const DString &fileName, const char *fileBuf, const std::shared_ptr< Entry > &root, ClangTUParser *clangParser) override
Parses a single input file with the goal to build an Entry tree.
~MarkdownOutlineParser() override
void parsePrototype(const DString &text) override
Callback function called by the comment block scanner.
std::unique_ptr< Private > p
std::unique_ptr< OutlineParserInterface > getOutlineParser(const DString &extension)
Gets the interface to the parser associated with a given extension.
static bool isEnabled()
Returns true if doxygen has been configured to run PlantUML, i.e.
static constexpr int Section
static constexpr int MaxLevel
static constexpr int Subsection
static constexpr int Subsubsection
static constexpr int MinLevel
static constexpr int Paragraph
static constexpr int Subsubparagraph
static constexpr int Subparagraph
Class representing a regular expression.
Object representing the matching results.
#define Config_getInt(name)
#define Config_getBool(name)
#define Config_getString(name)
#define Config_getEnum(name)
std::vector< std::string > StringVector
DirIterator end(const DirIterator &) noexcept
#define AUTO_TRACE_ADD(...)
#define AUTO_TRACE_EXIT(...)
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
bool isId(char c)
Returns true if c is a valid character for an identifier.
int dstrncmp(const char *str1, const char *str2, size_t len)
const char * qPrint(const char *s)
static DString escapeSpecialChars(const DString &s)
static bool isOtherPage(std::string_view data)
static constexpr bool isAllowedEmphStr(const std::string_view &data, size_t offset)
static bool hasLineBreak(std::string_view data)
@ explicitMainPage
docs start with a mainpage command
@ explicitPage
docs start with a page command
@ notExplicit
docs doesn't start with either page or mainpage
@ explicitOtherPage
docs start with a dir / defgroup / addtogroup command
static bool isBlockQuote(std::string_view data, size_t indent)
returns true if this line starts a block quote
static constexpr Alignment markersToAlignment(bool leftMarker, bool rightMarker)
helper function to convert presence of left and/or right alignment markers to an alignment value
static bool isEndOfList(std::string_view data)
static bool isFencedCodeBlock(std::string_view data, size_t refIndent, DString &lang, size_t &start, size_t &end, size_t &offset, DString &fileName, int lineNr)
static size_t computeIndentExcludingListMarkers(std::string_view data)
static const char * g_doxy_nbsp
static constexpr bool ignoreCloseEmphChar(char c, char cn)
static DString getFilteredImageAttributes(std::string_view fmt, const DString &attrs)
parse the image attributes and return attributes for given format
static constexpr bool isOpenEmphChar(char c)
static bool isCodeBlock(std::string_view data, size_t offset, size_t &indent)
static bool isEmptyLine(std::string_view data)
#define AUTO_TRACE_EXIT(...)
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 const size_t codeBlockIndent
static constexpr bool isIdChar(char c)
static ExplicitPageResult isExplicitPage(const DString &docs)
static const char * g_utf8_nbsp
static const std::unordered_map< std::string, std::string > g_quotationHeaderMap
static size_t isListMarker(std::string_view data)
static bool isHRuler(std::string_view data)
bool skipOverFileAndLineCommands(std::string_view data, size_t indent, size_t &offset, std::string &location)
static size_t isLinkRef(std::string_view data, DString &refid, DString &link, DString &title)
returns end of the link ref if this is indeed a link reference.
static constexpr bool extraChar(char c)
static DString escapeDoubleQuotes(const DString &s)
static bool isTableBlock(std::string_view data)
Returns true iff data points to the start of a table block.
static constexpr bool isUtf8Nbsp(char c1, char c2)
size_t isNewline(std::string_view data)
DString markdownFileNameToId(const DString &fileName)
processes string s and converts markdown into doxygen/html commands.
#define warn(file, line, fmt,...)
const Mapper< CommandType > * cmdMapper
bool isAbsolutePath(const DString &fileName)
const char * strnstr(const char *haystack, const char *needle, size_t haystack_len)
DString trunc(const DString &s, size_t numChars=15)
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
Portable versions of functions that are platform dependent.
Some helper functions for std::string.
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
std::string_view stripWhiteSpace(std::string_view s)
Given a string view s, returns a new, narrower view on that string, skipping over any leading or trai...
StringVector split(const std::string &s, const std::string &delimiter, bool retainEmpty=false)
split input string s by string delimiter delimiter.
LinkRef(const DString &l, const DString &t)
DString isBlockCommand(std::string_view data, size_t offset)
DString extractTitleId(DString &title, int level, bool *pIsIdGenerated=nullptr)
int processEmphasis1(std::string_view data, char c)
process single emphasis
int processQuoted(std::string_view data, size_t offset)
Process quoted section "...", can contain one embedded newline.
size_t writeTableBlock(std::string_view data)
size_t writeBlockQuote(std::string_view data)
Private(const DString &fn, int line, int indent)
void writeMarkdownImage(std::string_view fmt, bool inline_img, bool explicitTitle, const DString &title, const DString &content, const DString &link, const DString &attributes, const FileDef *fd)
size_t isSpecialCommand(std::string_view data, size_t offset)
int processEmphasis3(std::string_view data, char c)
Parsing triple emphasis.
int processCodeSpan(std::string_view data, size_t offset)
` parsing a code span (assuming codespan != 0)
int processSpecialCommand(std::string_view data, size_t offset)
void writeFencedCodeBlock(std::string_view data, std::string_view lang, size_t blockStart, size_t blockEnd)
int isHeaderline(std::string_view data, bool allowAdjustLevel)
returns whether the line is a setext-style hdr underline
size_t findEmphasisChar(std::string_view, char c, size_t c_size)
looks for the next emph char, skipping other constructs, and stopping when either it is found,...
std::unordered_map< std::string, LinkRef > linkRefs
void addStrEscapeUtf8Nbsp(std::string_view data)
size_t writeCodeBlock(std::string_view, size_t refIndent)
int processHtmlTag(std::string_view data, size_t offset)
int processEmphasis(std::string_view data, size_t offset)
int processLink(std::string_view data, size_t offset)
int isAtxHeader(std::string_view data, DString &header, DString &id, bool allowAdjustLevel, bool *pIsIdGenerated=nullptr)
int processHtmlTagWrite(std::string_view data, size_t offset, bool doWrite)
Process a HTML tag.
size_t findEndOfLine(std::string_view data, size_t offset)
int processEmphasis2(std::string_view data, char c)
process double emphasis
DString processQuotations(std::string_view data, size_t refIndent)
void processInline(std::string_view data)
int processNmdash(std::string_view data, size_t offset)
Process ndash and mdashes.
DString processBlocks(std::string_view data, size_t indent)
void writeOneLineHeaderOrRuler(std::string_view data)
CommentScanner commentScanner
bool isURL(const DString &url)
Checks whether the given url starts with a supported protocol.
DString detab(const DString &s, size_t &refIndent)
DString externalLinkTarget(const bool parent)
DString stripExtensionGeneral(const DString &fName, const DString &ext)
DString getFileNameExtension(const DString &fn)
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
DString escapeCharsInString(const DString &name, bool allowDots, bool allowUnderscore)
DString stripIndentation(const DString &s, bool skipFirstLine)
DString stripFromPath(const DString &path)
A bunch of utility functions.