markdown

package
v0.0.0-...-c8c5564 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2018 License: MIT Imports: 5 Imported by: 0

README

Markdown Builder

Godoc reference

This is a simple builder to help you create Mardown content in Go.

Usage

import "github.com/wI2L/fizz/markdown"

builder := markdown.Builder{}

builder.
   H1("Markdown Builder").
   P("A simple builder to help your write Markdown in Go").
   H2("Installation").
   Code("go get -u github.com/wI2L/fizz", "bash").
   H2("Todos").
   BulletedList(
     "write tests",
     builder.Block().NumberedList("A", "B", "C"),
     "add more markdown features",
   )

md := builder.String()
Markdown Builder
================

A simple builder to help your write Markdown in Go.

Installation
----------------------------------

```bash
go get -u github.com/wI2L/fizz", "bash
```

Todos
-----
* write tests
* 1. A
  2. B
  3. C
* add more markdown features

Elements

The builder have two kinds of elements, block and inline elements. Block elements are concatenated to the underlying builder buffer while inline elements are directly returned as string.

Inline
  • Alternative titles ⇒ builder.AltH1 and builder.AltH2
  • Emphasis ⇒ builder.Emphasis and builder.Italic
  • Strong emphasis ⇒ builder.StrongEmphasis and builder.Bold
  • Combined emphasis ⇒ builder.StrongEmphasis
  • Strikethrough ⇒ builder.Strikethrough
  • Code ⇒ builder.InlineCode
  • Link ⇒ builder.Link
  • Image ⇒ builder.Image
Block
  • Headers ⇒ builder.H1, builder.H2, builder.H3, builder.H4, builder.H5, builder.H6
  • Paragraph ⇒ builder.P
  • Line ⇒ builder.Line A line is similar to a paragraph but it doesn't insert a line break at the end.
  • Line break ⇒ builder.BR
  • Blockquote ⇒ builder.Blockquote
  • Horizontal rule ⇒ builder.HR
  • Code ⇒ builder.Code
  • Lists
    1. Bulleted ⇒ builder.BulletedList
    2. Numbered ⇒ builder.NumberedList
Github Flavor

The builder also support the tables extension of the GitHub Flavored Markdown Spec.

builder.Table(
  [][]string{
    []string{"Letter", "Title", "ID"},
    []string{"A", "The Good", "500"},
    []string{"B", "The Very very Bad Man", "2885645"},
    []string{"C", "The Ugly"},
    []string{"D", "The\nGopher", "800"},
  },[]markdown.TableAlignment{
      markdown.AlignCenter,
      markdown.AlignCenter,
      markdown.AlignRight,
  }
)
| Letter |         Title         |      ID |
| :----: | :-------------------: | ------: |
|   A    |       The Good        |     500 |
|   B    | The Very very Bad Man | 2885645 |
|   C    |       The Ugly        |         |
|   D    |      The Gopher       |     800 |

Credits

This work is based on this PHP markdown builder.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is a simple Markdown builder that simplify the creation of content.

func (*Builder) AltH1

func (b *Builder) AltH1(header string) *Builder

AltH1 adds a level 1 header to the markdown. with an underline-ish style.

func (*Builder) AltH2

func (b *Builder) AltH2(header string) *Builder

AltH2 adds a level 2 header to the markdown with an underline-ish style.

func (*Builder) BR

func (b *Builder) BR() *Builder

BR adds a line break to the markdown.

func (*Builder) Block

func (b *Builder) Block() *Builder

Block returns a new markdown block.

func (*Builder) Blockquote

func (b *Builder) Blockquote(text string) *Builder

Blockquote adds a blockquote to the markdown.

func (*Builder) Bold

func (b *Builder) Bold(text string) string

Bold returns a bold inlined text.

func (*Builder) BulletedList

func (b *Builder) BulletedList(list ...interface{}) *Builder

BulletedList adds the given list as a bulleted list to the markdown.

func (*Builder) Code

func (b *Builder) Code(code, lang string) *Builder

Code adds a code portion with the given language format to the markdown.

func (*Builder) CombinedEmphasis

func (b *Builder) CombinedEmphasis(text string) string

CombinedEmphasis returns a bold/italic text.

func (*Builder) Emphasis

func (b *Builder) Emphasis(text string) string

Emphasis is an alias for Italic.

func (*Builder) H1

func (b *Builder) H1(text string) *Builder

H1 adds a level 1 header to the markdown.

func (*Builder) H2

func (b *Builder) H2(text string) *Builder

H2 adds a level 2 header to the markdown.

func (*Builder) H3

func (b *Builder) H3(text string) *Builder

H3 adds a level 3 header to the markdown.

func (*Builder) H4

func (b *Builder) H4(text string) *Builder

H4 adds a level 4 header to the markdown.

func (*Builder) H5

func (b *Builder) H5(text string) *Builder

H5 adds a level 5 header to the markdown.

func (*Builder) H6

func (b *Builder) H6(text string) *Builder

H6 adds a level 6 header to the markdown.

func (*Builder) HR

func (b *Builder) HR() *Builder

HR adds a horizontal rule to the markdown.

func (*Builder) Image

func (b *Builder) Image(url, title string) string

Image returns an inlined image.

func (*Builder) InlineCode

func (b *Builder) InlineCode(code string) string

InlineCode returns a quoted inline code.

func (*Builder) Italic

func (b *Builder) Italic(text string) string

Italic returns an italic inlined text.

func (*Builder) Line

func (b *Builder) Line(text string) *Builder

Line adds a new line with no new line at the end to the markdown.

func (b *Builder) Link(url, title string) string

Link returns an inlined link.

func (*Builder) NumberedList

func (b *Builder) NumberedList(list ...interface{}) *Builder

NumberedList adds the given list as a numbered list to the markdown.

func (*Builder) P

func (b *Builder) P(text string) *Builder

P adds a new paragraph to the markdown.

func (*Builder) Strikethrough

func (b *Builder) Strikethrough(text string) string

Strikethrough returns a strikethrough inlined text.

func (*Builder) String

func (b *Builder) String() string

String implements fmt.Stringer for Builder.

func (*Builder) StrongEmphasis

func (b *Builder) StrongEmphasis(text string) string

StrongEmphasis is an alias for Bold.

func (*Builder) Table

func (b *Builder) Table(table [][]string, align []TableAlignment) *Builder

Table adds a table from the given two-dimensional interface array to the markdown content. The first row of the array is considered as the table header. Align represents the alignment of each column, left to right. If the alignment of a column is not defined, the rigth alignment will be used instead as default.

type TableAlignment

type TableAlignment uint8

TableAlignment represents the alignment of a table cell.

const (
	AlignLeft TableAlignment = iota
	AlignCenter
	AlignRight
)

Alignment constants.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL