Exemple #1
0
func (this MarkdownHandlerFunc) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	markdown, err := this(req)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if _, plain := req.URL.Query()["plain"]; plain {
		w.Header().Set("Content-Type", "text/plain")
		w.Write(markdown)
	} else if _, github := req.URL.Query()["github"]; github {
		w.Header().Set("Content-Type", "text/html")
		started := time.Now()
		u1.WriteGitHubFlavoredMarkdownViaGitHub(w, markdown)
		fmt.Println("rendered GFM via GitHub, took", time.Since(started))
	} else {
		w.Header().Set("Content-Type", "text/html")
		started := time.Now()
		u1.WriteGitHubFlavoredMarkdownViaLocal(w, markdown)
		fmt.Println("rendered GFM locally, took", time.Since(started))
	}
}
Exemple #2
0
func (this MarkdownOptionsHandlerFunc) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	markdown, opt, err := this(req)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if opt == nil {
		opt = &Options{}
	}

	if _, plain := req.URL.Query()["plain"]; plain {
		w.Header().Set("Content-Type", "text/plain")
		w.Write(markdown)
	} else if _, github := req.URL.Query()["github"]; github {
		w.Header().Set("Content-Type", "text/html")
		started := time.Now()
		switch opt.TableOfContents {
		case false:
			u1.WriteGitHubFlavoredMarkdownViaGitHub(w, markdown)
		case true:
			http.Error(w, "not implemented", 500)
			panic("not implemented")
		}
		fmt.Println("rendered GFM via GitHub, took", time.Since(started))
	} else {
		w.Header().Set("Content-Type", "text/html")
		started := time.Now()
		switch opt.TableOfContents {
		case false:
			u1.WriteGitHubFlavoredMarkdownViaLocal(w, markdown)
		case true:
			writeGitHubFlavoredMarkdownViaLocalWithToc(w, markdown)
		}
		fmt.Println("rendered GFM locally, took", time.Since(started))
	}
}