@@ -9,9 +9,12 @@ import scala.io.StdIn.readLine
9
9
import scala .util .Random
10
10
import scala .util .matching .Regex
11
11
12
- val SnippetBlock = """ *```[^ ]+ title=([\w\d\.\-\/_]+) *""" .r
13
- val CompileBlock = """ *``` *(\w+) +(compile|fail) *(?:title=([\w\d\.\-\/_]+))? *""" .r
14
- val CodeBlockEnds = """ *``` *""" .r
12
+ val SnippetBlock = """ *(```[`]*)[^ ]+ title=([\w\d\.\-\/_]+) *""" .r
13
+ val CompileBlock = """ *(```[`]*) *(\w+) +(compile|fail) *(?:title=([\w\d\.\-\/_]+))? *""" .r
14
+ def compileBlockEnds (backticks : String ): Regex = {
15
+ val regexString = s """ * $backticks * """
16
+ regexString.r
17
+ }
15
18
val BashCommand = """ *```bash *(fail)? *""" .r
16
19
val CheckBlock = """ *\<\!-- Expected(-regex)?: *""" .r
17
20
val CheckBlockEnd = """ *\--> *""" .r
@@ -67,7 +70,7 @@ def parse(content: Seq[String], currentCommands: Seq[Commands], context: Context
67
70
inline def parseMultiline (
68
71
lines : Seq [String ],
69
72
newCommand : Seq [String ] => Commands ,
70
- endMarker : Regex = CodeBlockEnds
73
+ endMarker : Regex = compileBlockEnds( " ``` " )
71
74
) =
72
75
val codeLines = lines.takeWhile(l => ! endMarker.matches(l))
73
76
check(codeLines.size > 0 , " Block cannot be empty!" )
@@ -81,12 +84,17 @@ def parse(content: Seq[String], currentCommands: Seq[Commands], context: Context
81
84
content match
82
85
case Nil => currentCommands
83
86
84
- case SnippetBlock (name) :: tail =>
85
- parseMultiline(tail, Commands .Write (name, _, context))
87
+ case SnippetBlock (backticks, name) :: tail =>
88
+ parseMultiline(tail, Commands .Write (name, _, context), compileBlockEnds(backticks) )
86
89
87
- case CompileBlock (name, status, fileName) :: tail =>
88
- val file = Option (fileName).getOrElse(" snippet_" + Random .nextInt(1000 ) + " ." + name)
89
- parseMultiline(tail, Commands .Compile (file, _, context, status == " fail" ))
90
+ case CompileBlock (backticks, name, status, fileName) :: tail =>
91
+ val fileSuffix = if name == " markdown" then " .md" else s " . $name"
92
+ val file = Option (fileName).getOrElse(" snippet_" + Random .nextInt(1000 ) + fileSuffix)
93
+ parseMultiline(
94
+ tail,
95
+ Commands .Compile (file, _, context, status == " fail" ),
96
+ compileBlockEnds(backticks)
97
+ )
90
98
91
99
case BashCommand (failGroup) :: tail =>
92
100
parseMultiline(tail, Commands .Run (_, failGroup != null , context))
0 commit comments