blocks

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 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 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()

	// ID returns an id for the block. It should be unique when possible. The block should increment a value in the counter depending on its type.
	ID(counter *IDCounter) string
}

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) ID added in v0.4.5

func (cb CodeBlock) ID(counter *IDCounter) string

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) ID added in v0.4.5

func (p Formatted) ID(_ *IDCounter) 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(_ *IDCounter) 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(counter *IDCounter) string

func (HorizontalLine) IsBlock added in v0.4.1

func (h HorizontalLine) IsBlock()

type IDCounter added in v0.4.5

type IDCounter struct {
	// In some cases using the results of counting is not needed because the IDs are not needed themselves. This variable is true when this is the case.
	ShouldUseResults bool
	// contains filtered or unexported fields
}

func (IDCounter) UnusableCopy added in v0.4.5

func (c IDCounter) UnusableCopy() *IDCounter

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) ID added in v0.4.5

func (img Img) ID(counter *IDCounter) string

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) ID added in v0.4.5

func (entry ImgEntry) ID(_ *IDCounter) string

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) ID added in v0.4.5

func (lp LaunchPad) ID(counter *IDCounter) string

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) ID added in v0.4.5

func (l List) ID(counter *IDCounter) string

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) ID added in v0.4.5

func (l ListItem) ID(_ *IDCounter) string

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) ID added in v0.4.5

func (p Paragraph) ID(counter *IDCounter) string

type Quote added in v0.2.0

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

Quote is the block representing a quote.

func (*Quote) AddBlock added in v0.4.3

func (q *Quote) AddBlock(block Block)

func (*Quote) Contents added in v0.2.0

func (q *Quote) Contents() []Block

func (Quote) ID added in v0.4.5

func (q Quote) ID(counter *IDCounter) 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) ID added in v0.4.5

func (r RocketLink) ID(_ *IDCounter) string

func (RocketLink) IsBlock added in v0.4.1

func (r RocketLink) IsBlock()

type Table

type Table struct {
	// data
	HyphaName string
	Caption   string
	Rows      []*TableRow
	// state
	InMultiline bool
	// tmp
	CurrCellMarker  rune
	CurrColspan     uint
	CurrCellBuilder strings.Builder
}

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

func (Table) ID added in v0.4.5

func (t Table) ID(counter *IDCounter) string

func (Table) IsBlock added in v0.4.1

func (t Table) IsBlock()

type TableCell added in v0.1.2

type TableCell struct {
	IsHeaderCell bool
	Contents     Formatted
	Colspan      uint
}

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) ID added in v0.4.5

func (tc TableCell) ID(_ *IDCounter) string

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) ID added in v0.4.5

func (tr TableRow) ID(_ *IDCounter) string

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 TransclusionSelector
}

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(counter *IDCounter) string

func (Transclusion) IsBlock added in v0.4.1

func (t Transclusion) IsBlock()

type TransclusionSelector added in v0.4.5

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

func DefaultSelector added in v0.4.5

func DefaultSelector() TransclusionSelector

func ParseSelector added in v0.4.5

func ParseSelector(selector string) TransclusionSelector

ParseSelector parses the selector according to the following rules.

If the selector is empty, we think of it as of selector start..description and try again.

If there is no .. in the selector, the selector selects just one block with the matching id.

If there is a .. in selector, there are two bounds: left and right. Both bounds are ids of some blocks.

Special bounds:

attachment: hypha's attachment.
start: hypha's text's first block.
description: hypha's text's first paragraph.
end: hypha's last block.

If the left bound is empty, it is set to start. If the right bound is empty, it is set to end.

Jump to

Keyboard shortcuts

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