commonmark

package module
v0.0.0-...-b6e895a Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2017 License: BSD-2-Clause, BSD-3-Clause, MIT Imports: 5 Imported by: 6

README

go-commonmark

Build Status

Description

go-commonmark is a Go (golang) wrapper for the CommonMark C library

Installation

go get github.com/rhinoman/go-commonmark

Note: The cmark C reference implementation has been folded into this repository, no need to install it separately. It will be built automagically by cgo.

Documentation

See the Godoc: http://godoc.org/github.com/rhinoman/go-commonmark

Example Usage

If all you need is to convert CommonMark text to Html, just do this:


import "github.com/rhinoman/go-commonmark"

...

	htmlText := commonmark.Md2Html(mdText)  

Documentation

Overview

Package commonmark provides a Go wrapper for the CommonMark C Library

Index

Constants

View Source
const (
	CMARK_NO_DELIM = iota
	CMARK_PERIOD_DELIM
	CMARK_PAREN_DELIM
)
View Source
const CMARK_OPT_DEFAULT = 0

CMark writer options for render functions

View Source
const CMARK_OPT_HARDBREAKS = 2
View Source
const CMARK_OPT_NORMALIZE = 4
View Source
const CMARK_OPT_SAFE = 32
View Source
const CMARK_OPT_SMART = 8
View Source
const CMARK_OPT_SOURCEPOS = 1
View Source
const CMARK_OPT_VALIDATE_UTF8 = 16

Variables

This section is empty.

Functions

func CMarkVersion

func CMarkVersion() int

Version information

func Md2Html

func Md2Html(mdtext string, options int) string

Converts Markdo--, er, CommonMark text to Html. Parameter mdtext contains CommonMark text. The return value is the HTML string

Types

type CMarkEvent

type CMarkEvent int
const (
	CMARK_EVENT_NONE CMarkEvent = iota
	CMARK_EVENT_DONE
	CMARK_EVENT_ENTER
	CMARK_EVENT_EXIT
)

type CMarkIter

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

Wraps a cmark_iter

func NewCMarkIter

func NewCMarkIter(node *CMarkNode) *CMarkIter

Creates a new iterator starting with the given node.

func (*CMarkIter) Free

func (iter *CMarkIter) Free()

Frees an iterator

func (*CMarkIter) GetNode

func (iter *CMarkIter) GetNode() *CMarkNode

Returns the next node in the sequence

func (*CMarkIter) Next

func (iter *CMarkIter) Next() CMarkEvent

Returns the event type for the next node

func (*CMarkIter) Reset

func (iter *CMarkIter) Reset(current *CMarkNode, event CMarkEvent)

Reset the iterator so the current node is 'current' and the event type is 'event'. Use this to resume after desctructively modifying the tree structure

type CMarkNode

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

Wraps the cmark_node. CommonMark nodes are represented as Trees in memory.

func NewCMarkNode

func NewCMarkNode(nt NodeType) *CMarkNode

Creates a new node of the specified type

func ParseDocument

func ParseDocument(buffer string, options int) *CMarkNode

Generates a document directly from a string

func ParseFile

func ParseFile(filename string, options int) (*CMarkNode, error)

Parses a file and returns a CMarkNode Returns an error if the file can't be opened

func (*CMarkNode) AppendChild

func (node *CMarkNode) AppendChild(child *CMarkNode) bool

Append a child node

func (*CMarkNode) ConsolidateTextNodes

func (node *CMarkNode) ConsolidateTextNodes()

Consolidates adjacent text nodes.

func (*CMarkNode) FirstChild

func (node *CMarkNode) FirstChild() *CMarkNode

Get first child node

func (*CMarkNode) Free

func (node *CMarkNode) Free()

Cleanup a node, including any children. Unlinks a node from the tree and frees it.

func (*CMarkNode) GetEndColumn

func (node *CMarkNode) GetEndColumn() int

Returns the column at which 'node' ends

func (*CMarkNode) GetEndLine

func (node *CMarkNode) GetEndLine() int

Returns the line on which 'node' ends

func (*CMarkNode) GetFenceInfo

func (node *CMarkNode) GetFenceInfo() string

Get Fence info

func (*CMarkNode) GetHeaderLevel

func (node *CMarkNode) GetHeaderLevel() int

Get a Header node's level

func (*CMarkNode) GetListDelim

func (node *CMarkNode) GetListDelim() DelimType

Returns the list delimiter type of node, or CMARK_NO_DELIM if node is not a list

func (*CMarkNode) GetListStart

func (node *CMarkNode) GetListStart() int

Get a list's start

func (*CMarkNode) GetListTight

func (node *CMarkNode) GetListTight() bool

Get list 'tight'

func (*CMarkNode) GetListType

func (node *CMarkNode) GetListType() ListType

Get a List node's list type

func (*CMarkNode) GetLiteral

func (node *CMarkNode) GetLiteral() string

Get the node's string content

func (*CMarkNode) GetNodeType

func (node *CMarkNode) GetNodeType() NodeType

Get the node type

func (*CMarkNode) GetNodeTypeString

func (node *CMarkNode) GetNodeTypeString() string

Get the node type as a string

func (*CMarkNode) GetNodeUserData

func (node *CMarkNode) GetNodeUserData() string

Returns the user data of the node as an unsafe.Pointer. Hope you know what you're doing.

func (*CMarkNode) GetOnEnter

func (node *CMarkNode) GetOnEnter() string

Returns the literal "on enter" text for a custom node, or an empty string if no on_enter is set

func (*CMarkNode) GetOnExit

func (node *CMarkNode) GetOnExit() string

Returns the literal "on exit" text for a custom node, or an empty string if no on_exit is set

func (*CMarkNode) GetStartColumn

func (node *CMarkNode) GetStartColumn() int

Returns the column at which 'node' begins

func (*CMarkNode) GetStartLine

func (node *CMarkNode) GetStartLine() int

Returns the line on which 'node' begins

func (*CMarkNode) GetTitle

func (node *CMarkNode) GetTitle() string

Get a node's title

func (*CMarkNode) GetUrl

func (node *CMarkNode) GetUrl() string

Get a node's url

func (*CMarkNode) InsertAfter

func (node *CMarkNode) InsertAfter(sibling *CMarkNode) bool

InsertAfter can cause a panic quite readily :) Hint: Both nodes had better already be in the 'tree' Insert a node after another 'sibling' node

func (*CMarkNode) InsertBefore

func (node *CMarkNode) InsertBefore(sibling *CMarkNode) bool

InsertBefore can cause a panic quite readily :) Hint: Both nodes had better already be in the 'tree' Insert a node before another 'sibling' node

func (*CMarkNode) LastChild

func (node *CMarkNode) LastChild() *CMarkNode

Get last child node

func (*CMarkNode) Next

func (node *CMarkNode) Next() *CMarkNode

Get next node

func (*CMarkNode) Parent

func (node *CMarkNode) Parent() *CMarkNode

Get parent node

func (*CMarkNode) PrependChild

func (node *CMarkNode) PrependChild(child *CMarkNode) bool

Prepend a child node

func (*CMarkNode) Previous

func (node *CMarkNode) Previous() *CMarkNode

Get previous node

func (*CMarkNode) RenderCMark

func (node *CMarkNode) RenderCMark(options int, width int) string

Renders node tree as commonmark text.

func (*CMarkNode) RenderHtml

func (node *CMarkNode) RenderHtml(options int) string

Renders the document as HTML. Returns an HTML string.

func (*CMarkNode) RenderLatex

func (node *CMarkNode) RenderLatex(options int, width int) string

Renders node tree as a LaTeX document

func (*CMarkNode) RenderMan

func (node *CMarkNode) RenderMan(options int, width int) string

Renders the document as a groff man page, without the header

func (*CMarkNode) RenderXML

func (node *CMarkNode) RenderXML(options int) string

print structure as XML

func (*CMarkNode) Replace

func (newNode *CMarkNode) Replace(oldNode *CMarkNode) bool

Replaces 'oldNode' with 'newNode' and unlinks 'oldnode' (but does not free its memory). Returns true on success, false on failure.

func (*CMarkNode) SetFenceInfo

func (node *CMarkNode) SetFenceInfo(fenceInfo string) bool

Set Fence info

func (*CMarkNode) SetHeaderLevel

func (node *CMarkNode) SetHeaderLevel(level int) bool

Set a Header node's level (1,2, etc.)

func (*CMarkNode) SetListDelim

func (node *CMarkNode) SetListDelim(dt DelimType) bool

Sets the list delimeter type of the node, returns true on success

func (*CMarkNode) SetListStart

func (node *CMarkNode) SetListStart(start int) bool

Set a list's start

func (*CMarkNode) SetListTight

func (node *CMarkNode) SetListTight(isTight bool) bool

Set list 'tight'

func (*CMarkNode) SetListType

func (node *CMarkNode) SetListType(lt ListType) bool

Set a List node's list type

func (*CMarkNode) SetLiteral

func (node *CMarkNode) SetLiteral(content string) bool

Set the node's string content

func (*CMarkNode) SetNodeUserData

func (node *CMarkNode) SetNodeUserData(userData string) bool

Sets arbitrary user data for node

func (*CMarkNode) SetOnEnter

func (node *CMarkNode) SetOnEnter(onEnter string) bool

Sets the literal text to render "on enter" for a custom node. Any children of the node will be rendered after this text. Returns true on success and false on failure

func (*CMarkNode) SetOnExit

func (node *CMarkNode) SetOnExit(onExit string) bool

Sets the literal text to render "on exit" for a custom node. Any children of the node will be rendered before this text. Returns true on success and false on failure

func (*CMarkNode) SetTitle

func (node *CMarkNode) SetTitle(title string) bool

Set a node's title

func (*CMarkNode) SetUrl

func (node *CMarkNode) SetUrl(url string) bool

Set a node's url

func (node *CMarkNode) Unlink()

Unlink a node from the tree

type CMarkParser

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

Wraps the cmark_doc_parser

func NewCmarkParser

func NewCmarkParser(options int) *CMarkParser

Retruns a new CMark Parser. You must call Free() on this thing when you're done with it! Please.

func (*CMarkParser) Feed

func (cmp *CMarkParser) Feed(text string)

Process some text

func (*CMarkParser) Finish

func (cmp *CMarkParser) Finish() *CMarkNode

Finish parsing and generate a document You must call Free() on the document when you're done with it!

func (*CMarkParser) Free

func (cmp *CMarkParser) Free()

Cleanup the parser Once you call Free on this, you can't use it anymore

type DelimType

type DelimType int

type ListType

type ListType int

Maps to a cmark_list_type in cmark.h

const (
	CMARK_NO_LIST ListType = iota
	CMARK_BULLET_LIST
	CMARK_ORDERED_LIST
)

type NodeType

type NodeType int

Maps to a cmark_node_type enum in cmark.h

const (
	//Error Status
	CMARK_NODE_NONE NodeType = iota

	//Block
	CMARK_NODE_DOCUMENT
	CMARK_NODE_BLOCK_QUOTE
	CMARK_NODE_LIST
	CMARK_NODE_ITEM
	CMARK_NODE_CODE_BLOCK
	CMARK_NODE_HTML_BLOCK
	CMARK_NODE_CUSTOM_BLOCK
	CMARK_NODE_PARAGRAPH
	CMARK_NODE_HEADING
	CMARK_NODE_THEMATIC_BREAK

	//Inline
	CMARK_NODE_TEXT
	CMARK_NODE_SOFTBREAK
	CMARK_NODE_LINEBREAK
	CMARK_NODE_CODE
	CMARK_NODE_HTML_INLINE
	CMARK_NODE_CUSTOM_INLINE
	CMARK_NODE_EMPH
	CMARK_NODE_STRONG
	CMARK_NODE_LINK
	CMARK_NODE_IMAGE
	//Block
	CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT
	CMARK_NODE_LAST_BLOCK  = CMARK_NODE_THEMATIC_BREAK
	//Inline
	CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT
	CMARK_NODE_LAST_INLINE  = CMARK_NODE_IMAGE
)

Jump to

Keyboard shortcuts

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