summaryrefslogtreecommitdiff
path: root/gemtext/types.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-01-14 09:57:16 -0700
committertjpcc <tjp@ctrl-c.club>2023-01-14 09:58:32 -0700
commit0d904f9f10590d3a9117af27151f8c4fe2aea5ff (patch)
tree95a6f1a0055bdb2120684c239a14c7466a3a117f /gemtext/types.go
parentaa23984bc21f99e00b8552e928d23ef02bb745f3 (diff)
Completed gemtext package.
resolves #2 - fuzz testing - split out line parsing into a separate file - changed line type-specific public []byte fields to string accessor methods - added document parsing test for a stress test doc - added dependency on stretchr/testify
Diffstat (limited to 'gemtext/types.go')
-rw-r--r--gemtext/types.go65
1 files changed, 34 insertions, 31 deletions
diff --git a/gemtext/types.go b/gemtext/types.go
index fb9352a..fefbece 100644
--- a/gemtext/types.go
+++ b/gemtext/types.go
@@ -91,39 +91,39 @@ func (tl TextLine) Raw() []byte { return tl.raw }
// LinkLine is a line of LineTypeLink.
type LinkLine struct {
raw []byte
-
- // URL is the original bytes of the url portion of the line.
- //
- // It is not guaranteed to be a valid URL.
- URL []byte
-
- // Label is the label portion of the line.
- //
- // If there was no label it will always be nil, never []byte{}.
- Label []byte
+ url []byte
+ label []byte
}
func (ll LinkLine) Type() LineType { return LineTypeLink }
func (ll LinkLine) Raw() []byte { return ll.raw }
+// URL returns the original url portion of the line.
+//
+// It is not guaranteed to be a valid URL.
+func (ll LinkLine) URL() string { return string(ll.url) }
+
+// Label returns the label portion of the line.
+func (ll LinkLine) Label() string { return string(ll.label) }
+
// PreformatToggleLine is a preformatted text toggle line.
type PreformatToggleLine struct {
raw []byte
-
- // AltText contains the alt-text portion of the line.
- //
- // It will either have len() > 0 or be nil.
- //
- // If the line was parsed as part of a full document by Parse(),
- // and this is a *closing* toggle, any alt-text present will be
- // stripped and this will be nil. If the line was parsed by
- // ParseLine() no such correction is performed.
- AltText []byte
+ altText []byte
}
func (tl PreformatToggleLine) Type() LineType { return LineTypePreformatToggle }
func (tl PreformatToggleLine) Raw() []byte { return tl.raw }
-func (tl *PreformatToggleLine) clearAlt() { tl.AltText = nil }
+
+// AltText returns the alt-text portion of the line.
+//
+// If the line was parsed as part of a full document by Parse(),
+// and this is a *closing* toggle, any alt-text present will be
+// stripped and this will be empty. If the line was parsed by
+// ParseLine() no such correction is performed.
+func (tl PreformatToggleLine) AltText() string { return string(tl.altText) }
+
+func (tl *PreformatToggleLine) clearAlt() { tl.altText = nil }
// PreformattedTextLine represents a line between two toggles.
//
@@ -140,32 +140,35 @@ func (tl PreformattedTextLine) Raw() []byte { return tl.raw }
type HeadingLine struct {
raw []byte
lineType LineType
-
- // Body is the portion of the line with the header text.
- Body []byte
+ body []byte
}
func (hl HeadingLine) Type() LineType { return hl.lineType }
func (hl HeadingLine) Raw() []byte { return hl.raw }
+// Body returns the portion of the line with the header text.
+func (hl HeadingLine) Body() string { return string(hl.body) }
+
// ListItemLine is a line of LineTypeListItem.
type ListItemLine struct {
raw []byte
-
- // Body is the text of the list item.
- Body []byte
+ body []byte
}
func (li ListItemLine) Type() LineType { return LineTypeListItem }
func (li ListItemLine) Raw() []byte { return li.raw }
+// Body returns the text of the list item.
+func (li ListItemLine) Body() string { return string(li.body) }
+
// QuoteLine is a line of LineTypeQuote.
type QuoteLine struct {
- raw []byte
-
- // Body is the text of the quote.
- Body []byte
+ raw []byte
+ body []byte
}
func (ql QuoteLine) Type() LineType { return LineTypeQuote }
func (ql QuoteLine) Raw() []byte { return ql.raw }
+
+// Body returns the text of the quote.
+func (ql QuoteLine) Body() string { return string(ql.body) }