package main import ( "bufio" "os" "strconv" "text/template" ) const tmpl = ` {{.Title}} {{range .SlideDeck}}
{{if .Prev}}{{- end}}{{if .Next}}{{- end}}{{if .IsEnd}}{{- end}}
{{.Content}}
{{end}} ` type Slide struct { Content string Position int Id string Prev bool Next bool PrevId string NextId string IsEnd bool } type SlideSet struct { SlideDeck []Slide Title string } func main() { reader := bufio.NewReader(os.Stdin) var slides SlideSet var us Slide for { line, _, err := reader.ReadLine() if err != nil { us.Next = false us.IsEnd = true us.NextId = "/" slides.SlideDeck = append(slides.SlideDeck, us) break } if len(slides.SlideDeck) == 0 { slides.Title = us.Content us.Prev = false us.Next = true us.IsEnd = false us.Id = "start" us.Position = 0 us.NextId = "slide" + strconv.Itoa(us.Position+1) } if string(line) == "" { slides.SlideDeck = append(slides.SlideDeck, us) us.Content = "" us.Next = true us.Prev = true us.Position++ us.NextId = "slide" + strconv.Itoa(us.Position+1) us.PrevId = "slide" + strconv.Itoa(us.Position-1) us.Id = "slide" + strconv.Itoa(us.Position) } else { switch string(line[0]) { case "@": line = []byte("") case `"`: line = []byte{} } if us.Content == "" { us.Content = string(line) } else { us.Content = us.Content + "\n" + string(line) } } } t := template.Must(template.New("slides").Parse(tmpl)) t.Execute(os.Stdout, slides) }