1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:54:45 -07:00

present: add speaker notes to the title page

Change-Id: I68f17f933e2526c6419e1463acfcb3c838aeecf4
Reviewed-on: https://go-review.googlesource.com/31396
Reviewed-by: Jaana Burcu Dogan <jbd@google.com>
This commit is contained in:
Alex Carol 2016-10-16 23:18:27 +02:00 committed by Jaana Burcu Dogan
parent 1a954d519b
commit c6efba04dd
3 changed files with 42 additions and 13 deletions

View File

@ -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 = '';
}
};

View File

@ -14,6 +14,7 @@
{{if .NotesEnabled}}
<script>
var sections = {{.Sections}};
var titleNotes = {{.TitleNotes}}
</script>
<script src='/static/notes.js'></script>
{{end}}
@ -40,7 +41,7 @@
<body style='display: none'>
<section class='slides layout-widescreen'>
<article>
<h1>{{.Title}}</h1>
{{with .Subtitle}}<h3>{{.}}</h3>{{end}}
@ -51,7 +52,7 @@
</div>
{{end}}
</article>
{{range $i, $s := .Sections}}
<!-- start of slide {{$s.Number}} -->
<article>

View File

@ -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, ": ")
}