Documentation ¶
Overview ¶
Package blocks provides some of the Mycomarkup's blocks.
Index ¶
- func MatchesImg(line string) bool
- type Block
- type CodeBlock
- type Formatted
- type Heading
- type HorizontalLine
- type IDCounter
- type Img
- type ImgEntry
- type LaunchPad
- type List
- type ListItem
- type ListMarker
- type Paragraph
- type Quote
- type RocketLink
- type Table
- type TableCell
- type TableRow
- type Transclusion
- type TransclusionError
- type TransclusionErrorReason
- type TransclusionSelector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchesImg ¶
MatchesImg is true if the line starts with img {.
Types ¶
type Block ¶
type Block interface { // 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 // contains filtered or unexported methods }
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
MakeCodeBlock returns a code block with the given language and contents.
func (*CodeBlock) AddLine ¶ added in v0.2.0
AddLine adds a line to the code block's contents. The line should be without line breaks.
type Formatted ¶ added in v0.2.0
type Formatted struct { HyphaName string Html string *bytes.Buffer // contains filtered or unexported fields }
Formatted is a piece of formatted text.
func MakeFormatted ¶ added in v0.3.0
MakeFormatted parses the formatted text in the input and returns it.
type Heading ¶ added in v0.1.2
type Heading struct { // Level is a number between 1 and 6. Level uint // contains filtered or unexported fields }
Heading is a formatted heading in the document.
func MakeHeading ¶ added in v0.1.2
MakeHeading parses the heading on the given line and returns it. Set its level by yourself though.
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(line string) HorizontalLine
MakeHorizontalLine parses the horizontal line block on the given text line and returns it.
func (HorizontalLine) ID ¶
func (h HorizontalLine) ID(counter *IDCounter) string
ID returns the line's id. By default, it is hr- and a number. If the line was written like that:
----id
, the specified id is returned instead.
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 }
IDCounter is a struct with counters of how many times some blocks have appeared. Block's ID depends on these counters.
func (IDCounter) UnusableCopy ¶ added in v0.4.5
UnusableCopy returns a copy of the counter with ShouldUseResults set to false.
type Img ¶
type Img struct { Entries []ImgEntry // contains filtered or unexported fields }
Img is an image gallery, consisting of zero or more images.
func MakeImg ¶ added in v0.2.0
MakeImg parses the image gallery on the line and returns it. It also tells if the gallery is finished or not.
func (*Img) HasOneImage ¶ added in v0.1.1
HasOneImage returns true if img has exactly one image and that images has no description.
func (*Img) MarkExistenceOfSrcLinks ¶ added in v0.1.1
func (img *Img) MarkExistenceOfSrcLinks()
MarkExistenceOfSrcLinks effectively checks if the links in the gallery are blue or red.
func (*Img) ProcessLine ¶ added in v0.2.0
ProcessLine parses the line and tells if the gallery is finished.
func (*Img) ProcessRune ¶ added in v0.2.0
ProcessRune parses the rune.
type ImgEntry ¶ added in v0.1.1
ImgEntry is an entry of an image gallery. It can only be nested into Img.
func (*ImgEntry) Description ¶ added in v0.2.0
Description returns the description of the image.
func (ImgEntry) ID ¶ added in v0.4.5
ID returns an empty string because images do not have ids. Image galleries do have them, by the way, see Img.
func (*ImgEntry) SizeHAsAttr ¶ added in v0.1.1
SizeHAsAttr returns either an empty string or the height attribute for the image, depending on what has been written in the markup.
func (*ImgEntry) SizeWAsAttr ¶ added in v0.1.1
SizeWAsAttr returns either an empty string or the width attribute for the image, depending on what has been written in the markup.
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
MakeLaunchPad returns an empty launchpad. Add rocket links there using AddRocket.
func (*LaunchPad) AddRocket ¶ added in v0.1.2
func (lp *LaunchPad) AddRocket(rl RocketLink)
AddRocket stores the rocket link in the launchpad.
func (*LaunchPad) ColorRockets ¶ added in v0.5.2
func (lp *LaunchPad) ColorRockets()
ColorRockets marks links to existing hyphae as existing.
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.
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 contained in this list item. Contents []Block }
ListItem is an entry in a List.
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 Quote ¶ added in v0.2.0
type Quote struct {
// contains filtered or unexported fields
}
Quote is the block representing a quote.
type RocketLink ¶ added in v0.1.2
RocketLink is a rocket link which is meant to be nested inside LaunchPad.
func MakeRocketLink ¶ added in v0.1.2
func MakeRocketLink(line, hyphaName string) RocketLink
MakeRocketLink parses the rocket link on the given line and returns it.
func (RocketLink) ID ¶ added in v0.4.5
func (r RocketLink) ID(_ *IDCounter) string
ID returns an empty string because rocket links do not have ids on their own.
type TableCell ¶ added in v0.1.2
TableCell is a cell in TableRow.
func (*TableCell) ColspanAttribute ¶ added in v0.2.0
ColspanAttribute returns either an empty string (if the cell doesn't have colspan) or a string in this format:
colspan="<number here>"
type TableRow ¶ added in v0.1.2
TableRow is a row in a table. Thus, it can only be nested inside a table.
func (TableRow) ID ¶ added in v0.4.5
ID returns and empty string because table rows do not have ids.
func (*TableRow) LooksLikeThead ¶ added in v0.1.2
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 Blend bool Selector TransclusionSelector TransclusionError }
Transclusion is the block representing an extract from a different document. TODO: visitors for transclusion.
func MakeTransclusion ¶ added in v0.2.0
func MakeTransclusion(line, hyphaName string) Transclusion
MakeTransclusion parses the line and returns a transclusion block.
TODO: move to the parser module.
func (Transclusion) ID ¶ added in v0.2.0
func (t Transclusion) ID(counter *IDCounter) string
ID returns the transclusion's id which is transclusion- and a number.
type TransclusionError ¶ added in v0.2.0
type TransclusionError struct {
Reason TransclusionErrorReason
}
TransclusionError is the error that occured during transclusion.
func (*TransclusionError) HasError ¶ added in v0.5.5
func (te *TransclusionError) HasError() bool
HasError is true if there is indeed an error.
type TransclusionErrorReason ¶ added in v0.5.5
type TransclusionErrorReason int
TransclusionErrorReason is the reason why the transclusion failed during parsing.
const ( // TransclusionNoError means there is no error. TransclusionNoError TransclusionErrorReason = iota // TransclusionInTerminal means that Mycomarkup CLI is used. Transclusion is not supported in it. TransclusionInTerminal // TransclusionErrorNoTarget means that no target hypha was specified. TransclusionErrorNoTarget // TransclusionErrorOldSyntax means : was found in the target. TransclusionErrorOldSyntax // TransclusionErrorNotExists means the target hypha does not exist. TransclusionErrorNotExists )
type TransclusionSelector ¶ added in v0.4.5
type TransclusionSelector int
TransclusionSelector is the thing that specifies what parts of the document shall be transcluded.
const ( // SelectorOverview is SelectorAttachment and SelectorDescription combined. SelectorOverview TransclusionSelector = iota // SelectorAttachment selects the attachment of the target hypha. SelectorAttachment // SelectorDescription selects the description of the target hypha. The first paragraph of the text part of the hypha is considered its description. SelectorDescription // SelectorText selects all of the text in the hypha, but not the attachment. SelectorText // SelectorFull selects everything in the hypha, including the attachment. SelectorFull )