Documentation ¶
Overview ¶
Package markup converts a custom html-like markup into markdown-like text.
Using an interpretation of English-like text as a series of characters in left-to-right columns and top-to-bottom rows, then:
- Newlines: move to the start of the next row.
- Paragraphs: act as a newline followed by an empty row.
- Soft-newlines: at the start of a row, these do nothing. Otherwise they act like a newline.
- Soft-paragraphs: after an empty row, these do nothing. Otherwise they act like a paragraph.
- Lists: a set of uniformly indented rows which may contain nested lists of deeper indentation.
- Ordered lists : each row in the list starts with a number, starting with 1. increasing by 1.
- Unordered lists: each row in the list starts with some uniform marker, ex. a bullet.
The custom html elements include:
<b> - bold text <i> - italic text <s> - strikethrough <u> - underlined text <hr> - horizontal divider <br> - new line <p> - soft-paragraph ( there is no "hard" paragraph marker ) <wbr> - soft-newline <a="ref"></a> - link text <ol></ol> - ordered list <ul></ul> - unordered list <li></li> - line item in a list
Nested tags are okay; interleaved tags are not supported. For example:
<b><i></i></b>
is fine. While this:
<b><i></b></i>
will cause trouble.
Unknown tags are left as is.
Generalized tags attributes ( `<b class="...">` ) are not supported. Links using `<a>` were added for use with menus. Their interpretation depends on the host and context.
Index ¶
Constants ¶
const ( // Starts a new line of text. Newline = '\n' // Conditionally prints a single line of blank text; // doesn't write a blank line if there already is one. Paragraph = '\v' // Starts a new line only if the output isnt already at the start of a newline. Softline = '\r' Space = ' ' )
const ( TagLink = "a" TagBold = "b" TagDivider = "hr" TagItalic = "i" TagItem = "li" TagStrike = "s" TagUnderline = "u" TagParagraph = "p" TagNewline = "br" TagSoftline = "wbr" TagOrderedList = "ol" TagUnorderedList = "ul" )
Variables ¶
var Formats = Formatting{ TagLink: FormatFunc(linkFormat), TagBold: Format{Sub: "**"}, TagDivider: Format{Sub: "\r-----------------------------\n"}, TagItalic: Format{Sub: "*"}, TagStrike: Format{Sub: "~~"}, TagUnderline: Format{Sub: "__"}, TagParagraph: Format{Rune: Paragraph}, TagNewline: Format{Rune: Newline}, TagSoftline: Format{Rune: Softline}, TagItem: FormatFunc(listItem), TagOrderedList: listFormat(true), TagUnorderedList: listFormat(false), }
Formats - the default set of replacement string values.
var Tabwidth = 2
Tabwidth - how many spaces should list indentation generate
Functions ¶
Types ¶
type Format ¶
type Format struct { Sub string // replaces the opening tag Close string // optionally, replaces the closing tag ( but only if sub is specified ) Rune rune // when sub is empty }
Format - generic implementation of FormatWriter If a substitution string exists, it replaces the opening and closing tags; otherwise the specified rune replaces the opening tag, and Close is ignored.
func (Format) WriteClose ¶ added in v0.24.8
type FormatFunc ¶ added in v0.24.8
function based implementation of FormatWriter interface
func (FormatFunc) WriteClose ¶ added in v0.24.8
func (fn FormatFunc) WriteClose(c *converter) error
func (FormatFunc) WriteOpen ¶ added in v0.24.8
func (fn FormatFunc) WriteOpen(c *converter, attr string) error
type FormatWriter ¶ added in v0.24.8
type FormatWriter interface { WriteOpen(c *converter, attr string) error WriteClose(c *converter) error }
FormatWriter - generate replacement text for certain html-like tags.
type Formatting ¶
type Formatting map[string]FormatWriter
Formatting - all of the unique replacement strings. Which html tags map to which format is hardcoded.