From 29494bd0287f2e4e057ddc3952ae71cc2f3d78d9 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Mon, 8 Oct 2012 11:06:20 -0700 Subject: [PATCH] use markdown for title and introduction --- src/book.css | 2 +- src/introduction.html | 30 ------------------------------ src/introduction.md | 28 ++++++++++++++++++++++++++++ src/title.html | 5 ----- src/title.md | 3 +++ tool/build-html.go | 21 +++++++++++++++++---- 6 files changed, 49 insertions(+), 40 deletions(-) delete mode 100644 src/introduction.html create mode 100644 src/introduction.md delete mode 100644 src/title.html create mode 100644 src/title.md diff --git a/src/book.css b/src/book.css index 9d3233d..cb7a6cc 100644 --- a/src/book.css +++ b/src/book.css @@ -28,7 +28,7 @@ div#title h1 { font-size: 72px; margin-top: 4em; } -div#title h4 { +div#title h3 { font-size: 24px; margin-top: 4em; margin-bottom: 18em; diff --git a/src/introduction.html b/src/introduction.html deleted file mode 100644 index 2d2a795..0000000 --- a/src/introduction.html +++ /dev/null @@ -1,30 +0,0 @@ -

Introduction

- -

Go is an open-source programming language designed for - building simple, fast, and reliable software. It's - powerful to use and fun to learn.

- -

This book is a hands-on introduction to Go. It gives - you the tools you need to understand the why of Go and - how to write real Go programs.

- - -

Intended Audience

- -

This book is intended for experienced programmers who - may be new to Go. If you have previous experience with - languages like Ruby, Python, Javascript, C#, or Java, - you should find this book immediately approachable even - if this is your first introduction to Go. Even if - you've worked with Go before, you may find that the - material covers ideas and techniques that you haven't - seen elsewhere.

- - -

An Example-Based Approach

- -

We believe that programmers learn to program by writing - programs. Go by Example therefore teaches Go - exclusively via working example programs, with each - chapter trying to provide the programmer a new tool for - writing her own programs.

diff --git a/src/introduction.md b/src/introduction.md new file mode 100644 index 0000000..678b89d --- /dev/null +++ b/src/introduction.md @@ -0,0 +1,28 @@ +## Introduction + +Go is an open-source programming language designed for +building simple, fast, and reliable software. +It's powerful to use and fun to learn. + +This book is a hands-on introduction to Go. It gives you +the tools you need to understand the why of Go and how to +write real Go programs. + +### Intended Audience + +This book is intended for experienced programmers who may +be new to Go. If you have previous experience with +languages like Ruby, Python, Javascript, C#, or Java, you +should find this book immediately approachable even if +this is your first introduction to Go. Even if you've +worked with Go before, you may find that the material +covers ideas and techniques that you haven't seen +elsewhere. + +### An Example-Based Approach + +Programmers learn to program by writing programs. +_Go by Example_ therefore teaches Go exclusively via +working example programs, with each chapter trying to +provide the programmer a new tool for writing her own +programs. diff --git a/src/title.html b/src/title.html deleted file mode 100644 index d3b4dd2..0000000 --- a/src/title.html +++ /dev/null @@ -1,5 +0,0 @@ -
-

Go by Example

- -

Mark McGranaghan

-
diff --git a/src/title.md b/src/title.md new file mode 100644 index 0000000..f7b5481 --- /dev/null +++ b/src/title.md @@ -0,0 +1,3 @@ +# Go by Example + +### Mark McGranaghan diff --git a/tool/build-html.go b/tool/build-html.go index 9331e1c..7479704 100644 --- a/tool/build-html.go +++ b/tool/build-html.go @@ -69,11 +69,22 @@ func cachedRender(bin string, arg []string, src string) string { return string(renderBytes) } +func cachedPygmentize(lex string, src string) string { + return cachedRender( + "/usr/local/bin/pygmentize", + []string{"-l", lex, "-f", "html"}, + src) +} + func ensureCache() { mkdirErr := os.MkdirAll(cacheDir, 0700) check(mkdirErr) } +func markdown(src string) string { + return string(blackfriday.MarkdownCommon([]byte(src))) +} + func readLines(path string) []string { src := mustReadFile(path) return strings.Split(src, "\n") @@ -170,10 +181,10 @@ func parseAndRenderSegs(sourcePath string) []*seg { lexer := whichLexer(sourcePath) for _, seg := range segs { if seg.docs != "" { - seg.docsRendered = string(blackfriday.MarkdownCommon([]byte(seg.docs))) + seg.docsRendered = markdown(seg.docs) } if seg.code != "" { - seg.codeRendered = cachedRender("/usr/local/bin/pygmentize", []string{"-l", lexer, "-f", "html"}, seg.code) + seg.codeRendered = cachedPygmentize(lexer, seg.code) } } return segs @@ -199,7 +210,9 @@ func main() { `) // Title page - fmt.Fprint(outF, mustReadFile("src/title.html")) + fmt.Fprintf(outF, + `
%s
`, + markdown(mustReadFile("src/title.md"))) // Contents page chapterIds := readLines("src/contents.txt") @@ -220,7 +233,7 @@ func main() { for _, chapterId := range chapterIds { fmt.Fprintf(outF, `
`, chapterId) if chapterId == "introduction" { - fmt.Fprint(outF, mustReadFile("src/introduction.html")) + fmt.Fprint(outF, markdown(mustReadFile("src/introduction.md"))) } else { chapterPath := "src/" + chapterId fmt.Fprintf(outF,