Skip to content

Commit 39ba42c

Browse files
author
Dimitri van Heesch
committed
Added documentation for ``` style fenced code block and more robust parsing
1 parent ba37d86 commit 39ba42c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

doc/markdown.doc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ int func(int a,int b) { return a*b; }
390390

391391
The curly braces and dot are optional by the way.
392392

393+
Another way to denote fenced code blocks is to use 3 or more backticks (```):
394+
395+
```
396+
also a fenced code block
397+
```
398+
393399
\subsection md_header_id Header Id Attributes
394400

395401
Standard Markdown has no support for labeling headers, which

src/pre.l

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,7 +2452,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
24522452
<SkipCComment>[\\@][\\@]("f{"|"f$"|"f[") {
24532453
outputArray(yytext,(int)yyleng);
24542454
}
2455-
<SkipCComment>"~~~"[~]* {
2455+
<SkipCComment>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
24562456
static bool markdownSupport = Config_getBool("MARKDOWN_SUPPORT");
24572457
if (!markdownSupport)
24582458
{
@@ -2465,7 +2465,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
24652465
BEGIN(SkipVerbatim);
24662466
}
24672467
}
2468-
<SkipCComment>"```"[`]* {
2468+
<SkipCComment>^({B}*"*"+)?{B}{0,3}"```"[`]* {
24692469
static bool markdownSupport = Config_getBool("MARKDOWN_SUPPORT");
24702470
if (!markdownSupport)
24712471
{
@@ -2612,14 +2612,14 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
26122612
BEGIN(SkipCComment);
26132613
}
26142614
}
2615-
<SkipVerbatim>"~~~"[~]* {
2615+
<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
26162616
outputArray(yytext,(int)yyleng);
26172617
if (g_fenceSize==yyleng)
26182618
{
26192619
BEGIN(SkipCComment);
26202620
}
26212621
}
2622-
<SkipVerbatim>"```"[`]* {
2622+
<SkipVerbatim>^({B}*"*"+)?{B}{0,3}"```"[`]* {
26232623
outputArray(yytext,(int)yyleng);
26242624
if (g_fenceSize==yyleng)
26252625
{
@@ -2629,7 +2629,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
26292629
<SkipVerbatim>"*/"|"/*" {
26302630
outputArray(yytext,(int)yyleng);
26312631
}
2632-
<SkipCComment,SkipVerbatim>[^*\\@\x06~\n\/]+ {
2632+
<SkipCComment,SkipVerbatim>[^*\\@\x06~`\n\/]+ {
26332633
outputArray(yytext,(int)yyleng);
26342634
}
26352635
<SkipCComment,SkipVerbatim>\n {

src/scanner.l

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6264,14 +6264,14 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
62646264
g_nestedComment=FALSE;
62656265
BEGIN(DocCopyBlock);
62666266
}
6267-
<DocBlock>"~~~"[~]* {
6267+
<DocBlock>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
62686268
docBlock+=yytext;
62696269
docBlockName="~~~";
62706270
g_fencedSize=yyleng;
62716271
g_nestedComment=FALSE;
62726272
BEGIN(DocCopyBlock);
62736273
}
6274-
<DocBlock>"```"[`]* {
6274+
<DocBlock>^({B}*"*"+)?{B}{0,3}"```"[`]* {
62756275
docBlock+=yytext;
62766276
docBlockName="```";
62776277
g_fencedSize=yyleng;
@@ -6389,14 +6389,14 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
63896389
REJECT;
63906390
}
63916391
}
6392-
<DocCopyBlock>"~~~"[~]* {
6392+
<DocCopyBlock>^({B}*"*"+)?{B}{0,3}"~~~"[~]* {
63936393
docBlock+=yytext;
63946394
if (g_fencedSize==yyleng)
63956395
{
63966396
BEGIN(DocBlock);
63976397
}
63986398
}
6399-
<DocCopyBlock>"```"[`]* {
6399+
<DocCopyBlock>^({B}*"*"+)?{B}{0,3}"```"[`]* {
64006400
docBlock+=yytext;
64016401
if (g_fencedSize==yyleng)
64026402
{

0 commit comments

Comments
 (0)