Quellcode durchsuchen

Render markdown files

Lucas Stadler vor 8 Jahren
Ursprung
Commit
134e2aaaf2
1 geänderte Dateien mit 24 neuen und 4 gelöschten Zeilen
  1. 24 4
      quit.go

+ 24 - 4
quit.go

10
	"time"
10
	"time"
11
11
12
	"github.com/libgit2/git2go"
12
	"github.com/libgit2/git2go"
13
	"github.com/russross/blackfriday"
13
)
14
)
14
15
15
func main() {
16
func main() {
174
	return strings.ToLower(fc.entry.Type.String())
175
	return strings.ToLower(fc.entry.Type.String())
175
}
176
}
176
177
177
func (fc *FancyFile) Contents() (string, error) {
178
func (fc *FancyFile) RawContents() (string, error) {
178
	blob, err := fc.repo.LookupBlob(fc.entry.Id)
179
	blob, err := fc.repo.LookupBlob(fc.entry.Id)
179
	if err != nil {
180
	if err != nil {
180
		return "", err
181
		return "", err
183
	return string(blob.Contents()), nil
184
	return string(blob.Contents()), nil
184
}
185
}
185
186
187
func (fc *FancyFile) Contents() (template.HTML, error) {
188
	blob, err := fc.repo.LookupBlob(fc.entry.Id)
189
	if err != nil {
190
		return "", err
191
	}
192
193
	buf := new(bytes.Buffer)
194
	contents := blob.Contents()
195
	if strings.HasSuffix(fc.entry.Name, ".md") {
196
		buf.Write(blackfriday.MarkdownCommon(contents))
197
	} else {
198
		buf.WriteString("<code><pre>")
199
		template.HTMLEscape(buf, contents)
200
		buf.WriteString("</pre></code>")
201
	}
202
203
	return template.HTML(buf.String()), nil
204
}
205
186
var repoTmpl = template.Must(template.New("").Parse(`<!doctype html>
206
var repoTmpl = template.Must(template.New("").Parse(`<!doctype html>
187
<html>
207
<html>
188
	<head>
208
	<head>
210
		{{ if .Repo.Commit.Readme }}
230
		{{ if .Repo.Commit.Readme }}
211
		<section id="file" class="readme">
231
		<section id="file" class="readme">
212
			<h1>{{ .Repo.Commit.Readme.Name }}</h1>
232
			<h1>{{ .Repo.Commit.Readme.Name }}</h1>
213
			<code>
214
				<pre>{{ .Repo.Commit.Readme.Contents }}</pre>
215
			</code>
233
			<div class="contents">
234
				{{ .Repo.Commit.Readme.Contents }}
235
			</div>
216
		</section>
236
		</section>
217
		{{ end }}
237
		{{ end }}
218
	</body>
238
	</body>