package blocks
import "github.com/bouncepaw/mycomarkup/blocks"
Package blocks provides some of the Mycomarkup's blocks.
Index ¶
- Constants
- Variables
- func CleanStyleState() map[SpanKind]bool
- func MatchesImg(line string) bool
- func TagFromState(stt SpanKind, tagState map[SpanKind]bool) string
- type Block
- type CodeBlock
- func MakeCodeBlock(language, contents string) CodeBlock
- func (cb *CodeBlock) AddLine(line string)
- func (cb *CodeBlock) Contents() string
- func (cb CodeBlock) ID(counter *IDCounter) string
- func (cb *CodeBlock) Language() string
- type Formatted
- type Heading
- type HorizontalLine
- func MakeHorizontalLine(line string) HorizontalLine
- func (h HorizontalLine) ID(counter *IDCounter) string
- type IDCounter
- type Img
- func (img *Img) HasOneImage() bool
- func (img Img) ID(counter *IDCounter) string
- func (img *Img) MarkExistenceOfSrcLinks()
- type ImgEntry
- func (entry ImgEntry) ID(_ *IDCounter) string
- func (entry *ImgEntry) SizeHAsAttr() string
- func (entry *ImgEntry) SizeWAsAttr() string
- type InlineLink
- type InlineText
- type LaunchPad
- func MakeLaunchPad() LaunchPad
- func (lp *LaunchPad) AddRocket(rl RocketLink)
- func (lp *LaunchPad) ColorRockets()
- func (lp LaunchPad) ID(counter *IDCounter) string
- type List
- type ListItem
- type ListMarker
- type Paragraph
- type Quote
- func (q *Quote) AddBlock(block Block)
- func (q *Quote) Contents() []Block
- func (q Quote) ID(counter *IDCounter) string
- type RocketLink
- type Span
- type SpanKind
- type SpanTableEntry
- type Table
- type TableCell
- func (tc *TableCell) ColspanAttribute() string
- func (tc TableCell) ID(_ *IDCounter) string
- func (tc *TableCell) TagName() string
- type TableRow
- type Transclusion
- func MakeTransclusion(line, hyphaName string) Transclusion
- func (t Transclusion) ID(counter *IDCounter) string
- type TransclusionError
- type TransclusionErrorReason
- type TransclusionSelector
Constants ¶
const ( InRoot imgState = iota InName InDimensionsW InDimensionsH InDescription )
Variables ¶
var SpanTable = []SpanTableEntry{ {SpanItalic, "//", "em"}, {SpanBold, "**", "strong"}, {SpanMono, "`", "code"}, {SpanSuper, "^^", "sup"}, {SpanSub, ",,", "sub"}, {SpanMark, "++", "mark"}, {SpanStrike, "~~", "s"}, {SpanUnderline, "__", "u"}, }
SpanTable is a table for easier span lexing, its entries are also Span too.
Functions ¶
func CleanStyleState ¶
CleanStyleState returns a map where keys are SpanKind representing inline style and values are booleans. Mutate this map to keep track of active and inactive styles.
Values: `false`: the style is not active `true`: the style is active
For example, for a Formatted line like that:
**Welcome** to //California
`CleanStyleState()SpanItalic == true` at the end of string.
func MatchesImg ¶
MatchesImg is true if the line starts with img {.
func TagFromState ¶
TagFromState returns an appropriate tag half (<left> or </right>) depending on tagState and also mutates it.
TODO: get rid of.
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 ¶
type CodeBlock struct {
// contains filtered or unexported fields
}
CodeBlock represents a block of preformatted text.
func MakeCodeBlock ¶
MakeCodeBlock returns a code block with the given language and contents.
func (*CodeBlock) AddLine ¶
AddLine adds a line to the code block's contents. The line should be without line breaks.
func (*CodeBlock) Contents ¶
Contents returns the code block's contents.
func (CodeBlock) ID ¶
ID returns the codeblock's id which is codeblock- and a number.
func (*CodeBlock) Language ¶
Language returns what kind of formal language the code block is written in. It returns "plain" if the language is not specified.
type Formatted ¶
type Formatted struct { // HyphaName is the name of the hypha that contains the Formatted text. HyphaName string // Lines are parsed lines of the Formatted text. Lines [][]Span }
Formatted is a piece of formatted text. It is always part of a bigger block, such as Paragraph.
func (*Formatted) AddLine ¶
AddLine stores an additional line of the formatted text.
func (Formatted) ID ¶
ID returns an empty string because Formatted is always part of a bigger block.
type Heading ¶
type Heading struct { // Level is a number between 1 and 6. Level uint Contents Formatted Src string }
Heading is a formatted heading in the document.
func (*Heading) GetContents ¶
GetContents returns the heading's contents.
func (Heading) ID ¶
ID returns the heading's id which is basically a stripped version of its contents. See util.StringID.
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 ¶
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 ¶
UnusableCopy returns a copy of the counter with ShouldUseResults set to false.
type Img ¶
type Img struct { // All entries but the last one Entries []ImgEntry // The last entry CurrEntry ImgEntry HyphaName string // Parsing state. TODO: move to a different place. State imgState }
Img is an image gallery, consisting of zero or more images.
func (*Img) HasOneImage ¶
HasOneImage returns true if img has exactly one image and that images has no description.
func (Img) ID ¶
ID returns the gallery's id which is img- and a number.
func (*Img) MarkExistenceOfSrcLinks ¶
func (img *Img) MarkExistenceOfSrcLinks()
MarkExistenceOfSrcLinks effectively checks if the links in the gallery are blue or red.
type ImgEntry ¶
type ImgEntry struct { Srclink *links.Link HyphaName string Path strings.Builder SizeW strings.Builder SizeH strings.Builder Desc strings.Builder }
ImgEntry is an entry of an image gallery. It can only be nested into Img.
func (ImgEntry) ID ¶
ID returns an empty string because images do not have ids. Image galleries do have them, by the way, see Img.
func (*ImgEntry) SizeHAsAttr ¶
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 ¶
SizeWAsAttr returns either an empty string or the width attribute for the image, depending on what has been written in the markup.
type InlineLink ¶
InlineLink is a link that is part of a Formatted text. Basically a wrapper over links.Link.
func (InlineLink) Kind ¶
func (il InlineLink) Kind() SpanKind
Kind returns SpanLink.
type InlineText ¶
type InlineText struct { Contents string }
InlineText is the most wholesome thing in Mycomarkup, just a bunch of characters with no formatting or any other special meaning.
func (InlineText) Kind ¶
func (it InlineText) Kind() SpanKind
Kind returns SpanText.
type LaunchPad ¶
type LaunchPad struct { Rockets []RocketLink }
LaunchPad is a container for RocketLinks.
func MakeLaunchPad ¶
func MakeLaunchPad() LaunchPad
MakeLaunchPad returns an empty launchpad. Add rocket links there using AddRocket.
func (*LaunchPad) AddRocket ¶
func (lp *LaunchPad) AddRocket(rl RocketLink)
AddRocket stores the rocket link in the launchpad.
func (*LaunchPad) ColorRockets ¶
func (lp *LaunchPad) ColorRockets()
ColorRockets marks links to existing hyphae as existing.
func (LaunchPad) ID ¶
ID returns the launchpad's id which is rocket- and a number. Note that it does not say launchpad.
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 ¶
ID returns this list's id. It is list- and the list's number.
type ListItem ¶
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.
func (ListItem) ID ¶
ID returns an empty string because list items don't have ids.
type ListMarker ¶
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 ¶
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 }
Paragraph is a block of formatted text.
func (Paragraph) ID ¶
ID returns the paragraph's id which is paragraph- and a number.
type Quote ¶
type Quote struct {
// contains filtered or unexported fields
}
Quote is the block representing a quote.
func (*Quote) AddBlock ¶
AddBlock adds the block to the quote.
func (*Quote) Contents ¶
Contents returns the quote's contents.
func (Quote) ID ¶
ID returns the quote's id which is quote- and a number.
type RocketLink ¶
RocketLink is a rocket link which is meant to be nested inside LaunchPad.
func MakeRocketLink ¶
func MakeRocketLink(line, hyphaName string) RocketLink
MakeRocketLink parses the rocket link on the given line and returns it.
func (RocketLink) ID ¶
func (r RocketLink) ID(_ *IDCounter) string
ID returns an empty string because rocket links do not have ids on their own.
type Span ¶
type Span interface { Kind() SpanKind }
Span is a piece of Formatted text. There are three implementors of this interface: SpanTableEntry (styles), InlineLink ([links]), InlineText (usual text).
type SpanKind ¶
type SpanKind int
SpanKind is a kind of a span, such as italic, bold, etc.
const ( SpanItalic SpanKind = iota SpanBold SpanMono SpanSuper SpanSub SpanMark SpanStrike SpanUnderline SpanLink SpanText )
type SpanTableEntry ¶
type SpanTableEntry struct { Token string // contains filtered or unexported fields }
SpanTableEntry is an entry of SpanTable and simultaneously a Span.
func (SpanTableEntry) Kind ¶
func (ste SpanTableEntry) Kind() SpanKind
Kind returns one of SpanKind. See the first column of SpanTable to learn what values are possible.
type Table ¶
Table is a table, which consists of several Rows and has a Caption.
func (Table) ID ¶
ID returns table's id which is table- and its number.
type TableCell ¶
TableCell is a cell in TableRow.
func (*TableCell) ColspanAttribute ¶
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 ¶
ID returns and empty string because table cells do not have ids.
func (*TableCell) TagName ¶
TagName returns "th" if the cell is a header cell, "td" elsewise.
type TableRow ¶
TableRow is a row in a table. Thus, it can only be nested inside a table.
func (TableRow) ID ¶
ID returns and empty string because table rows do not have ids.
func (*TableRow) LooksLikeThead ¶
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 ¶
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 ¶
func MakeTransclusion(line, hyphaName string) Transclusion
MakeTransclusion parses the line and returns a transclusion block.
TODO: move to the parser module.
func (Transclusion) ID ¶
func (t Transclusion) ID(counter *IDCounter) string
ID returns the transclusion's id which is transclusion- and a number.
type TransclusionError ¶
type TransclusionError struct { Reason TransclusionErrorReason }
TransclusionError is the error that occured during transclusion.
func (*TransclusionError) HasError ¶
func (te *TransclusionError) HasError() bool
HasError is true if there is indeed an error.
type TransclusionErrorReason ¶
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 ¶
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 )
Source Files ¶
blocks.go codeblock.go formatted.go heading.go hr.go img.go img_entry.go list.go paragraph.go quote.go rocket.go table.go transclusion.go
- Version
- v1.0.4 (latest)
- Published
- Sep 10, 2021
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 1 day ago –
Tools for package owners.