-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced.go
95 lines (82 loc) · 3.31 KB
/
advanced.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package gomarkdown
import (
"fmt"
"strings"
)
// Table generates a table
func (mw *MarkdownWriter) Table(headers []string, rows [][]string) {
mw.writeLine(strings.Join(headers, " | "))
mw.writeLine(strings.Repeat("--- | ", len(headers)))
for _, row := range rows {
mw.writeLine(strings.Join(row, " | "))
}
}
// TaskList generates a task list
func (mw *MarkdownWriter) TaskList(items []*TaskModel) {
for _, item := range items {
status := " "
if item.Done {
status = "x"
}
mw.writeLine(fmt.Sprintf("- [%s] %s", status, item.Text))
}
}
// AlertBox generates a GitHub-style alert box
func (mw *MarkdownWriter) AlertBox(alertType, text string) error {
switch alertType {
case "note":
return mw.writeLine(fmt.Sprintf("> **Note**: %s", text))
case "warning":
return mw.writeLine(fmt.Sprintf("> **Warning**: %s", text))
case "danger":
return mw.writeLine(fmt.Sprintf("> **Danger**: %s", text))
default:
return mw.writeLine(fmt.Sprintf("> %s", text))
}
}
// Image generates an image
func (mw *MarkdownWriter) Image(altText, url string) {
mw.writeLine(fmt.Sprintf("![%s](%s)", altText, url))
}
// ImageWithSize generates an image with specified width and height
func (mw *MarkdownWriter) ImageWithSize(altText, url string, width, height int) error {
// If both width and height are provided, use both; otherwise, use only the specified dimension
if width > 0 && height > 0 {
return mw.writeLine(fmt.Sprintf("<img src=\"%s\" alt=\"%s\" width=\"%d\" height=\"%d\" />", url, altText, width, height))
} else if width > 0 {
return mw.writeLine(fmt.Sprintf("<img src=\"%s\" alt=\"%s\" width=\"%d\" />", url, altText, width))
} else if height > 0 {
return mw.writeLine(fmt.Sprintf("<img src=\"%s\" alt=\"%s\" height=\"%d\" />", url, altText, height))
}
// Default to the original Image function if no size is specified
return mw.writeLine(fmt.Sprintf("![%s](%s)", altText, url))
}
// ImageWithScale generates an image with a specified zoom percentage
func (mw *MarkdownWriter) ImageWithScale(altText, url string, scale int) error {
// Ensure scale is a positive integer
if scale <= 0 {
return fmt.Errorf("scale must be a positive integer")
}
// Generate the image with a specified zoom percentage
return mw.writeLine(fmt.Sprintf("<img src=\"%s\" alt=\"%s\" style=\"zoom:%d%%;\" />", url, altText, scale))
}
// SequenceDiagram generates a sequence diagram using Mermaid syntax
func (mw *MarkdownWriter) SequenceDiagram(content string) error {
return mw.writeLine(fmt.Sprintf("```mermaid\nsequenceDiagram\n%s\n```", content))
}
// Flowchart generates a flowchart using Mermaid syntax
func (mw *MarkdownWriter) Flowchart(content string) error {
return mw.writeLine(fmt.Sprintf("```mermaid\nflowchart TD\n%s\n```", content))
}
// MermaidDiagram generates a custom Mermaid diagram
func (mw *MarkdownWriter) MermaidDiagram(content string) error {
return mw.writeLine(fmt.Sprintf("```mermaid\n%s\n```", content))
}
// CodeBlockMath generates a code block containing a mathematical expression using LaTeX syntax
func (mw *MarkdownWriter) CodeBlockMath(expression string) error {
return mw.writeLine(fmt.Sprintf("```math\n%s\n```", expression))
}
// InlineMath generates inline mathematical expressions using LaTeX syntax
func (mw *MarkdownWriter) InlineMath(expression string) error {
return mw.writeLine(fmt.Sprintf("$%s$", expression))
}