Skip to content

Commit

Permalink
add support for github flavored fenced code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
halex2005 committed Mar 30, 2015
1 parent 9d631b5 commit 288ea42
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/markdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,9 @@ static bool isFencedCodeBlock(const char *data,int size,int refIndent,
int startTildes=0;
while (i<size && data[i]==' ') indent++,i++;
if (indent>=refIndent+4) return FALSE; // part of code block
while (i<size && data[i]=='~') startTildes++,i++;
char tildaChar='~';
if (i<size && data[i]=='`') tildaChar='`';
while (i<size && data[i]==tildaChar) startTildes++,i++;
if (startTildes<3) return FALSE; // not enough tildes
if (i<size && data[i]=='{') i++; // skip over optional {
int startLang=i;
Expand All @@ -1376,11 +1378,11 @@ static bool isFencedCodeBlock(const char *data,int size,int refIndent,
start=i;
while (i<size)
{
if (data[i]=='~')
if (data[i]==tildaChar)
{
end=i-1;
int endTildes=0;
while (i<size && data[i]=='~') endTildes++,i++;
while (i<size && data[i]==tildaChar) endTildes++,i++;
while (i<size && data[i]==' ') i++;
if (i==size || data[i]=='\n')
{
Expand Down
20 changes: 20 additions & 0 deletions src/pre.l
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,19 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
BEGIN(SkipVerbatim);
}
}
<SkipCComment>"```"[~]* {
static bool markdownSupport = Config_getBool("MARKDOWN_SUPPORT");
if (!markdownSupport)
{
REJECT;
}
else
{
outputArray(yytext,(int)yyleng);
g_fenceSize=yyleng;
BEGIN(SkipVerbatim);
}
}
<SkipCComment>[\\@][\\@]("verbatim"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly"|"dot"|"code"("{"[^}]*"}")?){BN}+ {
outputArray(yytext,(int)yyleng);
g_yyLineNr+=QCString(yytext).contains('\n');
Expand Down Expand Up @@ -2606,6 +2619,13 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
BEGIN(SkipCComment);
}
}
<SkipVerbatim>"```"[~]* {
outputArray(yytext,(int)yyleng);
if (g_fenceSize==yyleng)
{
BEGIN(SkipCComment);
}
}
<SkipVerbatim>"*/"|"/*" {
outputArray(yytext,(int)yyleng);
}
Expand Down
14 changes: 14 additions & 0 deletions src/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -6271,6 +6271,13 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
g_nestedComment=FALSE;
BEGIN(DocCopyBlock);
}
<DocBlock>"```"[~]* {
docBlock+=yytext;
docBlockName="```";
g_fencedSize=yyleng;
g_nestedComment=FALSE;
BEGIN(DocCopyBlock);
}
<DocBlock>{B}*"<code>" {
if (insideCS)
{
Expand Down Expand Up @@ -6389,6 +6396,13 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
BEGIN(DocBlock);
}
}
<DocCopyBlock>"```"[~]* {
docBlock+=yytext;
if (g_fencedSize==yyleng)
{
BEGIN(DocBlock);
}
}
<DocCopyBlock>[^\<@/*\]~\$\\\n]+ { // any character that is not special
docBlock+=yytext;
}
Expand Down

0 comments on commit 288ea42

Please sign in to comment.