Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bistutu authored and gochen committed Oct 21, 2024
1 parent 8c8c2c5 commit 228fd59
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
22 changes: 11 additions & 11 deletions advanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Table generates a table
func (mw *markdownWriter) Table(headers []string, rows [][]string) {
func (mw *MarkdownWriter) Table(headers []string, rows [][]string) {
mw.writeLine(strings.Join(headers, " | "))
mw.writeLine(strings.Repeat("--- | ", len(headers)))
for _, row := range rows {
Expand All @@ -15,7 +15,7 @@ func (mw *markdownWriter) Table(headers []string, rows [][]string) {
}

// TaskList generates a task list
func (mw *markdownWriter) TaskList(items []*TaskModel) {
func (mw *MarkdownWriter) TaskList(items []*TaskModel) {
for _, item := range items {
status := " "
if item.Done {
Expand All @@ -26,7 +26,7 @@ func (mw *markdownWriter) TaskList(items []*TaskModel) {
}

// AlertBox generates a GitHub-style alert box
func (mw *markdownWriter) AlertBox(alertType, text string) error {
func (mw *MarkdownWriter) AlertBox(alertType, text string) error {
switch alertType {
case "note":
return mw.writeLine(fmt.Sprintf("> **Note**: %s", text))
Expand All @@ -40,12 +40,12 @@ func (mw *markdownWriter) AlertBox(alertType, text string) error {
}

// Image generates an image
func (mw *markdownWriter) Image(altText, url string) {
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 {
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))
Expand All @@ -59,7 +59,7 @@ func (mw *markdownWriter) ImageWithSize(altText, url string, width, height int)
}

// ImageWithScale generates an image with a specified zoom percentage
func (mw *markdownWriter) ImageWithScale(altText, url string, scale int) error {
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")
Expand All @@ -70,26 +70,26 @@ func (mw *markdownWriter) ImageWithScale(altText, url string, scale int) error {
}

// SequenceDiagram generates a sequence diagram using Mermaid syntax
func (mw *markdownWriter) SequenceDiagram(content string) error {
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 {
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 {
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 {
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 {
func (mw *MarkdownWriter) InlineMath(expression string) error {
return mw.writeLine(fmt.Sprintf("$%s$", expression))
}
50 changes: 25 additions & 25 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,136 +6,136 @@ import (
)

// Text generates plain text.
func (mw *markdownWriter) Text(text string) error {
func (mw *MarkdownWriter) Text(text string) error {
return mw.writeLine(text)
}

// H1 generates a level 1 heading
func (mw *markdownWriter) H1(text string) error {
func (mw *MarkdownWriter) H1(text string) error {
return mw.writeLine(fmt.Sprintf("# %s", text))
}

// H2 generates a level 2 heading
func (mw *markdownWriter) H2(text string) error {
func (mw *MarkdownWriter) H2(text string) error {
return mw.writeLine(fmt.Sprintf("## %s", text))
}

// H3 generates a level 3 heading
func (mw *markdownWriter) H3(text string) error {
func (mw *MarkdownWriter) H3(text string) error {
return mw.writeLine(fmt.Sprintf("### %s", text))
}

// H4 generates a level 4 heading
func (mw *markdownWriter) H4(text string) error {
func (mw *MarkdownWriter) H4(text string) error {
return mw.writeLine(fmt.Sprintf("#### %s", text))
}

// H5 generates a level 5 heading
func (mw *markdownWriter) H5(text string) error {
func (mw *MarkdownWriter) H5(text string) error {
return mw.writeLine(fmt.Sprintf("##### %s", text))
}

// H6 generates a level 6 heading
func (mw *markdownWriter) H6(text string) error {
func (mw *MarkdownWriter) H6(text string) error {
return mw.writeLine(fmt.Sprintf("###### %s", text))
}

// Hr generates a horizontal rule
func (mw *markdownWriter) Hr() error {
func (mw *MarkdownWriter) Hr() error {
return mw.writeLine("---")
}

// Bold generates bold text
func (mw *markdownWriter) Bold(text string) error {
func (mw *MarkdownWriter) Bold(text string) error {
return mw.writeLine(fmt.Sprintf("**%s**", text))
}

// Italic generates italic text
func (mw *markdownWriter) Italic(text string) error {
func (mw *MarkdownWriter) Italic(text string) error {
return mw.writeLine(fmt.Sprintf("*%s*", text))
}

// Strikethrough generates strikethrough text
func (mw *markdownWriter) Strikethrough(text string) error {
func (mw *MarkdownWriter) Strikethrough(text string) error {
return mw.writeLine(fmt.Sprintf("~~%s~~", text))
}

// InlineCode generates inline code
func (mw *markdownWriter) InlineCode(code string) error {
func (mw *MarkdownWriter) InlineCode(code string) error {
return mw.writeLine(fmt.Sprintf("`%s`", code))
}

// Footnote generates a footnote
func (mw *markdownWriter) Footnote(identifier, text string) error {
func (mw *MarkdownWriter) Footnote(identifier, text string) error {
mw.writeLine(fmt.Sprintf("[%s]: %s", identifier, text))
return nil
}

// Highlight generates highlighted text
func (mw *markdownWriter) Highlight(text string) error {
func (mw *MarkdownWriter) Highlight(text string) error {
return mw.writeLine(fmt.Sprintf("==%s==", text))
}

// CustomHTML inserts custom HTML content
func (mw *markdownWriter) CustomHTML(html string) error {
func (mw *MarkdownWriter) CustomHTML(html string) error {
return mw.writeLine(html)
}

// Code generates a code block
func (mw *markdownWriter) Code(language, code string) {
func (mw *MarkdownWriter) Code(language, code string) {
mw.writeLine(fmt.Sprintf("```%s\n%s\n```", language, code))
}

// List generates an unordered list
func (mw *markdownWriter) List(items []string) {
func (mw *MarkdownWriter) List(items []string) {
for _, item := range items {
mw.writeLine(fmt.Sprintf("- %s", item))
}
}

// Link generates a hyperlink
func (mw *markdownWriter) Link(text, url string) {
func (mw *MarkdownWriter) Link(text, url string) {
mw.writeLine(fmt.Sprintf("[%s](%s)", text, url))
}

// Quote generates a blockquote
func (mw *markdownWriter) Quote(text string) {
func (mw *MarkdownWriter) Quote(text string) {
mw.writeLine(fmt.Sprintf("> %s", text))
}

// Subscript generates subscript text
func (mw *markdownWriter) Subscript(text string) error {
func (mw *MarkdownWriter) Subscript(text string) error {
return mw.writeLine(fmt.Sprintf("<sub>%s</sub>", text))
}

// Superscript generates superscript text
func (mw *markdownWriter) Superscript(text string) error {
func (mw *MarkdownWriter) Superscript(text string) error {
return mw.writeLine(fmt.Sprintf("<sup>%s</sup>", text))
}

// DefinitionList generates a definition list
func (mw *markdownWriter) DefinitionList(items []*DefinitionList) {
func (mw *MarkdownWriter) DefinitionList(items []*DefinitionList) {
for _, item := range items {
mw.writeLine(fmt.Sprintf("%s\n: %s", item.Term, item.Definition))
}
}

// OrderedList generates an ordered list
func (mw *markdownWriter) OrderedList(items []string) {
func (mw *MarkdownWriter) OrderedList(items []string) {
for i, item := range items {
mw.writeLine(fmt.Sprintf("%d. %s", i+1, item))
}
}

// TableOfContents generates a table of contents
func (mw *markdownWriter) TableOfContents(headers []string) {
func (mw *MarkdownWriter) TableOfContents(headers []string) {
for _, header := range headers {
mw.writeLine(fmt.Sprintf("- [%s](#%s)", header, strings.ToLower(strings.ReplaceAll(header, " ", "-"))))
}
}

// writeLine will write a line of text to the file
func (mw *markdownWriter) writeLine(text string) error {
func (mw *MarkdownWriter) writeLine(text string) error {
_, err := mw.file.WriteString(text + "\n\n")
if err != nil {
fmt.Errorf("write error: %v\n", err)
Expand Down
10 changes: 5 additions & 5 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const (
markdownSuffix = ".md"
)

type markdownWriter struct {
type MarkdownWriter struct {
file *os.File
}

// NewMarkdownWriter creates a new markdownWriter instance and opens the file.
// NewMarkdownWriter creates a new MarkdownWriter instance and opens the file.
// If the directory in the filename does not exist, it will be created.
func NewMarkdownWriter(filename string, append bool) (*markdownWriter, error) {
func NewMarkdownWriter(filename string, append bool) (*MarkdownWriter, error) {
// Ensure the filename ends with .md
if !strings.HasSuffix(filename, markdownSuffix) {
filename += markdownSuffix
Expand All @@ -42,10 +42,10 @@ func NewMarkdownWriter(filename string, append bool) (*markdownWriter, error) {
if err != nil {
return nil, fmt.Errorf("failed to open file: %v", err)
}
return &markdownWriter{file: file}, nil
return &MarkdownWriter{file: file}, nil
}

// Close closes the file
func (mw *markdownWriter) Close() error {
func (mw *MarkdownWriter) Close() error {
return mw.file.Close()
}
2 changes: 1 addition & 1 deletion writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// TestMarkdownWriter tests all the functions of the gomarkdown package
func TestMarkdownWriter(t *testing.T) {
// Create a new markdownWriter instance
// Create a new MarkdownWriter instance

mw, err := NewMarkdownWriter("example", false)
if err != nil {
Expand Down

0 comments on commit 228fd59

Please sign in to comment.