74 lines
3.0 KiB
Plaintext
74 lines
3.0 KiB
Plaintext
Heading 2 Core API
|
|
class mt-12
|
|
Markdown
|
|
**Note:** The Core API uses C-style conventions to optimize memory management
|
|
and improve portability to other environments and languages.
|
|
It is unwieldy and does not follow Go best practices.
|
|
|
|
For most projects you'll want to use the [Document API](#document-api) instead.
|
|
It provides an ergonomic wrapper around the Core API and lets you focus on parsing
|
|
your documents.
|
|
|
|
Heading 3 LineData
|
|
class mb-4 mt-12
|
|
CodeBlock go
|
|
// Type Definition
|
|
// Holds the parsed information from each line.
|
|
type LineData struct {
|
|
// Which character is being used for indentation.
|
|
Indent rune
|
|
// How many indent characters are present in the current line.
|
|
Level int
|
|
// The number of characters before the start of the line's "head" section.
|
|
OffsetHead int
|
|
// The number of characters before the start of the line's "tail" section.
|
|
OffsetTail int
|
|
}
|
|
|
|
Heading 3 NewLineData()
|
|
class mb-4 mt-12
|
|
Markdown
|
|
| Parameter | Type | Description
|
|
| -------------- | --------------------- | -----------------------------------------------------------------------
|
|
| indent | rune | The character used for indentation in the document. Only a single character is permitted.
|
|
| **@returns** | *LineData | A LineData instance with the specified indent character and all other values initialized to 0.
|
|
|
|
Initialize a LineData instance with default values to pass to [ParseLine()](#parse-line).
|
|
|
|
CodeBlock go
|
|
// Function Definition
|
|
func NewLineData(indent rune) *LineData
|
|
|
|
// Import Path
|
|
import "terrace.go"
|
|
|
|
// Usage
|
|
lineData := terrace.NewLineData(' ')
|
|
fmt.Printf("%+v\n", lineData)
|
|
// &{Indent:32 Level:0 OffsetHead:0 OffsetTail:0}
|
|
// Use the same lineData object for all calls to ParseLine in the same document.
|
|
|
|
Heading 3 ParseLine()
|
|
class mb-4 mt-12
|
|
Markdown
|
|
| Parameter | Type | Description
|
|
| -------------- | --------------------- | -----------------------------------------------------------------------
|
|
| line | string | A string containing a line to parse. Shouldn't end with a newline.
|
|
| lineData | *LineData | A LineData object to store information about the current line, from [NewLineData()](#new-line-data).<br/>**Mutated in-place!**
|
|
| **@returns** | error | Returns an error if the input parameters are invalid, nil otherwise.
|
|
|
|
Core Terrace parser function, sets `Level`, `OffsetHead`, and `OffsetTail` in a [LineData](#line-data) object based on the passed line.
|
|
Note that this is a C-style function, `lineData` is treated as a reference and mutated in-place.
|
|
|
|
CodeBlock go
|
|
// Function Definition
|
|
func ParseLine(line string, lineData *LineData) error
|
|
|
|
// Import Path
|
|
import "terrace.go"
|
|
|
|
// Usage
|
|
lineData := terrace.NewLineData(' ')
|
|
terrace.ParseLine("title Example Title", lineData)
|
|
fmt.Printf("%+v\n", lineData)
|
|
// &{Indent:32 Level:0 OffsetHead:0 OffsetTail:5} |