Documentation
¶
Index ¶
- Variables
- func Bold(text string) string
- func BoldItalic(text string) string
- func Code(text string) string
- func Highlight(text string) string
- func Image(text, url string) string
- func Italic(text string) string
- func Link(text, url string) string
- func Strikethrough(text string) string
- type CheckBoxSet
- type Markdown
- func (m *Markdown) Blockquote(text string) *Markdown
- func (m *Markdown) BlueBadge(text string) *Markdown
- func (m *Markdown) BlueBadgef(format string, args ...interface{}) *Markdown
- func (m *Markdown) Build() error
- func (m *Markdown) BulletList(items ...string) *Markdown
- func (m *Markdown) Caution(text string) *Markdown
- func (m *Markdown) Cautionf(format string, args ...interface{}) *Markdown
- func (m *Markdown) CheckBox(set []CheckBoxSet) *Markdown
- func (m *Markdown) CodeBlocks(lang SyntaxHighlight, text string) *Markdown
- func (m *Markdown) CustomTable(set TableSet, options TableOptions) *Markdown
- func (m *Markdown) Details(summary, text string) *Markdown
- func (m *Markdown) Detailsf(summary, format string, args ...interface{}) *Markdown
- func (m *Markdown) Error() error
- func (m *Markdown) GreenBadge(text string) *Markdown
- func (m *Markdown) GreenBadgef(format string, args ...interface{}) *Markdown
- func (m *Markdown) H1(text string) *Markdown
- func (m *Markdown) H1f(format string, args ...interface{}) *Markdown
- func (m *Markdown) H2(text string) *Markdown
- func (m *Markdown) H2f(format string, args ...interface{}) *Markdown
- func (m *Markdown) H3(text string) *Markdown
- func (m *Markdown) H3f(format string, args ...interface{}) *Markdown
- func (m *Markdown) H4(text string) *Markdown
- func (m *Markdown) H4f(format string, args ...interface{}) *Markdown
- func (m *Markdown) H5(text string) *Markdown
- func (m *Markdown) H5f(format string, args ...interface{}) *Markdown
- func (m *Markdown) H6(text string) *Markdown
- func (m *Markdown) H6f(format string, args ...interface{}) *Markdown
- func (m *Markdown) HorizontalRule() *Markdown
- func (m *Markdown) Important(text string) *Markdown
- func (m *Markdown) Importantf(format string, args ...interface{}) *Markdown
- func (m *Markdown) LF() *Markdown
- func (m *Markdown) Note(text string) *Markdown
- func (m *Markdown) Notef(format string, args ...interface{}) *Markdown
- func (m *Markdown) OrderedList(items ...string) *Markdown
- func (m *Markdown) PlainText(text string) *Markdown
- func (m *Markdown) PlainTextf(format string, args ...interface{}) *Markdown
- func (m *Markdown) RedBadge(text string) *Markdown
- func (m *Markdown) RedBadgef(format string, args ...interface{}) *Markdown
- func (m *Markdown) String() string
- func (m *Markdown) Table(set TableSet) *Markdown
- func (m *Markdown) TableOfContents(depth TableOfContentsDepth) *Markdown
- func (m *Markdown) Tip(text string) *Markdown
- func (m *Markdown) Tipf(format string, args ...interface{}) *Markdown
- func (m *Markdown) Warning(text string) *Markdown
- func (m *Markdown) Warningf(format string, args ...interface{}) *Markdown
- func (m *Markdown) YellowBadge(text string) *Markdown
- func (m *Markdown) YellowBadgef(format string, args ...interface{}) *Markdown
- type SyntaxHighlight
- type TableAlignment
- type TableOfContentsDepth
- type TableOptions
- type TableSet
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMismatchColumn is returned when the number of columns in the record doesn't match the header. ErrMismatchColumn = errors.New("number of columns in the record doesn't match the header") // ErrInitMarkdownIndex is returned when the index can't be initialized. ErrInitMarkdownIndex = errors.New("markdown index can't be initialized") // ErrCreateMarkdownIndex is returned when the index can't be created. ErrCreateMarkdownIndex = errors.New("markdown index can't be created") // ErrWriteMarkdownIndex is returned when the index can't be written. ErrWriteMarkdownIndex = errors.New("markdown index can't be written") )
Functions ¶
func BoldItalic ¶
BoldItalic return text with bold and italic format.
func Strikethrough ¶
Strikethrough return text with strikethrough format.
Types ¶
type CheckBoxSet ¶
CheckBoxSet configures a single checkbox entry.
type Markdown ¶
type Markdown struct {
// contains filtered or unexported fields
}
Markdown is markdown text.
func (*Markdown) Blockquote ¶
Blockquote appends a blockquote block.
func (*Markdown) BlueBadgef ¶
BlueBadgef set text with blue badge format.
func (*Markdown) BulletList ¶
BulletList appends an unordered list.
func (*Markdown) CheckBox ¶
func (m *Markdown) CheckBox(set []CheckBoxSet) *Markdown
CheckBox appends a checkbox list.
func (*Markdown) CodeBlocks ¶
func (m *Markdown) CodeBlocks(lang SyntaxHighlight, text string) *Markdown
CodeBlocks appends a fenced code block.
func (*Markdown) CustomTable ¶
func (m *Markdown) CustomTable(set TableSet, options TableOptions) *Markdown
CustomTable renders a table with optional formatting behaviors.
func (*Markdown) GreenBadge ¶
GreenBadge set text with green badge format.
func (*Markdown) GreenBadgef ¶
GreenBadgef set text with green badge format.
func (*Markdown) HorizontalRule ¶
HorizontalRule appends a thematic break.
func (*Markdown) Importantf ¶
Importantf set text with important format.
func (*Markdown) OrderedList ¶
OrderedList appends an ordered list.
func (*Markdown) PlainTextf ¶
PlainTextf set plain text with format
func (*Markdown) Table ¶
Table renders a markdown table using goldmark table AST nodes.
Example (Bars) ¶
ExampleMarkdown_Table_bars shows how to turn seven daily Bar values into a markdown table.
package main
import (
"fmt"
"os"
"time"
)
// Bar is an aggregate of trades.
type Bar struct {
Timestamp time.Time
Open float64
High float64
Low float64
Close float64
Volume uint64
TradeCount uint64
VWAP float64
}
// ExampleMarkdown_Table_bars shows how to turn seven daily Bar values into a markdown table.
func main() {
bars := []Bar{
{Timestamp: time.Date(2024, 10, 1, 0, 0, 0, 0, time.UTC), Open: 101.25, High: 105.50, Low: 100.90, Close: 104.20, Volume: 1200345, TradeCount: 3456, VWAP: 103.45},
{Timestamp: time.Date(2024, 10, 2, 0, 0, 0, 0, time.UTC), Open: 104.20, High: 106.80, Low: 103.75, Close: 105.10, Volume: 980456, TradeCount: 2980, VWAP: 104.95},
{Timestamp: time.Date(2024, 10, 3, 0, 0, 0, 0, time.UTC), Open: 105.10, High: 107.20, Low: 104.10, Close: 106.75, Volume: 1100456, TradeCount: 3104, VWAP: 106.15},
{Timestamp: time.Date(2024, 10, 4, 0, 0, 0, 0, time.UTC), Open: 106.75, High: 108.90, Low: 105.30, Close: 108.40, Volume: 1023400, TradeCount: 2890, VWAP: 107.85},
{Timestamp: time.Date(2024, 10, 5, 0, 0, 0, 0, time.UTC), Open: 108.40, High: 109.25, Low: 106.80, Close: 107.10, Volume: 954320, TradeCount: 2605, VWAP: 107.35},
{Timestamp: time.Date(2024, 10, 6, 0, 0, 0, 0, time.UTC), Open: 107.10, High: 108.75, Low: 106.40, Close: 108.20, Volume: 876540, TradeCount: 2400, VWAP: 107.95},
{Timestamp: time.Date(2024, 10, 7, 0, 0, 0, 0, time.UTC), Open: 108.20, High: 110.15, Low: 107.95, Close: 109.60, Volume: 1132050, TradeCount: 3250, VWAP: 109.05},
}
rows := make([][]string, len(bars))
for i, bar := range bars {
rows[i] = []string{
bar.Timestamp.Format("2006-01-02"),
fmt.Sprintf("%.2f", bar.Open),
fmt.Sprintf("%.2f", bar.High),
fmt.Sprintf("%.2f", bar.Low),
fmt.Sprintf("%.2f", bar.Close),
fmt.Sprintf("%d", bar.Volume),
fmt.Sprintf("%d", bar.TradeCount),
fmt.Sprintf("%.2f", bar.VWAP),
}
}
md := NewMarkdown(os.Stdout)
md.H2("Daily Bars")
md.Table(TableSet{
Header: []string{"Day", "Open", "High", "Low", "Close", "Volume", "Trades", "VWAP"},
Rows: rows,
})
if err := md.Build(); err != nil {
fmt.Fprintf(os.Stderr, "Error building markdown: %v\n", err)
return
}
}
Output: ## Daily Bars | Day | Open | High | Low | Close | Volume | Trades | VWAP | | ---------- | ------ | ------ | ------ | ------ | ------- | ------ | ------ | | 2024-10-01 | 101.25 | 105.50 | 100.90 | 104.20 | 1200345 | 3456 | 103.45 | | 2024-10-02 | 104.20 | 106.80 | 103.75 | 105.10 | 980456 | 2980 | 104.95 | | 2024-10-03 | 105.10 | 107.20 | 104.10 | 106.75 | 1100456 | 3104 | 106.15 | | 2024-10-04 | 106.75 | 108.90 | 105.30 | 108.40 | 1023400 | 2890 | 107.85 | | 2024-10-05 | 108.40 | 109.25 | 106.80 | 107.10 | 954320 | 2605 | 107.35 | | 2024-10-06 | 107.10 | 108.75 | 106.40 | 108.20 | 876540 | 2400 | 107.95 | | 2024-10-07 | 108.20 | 110.15 | 107.95 | 109.60 | 1132050 | 3250 | 109.05 |
func (*Markdown) TableOfContents ¶
func (m *Markdown) TableOfContents(depth TableOfContentsDepth) *Markdown
TableOfContents generates a table of contents from the recorded headers.
func (*Markdown) YellowBadge ¶
YellowBadge set text with yellow badge format.
func (*Markdown) YellowBadgef ¶
YellowBadgef set text with yellow badge format.
type SyntaxHighlight ¶
type SyntaxHighlight string
SyntaxHighlight is syntax highlight language.
const ( SyntaxHighlightNone SyntaxHighlight = "" SyntaxHighlightText SyntaxHighlight = "text" SyntaxHighlightAPIBlueprint SyntaxHighlight = "markdown" SyntaxHighlightShell SyntaxHighlight = "shell" SyntaxHighlightGo SyntaxHighlight = "go" SyntaxHighlightJSON SyntaxHighlight = "json" SyntaxHighlightYAML SyntaxHighlight = "yaml" SyntaxHighlightXML SyntaxHighlight = "xml" SyntaxHighlightHTML SyntaxHighlight = "html" SyntaxHighlightCSS SyntaxHighlight = "css" SyntaxHighlightJavaScript SyntaxHighlight = "javascript" SyntaxHighlightTypeScript SyntaxHighlight = "typescript" SyntaxHighlightSQL SyntaxHighlight = "sql" SyntaxHighlightC SyntaxHighlight = "c" SyntaxHighlightCSharp SyntaxHighlight = "csharp" SyntaxHighlightCPlusPlus SyntaxHighlight = "cpp" SyntaxHighlightJava SyntaxHighlight = "java" SyntaxHighlightKotlin SyntaxHighlight = "kotlin" SyntaxHighlightPHP SyntaxHighlight = "php" SyntaxHighlightPython SyntaxHighlight = "python" SyntaxHighlightRuby SyntaxHighlight = "ruby" SyntaxHighlightSwift SyntaxHighlight = "swift" SyntaxHighlightScala SyntaxHighlight = "scala" SyntaxHighlightRust SyntaxHighlight = "rust" SyntaxHighlightObjectiveC SyntaxHighlight = "objectivec" SyntaxHighlightPerl SyntaxHighlight = "perl" SyntaxHighlightLua SyntaxHighlight = "lua" SyntaxHighlightDart SyntaxHighlight = "dart" SyntaxHighlightClojure SyntaxHighlight = "clojure" SyntaxHighlightGroovy SyntaxHighlight = "groovy" SyntaxHighlightR SyntaxHighlight = "r" SyntaxHighlightHaskell SyntaxHighlight = "haskell" SyntaxHighlightErlang SyntaxHighlight = "erlang" SyntaxHighlightElixir SyntaxHighlight = "elixir" SyntaxHighlightOCaml SyntaxHighlight = "ocaml" SyntaxHighlightJulia SyntaxHighlight = "julia" SyntaxHighlightScheme SyntaxHighlight = "scheme" SyntaxHighlightFSharp SyntaxHighlight = "fsharp" SyntaxHighlightCoffeeScript SyntaxHighlight = "coffeescript" SyntaxHighlightVBNet SyntaxHighlight = "vbnet" SyntaxHighlightTeX SyntaxHighlight = "tex" SyntaxHighlightDiff SyntaxHighlight = "diff" SyntaxHighlightApache SyntaxHighlight = "apache" SyntaxHighlightDockerfile SyntaxHighlight = "dockerfile" SyntaxHighlightMermaid SyntaxHighlight = "mermaid" )
type TableAlignment ¶
type TableAlignment int
TableAlignment represents column alignment in markdown tables.
const ( // AlignDefault represents no specific alignment (left by default). AlignDefault TableAlignment = iota // AlignLeft represents left alignment (:------). AlignLeft // AlignCenter represents center alignment (:-----:). AlignCenter // AlignRight represents right alignment (------:). AlignRight )
type TableOfContentsDepth ¶
type TableOfContentsDepth int
TableOfContentsDepth represents the depth level for table of contents.
const ( TableOfContentsDepthH1 TableOfContentsDepth = 1 TableOfContentsDepthH2 TableOfContentsDepth = 2 TableOfContentsDepthH3 TableOfContentsDepth = 3 TableOfContentsDepthH4 TableOfContentsDepth = 4 TableOfContentsDepthH5 TableOfContentsDepth = 5 TableOfContentsDepthH6 TableOfContentsDepth = 6 )
type TableOptions ¶
TableOptions controls formatting when rendering custom tables.
type TableSet ¶
type TableSet struct {
Header []string
Rows [][]string
Alignment []TableAlignment
}
TableSet describes the content and layout for a markdown table.
func (*TableSet) ValidateColumns ¶
ValidateColumns checks if the number of columns in the header and records match.