From 2a7424839a70b906543c75eb23a5cc95e8d64444 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Mon, 10 Nov 2014 15:43:39 +0000
Subject: [PATCH] render the book description as HTML

---
 database_test.go           |  7 ++++---
 htdocs/templates/book.html |  4 ++--
 web.go                     | 15 +++++++++++----
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/database_test.go b/database_test.go
index 660ba83..7e5b177 100644
--- a/database_test.go
+++ b/database_test.go
@@ -52,9 +52,10 @@ func testEbook() *Book {
 	return &Book{
 		Id: NewID(),
 		Metadata: &Metadata{
-			Title:   "20,000 Leagues under the sea",
-			Creator: []string{"Jules Verne"},
-			ISBN:    []string{"1234"},
+			Title:       "20,000 Leagues under the sea",
+			Creator:     []string{"Jules Verne"},
+			ISBN:        []string{"1234"},
+			Description: "A pretty cool book.",
 		},
 	}
 }
diff --git a/htdocs/templates/book.html b/htdocs/templates/book.html
index 505b104..b6d8d8c 100644
--- a/htdocs/templates/book.html
+++ b/htdocs/templates/book.html
@@ -28,8 +28,8 @@
     </p>
     {{end}}
 
-    {{if .Book.Metadata.Description}}
-    <p>{{.Book.Metadata.Description}}</p>
+    {{if .Description}}
+    <p>{{.Description}}</p>
     {{end}}
 
     {{range $i, $f := .Files}}
diff --git a/web.go b/web.go
index 0e6bdd0..52a901b 100644
--- a/web.go
+++ b/web.go
@@ -149,11 +149,18 @@ func (s *uiServer) handleShowBook(book *Book, w http.ResponseWriter, req *http.R
 		return
 	}
 
+	// The book's Description, if present, should be rendered
+	// directly as HTML. So we deal with it separately.
 	ctx := struct {
-		Query string
-		Book  *Book
-		Files []*File
-	}{Book: book, Files: files}
+		Query       string
+		Book        *Book
+		Files       []*File
+		Description template.HTML
+	}{
+		Book:        book,
+		Files:       files,
+		Description: template.HTML(book.Metadata.Description),
+	}
 	render("book.html", w, &ctx)
 }
 
-- 
GitLab