Skip to content

Commit

Permalink
Pre-process any commands
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Jun 26, 2021
1 parent 7b1b2cd commit 9b3a09e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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])
Expand Down
21 changes: 21 additions & 0 deletions internal/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 9b3a09e

Please sign in to comment.