mirror of
https://github.com/maaslalani/slides.git
synced 2026-01-08 22:07:59 -05:00
Pre-process any commands
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user