mirror of
https://github.com/maaslalani/slides.git
synced 2026-01-09 14:28:05 -05:00
feat: execute code on slides
This commit is contained in:
@@ -21,7 +21,7 @@ type Result struct {
|
||||
}
|
||||
|
||||
// ?: means non-capture group
|
||||
var re = regexp.MustCompile("(?:```|~~~)(.*)\n(.*)\n(?:```|~~~)")
|
||||
var re = regexp.MustCompile("(?s)(?:```|~~~)(\\w+)\n(.*)\n(?:```|~~~)\n")
|
||||
|
||||
var (
|
||||
ErrParse = errors.New("Error: could not parse code block")
|
||||
|
||||
@@ -37,28 +37,38 @@ fmt.Println("Hello, world!")
|
||||
},
|
||||
{
|
||||
markdown: `
|
||||
# Welcome to Slides
|
||||
|
||||
A terminal based presentation tool
|
||||
|
||||
~~~go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Written in Go!")
|
||||
}
|
||||
~~~
|
||||
`,
|
||||
expected: code.Block{
|
||||
Code: `package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Written in Go!")
|
||||
}`,
|
||||
Language: "go",
|
||||
},
|
||||
},
|
||||
{
|
||||
markdown: `
|
||||
# Slide 1
|
||||
Just a regular slide, no code block
|
||||
`,
|
||||
expected: code.Block{},
|
||||
},
|
||||
{
|
||||
markdown: `
|
||||
# Multiple Code Blocks
|
||||
~~~go
|
||||
fmt.Println("Oh no!")
|
||||
~~~
|
||||
|
||||
# Secondary Code Block
|
||||
~~~ruby
|
||||
puts "We will only parse the first code block"
|
||||
~~~
|
||||
`,
|
||||
expected: code.Block{
|
||||
Code: `fmt.Println("Oh no!")`,
|
||||
Language: "go",
|
||||
},
|
||||
},
|
||||
{
|
||||
markdown: ``,
|
||||
expected: code.Block{},
|
||||
|
||||
Reference in New Issue
Block a user