package blocks
import "git.sr.ht/~bouncepaw/mycomarkup/v5/blocks"
Package blocks provides some of the Mycomarkup's blocks.
Index ¶
- Variables
- func CleanStyleState() map[SpanKind]bool
- func TagFromState(stt SpanKind, tagState map[SpanKind]bool) string
- type Block
- type CodeBlock
- func NewCodeBlock(language, contents string) CodeBlock
- func (cb CodeBlock) Contents() string
- func (cb CodeBlock) Language() string
- type Formatted
- type Heading
- func NewHeading(level uint, contents Formatted, srcLine string) Heading
- func (h Heading) Contents() Formatted
- func (h Heading) ID() string
- func (h Heading) Level() uint
- type Img
- func NewImg(entries []ImgEntry, layout ImgLayout) Img
- func (img Img) HasOneImage() bool
- func (img Img) Layout() ImgLayout
- func (img Img) WithExistingTargetsMarked(ctx mycocontext.Context) Img
- type ImgEntry
- func NewImgEntry(target links.Link, hyphaName, width, height string, description []Block) ImgEntry
- func (entry ImgEntry) Description() []Block
- func (entry ImgEntry) Height() string
- func (entry ImgEntry) Width() string
- type ImgLayout
- type InlineLink
- type InlineText
- type LaunchPad
- func NewLaunchPad(rockets []RocketLink) LaunchPad
- func (lp LaunchPad) LinksColored(ctx mycocontext.Context) LaunchPad
- type List
- type ListItem
- type ListMarker
- type Paragraph
- type Quote
- type RocketLink
- type Span
- type SpanKind
- type SpanTableEntry
- type Table
- func NewTable(caption string, rows []TableRow) Table
- func (t Table) Caption() string
- func (t Table) Rows() []TableRow
- func (t Table) WithNewRow(row TableRow) Table
- type TableCell
- func NewTableCell(isHeaderCell bool, colspan uint, contents []Block) TableCell
- func (tc TableCell) Colspan() uint
- func (tc TableCell) Contents() []Block
- func (tc TableCell) IsHeaderCell() bool
- type TableRow
- func NewTableRow(cells []TableCell) TableRow
- func (tr TableRow) Cells() []TableCell
- func (tr TableRow) LooksLikeThead() bool
- type ThematicBreak
- type Transclusion
- type TransclusionError
- type TransclusionErrorReason
- type TransclusionSelector
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 TagFromState ¶
TagFromState returns an appropriate tag half (<left> or </right>) depending on tagState and also mutates it. V3
TODO: get rid of.
Types ¶
type Block ¶
type Block interface { }
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 NewCodeBlock ¶
NewCodeBlock returns a code block with the given language and contents.
func (CodeBlock) Contents ¶
Contents returns the code block's contents.
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. Returns escaped text otherwise.
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. V3
type Heading ¶
type Heading struct {
// contains filtered or unexported fields
}
Heading is a formatted heading in the document.
func NewHeading ¶
NewHeading returns a Heading with the given data.
func (Heading) Contents ¶
Contents 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.
func (Heading) Level ¶
Level returns the Heading's level, 1 from 6.
Prefix | Level = | 1 == | 2 === | 3 ==== | 4
type Img ¶
type Img struct { Entries []ImgEntry // contains filtered or unexported fields }
Img is an image gallery, consisting of zero or more images.
func NewImg ¶
NewImg returns a new Img.
func (Img) HasOneImage ¶
HasOneImage returns true if img has exactly one image. The image may have a description.
TODO: get rid of the concept.
func (Img) Layout ¶
Layout returns Img's layout.
func (Img) WithExistingTargetsMarked ¶
func (img Img) WithExistingTargetsMarked(ctx mycocontext.Context) Img
WithExistingTargetsMarked returns a new Img with its ImgEntries colored according to their existence.
This functions iterates over hyphae once.
type ImgEntry ¶
ImgEntry is an entry of an image gallery. It can only be nested into Img. V3: proper readers, encapsulate
func NewImgEntry ¶
NewImgEntry returns a new ImgEntry.
func (ImgEntry) Description ¶
Description returns the description of the entry. The description is unparsed Mycomarkup string.
func (ImgEntry) Height ¶
Height returns the height property of the entry.
func (ImgEntry) Width ¶
Width returns the width property of the entry.
type ImgLayout ¶
type ImgLayout int
ImgLayout represents the layout of the Img element
const ( // ImgLayoutNormal is a main-column-wide one-column stack of images. ImgLayoutNormal ImgLayout = iota // ImgLayoutGrid is main-column-wide two-column stack of images. ImgLayoutGrid // ImgLayoutSide is a thin right-floating stack of images. ImgLayoutSide )
func (ImgLayout) String ¶
type InlineLink ¶
InlineLink is a link that is part of a Formatted text.
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 NewLaunchPad ¶
func NewLaunchPad(rockets []RocketLink) LaunchPad
NewLaunchPad returns a launchpad with the given RocketLinks inside
func (LaunchPad) LinksColored ¶
func (lp LaunchPad) LinksColored(ctx mycocontext.Context) LaunchPad
LinksColored marks links to existing hyphae as existing. V3
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 ¶
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 ¶
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.
type Quote ¶
type Quote struct {
// contains filtered or unexported fields
}
Quote is the block representing a quote.
func NewQuote ¶
NewQuote returns Quote with the given contents.
func (*Quote) Contents ¶
Contents returns the quote's contents.
type RocketLink ¶
RocketLink is a rocket link which is meant to be nested inside LaunchPad.
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 ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a table, which consists of several rows and has a caption.
func NewTable ¶
NewTable returns a new Table with the given rows and caption.
func (Table) Caption ¶
Caption returns Table's caption. It may be empty.
func (Table) Rows ¶
Rows returns Table's rows.
func (Table) WithNewRow ¶
WithNewRow returns a new table but with a new row.
type TableCell ¶
type TableCell struct {
// contains filtered or unexported fields
}
TableCell is a cell in TableRow.
func NewTableCell ¶
NewTableCell returns TableCell with the given data. Parameter isHeaderCell should be true when the cell starts with !. Colspans 0 and 1 are the same: they mean that the cell does not span columns.
func (TableCell) Colspan ¶
Colspan returns how many columns the cell spans.
func (TableCell) Contents ¶
Contents returns the cell's contents, which may be any Mycomarkup blocks.
func (TableCell) IsHeaderCell ¶
IsHeaderCell is true for header cells, i/e cells starting with !.
type TableRow ¶
type TableRow struct {
// contains filtered or unexported fields
}
TableRow is a row in a table. Thus, it can only be nested inside a table.
func NewTableRow ¶
NewTableRow returns a new TableRow. It gets the hypha name from ctx.
func (TableRow) Cells ¶
Cells returns the row's cells.
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 ThematicBreak ¶
type ThematicBreak struct {
// contains filtered or unexported fields
}
ThematicBreak represents the thematic line block, represented by a horizontal line.
In Mycomarkup it is written like that:
----
func NewThematicBreak ¶
func NewThematicBreak(line string) ThematicBreak
NewThematicBreak parses the horizontal line block on the given text line and returns it.
func (ThematicBreak) ID ¶
func (h ThematicBreak) ID() 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 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.
func MakeTransclusion ¶
func MakeTransclusion(ctx mycocontext.Context, line string) Transclusion
MakeTransclusion parses the line and returns a transclusion block. V3
type TransclusionError ¶
type TransclusionError struct { Reason TransclusionErrorReason }
TransclusionError is the error that occurred 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 // TransclusionNotSupported means that transclusion is not supported. TransclusionNotSupported // TransclusionErrorNoTarget means that no target hypha was specified. TransclusionErrorNoTarget // TransclusionCannotTranscludeURL means : was found in the target. TransclusionCannotTranscludeURL // TransclusionCannotTranscludeInterwiki means an interwiki transclusion was attempted. TransclusionCannotTranscludeInterwiki // 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 img.go img_entry.go img_kinds.go list.go paragraph.go quote.go rocket.go table.go table_cell.go thematic_break.go transclusion.go
- Version
- v5.6.0 (latest)
- Published
- Nov 29, 2023
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 10 hours ago –
Tools for package owners.