From 39ba42c3b21d08ec606eee18ee8b64c67ec6a42a Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 5 Apr 2015 20:52:42 +0200 Subject: Added documentation for ``` style fenced code block and more robust parsing --- doc/markdown.doc | 6 ++++++ src/pre.l | 10 +++++----- src/scanner.l | 8 ++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/markdown.doc b/doc/markdown.doc index a35b802..87af3d8 100644 --- a/doc/markdown.doc +++ b/doc/markdown.doc @@ -390,6 +390,12 @@ int func(int a,int b) { return a*b; } The curly braces and dot are optional by the way. +Another way to denote fenced code blocks is to use 3 or more backticks (```): + + ``` + also a fenced code block + ``` + \subsection md_header_id Header Id Attributes Standard Markdown has no support for labeling headers, which diff --git a/src/pre.l b/src/pre.l index 92912e6..ab2ad6f 100644 --- a/src/pre.l +++ b/src/pre.l @@ -2452,7 +2452,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) [\\@][\\@]("f{"|"f$"|"f[") { outputArray(yytext,(int)yyleng); } -"~~~"[~]* { +^({B}*"*"+)?{B}{0,3}"~~~"[~]* { static bool markdownSupport = Config_getBool("MARKDOWN_SUPPORT"); if (!markdownSupport) { @@ -2465,7 +2465,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) BEGIN(SkipVerbatim); } } -"```"[`]* { +^({B}*"*"+)?{B}{0,3}"```"[`]* { static bool markdownSupport = Config_getBool("MARKDOWN_SUPPORT"); if (!markdownSupport) { @@ -2612,14 +2612,14 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) BEGIN(SkipCComment); } } -"~~~"[~]* { +^({B}*"*"+)?{B}{0,3}"~~~"[~]* { outputArray(yytext,(int)yyleng); if (g_fenceSize==yyleng) { BEGIN(SkipCComment); } } -"```"[`]* { +^({B}*"*"+)?{B}{0,3}"```"[`]* { outputArray(yytext,(int)yyleng); if (g_fenceSize==yyleng) { @@ -2629,7 +2629,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) "*/"|"/*" { outputArray(yytext,(int)yyleng); } -[^*\\@\x06~\n\/]+ { +[^*\\@\x06~`\n\/]+ { outputArray(yytext,(int)yyleng); } \n { diff --git a/src/scanner.l b/src/scanner.l index c309289..b11d777 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -6264,14 +6264,14 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) g_nestedComment=FALSE; BEGIN(DocCopyBlock); } -"~~~"[~]* { +^({B}*"*"+)?{B}{0,3}"~~~"[~]* { docBlock+=yytext; docBlockName="~~~"; g_fencedSize=yyleng; g_nestedComment=FALSE; BEGIN(DocCopyBlock); } -"```"[`]* { +^({B}*"*"+)?{B}{0,3}"```"[`]* { docBlock+=yytext; docBlockName="```"; g_fencedSize=yyleng; @@ -6389,14 +6389,14 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) REJECT; } } -"~~~"[~]* { +^({B}*"*"+)?{B}{0,3}"~~~"[~]* { docBlock+=yytext; if (g_fencedSize==yyleng) { BEGIN(DocBlock); } } -"```"[`]* { +^({B}*"*"+)?{B}{0,3}"```"[`]* { docBlock+=yytext; if (g_fencedSize==yyleng) { -- cgit v0.12