FAQ
Reviewers: gri,

Message:
Hello gri (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go.talks


Description:
go.talks/pkg/present: fix header parsing; make subtitle optional

Fixes issue 4497.

Please review this at https://codereview.appspot.com/6907045/

Affected files:
M pkg/present/doc.go
M pkg/present/parse.go


Index: pkg/present/doc.go
===================================================================
--- a/pkg/present/doc.go
+++ b/pkg/present/doc.go
@@ -18,9 +18,10 @@
http://url/
@twitter_name

-The date line is optional, and may be written without a time as just:
+The subtitle and date lines are optional.
+The date line may be written without a time:
2 Jan 2006
-in which case it will be interpreted as 10am UTC for that date.
+In this case, the time will be interpreted as 10am UTC on that date.

The author section may contain a mixture of text, twitter names, and links.
For slide presentations, only the plain text lines will be displayed on the
Index: pkg/present/parse.go
===================================================================
--- a/pkg/present/parse.go
+++ b/pkg/present/parse.go
@@ -223,22 +223,9 @@
if err != nil {
return nil, err
}
- var ok bool
- // First non-empty line starts title.
- doc.Title, ok = lines.nextNonEmpty()
- if !ok {
- return nil, errors.New("no title")
- }
- doc.Subtitle, ok = lines.next()
- if !ok {
- return nil, errors.New("no subtitle")
- }
- text, ok := lines.next()
- if !ok {
- return nil, errors.New("unexpected EOF")
- }
- if t, ok := parseTime(text); ok {
- doc.Time = t
+ err = parseHeader(doc, lines)
+ if err != nil {
+ return nil, err
}
if mode&TitlesOnly > 0 {
return doc, nil
@@ -364,6 +351,34 @@
return sections, nil
}

+func parseHeader(doc *Doc, lines *Lines) error {
+ var ok bool
+ // First non-empty line starts header.
+ doc.Title, ok = lines.nextNonEmpty()
+ if !ok {
+ return errors.New("unexpected EOF; expected title")
+ }
+ for {
+ text, ok := lines.next()
+ if !ok {
+ return errors.New("unexpected EOF")
+ }
+ if text == "" {
+ break
+ }
+ if t, ok := parseTime(text); ok {
+ doc.Time = t
+ break
+ }
+ if doc.Subtitle == "" {
+ doc.Subtitle = text
+ continue
+ }
+ return fmt.Errorf("unexpected header line: %q", text)
+ }
+ return nil
+}
+
func parseAuthors(lines *Lines) (authors []Author, err error) {
// This grammar demarcates authors with blanks.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 6, '12 at 11:38p
activeDec 6, '12 at 11:38p
posts1
users1
websitegolang.org

1 user in discussion

Adg: 1 post

People

Translate

site design / logo © 2021 Grokbase