Pre-process any commands

This commit is contained in:
Maas Lalani
2021-06-25 22:56:11 -04:00
parent ee809ade8b
commit e7274f993e
2 changed files with 24 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ import (
"github.com/charmbracelet/glamour"
"github.com/maaslalani/slides/internal/code"
"github.com/maaslalani/slides/internal/meta"
"github.com/maaslalani/slides/internal/process"
"github.com/maaslalani/slides/styles"
)
@@ -67,6 +68,8 @@ func (m *Model) Load() error {
return err
}
content = process.Pre(content)
slides := strings.Split(content, delimiter)
metaData, exists := meta.New().ParseHeader(slides[0])

View File

@@ -67,3 +67,24 @@ func (b *Block) Execute() {
b.Output = string(out)
}
// Pre processes the markdown content by executing the commands necessary and
// returns the new processed content
func Pre(content string) string {
blocks := Parse(content)
if len(blocks) <= 0 {
return content
}
for _, block := range blocks {
// TODO: Use goroutines, if possible
block.Execute()
// If multiple blocks have the same Raw value The will _likely_ have the
// same Output value so we can probably optimize this
// There may be edge cases, though, since block execution is not deterministic.
content = strings.Replace(content, block.Raw, block.Output, 1)
}
return content
}