Exemple #1
0
func (options *Console) StrikeThrough(out *bytes.Buffer, text []byte) {
	out.WriteString(ansi.ColorCode("008+s"))
	out.WriteString("\u2015")
	out.Write(text)
	out.WriteString("\u2015")
	out.WriteString(ansi.ColorCode("reset"))
}
Exemple #2
0
func (options *Console) BlockCode(out *bytes.Buffer, text []byte, lang string) {
	s := string(text)
	reg, _ := regexp.Compile("\\n")

	out.WriteString("\n    ")
	out.WriteString(ansi.ColorCode("015"))
	out.WriteString(reg.ReplaceAllString(s, "\n    "))
	out.WriteString(ansi.ColorCode("reset"))
	out.WriteString("\n")
}
Exemple #3
0
func (options *Console) TitleBlock(out *bytes.Buffer, text []byte) {
	out.WriteString("\n")
	out.WriteString(headerStyles[0])
	out.Write(text)
	out.WriteString(ansi.ColorCode("reset"))
	out.WriteString("\n\n")
}
Exemple #4
0
func (options *Console) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) {
	out.Write(content)
	out.WriteString(" (")
	out.WriteString(linkStyle)
	out.Write(link)
	out.WriteString(ansi.ColorCode("reset"))
	out.WriteString(")")
}
Exemple #5
0
func (options *Console) ListItem(out *bytes.Buffer, text []byte, flags int) {
	current := options.lists[len(options.lists)-1]

	for i := 0; i < len(options.lists); i++ {
		out.WriteString("  ")
	}

	if current.kind == ORDERED {
		out.WriteString(fmt.Sprintf("%d. ", current.index))
		current.index += 1
	} else {
		out.WriteString(ansi.ColorCode("red+bh"))
		out.WriteString("* ")
		out.WriteString(ansi.ColorCode("reset"))
	}

	out.Write(text)
	out.WriteString("\n\n")
}
Exemple #6
0
func (options *Console) Header(out *bytes.Buffer, text func() bool, level int, id string) {
	out.WriteString("\n")
	out.WriteString(headerStyles[level-1])

	marker := out.Len()
	if !text() {
		out.Truncate(marker)
		return
	}

	out.WriteString(ansi.ColorCode("reset"))
	out.WriteString("\n\n")
}
Exemple #7
0
func (options *Console) TripleEmphasis(out *bytes.Buffer, text []byte) {
	out.WriteString(emphasisStyles[2])
	out.Write(text)
	out.WriteString(ansi.ColorCode("reset"))
}
Exemple #8
0
func (options *Console) RawHtmlTag(out *bytes.Buffer, tag []byte) {
	out.WriteString(ansi.ColorCode("magenta"))
	out.Write(tag)
	out.WriteString(ansi.ColorCode("reset"))
}
Exemple #9
0
func (options *Console) CodeSpan(out *bytes.Buffer, text []byte) {
	out.WriteString(ansi.ColorCode("015+b"))
	out.Write(text)
	out.WriteString(ansi.ColorCode("reset"))
}
Exemple #10
0
func (options *Console) AutoLink(out *bytes.Buffer, link []byte, kind int) {
	out.WriteString(linkStyle)
	out.Write(link)
	out.WriteString(ansi.ColorCode("reset"))
}
Exemple #11
0
package main

import (
	"bytes"
	"fmt"
	"github.com/russross/blackfriday"
	"github.com/samfoo/ansi"
	"html"
	"regexp"
	"strings"
)

// Index corresponds to the heading level (e.g. h1, h2, h3...)
var headerStyles = [...]string{
	ansi.ColorCode("yellow+bhu"),
	ansi.ColorCode("yellow+bh"),
	ansi.ColorCode("yellow"),
	ansi.ColorCode("yellow"),
}

var emphasisStyles = [...]string{
	ansi.ColorCode("cyan+bh"),
	ansi.ColorCode("cyan+bhu"),
	ansi.ColorCode("cyan+bhi"),
}

var linkStyle = ansi.ColorCode("015+u")

const (
	UNORDERED = 1 << iota
	ORDERED