Documentation
¶
Overview ¶
Package mt provides the Movable Type export format parser.
Index ¶
- func Parse(r io.Reader, opts ...ParseOption) iter.Seq2[*Entry, error]
- type Comment
- type ConvertBreaks
- type Entry
- type Field
- type InvalidConvertBreaksError
- type InvalidStatusError
- type NoKeyValueDelimiterFoundError
- type OptionWithDefaultAllowComments
- type OptionWithDefaultConvertBreaks
- type OptionWithTime
- type ParseError
- type ParseOption
- type Status
- type UnexpectedBooleanNumberError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse parses the contents from r as Entry.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/aereal/mt"
)
func main() {
r := strings.NewReader(exampleImportFile)
fmt.Println("entries:")
for entry, err := range mt.Parse(r) {
if err != nil {
panic(err)
}
fmt.Printf("title: %s", entry.Title)
}
}
var exampleImportFile = `
AUTHOR: Foo Bar
TITLE: A dummy title
BASENAME: filename
STATUS: Publish
ALLOW COMMENTS: 1
ALLOW PINGS: 1
CONVERT BREAKS: richtext
PRIMARY CATEGORY: News
CATEGORY: News
CATEGORY: Product
DATE: 08/08/2007 03:00:00 PM
TAGS: "Movable Type",foo,bar
-----
BODY:
これは本文です。
-----
EXTENDED BODY:
ここに追記の本文が表示されます。
-----
COMMENT:
AUTHOR: Foo
DATE: 01/31/2002 15:47:06
ここに
このコメントの本文が来ます。
-----
COMMENT:
AUTHOR: Bar
DATE: 02/01/2002 04:02:07 AM
IP: 205.66.1.32
EMAIL: [email protected]
これは2番目の
コメントです。 これは
ここまで来ます。
-----
--------
`
Output: entries: title: A dummy title
Types ¶
type Comment ¶
type Comment struct {
// Author is the name of the author of the comment.
Author string
// Date is the date on which the comment was posted.
Date time.Time
// URL is the URL of the author of the content.
URL string
// IP is the IP address of the author of the comment.
IP net.IP
// Email is the email address of the author of the comment.
Email string
Body string
}
Comment represents one comment on the entry.
type ConvertBreaks ¶
type ConvertBreaks string
ConvertBreaks is the value for the “convert breaks” flag for the entry.
const ( // ConvertBreaksNone means raw html. ConvertBreaksNone ConvertBreaks = "0" // ConvertBreaksConvert means that convert line breaks to <br />. ConvertBreaksConvert ConvertBreaks = "1" // ConvertBreaksMarkdown means Markdown. ConvertBreaksMarkdown ConvertBreaks = "markdown" // ConvertBreaksMarkdownWithSmartyPants means Markdown with Smartypants. ConvertBreaksMarkdownWithSmartyPants ConvertBreaks = "markdown_with_smarty_pants" // ConvertBreaksRichtext means Rich Text via HTML text editor. ConvertBreaksRichtext ConvertBreaks = "richtext" // ConvertBreaksTextile2 means Textile 2. ConvertBreaksTextile2 ConvertBreaks = "textile_2" )
func ParseConvertBreaks ¶
func ParseConvertBreaks(v string) (ConvertBreaks, error)
ParseConvertBreaks returns a ConvertBreaks corresponding to the argument.
type Entry ¶
type Entry struct {
// Author is the author of the entry.
Author string
// Title is the title of the entry.
Title string
// Basename is the basename of the entry.
Basename string
// Date is the authored-on or published date of the entry.
Date time.Time
// PrimaryCategory is the primary category to which the entry is assigned.
PrimaryCategory string
// Category is a secondary category to which the entry is assigned.
Category []string
// Tags is the tags associated with an entry.
Tags []string
// Status is the post status of the entry.
Status Status
// AllowComments is the value for the "allow comments" flag for the entry.
AllowComments bool
// AllowPings is the value for the "allow pings" flag for the entry.
AllowPings bool
// ConvertBreaks is the value for the "convert breaks" flag for the entry.
ConvertBreaks ConvertBreaks
// Body is the body of the entry.
Body string
// ExtendedBody is the extended body of the entry.
ExtendedBody string
// Excerpt is the excerpt of the entry.
Excerpt string
Comments []*Comment
}
type Field ¶
type Field string
Field is pre-defined identifiers of the metadata section.
const ( FieldNone Field = "" FieldAllowComments Field = "ALLOW COMMENTS" FieldAllowPings Field = "ALLOW PINGS" FieldAuthor Field = "AUTHOR" FieldBasename Field = "BASENAME" FieldBody Field = "BODY" FieldCategory Field = "CATEGORY" FieldComment Field = "COMMENT" FieldConvertBreaks Field = "CONVERT BREAKS" FieldDate Field = "DATE" FieldEmail Field = "EMAIL" FieldExcerpt Field = "EXCERPT" FieldExtendedBody Field = "EXTENDED BODY" FieldIP Field = "IP" FieldPrimaryCategory Field = "PRIMARY CATEGORY" FieldStatus Field = "STATUS" FieldTags Field = "TAGS" FieldTitle Field = "TITLE" FieldURL Field = "URL" )
type InvalidConvertBreaksError ¶
type InvalidConvertBreaksError struct {
Value string
}
func (*InvalidConvertBreaksError) Error ¶
func (e *InvalidConvertBreaksError) Error() string
type InvalidStatusError ¶
type InvalidStatusError struct {
Value string
}
func (*InvalidStatusError) Error ¶
func (e *InvalidStatusError) Error() string
type NoKeyValueDelimiterFoundError ¶
type NoKeyValueDelimiterFoundError struct{}
var ErrNoKeyValueDelimiterFound NoKeyValueDelimiterFoundError
func (NoKeyValueDelimiterFoundError) Error ¶
func (NoKeyValueDelimiterFoundError) Error() string
type OptionWithDefaultAllowComments ¶
type OptionWithDefaultAllowComments struct {
// contains filtered or unexported fields
}
func WithDefaultAllowComments ¶
func WithDefaultAllowComments(v bool) *OptionWithDefaultAllowComments
type OptionWithDefaultConvertBreaks ¶
type OptionWithDefaultConvertBreaks struct {
// contains filtered or unexported fields
}
func WithDefaultConvertBreaks ¶
func WithDefaultConvertBreaks(cb ConvertBreaks) *OptionWithDefaultConvertBreaks
type OptionWithTime ¶
type OptionWithTime struct {
// contains filtered or unexported fields
}
func WithTimeLocation ¶
func WithTimeLocation(loc *time.Location) *OptionWithTime
type ParseError ¶
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Is ¶
func (e *ParseError) Is(target error) bool
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type ParseOption ¶
type ParseOption interface {
// contains filtered or unexported methods
}
type UnexpectedBooleanNumberError ¶
type UnexpectedBooleanNumberError struct {
Actual int
}
func (*UnexpectedBooleanNumberError) Error ¶
func (e *UnexpectedBooleanNumberError) Error() string
Click to show internal directories.
Click to hide internal directories.