Browse Source

Support Markdown in list description

Gildas Chabot 4 years ago
parent
commit
cb217b24e3
3 changed files with 12 additions and 13 deletions
  1. 9 10
      pages/pages.go
  2. 0 1
      templates/home.html
  3. 3 2
      templates/list.html

+ 9 - 10
pages/pages.go

@@ -9,6 +9,7 @@ import (
9 9
 
10 10
 	"gogs.gildas.ch/gildas/movies"
11 11
 	"gogs.gildas.ch/gildas/movies/omdb"
12
+	"gopkg.in/russross/blackfriday.v2"
12 13
 )
13 14
 
14 15
 func Router(c *movies.Collection) http.HandlerFunc {
@@ -156,15 +157,9 @@ func List(c *movies.Collection) http.HandlerFunc {
156 157
 		}
157 158
 
158 159
 		if r.Method == "POST" {
159
-			updated, err := movies.UnmarshalList([]byte(r.FormValue("list_json")))
160
-			if err != nil {
161
-				errs = append(errs, err)
162
-			} else if listID != updated.ID {
163
-				errs = append(errs, fmt.Errorf("you cannot change the imdb id."))
164
-			} else {
165
-				l = updated
166
-				c.UpdateList(updated)
167
-			}
160
+			l.Title = r.FormValue("title")
161
+			l.Description = r.FormValue("description")
162
+			c.UpdateList(l)
168 163
 		}
169 164
 
170 165
 		b, err := json.MarshalIndent(l, "", "  ")
@@ -173,7 +168,11 @@ func List(c *movies.Collection) http.HandlerFunc {
173 168
 		}
174 169
 
175 170
 		t.Execute(w, map[string]interface{}{
176
-			"List":     l,
171
+			"List": l,
172
+			"Description": template.HTML(
173
+				blackfriday.Run(
174
+					[]byte(strings.ReplaceAll(l.Description, "\r\n", "\n")),
175
+					blackfriday.WithExtensions(blackfriday.CommonExtensions))),
177 176
 			"ListJSON": string(b),
178 177
 			"Errors":   errs,
179 178
 		})

+ 0 - 1
templates/home.html

@@ -40,7 +40,6 @@
40 40
             <a href="/l/{{ $l.ID }}">
41 41
                 <li class="list">
42 42
                     <h3>{{ $l.Title }} ({{ $l.ID }})</h3>
43
-                    <p>{{ $l.Description }}</p>
44 43
                 </li>
45 44
             </a>
46 45
             {{ end }}

+ 3 - 2
templates/list.html

@@ -12,11 +12,12 @@
12 12
 
13 13
         <h1>{{ .List.Title }}</h1>
14 14
 
15
-        <p>{{ .List.Description }}</p>
15
+        {{ .Description }}
16 16
 
17 17
         <form method="post">
18 18
             <p>Update list: <input type="submit" /><br />
19
-                <textarea name="list_json" style="width:90%;height:500px;">{{ .ListJSON }}</textarea>
19
+                <input type="text" name="title" value="{{ .List.Title }}" /><br />
20
+                <textarea name="description" style="width:90%;height:500px;">{{ .List.Description }}</textarea>
20 21
             </p>
21 22
         </form>
22 23
     </body>