markup

package
v0.24.6 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

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
<ol></ul> - 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. Tags attributes ( <b class="..."> ) are not supported.

Index

Constants

View Source
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    = ' '
)

Variables

View Source
var Formats = Formatting{
	Bold:      Format{Sub: "**"},
	Divider:   Format{Sub: "\r-----------------------------\n"},
	Italic:    Format{Sub: "*"},
	Item:      Format{Sub: "\r- ", Close: "\r"},
	Strike:    Format{Sub: "~~"},
	Underline: Format{Sub: "__"},

	Paragraph: Format{Rune: Paragraph},
	Newline:   Format{Rune: Newline},
	Softline:  Format{Rune: Softline},
}

Formats - the default set of replacement string values.

View Source
var Tabwidth = 2

Tabwidth - how many spaces should list indentation generate

Functions

func ToText

func ToText(w io.Writer) io.Writer

listen for html-like markup written to the returned stream and write its plain text equivalent into the passed stream. ex. writing <b>bold</b> will output **bold** to w.

Types

type Format

type Format struct {
	Sub, Close string
	Rune       rune
}

Format - replacement text for certain html tags. If a substitution string exists, it replaces the opening and closing html tags; otherwise the specified rune replaces just the opening tag, and the closing tag gets ignored.

type Formatting

type Formatting struct {
	Bold, Divider, Italic, Item, Strike, Underline,
	Paragraph, Newline, Softline Format
}

Formatting - all of the unique replacement strings. Which html tags map to which format is hardcoded.

func (*Formatting) Select

func (fs *Formatting) Select(tag string) (ret Format, okay bool)

func (*Formatting) WriteTag

func (fs *Formatting) WriteTag(c *converter, tag string, open bool) (okay bool, err error)

returns true if it recognized the tag

Jump to

Keyboard shortcuts

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