コード例 #1
0
ファイル: web.go プロジェクト: rechen/wharf
func (this *WebController) GetRepository() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repository")

	repo := new(models.Repository)
	if exist, _, _ := repo.Has(namespace, repository); exist {
		user, exist := this.Ctx.Input.CruSession.Get("user").(models.User)
		if repo.Privated {
			if !exist == true {
				this.Abort("404")
				return
			} else {
				if user.Username != namespace {
					this.Abort("404")
					return
				}
				this.Data["username"] = user.Username
				this.Data["privated"] = repo.Privated
				this.Data["namespace"] = repo.Namespace
				this.Data["repository"] = repo.Repository
				this.Data["created"] = repo.Created
				this.Data["short"] = repo.Short
				this.Data["description"] = string(github_flavored_markdown.Markdown([]byte(repo.Description)))
				this.Data["download"] = repo.Download
				this.Data["comments"] = len(repo.Comments)
				this.Data["starts"] = len(repo.Starts)

				this.TplNames = "repository.html"
				this.Render()
				return
			}
		} else {
			this.Data["username"] = user.Username
			this.Data["privated"] = repo.Privated
			this.Data["namespace"] = repo.Namespace
			this.Data["repository"] = repo.Repository
			this.Data["created"] = repo.Created
			this.Data["short"] = repo.Short
			this.Data["description"] = string(github_flavored_markdown.Markdown([]byte(repo.Description)))
			this.Data["download"] = repo.Download
			this.Data["comments"] = len(repo.Comments)
			this.Data["starts"] = len(repo.Starts)

			this.TplNames = "repository.html"
			this.Render()
			return
		}
	} else {
		this.Abort("404")
		return
	}
	return
}
コード例 #2
0
ファイル: main_test.go プロジェクト: rechen/wharf
func ExampleMarkdown() {
	text := []byte("Hello world github/linguist#1 **cool**, and #1!")

	os.Stdout.Write(github_flavored_markdown.Markdown(text))

	// Output:
	//<p>Hello world github/linguist#1 <strong>cool</strong>, and #1!</p>
}
コード例 #3
0
ファイル: main_test.go プロジェクト: rechen/wharf
func ExampleHeader() {
	text := []byte("## git diff")

	os.Stdout.Write(github_flavored_markdown.Markdown(text))

	// Output:
	//<h2><a name="git-diff" class="anchor" href="#git-diff" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>git diff</h2>
}
コード例 #4
0
ファイル: main.go プロジェクト: rheinwein/markdown-parser
func main() {
	m := martini.Classic()
	m.Post("/parse-github-markdown", func(r *http.Request) []byte {
		formBody := r.FormValue("parse")
		return gh.Markdown([]byte(formBody))
	})

	m.Post("/parse", func(r *http.Request) []byte {
		formBody := r.FormValue("parse")
		return blackfriday.MarkdownBasic([]byte(formBody))
	})

	m.Run()
}
コード例 #5
0
ファイル: main_test.go プロジェクト: rechen/wharf
// An example of how to generate a complete HTML page, including CSS styles.
func ExampleMarkdown_completeHtmlPage() {
	var w io.Writer = os.Stdout // It can be an http.ResponseWriter.
	markdown := []byte("# GitHub Flavored Markdown\n\nHello.")

	io.WriteString(w, `<html><head><meta charset="utf-8"><link href=".../github-flavored-markdown.css" media="all" rel="stylesheet" type="text/css" /><link href="//cdnjs.cloudflare.com/ajax/libs/octicons/2.1.2/octicons.css" media="all" rel="stylesheet" type="text/css" /></head><body><article class="markdown-body entry-content" style="padding: 30px;">`)
	w.Write(github_flavored_markdown.Markdown(markdown))
	io.WriteString(w, `</article></body></html>`)

	// Output:
	//<html><head><meta charset="utf-8"><link href=".../github-flavored-markdown.css" media="all" rel="stylesheet" type="text/css" /><link href="//cdnjs.cloudflare.com/ajax/libs/octicons/2.1.2/octicons.css" media="all" rel="stylesheet" type="text/css" /></head><body><article class="markdown-body entry-content" style="padding: 30px;"><h1><a name="github-flavored-markdown" class="anchor" href="#github-flavored-markdown" rel="nofollow" aria-hidden="true"><span class="octicon octicon-link"></span></a>GitHub Flavored Markdown</h1>
	//
	//<p>Hello.</p>
	//</article></body></html>
}
コード例 #6
0
ファイル: repos.go プロジェクト: hawx/ggg
func (r *Repo) getReadme() {
	if r.Readme.Contents != "" {
		return
	}

	if r.Branch == "" {
		r.Branch = git.GetDefaultBranch(r.Path)
	}

	for _, file := range []string{"README.md", "Readme.md", "README.markdown", "readme.markdown"} {
		text, err := git.ReadFile(r.Path, r.Branch, file)
		if err != nil {
			log.Println(r.Name, "Readme(): ", err)
			continue
		}

		r.Readme = Readme{
			file,
			template.HTML(github_flavored_markdown.Markdown([]byte(text))),
		}

		return
	}

	for _, file := range []string{"README"} {
		text, err := git.ReadFile(r.Path, r.Branch, file)
		if err != nil {
			log.Println(r.Name, "Readme():", err)
			continue
		}

		r.Readme = Readme{file, template.HTML("<pre class='full'>" + text + "</pre>")}
		return
	}

	r.Readme = Readme{"README", "&hellip;"}
}