Documentation ¶
Overview ¶
Package netscape provides utilities to parse and export Web bookmarks using the Netscape Bookmark format.
Index ¶
Examples ¶
Constants ¶
const (
NetscapeBookmarkDoctype string = "NETSCAPE-Bookmark-file-1"
)
Variables ¶
Functions ¶
func Marshal ¶
Marshal returns the Netscape Bookmark encoding of d.
Example ¶
document := netscape.Document{ Title: "Bookmarks", Root: netscape.Folder{ Name: "Bookmarks", Bookmarks: []netscape.Bookmark{ { URL: "https://domain.tld", Title: "Test Domain", }, { Description: "Local\nLocal\nLocal", URL: "https://local.domain.tld", Title: "Local Test Domain", }, }, Subfolders: []netscape.Folder{ { Name: "Sub", Bookmarks: []netscape.Bookmark{ { URL: "https://domain.tld", Title: "Test Domain", Attributes: map[string]string{ "ATTR1": "v1", "ATTR2": "42", }, }, { Description: "Local\nLocal\nLocal", URL: "https://local.domain.tld", Title: "Local Test Domain", }, }, }, }, }, } m, err := netscape.Marshal(&document) if err != nil { panic(err) } fmt.Print(string(m))
Output: <!DOCTYPE NETSCAPE-Bookmark-file-1> <!-- This is an automatically generated file. It will be read and overwritten. DO NOT EDIT! --> <TITLE>Bookmarks</TITLE> <H1>Bookmarks</H1> <DL><p> <DT><A HREF="https://domain.tld" PRIVATE="0">Test Domain</A> <DT><A HREF="https://local.domain.tld" PRIVATE="0">Local Test Domain</A> <DD>Local Local Local <DT><H3>Sub</H3> <DL><p> <DT><A HREF="https://domain.tld" PRIVATE="0" ATTR1="v1" ATTR2="42">Test Domain</A> <DT><A HREF="https://local.domain.tld" PRIVATE="0">Local Test Domain</A> <DD>Local Local Local </DL><p> </DL><p>
Types ¶
type Bookmark ¶
type Bookmark struct { CreatedAt time.Time UpdatedAt time.Time Title string URL string Description string Private bool Tags []string Attributes map[string]string }
A Bookmark represents a Netscape Bookmark.
func (*Bookmark) MarshalJSON ¶ added in v2.1.0
type BookmarkNode ¶
type BookmarkNode struct { Href string Title string Description string Attributes map[string]string }
A BookmarkNode represents a Netscape bookmark.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder walks a Netscape Bookmark AST and returns the corresponding document.
type Document ¶
A Document represents a collection of Netscape Bookmarks.
func Unmarshal ¶
Unmarshal unmarshals a []byte representation of a Netscape Bookmark file and returns the corresponding Document.
Example ¶
blob := `<!DOCTYPE NETSCAPE-Bookmark-file-1> <TITLE>Bookmarks</TITLE> <H1>Bookmarks</H1> <DL><p> <DT><H3>Linux Distributions</H3> <DL><p> <DT><A HREF="https://archlinux.org" ADD_DATE="1654077848">Arch Linux</A> <DT><A HREF="https://debian.org" ADD_DATE="1653057612" LAST_MODIFIED="1653058043">Debian</A> </DL><p> <DT><H3>Programming Languages</H3> <DL><p> <DT><A HREF="https://go.dev">Go</A> <DT><A HREF="https://www.rust-lang.org/">Rust</A> </DL><p> <DT><H3>Secret stuff</H3> <DL><p> <DT><A HREF="https://https://en.wikipedia.org/wiki/Caesar_cipher" PRIVATE="1">Caesar cipher</A> <DT><A HREF="https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher" PRIVATE="1">Vigenère cipher</A> </DL><p> </DL><p> ` document, err := netscape.Unmarshal([]byte(blob)) if err != nil { fmt.Println("failed to unmarshal file:", err) os.Exit(1) } jsonData, err := json.MarshalIndent(document, "", " ") if err != nil { fmt.Println("failed to marshal data as JSON:", err) os.Exit(1) } fmt.Println(string(jsonData))
Output: { "title": "Bookmarks", "root": { "name": "Bookmarks", "subfolders": [ { "name": "Linux Distributions", "bookmarks": [ { "created_at": "2022-06-01T10:04:08Z", "updated_at": "2022-06-01T10:04:08Z", "title": "Arch Linux", "url": "https://archlinux.org", "private": false }, { "created_at": "2022-05-20T14:40:12Z", "updated_at": "2022-05-20T14:47:23Z", "title": "Debian", "url": "https://debian.org", "private": false } ] }, { "name": "Programming Languages", "bookmarks": [ { "title": "Go", "url": "https://go.dev", "private": false }, { "title": "Rust", "url": "https://www.rust-lang.org/", "private": false } ] }, { "name": "Secret stuff", "bookmarks": [ { "title": "Caesar cipher", "url": "https://https://en.wikipedia.org/wiki/Caesar_cipher", "private": true }, { "title": "Vigenère cipher", "url": "https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher", "private": true } ] } ] } }
func UnmarshalFile ¶
UnmarshalFile unmarshals a Netscape Bookmark file and returns the corresponding Document.
func UnmarshalString ¶
UnmarshalString unmarshals a string representation of a Netscape Bookmark file and returns the corresponding Document.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes Netscape Bookmark data to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
type FileNode ¶
type FileNode struct { Title string Root FolderNode }
A FileNode represents a Netscape Bookmark file.
type Folder ¶
type Folder struct { CreatedAt time.Time UpdatedAt time.Time Description string Name string Attributes map[string]string Bookmarks []Bookmark Subfolders []Folder }
A Folder represents a folder containing Netscape Bookmarks and child Folders.
func (*Folder) MarshalJSON ¶ added in v2.1.0
type FolderNode ¶
type FolderNode struct { Parent *FolderNode Name string Description string Attributes map[string]string Bookmarks []BookmarkNode Subfolders []FolderNode }
A FolderNode represents a bookmark (sub-)folder that may contain Bookmarks and child Folders.
type ParseError ¶
A ParseError is returned when we fail to parse a Netscape Bookmark token or XML element.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error returns the string representation for this error.
func (*ParseError) Is ¶
func (e *ParseError) Is(target error) bool
Is compares this Error with a target error to satisfy an equality check.
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
Unwrap returns the inner error wrapped by this Error.