Documentation
¶
Overview ¶
Unfinished implementation of a markdown formatter
Index ¶
Constants ¶
const ( // TokPipe is the pipe character. TokPipe string = " | " // TokNewLine is the newline character. TokNewLine string = "\n" )
const ( // CodeBlockLimiter is the string used to denote the start and end of a code block. CodeBlockLimiter string = "```" )
const ( // SectionStyling is the styling used to denote a section in the markdown file. SectionStyling string = "***" )
Variables ¶
var ( // PedanticMode is a flag that determines if the formatter should be pedantic. // // If the formatter is pedantic, it will add empty elements to rows that do not have // the same number of elements as the number of headers. // // If the formatter is not pedantic, it will return an error if a row does not have // the same number of elements as the number of headers. PedanticMode bool = true )
Functions ¶
func ExtractSectionAt ¶ added in v0.2.12
ExtractSectionAt extracts a section at the given position and returns the section content and the new position.
Parameters:
- lines: A slice of strings containing the lines of the file.
- at: The position to start parsing.
Returns:
- string: The section content.
- int: The new position (this is exclusive, i.e. the next line to parse).
- error: An error if the section is not formatted correctly.
Types ¶
type CodeBlock ¶ added in v0.2.12
type CodeBlock struct {
// Language represents the language of the code block.
Language string
// Content represents the content of the code block.
Content []string
}
CodeBlock represents a code block in a markdown file.
func ExtractCodeBlockAt ¶ added in v0.2.12
ExtractCodeBlockAt extracts a code block at the given position and returns the code block and the new position.
Parameters:
- lines: A slice of strings containing the lines of the file.
- at: The position to start parsing.
Returns:
- CodeBlock: The code block.
- int: The new position (this is exclusive, i.e. the next line to parse).
- error: An error if the code block is not formatted correctly.
type CommonLanguageName ¶ added in v0.2.12
type CommonLanguageName int
CommonLanguageName represents the common language names that can be used in a code block.
const ( // PlainText represents the plaintext language. PlainText CommonLanguageName = iota // OtherCML represents any non-standard language. OtherCML )
func ParseCommonLanguageName ¶ added in v0.2.12
func ParseCommonLanguageName(name string) CommonLanguageName
ParseCommonLanguageName parses a common language name from a string.
Parameters:
- name: The name of the language.
Returns:
- CommonLanguageName: The common language name. If the name is not recognized, -1 is returned.
func (CommonLanguageName) String ¶ added in v0.2.12
func (cln CommonLanguageName) String() string
String is a method of fmt.Stringer interface that returns the string representation of the language name.
Returns:
- string: The string representation of the language name.
type Header ¶
type Header struct {
// Text represents the text of the header.
Text string
// Style represents the style of the header.
Style TableAllignmentType
}
Header represents a header in a table.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a table.
func NewTable ¶
func NewTable() *Table
NewTable creates a new table.
Returns:
- *Table: A pointer to the new table.
func (*Table) AddRow ¶
AddRow adds a row to the table.
Parameters:
- elements: The elements of the row.
Returns:
- error: An error if the row could not be added.
func (*Table) AppendHeader ¶
AppendHeader appends a header to the table.
Parameters:
- header: The header to append.
Returns:
- error: An error if the header could not be appended.
func (*Table) CanAddRow ¶
CanAddRow returns true if the number of elements in the row matches the number of headers.
Parameters:
- elements: The elements of the row.
Returns:
- bool: True if the number of elements in the row matches the number of headers.
func (*Table) ToText ¶
ToText converts the table to slice of strings.
Returns:
- []string: The string representation of the table.
func (*Table) WithHeader ¶
WithHeader adds a header to the table.
Parameters:
- header: The header to add.
Returns:
- *Table: A pointer to the table.
type TableAllignmentType ¶
type TableAllignmentType int8
TableAllignmentType represents the type of alignment that a table can have.
const ( // TableStyleCenter represents a center alignment. TableStyleCenter TableAllignmentType = iota // TableStyleLeft represents a left alignment. TableStyleLeft // TableStyleRight represents a right alignment. TableStyleRight )
func (TableAllignmentType) String ¶
func (a TableAllignmentType) String() string
String is a methos of fmt.Stringer interface that returns the string representation of the alignment.
Returns:
- string: The string representation of the alignment.