add title

This commit is contained in:
Mark McGranaghan 2012-09-29 14:06:57 -07:00
parent f57c28f42c
commit dbf69907cc
2 changed files with 15 additions and 7 deletions

View File

@ -3,7 +3,7 @@
<html>
<head>
<meta http-eqiv="content-type" content="text/html;charset=utf-8">
<title>Page Title</title>
<title>golit</title>
<link rel=stylesheet href="book.css">
</head>
<body>
@ -35,6 +35,11 @@ documentation form Go source files.</p>
<tr><td class=docs><p>Recognize doc lines, extract their comment prefixes.</p>
</td><td class=code><div class="highlight"><pre><span class="k">var</span> <span class="n">docsPat</span> <span class="p">=</span> <span class="n">regexp</span><span class="p">.</span><span class="n">MustCompile</span><span class="p">(</span><span class="s">&quot;^\\s*\\/\\/\\s&quot;</span><span class="p">)</span>
</pre></div>
</td></tr>
<tr><td class=docs><p>Recognize title prefixes, for titling web page.</p>
</td><td class=code><div class="highlight"><pre><span class="k">var</span> <span class="n">titlePat</span> <span class="p">=</span> <span class="n">regexp</span><span class="p">.</span><span class="n">MustCompile</span><span class="p">(</span><span class="s">&quot;^\\/\\/\\s##\\s&quot;</span><span class="p">)</span>
</pre></div>
</td></tr>
<tr><td class=docs><p>Abort on non-nil errors.</p>
@ -148,12 +153,12 @@ Special case the header to go in its own segment.</p>
</pre></div>
</td></tr>
<tr><td class=docs><p>Print HTML header.</p>
</td><td class=code><div class="highlight"><pre> <span class="n">fmt</span><span class="p">.</span><span class="n">Print</span><span class="p">(</span><span class="s">`</span>
</td><td class=code><div class="highlight"><pre> <span class="n">fmt</span><span class="p">.</span><span class="n">Printf</span><span class="p">(</span><span class="s">`</span>
<span class="s">&lt;!DOCTYPE html&gt;</span>
<span class="s">&lt;html&gt;</span>
<span class="s"> &lt;head&gt;</span>
<span class="s"> &lt;meta http-eqiv=&quot;content-type&quot; content=&quot;text/html;charset=utf-8&quot;&gt;</span>
<span class="s"> &lt;title&gt;Page Title&lt;/title&gt;</span>
<span class="s"> &lt;title&gt;%s&lt;/title&gt;</span>
<span class="s"> &lt;link rel=stylesheet href=&quot;book.css&quot;&gt;</span>
<span class="s"> &lt;/head&gt;</span>
<span class="s"> &lt;body&gt;</span>
@ -163,7 +168,7 @@ Special case the header to go in its own segment.</p>
<span class="s"> &lt;thead&gt;</span>
<span class="s"> &lt;tr&gt;&lt;td class=docs&gt;&lt;/td&gt;&lt;td class=code&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<span class="s"> &lt;/thead&gt;</span>
<span class="s"> &lt;tbody&gt;`</span><span class="p">)</span>
<span class="s"> &lt;tbody&gt;`</span><span class="p">,</span> <span class="n">titlePat</span><span class="p">.</span><span class="n">ReplaceAllString</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s">&quot;&quot;</span><span class="p">))</span>
</pre></div>
</td></tr>

View File

@ -17,6 +17,9 @@ import (
// Recognize doc lines, extract their comment prefixes.
var docsPat = regexp.MustCompile("^\\s*\\/\\/\\s")
// Recognize title prefixes, for titling web page.
var titlePat = regexp.MustCompile("^\\/\\/\\s##\\s")
// Abort on non-nil errors.
func check(err error) {
if err != nil {
@ -108,12 +111,12 @@ func main() {
}
// Print HTML header.
fmt.Print(`
fmt.Printf(`
<!DOCTYPE html>
<html>
<head>
<meta http-eqiv="content-type" content="text/html;charset=utf-8">
<title>Page Title</title>
<title>%s</title>
<link rel=stylesheet href="book.css">
</head>
<body>
@ -123,7 +126,7 @@ func main() {
<thead>
<tr><td class=docs></td><td class=code></td></tr>
</thead>
<tbody>`)
<tbody>`, titlePat.ReplaceAllString(lines[0], ""))
// Print HTML docs/code segments.
for _, seg := range segments {