github_flavored_markdown

package
v0.0.0-...-8d38f2a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2015 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package github_flavored_markdown provides a GitHub Flavored Markdown renderer with fenced code block highlighting, clickable header anchor links.

The functionality should be equivalent to the GitHub Markdown API endpoint specified at https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode, except the rendering is performed locally.

See example below for how to generate a complete HTML page, including CSS styles.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Markdown

func Markdown(text []byte) []byte

Markdown renders GitHub Flavored Markdown text.

Example
package main

import (
	"os"

	"github.com/shurcooL/go/github_flavored_markdown"
)

func main() {
	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>
Example (CompleteHtmlPage)

An example of how to generate a complete HTML page, including CSS styles.

package main

import (
	"io"
	"os"

	"github.com/shurcooL/go/github_flavored_markdown"
)

func main() {
	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>

Types

This section is empty.

Directories

Path Synopsis
Package sanitized_anchor_name provides a func to create sanitized anchor names.
Package sanitized_anchor_name provides a func to create sanitized anchor names.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL