Documentation ¶
Overview ¶
The gemtext package contains a gemtext AST and parser.
Conversion sub-packages can convert this AST into other document types, and support overridable templates.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AutoAtom = types.Middleware(func(h types.Handler) types.Handler { return types.HandlerFunc(func(ctx context.Context, request *types.Request) *types.Response { if !strings.HasSuffix(request.Path, ".atom") { return h.Handle(ctx, request) } req := *request u := *request.URL u.Path = strings.TrimSuffix(u.Path, ".atom") req.URL = &u response := h.Handle(ctx, &req) if response.Status != gemini.StatusSuccess { return response } mtype, _, err := mime.ParseMediaType(response.Meta.(string)) if err != nil || mtype != "text/gemini" { return response } defer func() { _ = response.Close() }() doc, err := Parse(response.Body) if err != nil { return gemini.Failure(err) } buf := &bytes.Buffer{} if err := GmisubToAtom(doc, *request.URL, buf); err != nil { return gemini.Failure(err) } return gemini.Success("application/atom+xml; charset=utf-8", buf) }) })
AutoAtom is a middleware which builds atom feeds for any gemtext pages.
It looks for requests ending with the '.atom' extension, passes through the request with the extension clipped off, then if the response is in gemtext it converts it to an Atom feed according to the gmisub spec at gemini://gemini.circumlunar.space/docs/companion/subscription.gmi
Functions ¶
func GmisubToAtom ¶ added in v1.2.0
GmisubToAtom converts a gemini document to Atom format.
It identifies feed fields and entries according to the specification at gemini://gemini.circumlunar.space/docs/companion/subscription.gmi
Types ¶
type Document ¶
type Document []Line
Document is the list of lines that make up a full text/gemini resource.
type HeadingLine ¶
type HeadingLine struct {
// contains filtered or unexported fields
}
HeadingLine is a line of LineTypeHeading[1,2,3].
func (HeadingLine) Body ¶
func (hl HeadingLine) Body() string
Body returns the portion of the line with the header text.
func (HeadingLine) Raw ¶
func (hl HeadingLine) Raw() []byte
func (HeadingLine) String ¶
func (hl HeadingLine) String() string
func (HeadingLine) Type ¶
func (hl HeadingLine) Type() LineType
type Line ¶
type Line interface { // Type returns the specific type of the gemtext line. Type() LineType // Raw reproduces the original bytes from the source reader. Raw() []byte // String represents the original bytes from the source reader as a string. String() string }
Line is the interface implemented by all specific line types.
Many of those concrete implementation types have additional useful fields, so it can be a good idea to cast these to their concrete types based on the return value of the Type() method.
type LineType ¶
type LineType int
LineType represents the different types of lines in a gemtext document.
const ( // LineTypeText is the default case when nothing else matches. // // It indicates that the line object is a TextLine. LineTypeText LineType = iota + 1 // LineTypeLink is a link line. // // =>[<ws>]<url>[<ws><label>][\r]\n // // The line is a LinkLine. LineTypeLink // LineTypePrompt is a spartan =: prompt line. // // =:[<ws>]<url>[<ws><label>][\r]\n // // The line is a PromptLine. LineTypePrompt // LineTypePreformatToggle switches the document between pre-formatted text or not. // // “`[<alt-text>][\r]\n // // The line object is a PreformatToggleLine. LineTypePreformatToggle // LineTypePreformattedText is any line between two PreformatToggles. // // The line is a PreformattedTextLine. LineTypePreformattedText // LineTypeHeading1 is a top-level heading. // // #[<ws>]body[\r]\n // // The line is a HeadingLine. LineTypeHeading1 // LineTypeHeading2 is a second-level heading. // // ##[<ws>]body[\r]\n // // The line is a HeadingLine. LineTypeHeading2 // LineTypeHeading3 is a third-level heading. // // ###[<ws>]<body>[\r]\n // // The line is a HeadingLine. LineTypeHeading3 // LineTypeListItem is an unordered list item. // // * <body>[\r]\n // // The line object is a ListItemLine. LineTypeListItem // LineTypeQuote is a quote line. // // ><body>[\r]\n // // The line object is a QuoteLine. LineTypeQuote )
type LinkLine ¶
type LinkLine struct {
// contains filtered or unexported fields
}
LinkLine is a line of LineTypeLink.
type ListItemLine ¶
type ListItemLine struct {
// contains filtered or unexported fields
}
ListItemLine is a line of LineTypeListItem.
func (ListItemLine) Body ¶
func (li ListItemLine) Body() string
Body returns the text of the list item.
func (ListItemLine) Raw ¶
func (li ListItemLine) Raw() []byte
func (ListItemLine) String ¶
func (li ListItemLine) String() string
func (ListItemLine) Type ¶
func (li ListItemLine) Type() LineType
type PreformatToggleLine ¶
type PreformatToggleLine struct {
// contains filtered or unexported fields
}
PreformatToggleLine is a preformatted text toggle line.
func (PreformatToggleLine) AltText ¶
func (tl PreformatToggleLine) AltText() string
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 (PreformatToggleLine) Raw ¶
func (tl PreformatToggleLine) Raw() []byte
func (PreformatToggleLine) String ¶
func (tl PreformatToggleLine) String() string
func (PreformatToggleLine) Type ¶
func (tl PreformatToggleLine) Type() LineType
type PreformattedTextLine ¶
type PreformattedTextLine struct {
// contains filtered or unexported fields
}
PreformattedTextLine represents a line between two toggles.
It is never returned by ParseLine but can be part of a document parsed by Parse().
func (PreformattedTextLine) Raw ¶
func (tl PreformattedTextLine) Raw() []byte
func (PreformattedTextLine) String ¶
func (tl PreformattedTextLine) String() string
func (PreformattedTextLine) Type ¶
func (tl PreformattedTextLine) Type() LineType
type PromptLine ¶
type PromptLine struct {
// contains filtered or unexported fields
}
PromptLine is a Spartan =: prompt line.
func (PromptLine) Label ¶
func (pl PromptLine) Label() string
Label retrns the label portion of the line.
func (PromptLine) Raw ¶
func (pl PromptLine) Raw() []byte
func (PromptLine) String ¶
func (pl PromptLine) String() string
func (PromptLine) Type ¶
func (pl PromptLine) Type() LineType
func (PromptLine) URL ¶
func (pl PromptLine) URL() string
URL returns the original url portion of the line.
It is not guaranteed to be a valid URL.