mirror of
https://github.com/maaslalani/slides.git
synced 2026-01-09 14:28:05 -05:00
be able to run multiple code blocks in a single slide
This commit is contained in:
committed by
Maas Lalani
parent
4e3be668eb
commit
68adc0a622
@@ -21,7 +21,7 @@ type Result struct {
|
||||
}
|
||||
|
||||
// ?: means non-capture group
|
||||
var re = regexp.MustCompile("(?s)(?:```|~~~)(\\w+)\n(.*)\n(?:```|~~~)\\s?")
|
||||
var re = regexp.MustCompile("(?s)(?:```|~~~)(\\w+)\n(.*?)\n(?:```|~~~)\\s?")
|
||||
|
||||
var (
|
||||
ErrParse = errors.New("Error: could not parse code block")
|
||||
@@ -29,19 +29,28 @@ var (
|
||||
|
||||
// Parse takes a block of markdown and returns an array of Block's with code
|
||||
// and associated languages
|
||||
func Parse(markdown string) (Block, error) {
|
||||
match := re.FindStringSubmatch(markdown)
|
||||
func Parse(markdown string) ([]Block, error) {
|
||||
matchs := re.FindAllStringSubmatch(markdown, -1)
|
||||
|
||||
var rv []Block
|
||||
for _, match := range matchs {
|
||||
// There was either no language specified or no code block
|
||||
// Either way, we cannot execute the expression
|
||||
if len(match) < 3 {
|
||||
continue
|
||||
}
|
||||
rv = append(rv, Block{
|
||||
Language: match[1],
|
||||
Code: match[2],
|
||||
})
|
||||
|
||||
// There was either no language specified or no code block
|
||||
// Either way, we cannot execute the expression
|
||||
if len(match) < 3 {
|
||||
return Block{}, ErrParse
|
||||
}
|
||||
|
||||
return Block{
|
||||
Language: match[1],
|
||||
Code: match[2],
|
||||
}, nil
|
||||
if len(rv) == 0 {
|
||||
return nil, ErrParse
|
||||
}
|
||||
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user