示例#1
0
文件: renderer.go 项目: samfoo/mdcat
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"))
}
示例#2
0
文件: renderer.go 项目: samfoo/mdcat
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")
}
示例#3
0
文件: renderer.go 项目: samfoo/mdcat
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")
}
示例#4
0
文件: renderer.go 项目: samfoo/mdcat
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(")")
}
示例#5
0
文件: renderer.go 项目: samfoo/mdcat
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")
}
示例#6
0
文件: renderer.go 项目: samfoo/mdcat
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")
}
示例#7
0
文件: renderer.go 项目: samfoo/mdcat
func (options *Console) TripleEmphasis(out *bytes.Buffer, text []byte) {
	out.WriteString(emphasisStyles[2])
	out.Write(text)
	out.WriteString(ansi.ColorCode("reset"))
}
示例#8
0
文件: renderer.go 项目: samfoo/mdcat
func (options *Console) RawHtmlTag(out *bytes.Buffer, tag []byte) {
	out.WriteString(ansi.ColorCode("magenta"))
	out.Write(tag)
	out.WriteString(ansi.ColorCode("reset"))
}
示例#9
0
文件: renderer.go 项目: samfoo/mdcat
func (options *Console) CodeSpan(out *bytes.Buffer, text []byte) {
	out.WriteString(ansi.ColorCode("015+b"))
	out.Write(text)
	out.WriteString(ansi.ColorCode("reset"))
}
示例#10
0
文件: renderer.go 项目: samfoo/mdcat
func (options *Console) AutoLink(out *bytes.Buffer, link []byte, kind int) {
	out.WriteString(linkStyle)
	out.Write(link)
	out.WriteString(ansi.ColorCode("reset"))
}
示例#11
0
文件: renderer.go 项目: samfoo/mdcat
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