blocks

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package blocks provides some of the Mycomarkup's blocks.

Index

Constants

View Source
const TransclusionError = "err"

TransclusionError is a value that means that the transclusion is wrong.

Variables

This section is empty.

Functions

func MatchesImg

func MatchesImg(line string) bool

func MatchesTable

func MatchesTable(line string) bool

func ParagraphToHtml

func ParagraphToHtml(hyphaName, input string) string

Types

type Block

type Block interface {
	// IsBlock is the method that a block should implement. In the future, this method might be removed, but for now, we need it just to put something in the interface.
	IsBlock()
}

Block is a unit of Mycomarkup. It is somewhat analogous to HTML's tags.

type CodeBlock added in v0.2.0

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

CodeBlock represents a block of preformatted text.

func MakeCodeBlock added in v0.2.0

func MakeCodeBlock(language, contents string) CodeBlock

MakeCodeBlock returns a code block with the given language and contents.

func (*CodeBlock) AddLine added in v0.2.0

func (cb *CodeBlock) AddLine(line string)

AddLine adds a line to the code block's contents. The line should be without line breaks.

func (*CodeBlock) Contents added in v0.2.0

func (cb *CodeBlock) Contents() string

Contents returns the code block's contents.

func (CodeBlock) IsBlock added in v0.4.1

func (cb CodeBlock) IsBlock()

func (*CodeBlock) Language added in v0.2.0

func (cb *CodeBlock) Language() string

Language returns what kind of formal language the code block is written in. It returns "plain" if the language is not specified.

type Formatted added in v0.2.0

type Formatted struct {
	HyphaName string
	Html      string
	*bytes.Buffer
	// contains filtered or unexported fields
}

func MakeFormatted added in v0.3.0

func MakeFormatted(input, hyphaName string) Formatted

func (*Formatted) AddLine added in v0.2.0

func (p *Formatted) AddLine(line string)

func (Formatted) IsBlock added in v0.4.1

func (p Formatted) IsBlock()

type Heading added in v0.1.2

type Heading struct {
	Level uint
	// contains filtered or unexported fields
}

func MakeHeading added in v0.1.2

func MakeHeading(line, hyphaName string, level uint) Heading

func (*Heading) Contents added in v0.2.0

func (h *Heading) Contents() Formatted

func (*Heading) ID added in v0.1.2

func (h *Heading) ID() string

func (Heading) IsBlock added in v0.4.1

func (h Heading) IsBlock()

type HorizontalLine

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

HorizontalLine represents the horizontal line block.

In Mycomarkup it is written like that:

----

func MakeHorizontalLine

func MakeHorizontalLine(src string) HorizontalLine

func (*HorizontalLine) ID

func (h *HorizontalLine) ID() string

func (HorizontalLine) IsBlock added in v0.4.1

func (h HorizontalLine) IsBlock()

func (*HorizontalLine) String

func (h *HorizontalLine) String() string

type Img

type Img struct {
	Entries []ImgEntry
	// contains filtered or unexported fields
}

func MakeImg added in v0.2.0

func MakeImg(line, hyphaName string) (img Img, shouldGoBackToNormal bool)

func (*Img) HasOneImage added in v0.1.1

func (img *Img) HasOneImage() bool

HasOneImage returns true if img has exactly one image and that images has no description.

func (Img) IsBlock added in v0.4.1

func (img Img) IsBlock()
func (img *Img) MarkExistenceOfSrcLinks()

func (*Img) ProcessLine added in v0.2.0

func (img *Img) ProcessLine(line string) (shouldGoBackToNormal bool)

func (*Img) ProcessRune added in v0.2.0

func (img *Img) ProcessRune(r rune) (done bool)

type ImgEntry added in v0.1.1

type ImgEntry struct {
	Srclink *links.Link
	// contains filtered or unexported fields
}

ImgEntry is an entry of an image gallery. It can only be nested into Img.

func (*ImgEntry) Description added in v0.2.0

func (entry *ImgEntry) Description() Formatted

func (ImgEntry) IsBlock added in v0.4.1

func (entry ImgEntry) IsBlock()

func (*ImgEntry) SizeHAsAttr added in v0.1.1

func (entry *ImgEntry) SizeHAsAttr() string

func (*ImgEntry) SizeWAsAttr added in v0.1.1

func (entry *ImgEntry) SizeWAsAttr() string

type LaunchPad added in v0.1.2

type LaunchPad struct {
	Rockets []RocketLink
}

LaunchPad is a container for RocketLinks.

func MakeLaunchPad added in v0.1.2

func MakeLaunchPad() LaunchPad

func (*LaunchPad) AddRocket added in v0.1.2

func (lp *LaunchPad) AddRocket(rl RocketLink)

func (LaunchPad) IsBlock added in v0.4.1

func (lp LaunchPad) IsBlock()

type List

type List struct {
	// Items are the entries of the List. There should be at least one.
	Items []ListItem
	// Marker is the type of the list. All entries have the same type. See SameAs for information about same types.
	Marker ListMarker
}

List is the block representing a set of related elements. It must be the same as all ListItem.Marker.

func (List) IsBlock added in v0.4.1

func (l List) IsBlock()

type ListItem added in v0.3.0

type ListItem struct {
	Marker ListMarker
	// Level is equal to amount of asterisks.
	//     *    -> Level = 1
	//     **.  -> Level = 2
	Level uint
	// Contents are Mycomarkup blocks. TODO: proper type.
	Contents []Block
}

ListItem is an entry in a List.

func (ListItem) IsBlock added in v0.4.1

func (l ListItem) IsBlock()

type ListMarker added in v0.3.0

type ListMarker int

ListMarker is the type of a ListItem or a List.

const (
	// MarkerUnordered is for bullets like * (no point).
	MarkerUnordered ListMarker = iota
	// MarkerOrdered is for bullets like *. (with point).
	MarkerOrdered
	// MarkerTodoDone is for bullets like *v (with tick).
	MarkerTodoDone
	// MarkerTodo is for bullets like *x (with cross).
	MarkerTodo
)

func (ListMarker) SameAs added in v0.3.0

func (m1 ListMarker) SameAs(m2 ListMarker) bool

SameAs is true if both list markers are of the same type. MarkerTodoDone and MarkerTodo are considered same to each other. All other markers are different from each other.

type Paragraph

type Paragraph struct {
	Formatted
}

func (Paragraph) IsBlock added in v0.4.1

func (p Paragraph) IsBlock()

type Quote added in v0.2.0

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

Quote is the block representing a quote.

func MakeQuote added in v0.2.0

func MakeQuote(line, hyphaName string) Quote

func (*Quote) Contents added in v0.2.0

func (q *Quote) Contents() string

func (Quote) IsBlock added in v0.4.1

func (q Quote) IsBlock()
type RocketLink struct {
	IsEmpty bool
	links.Link
}

RocketLink is a rocket link which is meant to be nested inside LaunchPad.

func MakeRocketLink(line, hyphaName string) RocketLink

func (RocketLink) IsBlock added in v0.4.1

func (r RocketLink) IsBlock()

type Table

type Table struct {
	// data
	HyphaName string
	Caption   string
	Rows      []*TableRow
	// contains filtered or unexported fields
}

Table is a table, which consists of several Rows and has a Caption.

func TableFromFirstLine

func TableFromFirstLine(line, hyphaName string) Table

func (Table) IsBlock added in v0.4.1

func (t Table) IsBlock()

func (*Table) ProcessLine added in v0.2.0

func (t *Table) ProcessLine(line string) (done bool)

type TableCell added in v0.1.2

type TableCell struct {
	IsHeaderCell bool
	Contents     Formatted
	// contains filtered or unexported fields
}

TableCell is a cell in TableRow.

func (*TableCell) ColspanAttribute added in v0.2.0

func (tc *TableCell) ColspanAttribute() string

ColspanAttribute returns either an empty string (if the cell doesn't have colspan) or a string in this format:

colspan="<number here>"

func (TableCell) IsBlock added in v0.4.1

func (tc TableCell) IsBlock()

func (*TableCell) TagName added in v0.2.0

func (tc *TableCell) TagName() string

TagName returns "th" if the cell is a header cell, "td" elsewise.

type TableRow added in v0.1.2

type TableRow struct {
	HyphaName string
	Cells     []*TableCell
}

TableRow is a row in a table. Thus, it can only be nested inside a table.

func (TableRow) IsBlock added in v0.4.1

func (tr TableRow) IsBlock()

func (*TableRow) LooksLikeThead added in v0.1.2

func (tr *TableRow) LooksLikeThead() bool

LooksLikeThead is true if the table row looks like it might as well be a thead row.

Most likely, rows with more than two header cells are theads. I allow one extra datum cell for tables like this: | ! a ! b ! c | d | e ! f | g | h

type Transclusion added in v0.2.0

type Transclusion struct {
	// Target is the name of the hypha to be transcluded.
	Target string

	// Selector specifies what parts of the hypha to transclude.
	Selector string
}

Transclusion is the block representing an extract from a different document.

func MakeTransclusion added in v0.2.0

func MakeTransclusion(line, hyphaName string) Transclusion

func (*Transclusion) ID added in v0.2.0

func (t *Transclusion) ID() string

func (Transclusion) IsBlock added in v0.4.1

func (t Transclusion) IsBlock()

func (*Transclusion) String added in v0.2.0

func (t *Transclusion) String() string

Jump to

Keyboard shortcuts

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