From c6efba04dd0d931bb11cd7f556285fa3c9305398 Mon Sep 17 00:00:00 2001 From: Alex Carol Date: Sun, 16 Oct 2016 23:18:27 +0200 Subject: [PATCH] present: add speaker notes to the title page Change-Id: I68f17f933e2526c6419e1463acfcb3c838aeecf4 Reviewed-on: https://go-review.googlesource.com/31396 Reviewed-by: Jaana Burcu Dogan --- cmd/present/static/notes.js | 6 ++++- cmd/present/templates/slides.tmpl | 5 ++-- present/parse.go | 44 ++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/cmd/present/static/notes.js b/cmd/present/static/notes.js index 288ef4c7..a19f21eb 100644 --- a/cmd/present/static/notes.js +++ b/cmd/present/static/notes.js @@ -38,6 +38,8 @@ function initNotes() { // Check if section is valid before retrieving Notes. if (section) { formattedNotes = formatNotes(section.Notes); + } else if (curSlide == 0) { + formattedNotes = formatNotes(titleNotes); } // Hack to apply css. Requires existing html on notesWindow. @@ -99,7 +101,9 @@ function updateNotes() { if (section && section.Notes) { el.innerHTML = formatNotes(section.Notes); - } else { + } else if (destSlide == 0) { + el.innerHTML = formatNotes(titleNotes); + } else { el.innerHTML = ''; } }; diff --git a/cmd/present/templates/slides.tmpl b/cmd/present/templates/slides.tmpl index bc2fa805..878440b6 100644 --- a/cmd/present/templates/slides.tmpl +++ b/cmd/present/templates/slides.tmpl @@ -14,6 +14,7 @@ {{if .NotesEnabled}} {{end}} @@ -40,7 +41,7 @@
- +

{{.Title}}

{{with .Subtitle}}

{{.}}

{{end}} @@ -51,7 +52,7 @@ {{end}}
- + {{range $i, $s := .Sections}}
diff --git a/present/parse.go b/present/parse.go index 1cb0402e..b26d65bb 100644 --- a/present/parse.go +++ b/present/parse.go @@ -66,12 +66,13 @@ func Register(name string, parser ParseFunc) { // Doc represents an entire document. type Doc struct { - Title string - Subtitle string - Time time.Time - Authors []Author - Sections []Section - Tags []string + Title string + Subtitle string + Time time.Time + Authors []Author + TitleNotes []string + Sections []Section + Tags []string } // Author represents the person who wrote and/or is presenting the document. @@ -250,6 +251,17 @@ func (ctx *Context) Parse(r io.Reader, name string, mode ParseMode) (*Doc, error if err != nil { return nil, err } + + for i := lines.line; i < len(lines.text); i++ { + if strings.HasPrefix(lines.text[i], "*") { + break + } + + if isSpeakerNote(lines.text[i]) { + doc.TitleNotes = append(doc.TitleNotes, lines.text[i][2:]) + } + } + err = parseHeader(doc, lines) if err != nil { return nil, err @@ -257,12 +269,13 @@ func (ctx *Context) Parse(r io.Reader, name string, mode ParseMode) (*Doc, error if mode&TitlesOnly != 0 { return doc, nil } + // Authors if doc.Authors, err = parseAuthors(lines); err != nil { return nil, err } // Sections - if doc.Sections, err = parseSections(ctx, name, lines, []int{}, doc); err != nil { + if doc.Sections, err = parseSections(ctx, name, lines, []int{}); err != nil { return nil, err } return doc, nil @@ -286,7 +299,7 @@ func lesserHeading(text, prefix string) bool { // parseSections parses Sections from lines for the section level indicated by // number (a nil number indicates the top level). -func parseSections(ctx *Context, name string, lines *Lines, number []int, doc *Doc) ([]Section, error) { +func parseSections(ctx *Context, name string, lines *Lines, number []int) ([]Section, error) { var sections []Section for i := 1; ; i++ { // Next non-empty line is title. @@ -340,11 +353,11 @@ func parseSections(ctx *Context, name string, lines *Lines, number []int, doc *D } lines.back() e = List{Bullet: b} - case strings.HasPrefix(text, ": "): + case isSpeakerNote(text): section.Notes = append(section.Notes, text[2:]) case strings.HasPrefix(text, prefix+"* "): lines.back() - subsecs, err := parseSections(ctx, name, lines, section.Number, doc) + subsecs, err := parseSections(ctx, name, lines, section.Number) if err != nil { return nil, err } @@ -407,6 +420,9 @@ func parseHeader(doc *Doc, lines *Lines) error { if text == "" { break } + if isSpeakerNote(text) { + continue + } const tagPrefix = "Tags:" if strings.HasPrefix(text, tagPrefix) { tags := strings.Split(text[len(tagPrefix):], ",") @@ -447,6 +463,10 @@ func parseAuthors(lines *Lines) (authors []Author, err error) { break } + if isSpeakerNote(text) { + continue + } + // If we encounter a blank we're done with this author. if a != nil && len(text) == 0 { authors = append(authors, *a) @@ -508,3 +528,7 @@ func parseTime(text string) (t time.Time, ok bool) { } return time.Time{}, false } + +func isSpeakerNote(s string) bool { + return strings.HasPrefix(s, ": ") +}